Skip to content

fix(cli): ensure on_session_end hook fires on interrupted exits - #4159

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-cd7257f9
Mar 31, 2026
Merged

fix(cli): ensure on_session_end hook fires on interrupted exits#4159
teknium1 merged 1 commit into
mainfrom
hermes/hermes-cd7257f9

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #4038 by @kelsia14 with a fix for the double-fire nuance.

Changes:

  • SIGTERM/SIGHUP signal handlers → graceful cleanup instead of instant death
  • BrokenPipeError added to exit handling (SSH disconnects)
  • on_session_end plugin hook in the finally block for interrupted exits

Improvement over original PR: Guarded by _agent_running so the hook only fires when the agent was mid-turn at exit time. run_conversation() already fires this hook per-turn on normal completion — the CLI-level hook is a safety net for interrupts only, avoiding double-fire on normal /exit.

813 CLI tests pass.

Closes #4038.

- Add SIGTERM/SIGHUP signal handlers for graceful shutdown
- Add BrokenPipeError to exit exception handling (SSH disconnects)
- Fire on_session_end plugin hook in finally block, guarded by
  _agent_running to avoid double-firing on normal exits (the hook
  already fires per-turn from run_conversation)

Co-authored-by: kelsia14 <kelsia14@users.noreply.github.com>
@teknium1
teknium1 merged commit c1ef9b2 into main Mar 31, 2026
2 of 3 checks passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…Research#4159)

- Add SIGTERM/SIGHUP signal handlers for graceful shutdown
- Add BrokenPipeError to exit exception handling (SSH disconnects)
- Fire on_session_end plugin hook in finally block, guarded by
  _agent_running to avoid double-firing on normal exits (the hook
  already fires per-turn from run_conversation)

Co-authored-by: kelsia14 <kelsia14@users.noreply.github.com>
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…Research#4159)

- Add SIGTERM/SIGHUP signal handlers for graceful shutdown
- Add BrokenPipeError to exit exception handling (SSH disconnects)
- Fire on_session_end plugin hook in finally block, guarded by
  _agent_running to avoid double-firing on normal exits (the hook
  already fires per-turn from run_conversation)

Co-authored-by: kelsia14 <kelsia14@users.noreply.github.com>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…Research#4159)

- Add SIGTERM/SIGHUP signal handlers for graceful shutdown
- Add BrokenPipeError to exit exception handling (SSH disconnects)
- Fire on_session_end plugin hook in finally block, guarded by
  _agent_running to avoid double-firing on normal exits (the hook
  already fires per-turn from run_conversation)

Co-authored-by: kelsia14 <kelsia14@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants