Skip to content

fix: read the host-supplied transcript path instead of reconstructing it (#407) - #409

Merged
fdaviddpt merged 4 commits into
mainfrom
feat/407-transcript-path
Aug 28, 2026
Merged

fdaviddpt merged 4 commits into
mainfrom
feat/407-transcript-path

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Closes #407. pipeline/extract.py's find_session() now reads the transcript_path handed to us on the SessionStart/SessionEnd stdin payload (via pipeline/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 supplied session_id now 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 key get_last_save_line on the wrong string, re-summarizing from line 0 every save (the duplicate #140 exists to prevent). scripts/session-start-hook.sh and scripts/session-end-hook.sh extract transcript_path from the same payload they already read session_id from and export it as REMEMBER_TRANSCRIPT_PATH. scripts/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.

Scope was narrowed in the issue's own second comment before this lane started: the stdin-cwd -> PROJECT_DIR half is explicitly out of scope, deferred to #406, because the resolver runs before HOOK_STDIN is 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 inherited REMEMBER_TRANSCRIPT_PATH from the current session's own payload -- since find_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 by tests/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 bare set -u caller (${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 in REMEMBER_TRANSCRIPT_PATH is 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 their ENVIRONMENT header comments as CLAUDE_PLUGIN_ROOT-only, though all of them source resolve-paths.sh, which now prefers PLUGIN_ROOT. Purely cosmetic -- resolve-paths.sh is 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 the find_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 pinning resolve-paths.sh's PLUGIN_ROOT/CLAUDE_PLUGIN_ROOT precedence and the previously-untested derive-from-script-location fallback.
  • Full local suite: 1726 passed, 43 skipped (macOS/tooling-only skips: 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 report claims).
  • python3 .oss/assemble_changelog.py --check --check-links --dir 'changelog.d' --changelog CHANGELOG.md -- clean.
  • Windows/Git Bash: reasoned, not observed -- most bash-subprocess tests here (including both new test files) skip on win32; see report claims for the specific unresolved shape (a Windows-style transcript_path with unescaped backslashes reaching os.path.isfile()).

🤖 Generated with Claude Code

fdaviddpt and others added 4 commits August 28, 2026 21:48
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]>
@fdaviddpt
fdaviddpt merged commit b909b8f into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the feat/407-transcript-path branch September 26, 2026 20:46
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.

Read cwd and transcript_path from hook stdin instead of deriving them

1 participant