fix(hooks): emit valid Codex cleanup output - #1687
Conversation
|
CI note: the Ubuntu catch-all failure is an unrelated timeout in test_dynamically_activated_mode_is_provided_once_per_session[python] after 1,000 tests passed; the tool returned TimeoutError after two four-minute waits. The changed Codex cleanup-hook tests pass, and the other completed platform/language shards plus build, spelling, and CodeQL are green. |
|
The remaining two red Ubuntu lanes are infrastructure/flaky rather than branch failures: |
AmirF194
left a comment
There was a problem hiding this comment.
This resolves both scenarios from #1533 for the cleanup/Stop hook, confirmed against this branch (4231098) in a clean container: cleanup --client=codex with a session_id now prints {"continue": true}, and with a missing session_id it prints the same JSON to stdout while the ValueError goes to stderr, exit 0 either way.
One related gap this PR doesn't touch: activate (the SessionStart hook, hooks.py:586-588) has the identical failure shape as scenario 2. It has no try/except, so a missing session_id raises uncaught through Hook.__init__, same as cleanup did before this fix. Reproduced on this branch:
printf '%s' '{"stop_hook_active":false}' | serena-hooks activate --client=codex
exits nonzero with a raw traceback, no JSON on stdout, for every client including codex. If Codex's SessionStart hook has the same "must be valid JSON" contract as Stop, this would trip the same class of error this PR fixes for cleanup. Worth a follow-up PR applying the same guard to activate, or is SessionStart's contract different enough that it's a non-issue there?
Summary
Closes #1533
Verification