Repository navigation
Conversation
…mory injection and bootstrap (#662, #664, #666) detect-tools.sh unconditionally probed python3/python/py on every SessionStart even though $PYTHON is only read by four jq-less fallback call sites that never fire when jq is present. A new _remember_python() resolver defers that probe to first actual use, opted into only by session-start-hook.sh (every other sourcer genuinely needs $PYTHON right after sourcing). lib-memory-context.sh's MEMORY section render forked one wc + one tr + one basename per memory file; now batches wc -c once per group and uses parameter expansion for basename. The rotated-slice listing uses a glob array instead of ls | sort. session-start-hook.sh's capture-alive.d prune and staging-file count, and bootstrap-dirs.sh's stale-config sweep, now skip their fork-heavy pipelines entirely when a cheap glob-array check shows there is nothing to do. lib-clock.sh's builtin clock path now accepts %s (real POSIX strftime, not the GNU-only extension it was lumped in with) instead of always shelling out to date for it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…found in self-review
`declare -A` is silently ACCEPTED by bash 3.2 (it creates a plain indexed
array instead of erroring), so the fault surfaces one step later at the very
next `${arr[$key]}` lookup -- a fatal "syntax error: operand expected" that
aborts _remember_render_memory_section with nothing injected and nothing
visible beyond stderr. Stock macOS /bin/bash is 3.2.57 and this repo
documents it as a supported floor (lib-clock.sh, lib-lock.sh's own
_lock_timing_key comment) specifically because it lacks associative arrays.
Replaced with printf -v + indirect (${!name}) expansion, the same
named-variable-per-key pattern lib-lock.sh already uses for the identical
reason, confirmed directly against the real /bin/bash 3.2.57 on this machine.
Added a regression test: a static two-stage grep that fires on any
`declare -A` reintroduced under scripts/ (the first, single-regex attempt at
this silently failed to fire on a line where declare -A is the first token --
caught only by deliberately reintroducing the bug and finding the check
stayed green), plus a functional run against the real /bin/bash when it
actually identifies as bash < 4.
Found by the oss:auditor self-review spawn against the first commit on this
branch, before anything was pushed.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…und in the full suite The developer lane ran its own test file but not the whole suite; the whole suite caught two collection/assertion failures in tests that pin the code this change edits: - tests/test_windows_glob_backslash_517.py extracted two blocks by a trailing `ls ...` marker that #666 replaced with a glob array. The end markers now name the new last line of each block (the `unset` in session-start-hook.sh's staging count; the HAS_MEMORY assignment in lib-memory-context.sh's rotated-slice listing). All 23 tests pass against the extracted blocks, so the #517 backslash property holds for the rewritten code too. - tests/test_case_divergence_298.py byte-pins lib-slug.sh and lib-memory-dir.sh to origin/main so nothing adds a spawn to the per-tool-call path. The #662 lazy-PYTHON guard is a `declare -f` builtin check placed immediately before an existing python spawn, on branches that only run when that spawn runs -- no new spawn -- so it is sanctioned via the test's own _SANCTIONED_DIVERGENCE mechanism, which now takes a list of substitutions per file since lib-memory-dir.sh carries #429's as well. Positive control: an unsanctioned `git rev-parse` inserted next to the guard still fails the test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…SANCTIONED_DIVERGENCE CI on #675 failed 12/12 pytest legs on the same two tests in tests/test_sanctioned_divergence_state_440.py: they unpacked _SANCTIONED_DIVERGENCE[rel] as a single (old, new) tuple, and 80b8013 turned it into a list so lib-memory-dir.sh can carry both #429's and #662's allowance. 80b8013 was pushed on a targeted run of the #298 file only; the whole suite would have caught this before CI did, and did this time: 2372 passed, 47 skipped on macOS. The three tests now build their synthetic origin/main text from every pair for the file and assert each pair on its own; a fourth pins the mixed state (one allowance landed, another still open) that the list shape newly makes possible, and skips itself when a file carries only one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…he compact render (found by CI's macOS legs) PR #675 round 2: all four macos-latest pytest legs failed tests/test_start_context_cache_668.py::test_compact_mode_never_reads_or_writes_the_context_cache with rc 127 and an empty stderr. Reproduced on /bin/bash 3.2.57 with the render's stderr visible: lib-memory-context.sh: line 127: _remember_present[@]: unbound variable At SESSION_START_SOURCE=compact every non-identity file is skipped, so with no identity file the batched-wc present list is empty, and `for MFILE in "${arr[@]}"` over an EMPTY array is a fatal unbound- variable error under `set -u` on every bash before 4.4 -- which the #668 publish path runs under. bash 5 (the developer lane's Homebrew bash, and the Linux/Windows legs) does not have the error, which is why it reached CI. Three loops count-guarded: the main present-file loop and the compact deferred-list loop in lib-memory-context.sh, and the staging-count loop in session-start-hook.sh (an empty staging dir is the common case). Every other new `[@]` expansion in the diff was already behind a `${#arr[@]} -gt 0` check. Regression test in tests/test_session_start_promo_spawn_budget_660.py runs the compact render under `set -u` on the real /bin/bash when it is below 4.4 (skips with the reason stated elsewhere), with a positive control on the same bash; verified to fail with the guard removed. Whole suite with /bin/bash first on PATH (CI's macOS shape): 2372 passed, 47 skipped, 1 failed -- tests/test_log_sh.py's does-not-parse diagnostic, which fails identically on main under that PATH and passes on CI's macOS legs, so it is not this change's. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…ent lazy mode in detect-tools.sh The first draft of test_capture_seen_prune_is_gated_on_the_threshold ran only with no capture-alive.d at all -- a shape that never forked under the old code either, so it would have passed against it. Seed 2 entries for the negative half and CAPTURE_SEEN_KEEP+1 for a paired positive control that must see the `ls -t` prune fire and leave exactly CAPTURE_SEEN_KEEP behind (CLAUDE.md: a negative assertion needs a positive control). Found by the Explore self-review on #675. detect-tools.sh's header now names the _REMEMBER_LAZY_PYTHON=1 mode #662 added, and what PYTHON and the exit code mean under it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…of executing an empty $PYTHON Review finding on #675: with _REMEMBER_LAZY_PYTHON=1 and no interpreter on PATH, _remember_python returns 1 and _jq_fallback went on to run `$PYTHON -` as the empty word -- `-: command not found`, exit 127, empty output. The callers defaulted correctly either way; this makes the failure the plain return 1 it was meant to be. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
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 #662
Closes #664
Closes #666
Part of #660.
What was wrong
Three always-on fork sources on the SessionStart foreground path, each independently filed under #660's spawn-budget umbrella:
detect-tools.shprobedpython3/python/pyon every start, but$PYTHONis only read by four jq-less fallback call sites, none of which fire whenjqis on PATH (the common case).=== MEMORY ===section forked onewc+ onetr+ onebasenameper memory file; a typical 4-6 file store paid 8-12+ forks here alone.capture-alive.dprune (ls -t | tail), the staging-count check (ls | grep -v | grep -v | wc -l | tr -d ' ', five forks) andbootstrap-dirs.sh's stale-config sweep (find -mmin +30) all ran unconditionally, even with nothing to do; andlib-clock.shalways shelled out todatefor%s.What changed
scripts/detect-tools.sh: a lazy_remember_python()resolver, called only at first actual need and cached the same way the existing PATH-keyed verdict cache already was. Opted into via_REMEMBER_LAZY_PYTHON=1, set only bysession-start-hook.sh-- every other sourcer (post-tool-hook.sh,save-session.sh,run-consolidation.sh,doctor.sh) genuinely invokes$PYTHON -m pipeline.shellright after sourcing, so eager detection there is real work, not waste.scripts/lib-memory-context.sh: one batchedwc -cper group (present files; compact-mode deferred set; the up-to-10 rotated slices actually printed), parsed via plainread;basenamereplaced with${MFILE##*/}; rotated-slice listing via a glob array instead ofls | sort.scripts/session-start-hook.sh,scripts/bootstrap-dirs.sh: the prune, staging count and stale-config sweep skip their pipelines when a glob check shows nothing to do; the staging count is a glob array walked with acase, zero forks.scripts/lib-clock.sh: the bash >= 4.2printf '%(FMT)T'builtin now handles%s(POSIX strftime, not the GNU extension it was lumped with); builtin anddate +%sare pinned byte-identical by the new test.scripts/lib-memory-dir.sh,scripts/lib-slug.sh,scripts/log.sh: adeclare -f _remember_python >/dev/null 2>&1 && _remember_pythonguard immediately before each existing python spawn -- a builtin check, no new spawn, a no-op outside lazy mode.changelog.d/662.changed.md;tests/test_session_start_promo_spawn_budget_660.py(+313 lines, 6 tests).Self-review findings (developer lane)
declare -Ainlib-memory-context.sh. bash 3.2 silently acceptsdeclare -Aas a plain indexed array, then dies withsyntax error: operand expectedat the first${arr[$key]}lookup, so the whole MEMORY section render aborted with nothing injected. Fixed in 8e2322f withprintf -v+${!name}indirection (the patternlib-lock.shalready uses), verified against the real/bin/bash3.2.57. A static regression test grepsscripts/for any reintroduceddeclare -A; the first single-regex version of that check did NOT fire when the bug was deliberately reintroduced, so it was rewritten as a two-stage grep and re-verified to fire.Maintainer review (this PR's third commit, 80b8013)
The developer lane ran its own test file but not the whole suite. The whole suite (2370 passed, 47 skipped, 1 failed + 1 collection error on macOS, 10m45s) caught two guards the change moved out from under:
tests/test_windows_glob_backslash_517.pyextracted two blocks by a trailingls ...marker that SessionStart: ls|grep|wc counting pipelines, $(cat), $(dirname), ungated mkdir -p on every start (Part of #660) #666 replaced with a glob array (collectionStopIteration). End markers repointed at the new last line of each block; all 23 tests pass against the rewritten code, so the Bash's glob never splits on backslash: 7 more REMEMBER_DIR sweeps/checks silently miss on Windows (same class as #487) #517 backslash property holds for it too.tests/test_case_divergence_298.pybyte-pinslib-slug.shandlib-memory-dir.shtoorigin/mainso nothing adds a spawn to the per-tool-call path. This is exactly the review the guard exists to force: the SessionStart: drop the unconditional python -V probe from the foreground path (Part of #660) #662 guard line is adeclare -fbuiltin placed right before an already-existing python spawn, on branches that only run when that spawn runs -- no new spawn on the hot path. Sanctioned through the test's own_SANCTIONED_DIVERGENCEmechanism, now a list per file sincelib-memory-dir.shalso carries 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's. Positive control: an unsanctionedgit rev-parseinserted beside the guard still fails the test.Static:
grep -rn 'declare -A' scripts/finds only the comment explaining why not;bash -nunder/bin/bash3.2.57 is clean for every touched script.CI round 1 (80b8013): 12/12 pytest legs red, all on the review commit, not the developer's diff
Every pytest leg on all three OSes failed the same two tests in
tests/test_sanctioned_divergence_state_440.py-- the unit tests of the allowance helper, which unpacked_SANCTIONED_DIVERGENCE[rel]as a single tuple after 80b8013 had made it a list. The developer's own change was otherwise green across the matrix (ubuntu: 2405 passed; windows: 1049 passed, 1371 skipped). 80b8013 had been pushed on a targeted run of the #298 file rather than the whole suite -- the same lapse I called out in the developer's lane, repeated here. f8521e0 fixes the three tests for the list shape, adds a mixed-state test the list newly makes possible, and this time the whole suite ran first: 2372 passed, 47 skipped on macOS.CI round 2 (f8521e0): 12 green, 4 red -- the macOS legs, and this one IS the developer's diff
All four macos-latest legs failed
tests/test_start_context_cache_668.py::test_compact_mode_never_reads_or_writes_the_context_cachewith rc 127 and an empty stderr. Reproduced on/bin/bash3.2.57 with the render's stderr visible:lib-memory-context.sh: line 127: _remember_present[@]: unbound variable. At compact every non-identity file is skipped, so with no identity file the batched-wcpresent list is empty, andfor MFILE in "${arr[@]}"over an empty array is a fatal unbound-variable error underset -uon every bash before 4.4 -- the #668 publish path runs under it. bash 5 (the developer's Homebrew bash, the Linux and Windows legs) has no such error, which is why the developer's "observed on macOS" claim and my own full-suite run both missed it: both ran under bash 5. 5773e62 count-guards the three loops that could see an empty array (every other new[@]expansion was already behind a${#arr[@]} -gt 0check) and adds a regression test that runs the compact render underset -uon the real/bin/bashwhen it is below 4.4, verified to fail with the guard removed. Whole suite with/bin/bashfirst on PATH (CI's macOS shape): 2372 passed, 1 failed --test_log_sh.py's does-not-parse diagnostic, which fails identically onmainunder that PATH and passes on CI's macOS legs, so it is not this change's.Cross-platform claims
/bin/bash3.2.57 first on PATH after round 2; both bash-3.2 crashes (declare -A, empty array underset -u) reproduced and fixed directly.printf -v, indirect expansion,wc -c);%sinlib-clock.shrests on%sbeing POSIX strftime rather than a GNU extension. CI's 3-OS x 4-interpreter matrix is the evidence for those; nothing in the diff was run there.Generated with Claude Code: https://claude.com/claude-code
https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
[AI-generated]