Skip to content

fix(context_for_task): detect each directory's project once per call - #665

Merged
atlas-from-plumb merged 2 commits into
mainfrom
atlas/context-detect-memo
Oct 14, 2026
Merged

atlas-from-plumb merged 2 commits into
mainfrom
atlas/context-detect-memo

Conversation

@atlas-from-plumb

Copy link
Copy Markdown
Collaborator

What

After #663 a pack asks the sensitive-path decision once per distinct file, which is 100 to 250 files. Each ask still resolves the file's project with workspacePool.Detect, which globs for markers on disk. On the live daemon the slowest arm R pack (R05) still runs at 1.6–1.9 s of its 2 s graph deadline. In a baseline taken today on fa1fd85, a second pack (R08) was cut in 2 of 5 reps, losing its affected tests.

The files of one directory resolve to the same project, so within one call this PR detects each directory once.

  • tools.CallMemo: a small lookup memo carried on the call's context. Collect attaches a fresh one on every call; a nil memo runs every lookup.
  • historyRootFor (cli): detects through the memo. Outside a context_for_task call, which covers every write, there is no memo, so detection runs on every ask exactly as before.
  • changeSensitive stays the one decision. History and the response gate still share it.
  • workspaceFromArgs is split into detectStartDir and detectedRoot, with identical behaviour; its existing tests pin it.

Because the memo lives on the call's context, it can't outlive a call, and a marker created between two calls is seen by the second.

Tests

  • TestCallMemo_RemembersPerKeyAndNilRemembersNothing: one lookup per key, and a nil memo looks up on every ask.
  • TestContextForTask_SensitiveAsksShareOneMemoPerCall: every ask in one call carries the same memo, and the next call gets a fresh one.
  • TestHistoryRootFor_DetectsEachDirectoryOncePerContextCall:
    • a marker created part-way through a call is not detected again in that call, which proves the second ask reused the first detection;
    • the next call sees the marker;
    • so does an ask outside a call.
  • TestChangeSensitive_CallMemoKeepsEveryVerdict: each case is asked twice in a call and must give the same verdict as without the memo. Cases cover an ordinary file, a default glob, a project's own glob, the same name where no glob applies, and a move out of another project's file that is sensitive only by that project's glob. Controls require both verdicts to appear and the cross-project case to be sensitive.

Mutation (plumb mutation_test): all 7 valid mutants are killed:

  • Collect attaches no memo;
  • Once never stores;
  • a nil memo returns empty;
  • historyRootFor ignores the memo;
  • the memo uses one constant key, which leaks a verdict across directories;
  • detectStartDir always takes the parent (killed by the existing workspaceFromArgs and attribution tests);
  • historyRootFor bypasses the memo by passing a context with none.

Measure

A live replay on the installed build after merge, with per-pack latency, to show R05 well under 1.5 s and no cuts under sample. Baseline on fa1fd85 (5 reps): R01 0.36–0.42 s, R03 0.64–0.75 s, R05 1.58–1.66 s, R08 1.05–2.09 s with 2 of 5 cut.

Verification

make verify-full-container: result to follow in a comment. Review: a peer agent (warm-cobra), who filed PLAN-548.

🤖 Generated with Claude Code

atlas-from-plumb and others added 2 commits October 14, 2026 19:25
…(PLAN-548)

After #663's per-file memo, a pack still asked the daemon's sensitive-path
decision about each of its 100-250 distinct files, and each ask resolved the
file's project with workspacePool.Detect, globbing for markers on disk. On the
live daemon the slowest arm R pack ran at 1.6-1.9 s of its 2 s graph deadline,
and another was cut in 2 of 5 reps.

Collect now attaches a tools.CallMemo to the call's context. historyRootFor
reads it and detects each directory once for that call. The memo is fresh per
call, so a marker created between two calls is seen by the second, and writes,
which never carry one, detect on every ask as before. changeSensitive stays the
one decision; workspaceFromArgs is split into detectStartDir and detectedRoot
with identical behaviour.

Tests:
- one memo per call, and a fresh one for the next call;
- a marker created mid-call is not re-detected, but the next call and an ask
  outside a call both see it;
- changeSensitive gives the same verdict with and without the memo, including
  a source in another project that is sensitive only by that project's glob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plumb-Session: scarlet-badger
Review NIT on #665: a second kind of lookup through the same memo would share
its key space with directories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plumb-Session: scarlet-badger

@golimpio golimpio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved under the delegated merge bar, on head bdff688:

  • independent review by a peer agent (warm-cobra): PASS on 1204833; its NIT is folded in as bdff688, a comment-only change;
  • CI 9/9 green on this head;
  • make verify-full-container exited 0 on this head;
  • plumb mutation_test: 7/7 valid mutants killed.

@atlas-from-plumb
atlas-from-plumb merged commit fdf5639 into main Oct 14, 2026
9 checks passed
@atlas-from-plumb
atlas-from-plumb deleted the atlas/context-detect-memo branch October 14, 2026 08:58
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.

2 participants