fix(hooks): emit valid Codex Stop-hook JSON from cleanup (#1533) - #1738
fix(hooks): emit valid Codex Stop-hook JSON from cleanup (#1533)#1738arimu1 wants to merge 4 commits into
Conversation
AmirF194
left a comment
There was a problem hiding this comment.
The require_session_id opt-in/opt-out split is clean and the new tests cover both the missing-session-id and empty-stdin cases.
One thing to check: SessionStartActivateProjectHook (src/serena/hooks.py:531) doesn't override init, so it still inherits require_session_id=True from the base Hook. Docker-verified on this PR's head (dd9eb68):
printf '%s' '{"hookEventName":"SessionStart"}' | serena-hooks activate --client=codex
raises the same uncaught ValueError: Session ID is required in the hook input data that #1533 reports for cleanup. I don't have evidence Codex ever omits session_id on its SessionStart event, only that #1533's own repro shows it can omit one on Stop, so this might not happen in practice. But if it ever does, activate would crash the same way cleanup used to before this fix. Might be worth deciding whether activate should opt out the same way, or whether SessionStart is guaranteed to always carry a session id.
dd9eb68 to
0e99303
Compare
`serena-hooks cleanup --client=codex`, used as a Codex Stop hook, printed
nothing on success and raised a traceback when the payload carried no
session id, so Codex reported "hook returned invalid stop hook JSON
output". Cleanup now tolerates a missing session id (and empty stdin) as a
no-op and always emits {"continue": true} for the Codex client, while
other clients keep their silent behavior.
ty rejects Path(str | None) after session_persistence_dir became optional for SessionEndCleanupHook. PreToolUse state persistence still requires a dir.
e02a4c1 to
2bf3b85
Compare
…n_id SessionStartActivateProjectHook did not override __init__, so it inherited require_session_id=True from the base Hook class even though it never reads session_persistence_dir (it only emits a static reminder message). If a client ever omits session_id on SessionStart, activate would crash the same way cleanup did before oraios#1533. Opt it out of the session-id requirement the same way SessionEndCleanupHook does, and add tests for missing session_id, empty stdin, and the CLI path. Addresses review feedback from AmirF194 on oraios#1738.
|
Good catch — confirmed. On the failing |
Closes #1533.
Problem
When
serena-hooks cleanup --client=codexis configured as a CodexStophook, Codex reports:
Two causes:
SessionEndCleanupHook.execute()only ranshutil.rmtreeand printednothing, so stdout was empty — but Codex requires a Stop hook to print
valid Stop-hook JSON.
Hook.__init__raisedValueErrorwhen the payload had nosession_id,so a Stop payload without one produced a Python traceback.
Fix
Hook.__init__gains arequire_session_idflag (defaultTrue, so everyexisting hook is unchanged) and tolerates empty stdin.
SessionEndCleanupHookopts out of the requirement — cleanup is ano-op-safe operation, so a missing session id simply means there is
nothing to remove — and always emits
{"continue": true}for the Codexclient. Other clients stay silent, preserving current behavior.
Tests
Added unit tests (missing session id / empty stdin no longer raise) and CLI
tests asserting
cleanup --client=codexprints{"continue": true}bothwith and without a session id.
test_hooks.pygreen (90/90);ruffandtytype-check clean.