fix(codex): idempotent session-end under Stop collapse#116
Merged
Conversation
In Claude Code, SessionEnd fires once and quality-gate fires per-Stop. In Codex, the bridge maps SessionEnd → Stop because Codex has no native SessionEnd event, so the hook would otherwise run on every turn-stop — re-logging cost, re-incrementing trust counters, re-marking campaign continuation, and re-appending to the daemon log. Add a session_id-keyed marker at .planning/telemetry/session-end.lock that is checked at the top of main(). If the marker matches the current session_id, exit immediately. Otherwise, write the marker and run. The guard is runtime-agnostic on purpose: in Claude Code it's a no-op (SessionEnd only fires once per session anyway), in Codex it suppresses duplicates, and if Codex eventually ships a real SessionEnd event the same code continues to work without changes. Smoke tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevent
session-end.jsfrom firing on every turn-stop in Codex.In Claude Code,
SessionEndfires once at session close. In Codex, the bridge mapsSessionEnd → Stopbecause Codex has no nativeSessionEndevent, so without a guard the hook would re-run on every turn — re-logging cost, re-incrementing trust counters, re-marking campaign continuation, re-appending to the daemon log.This adds a session_id-keyed marker at
.planning/telemetry/session-end.lock. The hook checks it at the top ofmain()and exits early if the current session has already fired.The guard is keyed on
session_id, not runtime, so:Stopcollapse.SessionEndevent, the same code keeps working without changes.Context
This is the last of the bridge-hardening fixes I worked on this session. The other four (
install-hooks-codex --verbose/--json, full-tree skill copy, full-schema MCP translation, observable agent truncation) are already onmain— they were swept up into PR #115's squash-merge from earlier branch contamination, so the squash commit body lists their original messages even though the PR title doesn't. This PR contains only the session-end fix because that's all that wasn't already shipped.Test plan
node scripts/test-all.js— 20/20 PASSnode hooks_src/smoke-test.js— PASS