Skip to content

fix(plugins): rename per-turn hook from on_session_end to on_turn_end - #26509

Closed
beardthelion wants to merge 1 commit into
NousResearch:mainfrom
beardthelion:fix/plugin-hook-rename
Closed

fix(plugins): rename per-turn hook from on_session_end to on_turn_end#26509
beardthelion wants to merge 1 commit into
NousResearch:mainfrom
beardthelion:fix/plugin-hook-rename

Conversation

@beardthelion

Copy link
Copy Markdown
Contributor

What does this PR do?

Renames the per-turn plugin hook from on_session_end to on_turn_end in run_agent.py. The hook fired at the end of every run_conversation() call (once per user message), not at actual session boundaries — the name was misleading.

Note: This conflicts with PR #22095 which adds on_turn_start/on_turn_end as NEW hooks while keeping on_session_end firing per-turn. This PR takes the cleaner approach: rename the existing per-turn fire instead of adding redundant hooks. PR #22095 should adapt to use the on_turn_end hook added here.

Related Issue

Discovered during full repo audit (2026-05-14). No pre-existing issue.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • hermes_cli/plugins.py: Added on_turn_end to VALID_HOOKS
  • hermes_cli/hooks.py: Added on_turn_end test fixture
  • run_agent.py: Changed per-turn hook fire from on_session_end to on_turn_end
  • plugins/disk-cleanup/__init__.py: Migrated registration from on_session_end to on_turn_end
  • tests/plugins/test_disk_cleanup_plugin.py: Updated assertion to check on_turn_end

Not changed: google_meet plugin stays on on_session_end (fires at real session boundaries from CLI/gateway).

How to Test

  1. scripts/run_tests.sh tests/plugins/ tests/hermes_cli/test_hooks_cli.py -q — all pass
  2. Verify disk-cleanup plugin registers on_turn_end hook
  3. Verify google_meet plugin still registers on_session_end hook

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 15, 2026
run_agent.py fired the "on_session_end" plugin hook at the end of
every run_conversation() call (once per user message), not at actual
session boundaries. This was misleading and caused google_meet's
session-end cleanup to fire every turn.

Added "on_turn_end" to the hook registry and changed the per-turn
fire in run_agent.py to use it. Disk-cleanup plugin migrated to
on_turn_end (its per-turn behavior was intentional). Google_meet
stays on on_session_end (fires from CLI/gateway at real session
boundaries).
@beardthelion
beardthelion force-pushed the fix/plugin-hook-rename branch from e1f184a to f6c4d79 Compare May 15, 2026 18:40
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for identifying the naming mismatch. Current main still reproduces it: agent/turn_finalizer.py:489-505 emits on_session_end after every run_conversation() call.

Problems

  • This is a public-contract rename, not only a disk-cleanup migration. The documented contract at website/docs/user-guide/features/hooks.md:762-783 and existing registrations in plugins/observability/nemo_relay/__init__.py:406 and plugins/platforms/raft/adapter.py:849 still depend on on_session_end being per-turn.
  • Keeping Google Meet on on_session_end does not give it normal session-boundary cleanup: CLI cleanup emits on_session_finalize at cli.py:1166-1171, while Google Meet registers only on_session_end at plugins/google_meet/__init__.py:103.

Suggested changes

  • Define a compatibility/migration path for existing on_session_end consumers and update the hook documentation.
  • Port the per-turn call to agent/turn_finalizer.py and add tests for per-turn and real-boundary semantics.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
@beardthelion

Copy link
Copy Markdown
Contributor Author

Closing. Main still uses on_session_end as the session-end extraction hook, so renaming it to on_turn_end no longer lines up with current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants