Repository navigation
CONTRACT: fix(ui-server): version a kept draft when an acceptance releases its snapshot (#3733) - #4068
Merged
Conversation
…eases its snapshot (#3733) An acceptance that released a snapshot but kept the draft (a newer revision exists, or the draft changed chats) rewrote outgoing_snapshots without moving the revision. A tab or device that read the draft before the acceptance could then save its old list under its If-Match, and the sent snapshot came back as a new dispatched one: it held a slot of the chat's ten and its files went back to outgoing. The kept draft now moves to the next revision with the release, so that save is 409 DRAFT_CONFLICT with current. The http-api snapshot rules and the #3588 decision record state the rule and why it was chosen over refusing requestIds found in session_draft_sends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
Merged
9 tasks done
schlessera
marked this pull request as ready for review
November 16, 2026 19:34
This was referenced Nov 16, 2026
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.
Closes #3733
What changed
When an acceptance releases an outgoing snapshot and keeps the draft (a newer revision exists, or the draft changed chats), the draft now moves to a new revision. Before this,
acceptrewroteoutgoing_snapshotsin place and left the revision alone. A tab or device that read the draft before the acceptance could save its old list under the sameIf-Match, andnextSnapshotsfound no stored snapshot for the sent one, so it recreated it as a newdispatchedsnapshot. That phantom held one of the chat's ten slots and pointed its files back atoutgoing. Now the stale save gets409 DRAFT_CONFLICTwithcurrent, andcurrentno longer lists the snapshot. The single-slotoutgoingwrite follows the same rule, because it goes through the sameIf-Match.Why this shape
The issue allowed two rules. This PR takes the revision bump instead of having
nextSnapshotsrefuse arequestIdfound insession_draft_sends. That table can't answer the question: it records only first messages (!input.resumed), not sends into an existing chat, and those are the common snapshot case. It also keeps only the last eight sends per draft, while a chat can hold ten snapshots. The bump needs no new record, covers every acceptance path and gives the conflict theIf-Matchcontract already promises. The consumed path and the ownership move already bumped the revision. The newkeep()covers the remaining kept returns, and only when a snapshot was actually released.The client already holds a draft's saves while one of its snapshot sends is out (#3758), so the sending tab never saves over its own accepted snapshot. Only a tab or device that was already behind gets the new 409. Today the client shows that 409 as an ordinary conflict choice. A silent reconcile when the only difference is a released snapshot is filed as #4061 (the client is out of scope here, per the issue).
Contract (additive within
If-Match). A save after such an acceptance can newly get409 DRAFT_CONFLICT. This is documented indocs/http-api.md#outgoing-snapshot-list-additive-0450-3588and in thedocs/integration-contract.mdindex entry, and it has a minor@schlessera/brain-ui-serverchangeset. The choice and the reasons are recorded indocs/decisions/chat-attachments.mdunder "What #3588 built". Two client comments and the client section of that record said the release happened "without a revision"; they are corrected. No client code changes.Proof
Failing first (new test
a stale save cannot bring back a snapshot whose send the host accepted with the draft kept (#3733)inpackages/ui-server/tests/draft-snapshots.test.ts, withstore.tsatorigin/main): it failed atrefuse(...)witherror: expected a DraftError. The stale save of the old list was accepted, which is what recreates the phantom.Mutation: with
keep()'s bump disabled (if (false && released && …)), the same test fails at the same point (expected a DraftError). Restored, it passes (11/11 in the file).The test saves a
dispatchedsnapshot with a file, saves a newer revision, and accepts the request with the draft kept. Then it saves the old list under the revision that tab holds. Afterwards:409 DRAFT_CONFLICT, and itscurrentis at a newer revision, lists onlyrequest-2and keeps the newer text;outgoingwrite of the same request is alsoDRAFT_CONFLICT;request-1, the chat's live count stays 1, the file has nooutgoingref and keeps itsmessageref;current.revisiongoes through.attachment-ownership.test.tsasserted that a kept draft stays at revision 2 after the acceptance released its single-slot snapshot. That is the old behaviour, so the test now expects revision 3, with a comment explaining why.Broader local run: every ui-server test file that mentions drafts or snapshots, outside the runtime tier (124 files): 2,026 pass and 85 fail. The 85 failures are in 13 files, none of them about drafts (hygiene-review, governance-policy, http-supported-mounts, private-index-cache, turn-scope, jobs-board, …). Run on an unmodified
origin/mainworktree at the merge base (86003b261), the same 13 files fail 87 times, and each file fails at least as often there, except one. That one isrun-session.test.ts > an error result fails its turn…, which failed once under the load of the broad run and passes alone on this tree (16/16). Its wait is 200 one-millisecond ticks, so this is a timing budget, filed as #4066 with no milestone.Collisions:
bun scripts/collisions.ts --json --pr 4068at head40fb4f4b1. Two textual reports, both in docs: #3622 touchesdocs/http-api.md(its hunks are at lines 10–209 and 1809+, mine are at about 1180), and #4050 touchesdocs/integration-contract.md(its hunk is at line 20, mine at about 278). Neither overlaps these lines. Everything else is closure-only (the shared test graph), with no path collision onpackages/ui-server/src/drafts/store.ts.{"version":1,"kind":"brain-check-pr-receipt","head":"fdd25b495824b564526d43822d805b264641bec3","base":"origin/main","mode":"focused","startedAt":"2026-11-16T18:52:23.032Z","finishedAt":"2026-11-16T18:53:33.229Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":13057.064136},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":125.63348899999983},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":101.71474600000147},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":22.620653000001766},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":56873.580872000006}]}Checklist
docs/reflect the change, or nothing documented moved.docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.Anything left open
🤖 Generated with Claude Code