Skip to content

fix(memory): skip background-task-result blocks in the extraction window - #9

Merged
RowitZou merged 1 commit into
mainfrom
feature/extract-skip-bg-result
May 20, 2026
Merged

fix(memory): skip background-task-result blocks in the extraction window#9
RowitZou merged 1 commit into
mainfrom
feature/extract-skip-bg-result

Conversation

@RowitZou

Copy link
Copy Markdown
Owner

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 the memoryExtractor prompt. 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's afterEndTurn extraction then sees the same block and re-extracts the finding into the user-level root (L1) — and cannot dedup it, because collectExistingMemoriesForRole(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

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 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

  • New extract.test.ts case: buildExtractPrompt strips a <background-task-result> block (inner finding gone, marker present) while keeping the manager's surrounding turn.
  • The extract.test.ts JSON-ban regression guard is unaffected.
  • pnpm typecheck clean; pnpm test 1463/1463 pass.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings May 20, 2026 09:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@RowitZou
RowitZou merged commit c84edb4 into main May 20, 2026
1 check passed
@RowitZou
RowitZou deleted the feature/extract-skip-bg-result branch May 20, 2026 09:44
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