Skip to content

Keep a decision linked when a document rewrite leaves its text unchanged - #664

Merged
lavaman131 merged 1 commit into
mainfrom
keep-unchanged-decision-links
Oct 17, 2026
Merged

lavaman131 merged 1 commit into
mainfrom
keep-unchanged-decision-links

Conversation

@lavaman131

Copy link
Copy Markdown
Collaborator

What was wrong

A whole-document rewrite through MCP update_document (Plan.rewrite) called Questions.invalidate(..., "plan_changed"), which set pending: true on every answered decision's link, even when the blocks the link pointed at were unchanged. Only a Planner turn's anchor_plan clears pending. MCP has no tool for it, and the automatic re-link turn runs only after a build. As a result, answered Decision cards showed "Not linked yet" and lost "Show in document" after any later rewrite. A hosted end-to-end run found this.

Change

Plan.rewrite now takes a snapshot of each decision's links before it replaces the document. After the replace, a link stays reviewed only when all of these hold:

  • it was reviewed before the rewrite,
  • it points at one or more blocks, and
  • every one of those blocks still exists with the same digest.

Every other link still goes back to waiting for review, as before. That covers a link whose text changed, a link whose text was removed (it still shows "Related text was removed"), a link that was already waiting for review, and a decision that was deliberately left unlinked. edit_plan and comments are unchanged, and so is the connector. The MCP guide now says what happens to decision links after an update.

Tests

  • apps/server/src/questions/rewrite-links.test.ts:
    • A rewrite that edits only an unrelated block keeps the link reviewed, including after the document is reopened from storage. This test failed before the fix.
    • Editing the linked block makes the link wait for review.
    • Changing or removing either block of a link that points at two blocks makes it wait for review. Removing one leaves that anchor orphaned.
    • A link already waiting for review stays that way, and so does a deliberately unlinked decision.
  • e2e/mcp-update.e2e.ts: an answered, linked card still offers "Show in document" after an MCP rewrite of other text, including after a reload. This test failed before the fix: the card showed "Not linked yet".

Run locally: bun test apps/server packages apps/web, bun run types, bun run ci, and the mcp-update, sidecar-card-states, decision-marker, decision-anchor-stress and sidecar browser suites (83 passed).

A whole-document rewrite through MCP update_document marked every answered
decision's link as waiting for review, even when the blocks it pointed at were
unchanged. Only a Planner turn's anchor_plan clears that state, MCP has no tool
for it, and the automatic re-link turn runs only after a build, so answered
Decision cards showed "Not linked yet" and lost "Show in document" after any
later rewrite.

A rewrite now keeps a link reviewed when it was reviewed before, points at one
or more blocks, and every one of those blocks still exists with the same
digest. A link whose text changed or was removed, one already waiting for
review, and a deliberately unlinked decision wait for review as before.
edit_plan is unchanged.

Assistant-model: Claude Opus 5.5 (fast)
Assistant-workflow: inline (fast subagents)
Assistant-verification: red-before-fix: rewrite-links.test.ts "a rewrite that leaves a decision's blocks alone keeps its link reviewed" failed on the unfixed server (pending true); mcp-update.e2e.ts "an MCP rewrite of other prose keeps a linked decision's way to the document" failed on the unfixed server (the card showed "Not linked yet")
Assistant-verification: after fix: bun test apps/server packages apps/web passed (5779 pass, 0 fail); bun run types and bun run ci passed; mcp-update, sidecar-card-states, decision-marker, decision-anchor-stress and sidecar e2e passed (83)
Co-authored-by: Alex Lavaee <alexlavaee@microsoft.com>
@lavaman131 lavaman131 self-assigned this Oct 17, 2026
@lavaman131
lavaman131 merged commit 4b3e099 into main Oct 17, 2026
46 of 48 checks passed
@lavaman131
lavaman131 deleted the keep-unchanged-decision-links branch October 17, 2026 00:47
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