Repository navigation
Merged
Conversation
… SessionStart runs (#668, part of #660) Three of the four things #668 identified as recomputed on every SessionStart are now cached, each validated by mtime (`-nt`, never a tie -- FAT/exFAT's 2s granularity makes an equal mtime ambiguous, and ambiguous means miss, not hit): - The injected `=== MEMORY ===` section (six files headed/sized/concatenated, plus the rotated-slice listing) -- new scripts/lib-memory-context.sh is the single source of truth for both the render and the cache. session-start-hook.sh tries the cache first, and on a miss renders live while ALSO leaving a fresh cache behind via `tee` (no double render). save-session.sh and run-consolidation.sh refresh it at the tail of their own already-detached (`nohup ... & disown`) runs, right after the memory files they may have written/rotated have landed. - The flattened `config()` table (`_RCFG_*`, log.sh's `_config_load`), cached as sourceable `%q`-escaped assignments keyed on the three config layers' mtimes. Deliberately NOT a cache of the raw merged config.json, which can carry a live haiku.oauth_token and is already a short-lived scratch file -- both flatteners already drop the whole "haiku" key before emitting a row. - The python/jq tool-verdict probe (detect-tools.sh), cached keyed on the exact $PATH string under the system temp dir (REMEMBER_DIR is not known yet at this point in the source chain). The fourth item the issue named, session_dir_slug, is deliberately deferred: REMEMBER_DIR is already the one authoritative resolution lib-env-cache.sh caches across hooks (#158's "no second resolver" rule), and a parallel slug cache would reintroduce exactly the two-caches-can-disagree risk #158 was filed to eliminate. See the pull request body for the full reasoning. Each cache independently disables via an env var (REMEMBER_START_CACHE, REMEMBER_CONFIG_CACHE, REMEMBER_TOOLS_CACHE) for debugging. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…memory-path resolution, repoint 3 stale test markers, add compact/haiku regression coverage (#668) Two independent self-review spawns (Explore, oss:auditor) each found real regressions this diff introduced, all now fixed and re-verified with a full `pytest` run (2360 passed, 0 failed): - The flattened-config cache validated staleness against the three STANDARD config layers even when a caller points $REMEMBER_CONFIG at a file of its own choosing (a supported override this repo's own test suite uses in dozens of places, e.g. tests/test_git_backup_hook.py's `config_path=`). Reproduced: two runs with different override files in the same REMEMBER_DIR served the FIRST run's config to the SECOND -- silently serving stale content, the one failure mode #668 names as never permitted. Fixed by refusing both cache directions unless $REMEMBER_CONFIG's own basename still carries the mktemp template the standard merge always uses (`remember-config-*`). - Three existing tests located specific literal lines/markers inside scripts/session-start-hook.sh that this diff moved into the new shared scripts/lib-memory-context.sh (the ROTATED_SLICES glob block, the bare `cat "$MFILE"` #247 pins, and the `echo "=== MEMORY ==="` ordering marker). All three repointed to the code's new home / the closest equivalent call-site marker; the invariants they protect are unchanged. - A stray-temp leak test's TMPDIR glob (`remember-*`) incidentally matched the new, intentional, stably-named tool-verdict cache file (`remember-detect-tools-cache`) that detect-tools.sh now writes on every invocation -- excluded it by name, same as lib-env-cache.sh's own `remember-env-*` cache would need if anything in that test's call chain published it. Also, per the auditor's finding: session-start-hook.sh carried its own inline copy of the identity/memory-path resolution logic that lib-memory-context.sh's _remember_memory_paths already duplicates for save-session.sh and run-consolidation.sh -- the exact two-independently- maintained-copies risk #158 already documents for session_dir_slug. session-start-hook.sh now calls the shared function instead. Two test-coverage gaps the Explore review named (zero automated coverage, manually verified correct but unpinned) are now pinned: the compact-mode carve-out never reads or writes the context cache in either direction, and the haiku.oauth_token key never reaches the persisted config.rcfg cache. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
The auditor's self-review finding: the -L/-O symlink/ownership checks on each of the three new cache files were structurally correct but had no positive-control test proving they actually fire -- a future edit that silently weakened or dropped one of them would go undetected. Adds one test per cache (context, config, tool-verdict): plant a symlink at the cache's own path pointing to attacker-controlled content, and assert the loader refuses it and falls back to a live computation rather than trusting it -- for the config cache specifically, this also proves the forged content is never `source`d as shell (a `touch` command embedded in the planted file never executes). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
… .as_posix() (PR #670) CI reported all three windows-latest legs red (11 failed) on tests/test_start_context_cache_668.py and tests/test_config_flatten_cache_668.py. Job log: `scripts/detect-tools.sh: line 214: ./lib-slug.sh: No such file or directory` followed by `bootstrap-dirs.sh: line 47: REMEMBER_DIR: unbound variable`. Root cause: both files' HARNESS f-strings interpolated pathlib.Path objects (RESOLVE_PATHS, DETECT_TOOLS, BOOTSTRAP_DIRS, LOG_SH, and an inline REPO_ROOT / "scripts" / ... expression) directly -- str(Path(...)) on Windows is backslash-separated. detect-tools.sh's own BASH_SOURCE-relative sourcing of lib-slug.sh (`_REMEMBER_SRC_DIR="${BASH_SOURCE[0]%/*}"`) finds no '/' to strip in a fully-backslash path, so it falls through to its own documented "." fallback and then fails to find ./lib-slug.sh relative to whatever cwd the subprocess started in -- silently corrupting PYTHON/JQ detection, which then left REMEMBER_DIR unset for bootstrap-dirs.sh under set -u. This exact class already has an established fix in this repo -- tests/test_detect_tools_fatal_diagnostics_650.py, and this same PR's own tests/test_detect_tools_cache_668.py, both already use `.as_posix()` at every such interpolation site. The other two new test files in this PR just did not follow it consistently. Fixed by applying the same convention everywhere a Path is interpolated into a bash HARNESS string in these two files. No behavior change on POSIX (`.as_posix()` is a no-op there, and the targeted local suite -- 15 tests across all three new cache test files -- stays green). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
…Windows (PR #670) Ruled in/out per the requesting agent's own three hypotheses, rather than guess-fixing: NOT a behavior bug in the cache code (hypothesis c) -- the reported failure's own spawn list was COMPLETELY EMPTY (`got spawns: []`), not merely missing jq, which is the signature of the shim mechanism intercepting nothing at all, not of one specific fork being skipped. Root cause: `make_shim_dir` looked for each COUNTED command by its bare name only (`Path(d) / name`). On native Windows every one of those binaries (jq, git, python3, ...) is installed with a suffix (`jq.exe`, not `jq`), so the lookup found NOTHING for any of them -- not a Windows-specific gap in this PR's own code, a pre-existing gap in this SHARED test helper that nothing had exercised before: every other consumer either blanket-skips win32 (8 of 9 other files importing this module) or only asserts an UPPER bound on the spawn count (tests/test_log_sh.py's `assert len(reads) <= 1`), which still passes when the true count is 0 because a shim that intercepts nothing looks identical to a shim that intercepted one thing and the real code only forked once. My own test_config_flatten_cache_668.py is the first LOWER-bound assertion ("at least one spawn must be observed") run against this shim on Windows, which is what made the gap fail loud instead of passing vacuously. Fix: try each COUNTED name with no suffix first (POSIX, unchanged), then .exe/.cmd/.bat on Windows (os.name == "nt") until a real match is found. Also fixed, in the same function, the identical raw-Path-interpolation class of bug this same PR already fixed twice elsewhere: the shim script's own `exec "{real}"` line now uses `real.as_posix()`, since `real` can be a backslash-separated WindowsPath. Verified: the shim's own output is byte-identical on this (POSIX) platform before and after the change. Ran every consumer of this module (150 tests across 13 files, including every spawn-budget test in the repo) -- all pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
… spawn budget test (PR #670) Ruled in the requesting agent's hypothesis by instrumenting directly rather than guessing: reproduced the exact two-run pattern locally and confirmed the second ("warm") run's spawn count is a fresh #303-class race, not a behavior bug in the #668 cache itself. With REMEMBER_CONFIG_CACHE left at its default, the second run's cache hit/miss depends on whether the first run's cache write and config.json's own creation land in the same whole second -- on this machine (sub-second mtime resolution) it reliably hits; on the macOS CI runner that reported this failure it apparently missed, paying the flatten AND the new publish overhead (mkdir/mktemp/mv, +3 spawns), landing one over the budget's +2 slack (17 measured + 3 = 20 vs budget 19). Confirmed this is the identical class this same test file ALREADY neutralizes for the pre-existing lib-env-cache mechanism (`REMEMBER_ENV_CACHE=0`, with its own #303-referencing comment explaining exactly this race) -- my new cache introduced a second instance of the same race with no equivalent off switch in this test. Not a production regression: post-tool-hook.sh's own docstring already explains that in real use only the first tool call of a session (or the first after a config edit) ever reaches log.sh/config() at all -- every later call replays via lib-env-cache and never sources log.sh, so the #668 publish overhead is paid at most once per session/config-change here too, same as SessionStart. This test's whole point, per its own docstring, is "the COLD path ... stays exactly as it was" -- a regression guard on post-tool-hook.sh's own, pre-#668 cost, not a test of #668's caching benefit (which has its own dedicated suite, tests/test_config_flatten_cache_668.py). Swept every other test in this repo setting REMEMBER_ENV_CACHE=0 (6 files) for the same exposure: none of the other 5 use spawn_counting/make_shim_dir at all, so this is the only one affected. Verified: 5 consecutive local runs of the fixed test, all passing; the full file (10 tests), all passing; instrumented both with and without the new cache enabled to confirm the mechanism rather than assert it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
fdaviddpt
added a commit
that referenced
this pull request
Sep 12, 2026
… every startup (#676) * Fix jq-less _jq_fallback dropping --arg, spurious recovery re-save on every startup (#667) session_was_saved() (scripts/session-start-hook.sh) calls `$JQ -r --arg id "$1" "$SAVED_QUERY" "$LAST_SAVE_FILE"`. When jq is not on PATH (the default on a fresh Git for Windows / Git Bash install, related to #660), $JQ is _jq_fallback (scripts/detect-tools.sh), whose shim consumes every leading `-*` token into a variable it never reads, then treats the next positional argument as the query and the one after that as the file -- fed --arg's pair, that lands on query="id", file="$1" (the session id, not a real file), and the shim always prints nothing. session_was_saved compared that empty output against "saved" and always got false, so every previous session read as unsaved and session-start-hook.sh's recovery block spawned save-session.sh --force on every single jq-less startup, regardless of whether the session had actually been saved. Fix: session_was_saved() gets its own jq-free branch (checked via `[ "$JQ" = "_jq_fallback" ]`) that reads last-save.json with one direct Python call carrying the session id as argv, mirroring $SAVED_QUERY's own isline semantics exactly (type, non-bool, finite, floor-equal). Every other $JQ/$JQ_BIN --arg call site under scripts/ already guards itself with `command -v jq` first, so this is the only call site that ever reached the fallback with --arg; teaching the generic shim a --arg parser would have been strictly more code for the same coverage. Tests: tests/test_jq_fallback_arg_667.py, paired negative ("saved" -> no re-save) and positive control ("not saved" -> re-save observed), each run with jq present and jq masked off PATH. Red before the fix: the jq-absent negative case spuriously observed a save-session.sh --force invocation; green after. Docs: changelog.d/667.fixed.md, and a one-paragraph note in docs/windows.md (not itself a docs_targets entry, but directly named by this issue and covering exactly the code path fixed here). Related to #660. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5 * Address self-review findings on #667: jq/Python parity, CRLF-safe test stub Two findings from the Explore + oss:auditor pass over 869a901: - Explore: the jq-free branch's `isinstance(sessions, dict)` guard silently fell through to the legacy `.session`/`.line` check whenever `sessions` was present but malformed (e.g. a list) -- whereas real jq's own `(.sessions // {})[$id]` throws a hard runtime error the instant `.sessions` is present but not an object, aborting the WHOLE `$SAVED_QUERY` program with no fallback. A corrupted `sessions` value sitting next to an otherwise-valid legacy `session`/`line` pair therefore read as "saved" on the new Python path but "unsaved" on real jq for the same file. Fixed with an explicit short-circuit matching jq's abort behaviour, pinned by a new parametrized test (test_a_malformed_sessions_shape_reads_as_unsaved_on_both_paths) run with jq present and jq absent both. - oss:auditor: the new test's save-session.sh stub was written via Path.write_text's default universal-newline translation, which turns every `\n` into `\r\n` on Windows -- a broken `#!/bin/bash\r` shebang under Git Bash/MSYS, the exact defect class tests/spawn_counting.py's own make_shim_dir already exists to avoid (#669/#670). Unlike a shimmed COUNTED tool, this stub has no same-named real binary on PATH to silently fall through to, so a corrupted shebang would fail loudly with a "bad interpreter" error and break the positive-control assertion on windows-latest for a reason unrelated to #667. Fixed by writing it with newline="" instead. Both findings were argued as worth fixing directly (mechanism stated, one-file blast radius, same subsystem as the original fix) rather than filed or logged to trap.d/. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5 --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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 #668. Part of #660.
What this does
Caches three of the four things #668 identified as recomputed on every SessionStart invocation, each validated by mtime (
-nt, never a tie -- FAT/exFAT's 2s granularity makes an equal mtime ambiguous, and ambiguous means miss, not hit):=== MEMORY ===section (six memory files headed/sized/concatenated, plus the rotated-slice listing) -- newscripts/lib-memory-context.shis the single source of truth for both the render and the cache.session-start-hook.shtries the cache first; on a miss it renders live while also leaving a fresh cache viatee(no double render).save-session.shandrun-consolidation.shrefresh it at the tail of their own already-detached (nohup ... & disown) runs.config()table (_RCFG_*,log.sh's_config_load) -- cached as sourceable%q-escaped assignments keyed on the three config layers' mtimes. Deliberately NOT a cache of the raw merged config.json, which can carry a livehaiku.oauth_tokenand is already a short-lived scratch file deleted at process exit -- both flatteners already drop the wholehaikukey before a row is ever emitted, so the persisted cache never sees it.detect-tools.sh) -- cached keyed on the exact$PATHstring under the system temp dir (REMEMBER_DIRis not known yet at this point in the source chain).Each cache independently disables via an env var (
REMEMBER_START_CACHE,REMEMBER_CONFIG_CACHE,REMEMBER_TOOLS_CACHE) for debugging.Scoping decision: slug caching (the 4th item) deliberately not implemented
session_dir_slugwas the fourth thing #668 named. Not done, on purpose:REMEMBER_DIRis already the one authoritative resolutionlib-env-cache.shcaches across hooks, and issue #158 (already in this codebase) explicitly bans a second, independently-computed resolution path forREMEMBER_DIRto avoid "split-brain memory." A parallel slug cache would reintroduce exactly that risk -- two caches that could each go stale independently and disagree about which project a slug belongs to -- for a comparatively small win (the slug's own marginal cost for SessionStart is at most one Windows-onlycygpathfork per process;REMEMBER_DIR's own resolution already has to run regardless, since #158 forbids a second resolver for it). Flagging this explicitly rather than silently under-delivering against the issue's own fix shape.Self-review found and fixed two real regressions
Two independent spawns (
Explore,oss:auditor) reviewed the first commit. Between them they found: a config-cache staleness bug triggered by a supportedREMEMBER_CONFIGoverride pattern this repo's own test suite uses in 59 files (reproduced, fixed by scoping the cache to the standard 3-layer merge's own mktemp naming); a collection-breaking regression where moving code out ofsession-start-hook.shorphaned a marker-based test extraction (pytestwent from running to 0-collected-1-error); two more tests broken the same way (a#247pin, an ordering pin); a code-duplication risk the auditor flagged against this repo's own #158 precedent (fixed by deduping); and a test-coverage gap on two explicitly security-relevant invariants (compact-mode cache isolation, the haiku-key exclusion) plus a missing positive control proving the symlink/ownership checks actually fire on all three caches. All fixed, all re-verified, plus a full localpytestrun (2360 passed, 0 failed) to confirm no further collateral damage -- full detail and the verbatim reviewer exchange is in the developer note this lane wrote alongside this report.Windows claim: reasoned, not observed
No Windows host available to this lane. The mechanism removed -- subprocess forks on a warm run -- is exactly the lever #660's own report named as the multiplier under Git Bash (~50-200ms/spawn there vs ~1-5ms on macOS/Linux); this PR has no independent Windows measurement confirming the resulting wall-clock effect, only the subprocess-count reduction, measured on macOS.
🤖 Generated with Claude Code
https://claude.ai/code/session_01ScdCn6Xq622o2cRQhzVhi5
[AI-generated]