Skip to content

fix(ui-react): preserve newer principal outcome after cancellation - #4046

Merged
schlessera merged 2 commits into
mainfrom
fix/3093-cancel-principal-outcome
Nov 16, 2026
Merged

schlessera merged 2 commits into
mainfrom
fix/3093-cancel-principal-outcome

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3093

What changed

Cancellation now revalidates the captured queue entry after its storage deletion succeeds or fails. When a reconnect under a different principal has already signed the entry out and forgotten it, the late cancellation continuation stops there. The newer Signed out outcome stays, and the forgotten entry can no longer send a stale ask_answer_status query, install a cancelled receipt entry or re-settle itself through the failed-delete replay. Normal cancellation, deletion-failure recovery, Edit, accepted-receipt handling and logout/disposal semantics are unchanged. Includes a patch changeset for @schlessera/brain-ui-react.

Resumes the approach of the earlier draft #3116 (its single commit cherry-picked onto current main), which this PR supersedes.

Why this shape

Takeover already uses entry identity (entries.get(id) === entry) as its authority check. A principal change settles and forgets an entry without advancing the lifecycle epoch, so the existing disposed || epoch checks cannot see it. Adding the same narrow identity check to both cancellation continuations covers this case. We did not add terminal-state ranking, tombstones, a queue policy change or a protocol change: the issue rules all of them out of scope.

This is a stale-continuation check that drops an obsolete continuation. It is not a fail-closed guard that restricts anything, so the proportionate-containment checklist does not apply.

Proof

Base origin/main at e1ce188d7; head 8c294206f.

  • Tests: four controlled memory-storage schedules in packages/ui-react/tests/answer-delivery.test.ts, covering deletion success and failure across a same-principal and a different-principal reconnect. Each one holds the first deletion, connects, releases the deletion and joins the actual cancel() promise.
    • Different-principal cases require the exact Signed out delivery object seen at connect (including its settlement time), nothing held or persisted, no transport effects, and no accepted receipt overriding it.
    • Same-principal controls require normal cancellation (success) or queued recovery (failure), plus the exact status query and no answer frames.
  • Failing first (original manager.ts from origin/main, new tests): 69 pass / 2 fail. Both different-principal cases fail at expect(h.delivery()).toBe(connectedDelivery) (line 476).
  • Mutation A (remove only the success-branch identity check): 70 pass / 1 fail, success: … different principal connection at line 476. Restored.
  • Mutation B (remove only the failure-branch identity check): 70 pass / 1 fail, failure: … different principal connection at line 476. Restored.
  • Restored source: bun run test packages/ui-react/tests/answer-delivery.test.ts gives 71 pass / 0 fail, 351 expect() calls, exit 0.
  • Scope of the proof: these memory-storage controls prove manager causation only. They make no native IndexedDB/socket scheduling claim and no historical incident attribution.
  • Collisions: bun scripts/collisions.ts --json --paths <manager.ts, answer-delivery.test.ts> before claiming showed a path collision only with the superseded fix(ui-react): preserve newer principal outcome after cancellation #3116. Every other report was closure-only. The --pr result is recorded in a comment below.
bun run check:pr --base origin/main   # exit 0: lint/leakage, env docs, changesets, 456 affected fast tests pass
{"version":1,"kind":"brain-check-pr-receipt","head":"8c294206f883e04de11e308d1954dbf0c3a8e59d","base":"origin/main","mode":"focused","startedAt":"2026-11-15T20:52:18.647Z","finishedAt":"2026-11-15T20:53:13.693Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":19559.210956999996},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":209.5568179999973},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":118.37302500000078},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":20.17562600000383},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":35119.137887000004}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (Local done; hosted confirmation is run by the merge queue.)
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only: the provider-history guard passes, or nothing on a turn's path changed.

Anything left open

Nothing beyond hosted candidate confirmation and merge.

🤖 Generated with Claude Code

@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-react React chat/files/voice components, stores, WebSocket transport. labels Nov 15, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Collisions at head 8c294206f883e04de11e308d1954dbf0c3a8e59d (bun scripts/collisions.ts --json --pr 4046): no path or unknown collisions. Closure-only overlaps with #3054, #3056, #3059, #3069, #3116 (superseded, being closed), #3437, #3581, #3622, #3806, #4002, #4018, #4024, #4028, #4034–#4038, #4040–#4042. Closure overlaps are shared test-selection reach through ui-react, not edits to the same files.

@schlessera
schlessera marked this pull request as ready for review November 16, 2026 05:03
@schlessera
schlessera merged commit ec736e5 into main Nov 16, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-react React chat/files/voice components, stores, WebSocket transport. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-react: cancellation deletion can override a newer signed-out outcome

1 participant