Skip to content

test: pin the per-tool-call hot path's cost with spawn + read-builtin budgets (#330) - #380

Merged
fdaviddpt merged 4 commits into
mainfrom
fix/330
Aug 28, 2026
Merged

fdaviddpt merged 4 commits into
mainfrom
fix/330

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What

#329 replaced a byte-identity check on scripts/post-tool-hook.sh with three substring assertions (the code must not mention lib-case-divergence, case_divergence, or git ). #330 pointed out that substring check can be walked around while staying green: a git call spelled through a variable (GIT=git; "$GIT" -C ...) or command, an extra subprocess spawn of something that isn't git, or an extra bash builtin file read or loop -- the last two aren't even in the substring vocabulary.

This PR does not touch scripts/post-tool-hook.sh -- the hot path is already clean (#329 verified that). It adds one new test file, tests/test_hot_path_cost_pin_330.py, that measures the property #299 actually cares about: cost.

  • Reuses the existing spawn-count budget (tests/test_post_tool_fast_path_350.py's FAST_PATH_SPAWN_BUDGET).
  • Adds a new pin: bash builtin read/mapfile/readarray invocations, counted via bash -x (xtrace) parsed from stderr -- no ptrace-level tooling needed, portable to every platform this repo's CI runs.
  • Proves both pins are non-vacuous against a scratch copy of the hook, reintroducing each named vector: a GIT=git variable wrapper, a quoted command "git" wrapper (quoted specifically so it does not trip the old substring check, unlike a bare command git), and a 5-iteration builtin-read loop with no new spawn and no new literal.
  • States, rather than silently misses, the one boundary neither pin can see: a pure compute loop with no I/O, plus (added in self-review) the one read vector invisible to xtrace itself, x=$(< file).

Closes #330

Self-review

Spawned an Explore reviewer and an oss:auditor, foreground, in parallel, against the first commit. Both returned real findings, both fixed in a follow-up commit:

  • Reviewer: tests/test_case_divergence_298.py's own docstring on test_the_per_tool_call_path_is_not_touched still read as though its substring check were the whole story on hot-path cost, with no pointer to the new file. Cross-referenced both ways.
  • Auditor: _is_read_builtin only matched the literal word read; a rewrite from a while read loop to mapfile/readarray (bash >= 4, same file, same cost, zero new spawns) would have evaded the new pin silently. Widened the match set to include mapfile/readarray, and named the one genuinely unreachable vector (x=$(< file), confirmed to leave no trace line under bash -x at all) as a stated boundary rather than an undiscovered gap. Below-bar item, not filed: the $(< file) blind spot cannot be closed by an xtrace-based harness at all -- the read happens with no subprocess and no traceable simple command, so catching it would need a different mechanism entirely (ptrace/strace, unavailable in this repo's CI), and The per-tool-call hot path lost its byte-identity pin and the replacement can be walked around #330 explicitly allows "this cannot be made robust" as a valid outcome for whatever a cost pin does not cover.

Tests

python3 -m pytest tests/test_hot_path_cost_pin_330.py tests/test_case_divergence_298.py::test_the_per_tool_call_path_is_not_touched tests/test_post_tool_fast_path_350.py -v -- 21 passed. Full suite not run: change is confined to test files, no shared module (spawn_counting.py) or production code touched, no cross-cutting guard matched by scripts/lane_setup.py --lane.

Red/green evidence lives in the report at reports/fix-330-<timestamp>.json under tests.red/tests.green -- iterating on the harness itself surfaced two real bugs before it was correct (an exec 2>>hook-errors.log redirect on the fast path silently swallowing xtrace output for everything after it, and a command git -C ... fixture that accidentally spelled the literal substring it was meant to evade), both documented in the file's own comments so a future reader does not rediscover them by trial and error.

fdaviddpt and others added 3 commits August 27, 2026 19:55
…ss (#330)

#329's substring guard in test_case_divergence_298.py checks for three
literals; #330 named vectors that reintroduce #298/#299's per-tool-call
cost while staying green against it -- a git wrapper spelled through a
variable or `command`, and an extra file read or loop that spawns nothing
at all. tests/test_hot_path_cost_pin_330.py adds the measured pin the
issue asked for: a spawn budget (reusing the existing harness) plus a new
bash-builtin-`read` count via `bash -x` tracing, proven non-vacuous
against scratch reproductions of each named vector, with the pure-compute
boundary neither pin can see stated rather than hidden.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
's substring test

Self-review findings: the reviewer flagged that #298's substring-test
docstring still read as the whole story on hot-path coverage, with no
pointer to the new cost pin that closes its gap -- cross-referenced both
ways. The auditor flagged that _is_read_builtin only matched the literal
word "read", so a rewrite from a `while read` loop to `mapfile`/`readarray`
(same file, same cost, zero new spawns) would silently evade the new pin --
widened the match set and named the one vector that remains genuinely
unreachable (`x=$(< file)`, invisible to xtrace itself, confirmed locally)
in the module docstring instead of leaving it undiscovered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
…in_330.py (#330)

CI (macos-latest, 3.11/3.12) went red on the new file's own positive
control: "the injected read spawned a process", with a spawn list that
was pure cold-path signature (python3 -V, git rev-parse, jq -s, the
trap-stripping sed, the temp sweep). ubuntu and windows legs stayed
green.

Established rather than guessed: the fixture wrote config.json with a
plain write_text() instead of tests.env_cache.write_config(), and never
verified warmth with EnvCacheProbe. scripts/lib-env-cache.sh refuses its
own cache unless it is `-nt` every config layer, and macOS's system bash
3.2.57 -nt compares whole SECONDS (confirmed via
tests.env_cache.nt_granularity() == "second" on this platform) -- so a
config written in the same wall-clock second as the cache publish TIES
rather than loses, the cache is rejected, and every "warm" measurement
in this file was silently re-resolving instead. Reproduced
deterministically by forcing the tie by hand: identical spawn signature
to the CI failure. This is the exact #303 defect class this repo's own
tests.env_cache module exists to prevent, already used by the sibling
file this one is modeled on (test_post_tool_fast_path_350.py) -- this
file simply never adopted it.

Fixed with the established pattern rather than a platform skip, since
warmth is genuinely reachable everywhere once the race is closed:
config.json now goes through write_config() (backdated past any second
boundary), and every measured (non-priming) run goes through a new
_measure() helper that brackets it with an EnvCacheProbe and fails
loudly -- naming which run went cold and why -- instead of silently
reporting a cold-path count as the warm one this file claims to pin.

Verified stable across repeated local runs on this machine's bash
3.2.57 (matching macOS CI) after the fix; the x=$(< file) boundary this
file already names is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FLHVEH4aeVK93939UYnfFP
@fdaviddpt
fdaviddpt merged commit eedf877 into main Aug 28, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/330 branch August 28, 2026 06:32
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.

The per-tool-call hot path lost its byte-identity pin and the replacement can be walked around

1 participant