Repository navigation
fix: read the host-supplied transcript path instead of reconstructing it (#407) - #409
Merged
Merged
Conversation
Eleven tests, four of them red: the four that assert a supplied transcript_path is used. The other seven are the positive controls and the fallback pins -- they pass today, and they are what stops the four from being satisfied by a reader that simply stops reading. pipeline/host.py holds the two things three agent CLIs genuinely disagree about -- what they call their variables, and how to recognise them -- as data rather than as branches. It deliberately excludes event names, the summarizer, and shell path resolution; the docstring says why for each. Nothing consumes host.py yet. Wiring it into extract.py is the rest of the work. Refs #407 Co-Authored-By: Max <noreply>
… it (#407) find_session() now uses transcript_path from the SessionStart/SessionEnd stdin payload (via the new pipeline/host.py adapter) when it names a real file, falling back to _session_dir()'s slug reconstruction for every caller with no payload. extract_session() prefers a supplied session_id over the transcript's basename, so a host that names files differently (Codex's rollout-<date>-<uuid>.jsonl) can no longer key get_last_save_line on a string that never matches. session-start-hook.sh and session-end-hook.sh export REMEMBER_TRANSCRIPT_PATH from the same stdin payload they already read session_id from. resolve-paths.sh now reads ${PLUGIN_ROOT:-$CLAUDE_PLUGIN_ROOT} so the vendor-neutral name wins, with a parity test against pipeline.host.PLUGIN_ROOT_VARS and a pin on the previously-untested derive-from-script-location fallback. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…nto a rescued session's save (#407) Self-review (Explore + oss:auditor spawns against the first commit) found that session-start-hook.sh's recovery block -- which force-saves the PREVIOUS session in the background when it was left unsaved -- inherited REMEMBER_TRANSCRIPT_PATH from the CURRENT session's own SessionStart payload, exported a few lines earlier. find_session() trusts that variable unconditionally once it names a real file, so the rescue could silently read and summarize the wrong (current) session's transcript while still labelling the saved record with the previous session's id. The recovery spawn now runs in a subshell with REMEMBER_TRANSCRIPT_PATH unset, pinned by tests/test_recovery_transcript_leak_407.py (a failing repro plus a positive control proving the harness can see the variable when it is meant to). Also from that review: resolve-paths.sh's new PLUGIN_ROOT fallback is hardened against `set -u` (${CLAUDE_PLUGIN_ROOT:-} inside the outer expansion, matching test_host_shell_parity_407.py's updated regex), and both hooks' stdin-validation comments no longer overclaim that a raw newline is rejected by the case guard -- the read loop upstream already strips every line terminator, so that arm is provably unreachable and the comment now says so instead of implying live protection. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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
Closes #407.
pipeline/extract.py'sfind_session()now reads thetranscript_pathhanded to us on theSessionStart/SessionEndstdin payload (viapipeline/host.py, added earlier on this branch) instead of reconstructing it from a project-directory slug, with_session_dir()'s reconstruction kept as the fallback for every caller with no payload (consolidation,/remember:doctor, manual invocation). A suppliedsession_idnow wins over one derived from the transcript's basename, since a host is free to name its transcript file anything (Codex:rollout-<date>-<uuid>.jsonl) and a mismatch would silently keyget_last_save_lineon the wrong string, re-summarizing from line 0 every save (the duplicate #140 exists to prevent).scripts/session-start-hook.shandscripts/session-end-hook.shextracttranscript_pathfrom the same payload they already readsession_idfrom and export it asREMEMBER_TRANSCRIPT_PATH.scripts/resolve-paths.shnow reads${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}so the vendor-neutral name wins, with a parity test againstpipeline.host.PLUGIN_ROOT_VARSand a pin on the previously-untested derive-from-script-location fallback.Scope was narrowed in the issue's own second comment before this lane started: the stdin-
cwd->PROJECT_DIRhalf is explicitly out of scope, deferred to #406, because the resolver runs beforeHOOK_STDINis captured and the hoist that would fix that ordering cannot be verified without a real Codex install. Not touched here.Self-review found and fixed a real bug
A spawned reviewer (Explore) caught, before this ever shipped:
session-start-hook.sh's recovery block force-saves the previous, unsaved session in the background, and that background process inheritedREMEMBER_TRANSCRIPT_PATHfrom the current session's own payload -- sincefind_session()trusts the variable unconditionally once it names a real file, the rescue could silently summarize the wrong session's transcript while still labelling the saved record with the previous session's id. Fixed by unsetting the variable for that one spawn; pinned bytests/test_recovery_transcript_leak_407.py(a negative assertion with a positive control, per this repo's own testing rule).The same review round hardened
scripts/resolve-paths.sh's new fallback against a bareset -ucaller (${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}) and corrected both hooks' stdin-validation comments, which had claimed a raw newline was rejected by a case guard that a preceding read loop already makes unreachable -- true and harmless, but worth saying accurately since a future change to that loop could silently reactivate the gap the comment implied was already closed.Below the filing bar, recorded here rather than as a separate issue: the review also flagged that
find_session()'s trust inREMEMBER_TRANSCRIPT_PATHis unconditional for any caller, not just the one live call site fixed above -- true in the general case, but every other caller either never sees this env var (consolidation,/remember:doctor) or is the one legitimate, matching use (session-end-hook.sh's own flush of its own session). No reachable caller today; not fixed, not filed.Also below the bar: six sibling hook scripts (
post-tool-hook.sh,user-prompt-hook.sh,run-consolidation.sh,doctor.sh, and this diff's own two) still document theirENVIRONMENTheader comments asCLAUDE_PLUGIN_ROOT-only, though all of them sourceresolve-paths.sh, which now prefersPLUGIN_ROOT. Purely cosmetic --resolve-paths.shis the single source of truth these scripts already defer to, nothing reads the header comments -- and spans more files than this diff's own blast radius, so it is named here rather than fixed inline.Test plan
tests/test_transcript_path_407.py-- 11 tests, watched RED (4 failing) before thefind_session()/extract_session()change, GREEN (11 passing) after.tests/test_recovery_transcript_leak_407.py-- new, watched RED (the leak reproduced) before the recovery-block fix, GREEN after.tests/test_host_shell_parity_407.py-- new, 4 tests pinningresolve-paths.sh'sPLUGIN_ROOT/CLAUDE_PLUGIN_ROOTprecedence and the previously-untested derive-from-script-location fallback.flock, Git Bash,pwsh, bash < 4.2), 1 error at teardown attributable to a concurrent process removing unrelated sibling worktrees mid-run on the shared machine -- not caused by this diff (see reportclaims).python3 .oss/assemble_changelog.py --check --check-links --dir 'changelog.d' --changelog CHANGELOG.md-- clean.win32; see reportclaimsfor the specific unresolved shape (a Windows-styletranscript_pathwith unescaped backslashes reachingos.path.isfile()).🤖 Generated with Claude Code