Skip to content

fix(scopeuse): narrow F2 from the bare substring to the cache-root path - #313

Closed
ZacxDev wants to merge 3 commits into
mainfrom
fix/f2-cache-root-scope
Closed

ZacxDev wants to merge 3 commits into
mainfrom
fix/f2-cache-root-scope

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Why

Re-census 2026-11-11: in the fresh handoff-writer cohort, all 13 * sessions got * from the derived set, none from the ledger. The inputs that set off F2 were mostly named reads of one cache file (sed -n … ~/.cache/subsystem-store/<scope>/x.md). The rest were not cache reads at all: a kubectl -n subsystem-store namespace flag, a script named …-subsystem-store-….sh, a repo path …/apps/subsystem-store/…, and ~/.config/subsystem-store/. The operator chose "narrow F2 to the cache-root path; stay fail-closed".

The rule (eachCacheRead in internal/transcript/scopeuse/scopeuse.go)

Each subsystem-store (case-insensitive) in a tool input is checked as a path name:

  • Named read: adds the scope. The parent component contains cache (~/.cache, /home/<u>/.cache, $HOME/.cache, "${HOME}/.cache", $XDG_CACHE_HOME, ${XDG_CACHE_HOME:-…}). There is no -<alias> suffix. A / follows the root. The next component (up to / or a shell separator) passes ValidScope. The input has no .. path component and no cd/pushd into the cache.
  • Adds * (fail-closed): every other cache root:
    • the bare root (S=~/.cache/subsystem-store;, ls ~/.cache/subsystem-store)
    • a glob, $VAR, {a,b}, quoted, empty or dotted component
    • another instance's subsystem-store-<alias>
    • .new-… staging siblings
    • a relative subsystem-store/…, ./subsystem-store/…
    • a root whose parent is neither a cache nor a plain literal word ($C/subsystem-store, "$C"/subsystem-store). An unrecognised spelling is * and never counts as "not a cache".
  • Adds nothing:
    • a longer word (check-subsystem-store-x.sh, subsystem-stores)
    • a parent that is a plain literal non-cache word (apps/, .config/, deploy/)
    • a bare word with no / after it (-n subsystem-store)
    • the subsystem-store[-alias].lock sibling

The named scopes are folded into R_header, as R_memo already is. The capture agent (Declare/V, Evidence round-trip) and the pod's re-derivation (archive.go, which unions res.Headers) therefore both carry them with no change at either call site. F2 now means "F2 contributed *".

Instances (requirement 3)

Derived scopes are bare names. capture.DecideRun routes each one by routing.AliasFor(scope), and nothing carries (instance, scope). So a named read under subsystem-store-<alias>/<scope>/ cannot be attributed: routing would send that scope by name to whichever instance the table names. Every non-default-instance cache path therefore fails closed to *. This is deliberate and pinned by test and mutant. The cross-instance * from #308 is unchanged.

Not seen (T3, in the package doc)

  • A variable or cwd set in an earlier call ($S/notes1/x.md). The call that sets a bare root or cds into the cache is itself *. A call that sets S=…/subsystem-store/notes1 adds only notes1, and a later $S/../alpha is not seen.
  • A bare relative subsystem-store with no / (it looks the same as the namespace).
  • A copy under a literal non-cache parent.
  • Symlinks.

The client does not honour XDG_CACHE_HOME for the store cache (client.DefaultCacheRoot is $HOME/.cache/subsystem-store; the Python oracle matches). The XDG spellings are caught only to fail closed. TestCacheScopesMatchesTheClientsCacheRoot checks the parser against client.CacheRootFor.

Existing data

names_cache evidence and V/Derived are grow-only, so sessions already marked * stay *. The fix applies to sessions derived from now on.

Tests

f2_test.go has literal tables for every case, with pairwise-distinct scope names. The F2 fixture test is now TestF2CacheReadAddsItsScope ([alpha-notes], was [*]).

Red at origin/main (d000023) / green at HEAD. For base, a test-only adapter maps CacheScopes(s) to base's F2 answer ([*] if ToolInput set F2, else none):

test base HEAD
TestF2NamedCacheReadAddsThatScope FAIL (17 assertions) ok
TestF2NonCachePathsAddNothing FAIL (18) ok
TestF2CacheReadAddsItsScope (fixture) FAIL ok
TestCacheScopesMatchesTheClientsCacheRoot FAIL ok
TestCacheScopesIsLinear FAIL (answer: alias run gave [*]) ok
TestF2UnattributableCacheReadAddsStar ok (invariant guard: base was already *) ok

TestCacheScopesIsLinear also caught a real quadratic in an intermediate version of this PR: 52.6 s on a 2 MiB subsystem-store- run. After the fix the same run takes 0.44 ms, about 8× growth for 8× the input.

Mutants. Rows are in tests/control_mutants.py. Each was run with --only and is KILLED, positive control GREEN:

  • scopeuse-cache-path-read-ignored (re-pointed): killed by TestF2CacheReadAddsItsScope (+ Named, Unattributable)
  • scopeuse-f2-bare-substring (a): Named (F2=true V=[* ember_7]), plus NonCache and the fixture test
  • scopeuse-f2-bare-root-not-star (b): Unattributable. The bare-root rows return [] and the Deriver assertion fails: bare root: F2=false V=[] Declare=[]
  • scopeuse-f2-component-not-validated (c): Unattributable (bad.name1, {alder1,birch1}, no"tes1", .sync-stamp, $SC1 were each taken as a scope)
  • scopeuse-f2-other-instance-scope-trusted: Unattributable (other-instance rows), plus ClientsCacheRoot
  • scopeuse-f2-unknown-parent-not-a-cache: Unattributable ($C/… rows)

Hand-run extras, not in the battery: turning off the .. check, turning off the cd check, or both, each turns Unattributable red. Widening .. to "anywhere" or cd to "any cd" turns Named red through the main..HEAD / cd /work/repo controls.

Run locally: go test + go vet on ./internal/transcript/scopeuse/... ./internal/capture/... ./internal/transcript/archive/..., all ok. Whole suite left to CI.

A second commit replaces real identifiers in the fixtures with synthetic names, after the first CI run's leakscan refused them. leakscan was run locally afterwards: 0 findings, controls PASS.

Also updated claudedocs/plan-cairn-plugins.md: a dated note under the F2 definition, superseding O18's "F2 is not narrowed".

🤖 Generated with Claude Code

ZacxDev and others added 3 commits November 11, 2026 11:17
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
F2 made a session owner-only (`*`) whenever any tool input contained
`subsystem-store`. The 2026-11-11 re-census found all 13 derived-`*`
sessions in the fresh cohort got it from F2, overwhelmingly from named
reads of one cache file, plus false positives that are not cache reads at
all (a kubectl namespace, a repo path, a script name, ~/.config/...).

Now a tool input naming `<...cache...>/subsystem-store/<valid scope>/...`
adds THAT scope (folded into R_header, so the capture agent and the pod's
re-derivation both carry it through the existing paths). Still `*`: the
bare root, an invalid/glob/$VAR component, another instance's
`subsystem-store-<alias>` root (derived scopes carry no instance), a sync
staging sibling, a relative root, a root under an unreadable parent
spelling (`$C/subsystem-store`), and any input with a `..` component or a
`cd` into the cache. Adds nothing: a non-cache mention (namespace, literal
repo/config parent, longer word, the `.lock` sibling).

Tests: f2_test.go (named, fail-closed, non-cache tables; the client's own
CacheRootFor; a linearity test that caught a 52 s quadratic in an
intermediate version). Mutant battery: the F2 row is re-pointed and five
rows added (bare-substring, bare-root-not-star, component-not-validated,
other-instance-scope-trusted, unknown-parent-not-a-cache), each KILLED.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
leakscan refused 8 denied identifiers (real project, cluster and host
names) in the new F2 tests and doc comment. Replaced with synthetic ones;
no behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #314 (same final tree, single commit).

@ZacxDev ZacxDev closed this Nov 11, 2026
@ZacxDev
ZacxDev deleted the fix/f2-cache-root-scope branch November 11, 2026 18:13
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.

1 participant