Skip to content

fix(tasks): keep board snapshots whose anchors survive compaction - #1458

Merged
alvinunreal merged 2 commits into
alvinunreal:masterfrom
drakeo338:claude/1457-fix
Oct 6, 2026
Merged

alvinunreal merged 2 commits into
alvinunreal:masterfrom
drakeo338:claude/1457-fix

Conversation

@drakeo338

@drakeo338 drakeo338 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1457

With backgroundJobs.strategy: "checkpoint-compatible", a shorter message list after a Magic Context compaction made updateBoardHistoryState delete all retained board snapshots, including ones whose anchor messages were still present, which busted the prompt cache a second time. It now drops only snapshots whose anchors are gone and deletes the state only when none survive. Added a regression test that fails on the base commit and passes with the change; biome check and typecheck pass.

Snapshots anchored to anonymous messages (no id) are not retained, because their occurrence-index key can point at a different message after pruning.

updateBoardHistoryState dropped the whole retained board state whenever
compaction was detected, starting a new epoch and sequence and busting the
prompt cache for snapshots whose anchor messages were still present. Keep
the snapshots whose anchors survive, and delete the state only when none do.

Fixes alvinunreal#1457
@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes how board snapshots survive message compaction.

The PR should not merge until partial pruning handles duplicate anonymous anchors without replaying a removed message’s snapshot.

Findings

  1. P1 Anonymous anchors can shift ▶
  2. P2 Test misses prompt changes ▶

Summary

The PR retains checkpoint-compatible board snapshots whose anchors remain after compaction and adds a regression test for partial history removal.

  • The retention check can mistake a surviving anonymous message for a removed, identical one.
  • The new test checks snapshot IDs but not the provider-visible prefix or placement.

Reviews (1) · Last reviewed commit: "fix(tasks): keep board snapshots whose a..."

Comment on lines +2064 to +2066
previous.snapshots = previous.snapshots.filter((snapshot) =>
currentAnchorKeys.includes(snapshot.anchorKey),
);

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.

P1 Anonymous anchors can shift If compaction removes the first of two identical messages without an ID, the surviving message takes the removed message’s anchor key. This filter then keeps the removed message’s board snapshot and replays it after the wrong message, while dropping the survivor’s snapshot. The compacted prompt can show stale board content and lose the cache reuse this change aims to preserve.

Knowledge Base Used: Task sessions and background jobs

Comment on lines +554 to +568
const boardIDs = (r: TurnResult) =>
summarizeInjected(r.injected as never).filter((s) =>
s.startsWith('BOARD('),
);
expect(boardIDs(before).length).toBe(3);

// Compaction: the oldest messages disappear, later anchors remain.
const compacted = history.slice(2);
const after = await runTurn(hook, compacted);

// Snapshots anchored on surviving messages must be replayed unchanged
// (same id, so same epoch and sequence), not purged into a new epoch.
const surviving = boardIDs(before).slice(1);
expect(boardIDs(after)).toEqual(surviving);
}, 20_000);

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.

P2 Test misses prompt changes This assertion checks board snapshot IDs but not their text or position among real messages. A snapshot could keep its ID while changing the provider-visible prompt or moving to the wrong anchor, and the test would still pass. Comparing the provider-visible payload and snapshot positions would make this regression test cover those cache failures.

Knowledge Base Used: Task sessions and background jobs

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Anonymous anchor keys use an occurrence index, so pruning a duplicate
anonymous message made the survivor inherit the removed message's key.
Retain only id-backed anchors, and extend the test to cover the
provider-visible prefix plus the anonymous-duplicate case.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: drakeo338 <[email protected]>
@alvinunreal
alvinunreal merged commit 0abc679 into alvinunreal:master Oct 6, 2026
4 checks passed
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.

[Bug]: checkpoint-compatible boards are purged after every Magic Context compaction, busting the prompt cache a second time

2 participants