Repository navigation
Merged
Conversation
… a silent rejection (#468) #459 fixed the loud "no session dir" WARNING on this same code path but discarded STDIN_SESSION_ID -- already extracted and validated four lines earlier -- so post-tool-hook.sh kept deriving the session id from the transcript's own basename. Codex's rollout-<date>-<uuid>.jsonl basename is not a session id, and save-session.sh's [a-f0-9-]+ gate rejected every one of them, silently, into an autonomous log nobody reads. SessionEnd was unaffected (it passes the stdin id directly), which is why Codex looked fully captured while only incremental saves were actually lost. Prefer STDIN_SESSION_ID when it is TRUSTED -- i.e. it is the id that actually resolved TRANSCRIPT, not merely a value that showed up on stdin -- falling back to the basename otherwise, the same precedence #407 gave the transcript path. A naive "stdin id wins whenever set" regressed the #212 mtime-fallback pin (a stdin session_id naming no transcript here must still capture the newest transcript under its OWN id); the trust flag keeps that case byte-identical. Co-Authored-By: Max <noreply>
#468 follow-up) Self-review caught a regression in the #468 fix itself: STDIN_SESSION_ID_TRUSTED went true whenever STDIN_TRANSCRIPT_PATH was present, with no check that a session_id had actually arrived alongside it. A payload shape with transcript_path but no session_id (an older CLI, or simply Codex's own shape when STDIN_SESSION_ID failed the earlier character-class guard) then handed save-session.sh an EMPTY session id -- not the intended basename fallback, and not a "trusted" value either. save-session.sh's own `[ -z "$SESSION_ID" ]` branch then silently re-picks a session by mtime, reintroducing the exact #212/#204/#129 wrong-session-attribution class this file's own header names as a repeat offender. Now STDIN_SESSION_ID_TRUSTED only goes true in that branch when STDIN_SESSION_ID is also non-empty; otherwise SESSION_ID falls through to the transcript basename, exactly as #212's own fallback pin requires. tests/test_codex_stdin_session_id_468.py's basename-fallback test now checks the capture-alive marker directly (which id was actually used), not merely that a save was forked at all -- an empty-id fork would have passed the weaker check. Co-Authored-By: Max <noreply>
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.
Fixes #468.
Problem
#459 fixed the loud "no session dir" WARNING on the Codex capture path but discarded
STDIN_SESSION_ID-- already extracted and validated four lines earlier inscripts/post-tool-hook.sh-- soSESSION_IDstayed derived from the resolved transcript's own basename. That is correct on Claude Code (<session-id>.jsonl) but not on Codex (rollout-<date>-<uuid>.jsonl), andsave-session.sh's own[a-f0-9-]+validation gate rejected every one of those ids, silently, into an autonomous log nobody reads.SessionEndwas unaffected (it passes the stdin id directly), which is why a Codex session still looked fully captured end to end while every incremental save between tool calls was actually lost.Fix
post-tool-hook.shnow prefersSTDIN_SESSION_IDwhen it is TRUSTED -- confirmed to actually correspond to the resolvedTRANSCRIPT, via one of two existing branches in the transcript-resolution if/elif/else block -- falling back to the basename derivation otherwise, the same precedence #407 gave the transcript path itself.Self-review (Explore agent) caught a real regression in the first pass: the TRUSTED flag went true whenever
STDIN_TRANSCRIPT_PATHwas present, with no check that asession_idhad actually arrived alongside it -- a transcript_path-with-no-session_id payload shape then handedsave-session.shan EMPTY id, which its own[ -z ]mtime-fallback silently re-attributes to whatever session happens to be newest, reintroducing the #212/#204/#129 wrong-session-attribution class. Fixed in the follow-up commit by gating that branch onSTDIN_SESSION_IDalso being non-empty, and the paired regression test now checks the capture-alive marker directly (which id was actually used) rather than merely that a save was forked at all.Tests
tests/test_codex_stdin_session_id_468.py: a positive control isolatingsave-session.sh's own validation gate (proves the harness can see the exact rejection), the actual bug reproduction driven through the real hook on a Codex-shaped payload (asserts the save is attempted AND accepted, not merely that a warning is absent), and the paired basename-fallback regression test described above. Pinned green:tests/test_post_tool_session_id.py,tests/test_codex_transcript_path_459.py,tests/test_post_tool_fast_path_350.py,tests/test_post_tool_hook_spawns.py.Docs
README.md's Codex support section updated: the "Not yet known: whether PostToolUse fires" line was stale (it does fire, and #444 already fixed project-root resolution on Codex) -- replaced with an accurate account of both #444 and this fix.
changelog.d/468.fixed.mdadded.Below-bar finding (not filed)
The auditor (oss:auditor agent) flagged that
STDIN_SESSION_ID's own validation guard (pre-existing,post-tool-hook.sh:396, unchanged by this diff) accepts[A-Za-z0-9._-]+, broader thansave-session.sh's own gate^[a-f0-9-]+$(lowercase hex + hyphen only). Before this diff that mismatch was inert, becauseSESSION_IDwas always re-derived from the basename regardless of stdin. After this diff, a hypothetical host session id containing uppercase/./_would be "trusted" and silently rejected downstream by save-session.sh's stricter gate -- narrowing, not reopening, the bug this issue fixes. Below-bar: real mechanism, no reachable caller today -- neither host this plugin targets (Claude Code, Codex) emits a session id outside[a-f0-9-]+; both use lowercase-hex UUIDs. Recorded here rather than filed, since there is no concrete input either supported host produces that hits this path.Verification not reached
I did not run a live end-to-end Codex session against a real install to confirm the fix in production (the brief explicitly warned that watching only SessionEnd is insufficient evidence, having caught exactly that gap once already) -- I verified the mechanism directly instead, via the unit-level integration tests above driving the real
post-tool-hook.shscript with Codex-shaped stdin payloads and inspectingsave-session.sh's own actual acceptance/rejection, which is a more precise probe of the specific defect than an end-to-end session would be, but it is not a substitute for a live install confirmation.