Skip to content

fix: pure-ASCII printed output across scripts/ and pipeline/, and a leaked REMEMBER_HOOK_CWD no hook could set - #421

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/405
Aug 29, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/405

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

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_CWD near 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 via log "$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 with python3 .oss/assemble_changelog.py --check.

…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
fdaviddpt merged commit a019b64 into main Aug 29, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/405 branch August 29, 2026 00:28
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant