Skip to content

Guard the compact-mode deferred-file list with the injection check (#777) - #790

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/777
Sep 26, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/777

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #777

What

The compact-mode deferred-file loop in scripts/lib-memory-context.sh never called the injection guard _remember_may_inject before listing a file as deferred. Because the main (non-compact) injection loop skips every non-identity file at source=compact before it ever reaches the guard, the guard ran on zero non-identity files during compact -- so a git-tracked or symlinked memory file (exactly what the guard exists to refuse) was still listed under the deferred header, falsely claiming it had been delivered at session start, with its path printed as an invitation to read the refused content via a follow-up tool call.

Fix

Call _remember_may_inject inside the deferred loop as well, and list a refused file under its own header (refused, would have been listed as deferred (not injected)) instead of the deferred one.

Tests

New file tests/test_compact_deferred_guard_777.py, 3 cases: tracked file not listed as deferred, symlinked file not listed as deferred, untracked file still listed as deferred (positive control). Red before the fix: 2 failed, 1 passed (both negative cases failed, the positive control already passed). Green after: 3 passed. Adjacent suites (test_injection_guard_754_755_756.py, test_session_start_compact_recap_339.py) re-run alongside, 42 passed, 0 failed.

Self-review

Two independent reviewers (Explore, oss:auditor) both found the same single finding: the new refusal block initially shared its header text with the main loop's own pre-existing refusal header, which could let a reader or downstream parser merge or misattribute the two populations when both blocks co-occur in one compact-mode render. Ranked low-severity/misreports, non-blocking, by both -- fixed directly in a follow-up commit by giving the deferred-loop's refusal a distinct header text.

Adjacent (not fixed here, out of scope)

A sibling instance of the same bug shape exists in the same function's rotated-slices block (prints file paths under a "rotated memory slices" header with no guard call at all), but it is not gated by compact mode and is a different code path -- out of #777's stated scope. Needs its own issue.

Full suite

The full pytest suite was deliberately not run locally (targeted plus adjacent suites only, per this repo's own developer guidance); CI's cross-platform matrix is the gate of record.

[AI-generated]

fdaviddpt and others added 2 commits September 26, 2026 13:59
…on check

The deferred-file loop that lists which memory files were "delivered at
session start; read or grep on request" at source=compact never called
`_remember_may_inject` before adding a file to that list. Since the main
injection loop already skips every non-identity file at source=compact
before it ever reaches the guard call, that meant a git-tracked or
symlinked memory file -- exactly the kind session start itself refuses to
inject -- was still listed under a header falsely claiming it had been
delivered, with its path printed right below, inviting a follow-up read of
the refused (and possibly planted) content.

The deferred loop now runs the same guard the main loop already applies; a
refused file is listed under the existing "refused (not injected)" header
instead, reusing the vocabulary the main loop already uses for the same
refusal.

Adds tests/test_compact_deferred_guard_777.py (red before, green after --
2 failed/1 passed before the fix, 3 passed after), a changelog.d/777.fixed.md
fragment, and a docs/windows-skip-triage.md row for the new blanket win32
skip the test file carries (same shape/reason as
tests/test_injection_guard_754_755_756.py, which it borrows its fixtures
from).

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

Self-review finding (Explore reviewer and oss:auditor, same finding
independently): the previous commit reused the main injection loop's
"--- refused (not injected) ---" header verbatim for the new compact-mode
deferred-loop refusal. Both loops can fire refusals in the same compact
render (the main loop only reaches the guard for IDENTITY_FILE at compact;
the new loop covers every other file), so the identical header let the two
populations be merged or misattributed by a reader, or by anything parsing
this output by header text rather than by sequence. Ranked non-blocking
(cosmetic) by both reviewers; fixed directly since it is a one-line,
same-subsystem, testable change to code this diff already owns.

The deferred-loop refusal now prints under its own
"--- refused, would have been listed as deferred (not injected) ---"
header. Updated changelog.d/777.fixed.md to describe the actual header
text; tests/test_compact_deferred_guard_777.py's own assertions were
already header-agnostic (they check the deferred SECTION specifically, via
_deferred_section()) so they needed no change -- 42/42 passed, including
the full test_injection_guard_754_755_756.py and
test_session_start_compact_recap_339.py suites, after this commit.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

Compact-mode deferred list advertises memory files the injection guard already refused

1 participant