fix(memory): skip background-task-result blocks in the extraction window - #9
Merged
Merged
Conversation
Bug 3 from the 2026-05-20 dogfood had three parts; the prompt PR (ce8ef67) fixed transient snapshots and role-name filenames. This closes the third: cross-layer duplication. When a background dispatch completes, its deliverable is injected into the manager's prompt as a <background-task-result> block. The worker that produced it has already run its own extraction over its fork transcript (into its role-private L3). The manager's afterEndTurn extraction then sees the same block and re-extracts the finding into the user-level root — and cannot dedup it, because the manager's existing-memories list does not include worker L3 dirs. The dogfood saw one PKM research topic land 3 copies in the user root on top of the worker's own L3 entries. buildExtractPrompt now runs stripBackgroundResultBlocks over the rendered conversation text: each <background-task-result>…</background-task-result> span is replaced with a one-line marker. The manager's own assistant messages — its synthesis and reactions — are untouched and still extracted. Applies to every extraction (manager and worker), so a worker that itself received a sub-dispatch result also won't re-extract it. The remaining same-topic copies across role-private L3 dirs are by design (per-role extraction) and are the curator's job to reconcile — Bug 4's fix restored the curator so that path works again. New test in extract.test.ts. typecheck clean, 1463/1463 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes cross-layer memory duplication caused by <background-task-result>...</background-task-result> blocks being re-ingested by the manager’s extraction pass after a background dispatch completes. It prevents the manager (and any worker) from re-extracting the worker’s raw deliverable by stripping these blocks from the extraction window while keeping surrounding conversation context.
Changes:
- Add
stripBackgroundResultBlocks()to replace<background-task-result>...</background-task-result>spans with a single-line omission marker. - Apply the stripping step inside
buildExtractPrompt()before truncating the extraction window. - Add a regression test ensuring the block contents are removed while surrounding turns remain.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/memory/extract.ts |
Strips <background-task-result> blocks from the conversation text used for memory extraction to avoid cross-layer duplication. |
src/memory/extract.test.ts |
Adds a test case asserting background-result blocks are removed from the extract prompt while adjacent user content remains. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Bug 3 from the 2026-05-20 dogfood had three parts. PR #8 (
ce8ef67) fixed the transient-snapshot and role-name-filename symptoms via thememoryExtractorprompt. This PR closes the third — cross-layer duplication — which is a code issue, not a prompt one.When a background dispatch completes, its deliverable is injected into the manager's prompt as a
<background-task-result>block. The worker that produced it has already run its own extraction over its fork transcript (into its role-private L3). The manager'safterEndTurnextraction then sees the same block and re-extracts the finding into the user-level root (L1) — and cannot dedup it, becausecollectExistingMemoriesForRole(main)only covers L1 +_shared, not worker L3. The dogfood saw one "AI Agent PKM" research topic land 3 copies in the user root, on top of the worker's own L3 entries.Fix
buildExtractPromptnow runsstripBackgroundResultBlocksover the rendered conversation text: each<background-task-result>…</background-task-result>span is replaced with a one-line marker. The manager's own assistant messages — its synthesis and reactions to the result — are untouched and still extracted; only the worker's raw deliverable is dropped.It applies to every extraction (manager and worker), so a worker that itself received a sub-dispatch result also won't re-extract it.
Scope
The remaining same-topic copies across role-private L3 dirs (e.g.
generalist/+webSearcher/both holding a PKM note) are by design — per-role extraction is intentional, and reconciling those is the curator's job. Bug 4's fix (536ba51) restored the curator's runtime + throttle so that path works again; the historical 113-file backlog will be consolidated once it runs.This is the last of the Bug 3 / Bug 4 chain. No prompt strings changed.
Testing
extract.test.tscase:buildExtractPromptstrips a<background-task-result>block (inner finding gone, marker present) while keeping the manager's surrounding turn.extract.test.tsJSON-ban regression guard is unaffected.pnpm typecheckclean;pnpm test1463/1463 pass.🤖 Generated with Claude Code