Repository navigation
Merged
Conversation
…nd post-tool/user-prompt hooks no longer trust a leaked REMEMBER_HOOK_CWD #405 generalises #367s ASCII-only rule for printed lines from session-start-hook.sh alone to the whole scripts/ tree and to pipeline/*.py, where the same fallback-to-stderr shape carries a real UnicodeEncodeError crash risk rather than just cosmetic mojibake. #417 has post-tool-hook.sh and user-prompt-hook.sh unset REMEMBER_HOOK_CWD before sourcing resolve-paths.sh, since neither hook has a stdin cwd of its own to offer and both previously inherited whatever the process environment already held. Closes #405 Closes #417 Co-Authored-By: Max <noreply>
Both the Explore reviewer and oss:auditor independently found the same gap in tests/test_printed_lines_ascii_405.py: its shell-side scan only matched lines that OPENED with echo/printf/log/report_error, missing the "cond && log ..." guarded-print idiom (post-tool-hook.sh:428) and the "local _msg=...; log $_msg" build-then-print idiom (log.sh:747) -- both of which the actual #405 fix already covers correctly, so this was a coverage gap in the regression pin, not a remaining production bug. Verified by reverting each shape back to an em-dash and confirming the widened scan now fails loudly on both, then restoring. Co-Authored-By: Max <noreply>
fdaviddpt
added a commit
that referenced
this pull request
Aug 29, 2026
#423) tests/test_stdin_source_top_level_wins_344.py and tests/test_session_start_compact_recap_339.py named their own "today" staging file with time.strftime() at pytest collection time while scripts/session-start-hook.sh computes $TODAY at run time; a real UTC midnight crossing between those two reads (observed once, PR #421, pytest macos-latest/3.9, 57s past midnight) drops the today body from the recap and forks a stray background consolidation. Both files now shim `date` on PATH so both sides read one frozen value, and a new pinning test in the 344 file drives the two dates apart deliberately to confirm a genuine mismatch excludes only the stale file rather than blanking the rest of the recap. Fixes #422
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.
Closes #405
Closes #417
Bundled on one branch because both touch scripts/post-tool-hook.sh (and one, #417, also touches scripts/resolve-paths.sh and scripts/user-prompt-hook.sh), but they are two independent fixes with their own test story and their own changelog fragment.
#405
#367 pinned session-start-hook.sh alone: no printed (echo/printf/log/report_error) line may carry a byte outside ASCII, because it renders as mojibake on a cp1252 Windows console. This generalises that decision to every script under scripts/, and -- a judgment call argued for in the PR, not assumed -- to pipeline/*.py as well, where the same fallback-to-stderr shape (pipeline/log.py's log(), pipeline/haiku.py's _warn()) uses Python's print(), which genuinely performs a console-codepage encode step. A non-ASCII byte there is a live UnicodeEncodeError crash risk, not cosmetic garbling.
Mechanical fix: em-dash -> "--", arrow -> "->", three status glyphs in run-tests.sh -> PASS/FAIL/SKIP text, across ~16 shell scripts and 3 pipeline/*.py files. One deliberate exemption: scripts/bench-slug.sh keeps its own non-ASCII benchmark input (a cafe/nihongo/emoji test path) since that is the subject of the benchmark, not a diagnostic message.
New guard: tests/test_printed_lines_ascii_405.py -- scans every non-comment line of scripts/.sh, and walks the AST of pipeline/.py collecting every string reaching _warn()/log()/print() or a raised exception's message. Widened once already after review (see below). tests/test_printed_lines_ascii_367.py continues to pin session-start-hook.sh on its own, untouched.
Six pre-existing tests updated to expect "--" instead of an em-dash in exact-string assertions on real hook output: test_doctor_session_end_370.py, test_doctor_verdict_ordering_404.py, test_prompt_stamp_301.py, test_prompt_hook_spawns.py, test_types.py.
#417
scripts/post-tool-hook.sh and scripts/user-prompt-hook.sh source scripts/resolve-paths.sh, which falls back to env var REMEMBER_HOOK_CWD when CLAUDE_PROJECT_DIR is unset (#411). Only session-start-hook.sh and session-end-hook.sh ever legitimately set that variable, each fresh from their own stdin cwd on every run -- these two hooks never set, cleared or validated it, so they could inherit whatever a different session's SessionStart left in the process environment on a host that reuses one environment across hook invocations. Reachability of that leak was explicitly not established either way (see the issue). The fix does not depend on the answer: both hooks now
unset REMEMBER_HOOK_CWDnear the top of the file, before sourcing anything, which is correct regardless of reachability since neither hook has a stdin cwd of its own to offer. scripts/resolve-paths.sh documents the assumption at the consulting site.session-start-hook.sh itself is untouched -- it is off-limits, owned by the concurrently open fix/402 lane (PR #418).
New test: tests/test_hook_cwd_leak_417.py, with a positive control proving REMEMBER_HOOK_CWD's fallback mechanism in resolve-paths.sh genuinely still works (so the negative assertion cannot pass by testing dead code), plus a test extracting each hook's own preamble and confirming a pre-set fake value comes out cleared.
Review
Both a review agent and the audit agent, spawned in parallel against the first commit, independently found the same real gap: the #405 guard test's shell-side scan was keyword-anchored and missed a guarded-print idiom (
[ cond ] && log ...) and a build-then-print idiom (a message assigned to a local variable on one line, printed vialog "$var"several lines later) -- both already handled correctly by the actual production fix, verified by grep, but not caught by the regression pin as first written. Fixed in a follow-up commit: the assertion now scans every non-comment line rather than only keyword-opened ones, verified red-then-green a second time against both flagged shapes.Testing
Full local suite:
python3 -m pytest -q-- 1776 passed, 43 skipped, 0 failed (run twice, once before and once after the review follow-up; the follow-up only changed a test file). Changelog fragments (405.fixed.md, 417.fixed.md) verified withpython3 .oss/assemble_changelog.py --check.