Skip to content

fix(agent): keep a nested directory's instructions after its read shrinks - #428

Merged
mrnasil merged 1 commit into
mainfrom
fix/nested-instructions-survive-pruning
Nov 7, 2026
Merged

mrnasil merged 1 commit into
mainfrom
fix/nested-instructions-survive-pruning

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 7, 2026

Copy link
Copy Markdown
Member

Found in the context audit for the token-efficiency series (#418–#427).

Problem

The first read into a nested directory (for example pkg/ in a monorepo) appended that directory's AGENTS.md and siblings to the end of the read's tool result. A few steps later the per-step passes shrink old results: spill keeps a 400-char head plus a pointer, and prune keeps the first 2 KiB. Either way the instructions at the tail were cut off. Each directory is attached only once per session (instruction_dirs), so they never came back, and the agent stopped following the package's rules partway through the work.

Change

The instructions now go into one agent note right after the step's results (nested_instructions_for). Agent notes are never spilled, pruned or shaken, so the rules stay until compaction. Appending after the results keeps the cached prefix byte-stable, as before. The size cap (MAX_NESTED_BYTES) and the once-per-directory rule are unchanged.

Checks

  • a_read_below_the_project_attaches_that_directory_s_agents_md_once now asserts:
    • the read result itself is clean;
    • exactly one note follows r1, and none follows r2;
    • the note survives repeated prune passes.
  • whycodes-agent --lib 764 passed; clippy is ok. Local llvm-cov: every changed line is covered.
  • docs/internals/turn-loop.md §11 and the prompt-cache.md break table are updated.

Note: #418 also touches turn.rs (the recovery note just below this hunk). Whichever merges second needs a trivial rebase.

🤖 Generated with Claude Code

…inks

The first `read` into a nested directory appended that directory's
`AGENTS.md` (and siblings) to the end of the read's result. A few steps
later spill keeps 400 chars of an old result and prune keeps 2 KiB from
its head, so the instructions were cut off, and since each directory is
attached once per session they never came back: the agent stopped
following the package's rules partway through the work.

The instructions now go into one agent note right after the step's
results. Agent notes are never spilled or pruned, so the rules stay until
compaction, and appending after the results keeps the cached prefix
stable as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil force-pushed the fix/nested-instructions-survive-pruning branch from 0b6d099 to cc4d040 Compare November 7, 2026 14:41
@mrnasil
mrnasil merged commit 3cec8cd into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/nested-instructions-survive-pruning branch November 7, 2026 14:49
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