Skip to content

fix(#774,#775): quote-safe git-ls-files tracked-path compare; version-stamp the start-context cache - #779

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/774
Sep 25, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/774

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What changed

#774 -- The shared injection guard's tracked-file check (_remember_root_tracked_state_into /
_remember_file_tracked_state_into in scripts/lib-memory-context.sh) compared git ls-files
output against a raw relative path. git ls-files quotes and octal-escapes any non-ASCII byte in a
path whenever core.quotePath is on (the default everywhere), so a tracked path running through a
non-ASCII directory name never matched the raw comparison and was injected instead of refused.
Fixed by adding -c core.quotePath=false to both ls-files invocations.

Self-review on that first fix (two independent spawns, an Explore subagent and oss:auditor, both
against agents/developer/review.md and its own checklist) found the fix incomplete:
core.quotePath=false only covers non-ASCII bytes, but git ls-files C-quotes a literal
backslash, double quote, or control byte in a path unconditionally, and the same literal-string
comparison bypass still let those through. Follow-up fix: a new _remember_git_unquote_into
helper unquotes each ls-files line (printf '%b' after stripping the C-quote wrapper) before the
comparison runs.

#775 -- The start-context cache (_remember_start_cache_context_load) never consults the
injection guard on a cache hit, and its manifest previously invalidated only on source-file mtime,
which an upgrade to the guard does not change. A cache published before the guard existed, or
before a later guard fix, could keep replaying content the current guard would refuse. Fixed by
adding _REMEMBER_CACHE_FORMAT_VERSION, written as a VERSION= line in the manifest and checked
by the loader; a missing (pre-fix shape) or mismatched stamp is now always a miss, additive to the
existing mtime checks.

Closes #774
Closes #775

Tests

Both issues were watched red before their fix and green after:

  • tests/test_injection_guard_754_755_756.py::TestNonAsciiTrackedPathBypassesGuard -- red via
    git stash push -- scripts/lib-memory-context.sh then re-running (failed for the right reason:
    assert 'PLANTED-BY-REPO' not in out); green after the quotePath=false fix. Includes a positive
    untracked-file control.
  • tests/test_injection_guard_754_755_756.py::TestQuotedSpecialCharacterTrackedPathBypassesGuard
    (added during self-review) -- same red/green shape for a tracked path with a literal backslash in
    a directory name; green after the unquote fix. Includes the same positive control.
  • tests/test_start_context_cache_668.py::test_manifest_without_a_version_stamp_is_a_miss -- red
    via a hand-built pre-fix-shape manifest (SRC= lines only, no VERSION=), observed as a served
    cache hit (load.returncode == 0) before the fix; green (== 1) after.

Full-file runs after both fixes: tests/test_injection_guard_754_755_756.py 19 passed,
tests/test_start_context_cache_668.py 7 passed. Also ran .oss/assemble_changelog.py --check
(12 fragments, ok) and lane_setup.py --lane against all three touched files (all three
CROSS_CUTTING_GUARDS rows report no additional guard tests exist in this repo). Full repository-wide
pytest was not run locally, per this repo's policy that CI (3 OSes, 4 interpreters) is the gate.

Cross-platform

The quotePath=false and unquote fixes are reasoned, not separately observed, to behave the same on
all three CI legs' bash where bash exists.

The new regression tests for #774/#775 are skipped on windows-latest because the whole test file
already carries a pre-existing blanket win32 skip (#79); this is an existing convention, not
something this diff weakens.

Docs

README.md was checked (grepped for injection-guard/tracked-file/cache-manifest terminology,
zero hits) -- it documents nothing about this internal guard/cache mechanism, so no doc change is
needed.

[AI-generated]

fdaviddpt and others added 2 commits September 26, 2026 00:15
…context cache

#774: the injection guard's tracked-file check listed the repository
with a plain `git ls-files`, which quotes/octal-escapes non-ASCII path
bytes (core.quotePath, on by default), then compared that line against
a raw, unquoted relative path. A tracked memory file whose path ran
through a non-ASCII directory never matched, so the guard answered
"not tracked" and injected it. Both `ls-files` invocations now run with
`-c core.quotePath=false`.

#775: the start-context cache's manifest invalidated only on source
mtime, so upgrading past a change to the injection guard did not
invalidate a cache that already held bytes rendered before that guard
existed (the cache-hit path never consults the guard). The manifest now
carries a VERSION= stamp (_REMEMBER_CACHE_FORMAT_VERSION); a manifest
missing it or naming a different version is always a miss, additive to
the existing mtime check.

Both fixes are red-before/green-after with a new regression test each
(TestNonAsciiTrackedPathBypassesGuard, test_manifest_without_a_version_stamp_is_a_miss).

Closes #774
Closes #775

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…n-ASCII

Self-review on the previous commit (both the Explore reviewer and
oss:auditor independently found the same gap) showed `-c
core.quotePath=false` only stops git from quoting non-ASCII bytes; a
literal backslash, double quote, or control byte in a tracked path is
still C-quoted by `git ls-files` unconditionally, so the guard's literal
string comparison still silently answered "not tracked" for those
characters -- the same bypass #774 closed for non-ASCII, still open for
this narrower class.

Added `_remember_git_unquote_into`, which strips a `ls-files` C-quoted
wrapper and expands its escape set via `printf '%b'`, and wired it into
the comparison in `_remember_file_tracked_state_into`. New regression
test class `TestQuotedSpecialCharacterTrackedPathBypassesGuard` (tracked
backslash-directory path refused; untracked positive control still
delivered), red before this fix, green after.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 152f674 into main Sep 25, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/774 branch September 25, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant