Skip to content

fix: per-tool-call capture on Codex still forked save-session.sh into a silent rejection (#468) - #473

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/468
Aug 29, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/468

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

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 in scripts/post-tool-hook.sh -- so SESSION_ID stayed 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), and save-session.sh's own [a-f0-9-]+ validation gate rejected every one of those ids, silently, into an autonomous log nobody reads. SessionEnd was 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.sh now prefers STDIN_SESSION_ID when it is TRUSTED -- confirmed to actually correspond to the resolved TRANSCRIPT, 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_PATH was present, with no check that a session_id had actually arrived alongside it -- a transcript_path-with-no-session_id payload shape then handed save-session.sh an 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 on STDIN_SESSION_ID also 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 isolating save-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.md added.

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 than save-session.sh's own gate ^[a-f0-9-]+$ (lowercase hex + hyphen only). Before this diff that mismatch was inert, because SESSION_ID was 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.sh script with Codex-shaped stdin payloads and inspecting save-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.

… 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>
@fdaviddpt
fdaviddpt merged commit ca13e6a into main Aug 29, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/468 branch August 29, 2026 14:57
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.

PostToolUse still cannot save on Codex: the session id is taken from the transcript basename, which #459 stopped controlling

1 participant