Skip to content

feat(chat): order queue edits by a server revision so a stale echo cannot overwrite a newer edit - #22479

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/queue-edit-revision-protocol
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/queue-edit-revision-protocol

Conversation

@rnoack1

@rnoack1 rnoack1 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A queued message edited in two places at once ends up showing the text the agent will actually run, instead of whichever edit's echo happened to arrive last.

Split out of #6825, as its maintainer triage asked: this is the queue-edit revision protocol, one of the three units named there.

A queue edit today broadcasts only {queue_id, content}. Nothing in that frame says in what order edits happened, so a client cannot tell a late echo of an edit the server has already replaced from a genuinely newer one. Comparing the text does not work either: the display form is redacted, so two different edits can render identically.

Why it matters

When two tabs edit the same queued card, or a tab rebuilds the card from slot detail and then receives an older echo, the card can settle on text the queue no longer holds. The user then reads one prompt on screen while the agent runs another.

Not a goal

  • Surfacing a rejected edit to the user, with a rollback and an inline error. That is a separate change and depends on the queued-send stash module.
  • Echoing sendId on the queue_push broadcast. That is a separate decision with its own scope.
  • Changing what an edit is allowed to rewrite. Attachment pruning and quote handling are untouched.

What changed (motivation → approach → change)

The server assigns each queue entry a revision that goes up by one on every edit, and the client refuses only an edit frame older than the revision it already holds.

  • Server. queue_edit_by_id increments edit_rev on the entry. The edit endpoint puts editRev on the queue_edit frame. The HTTP response is unchanged.
  • Restart. edit_rev is saved with the queued entry (_DURABLE_QUEUE_KEYS) and sanitize_restored_queue restores it only as a positive integer, so after a gateway restart the next edit continues above the revision a tab still holds instead of starting over at 1.
  • Slot detail. queue_entry_view serves editRev, and the detail handler's snapshot copies edit_rev, so a row rebuilt by a refetch (reconnect, slot switch, new tab) keeps its revision.
  • Client.
    • normalizeQueueEntries carries editRev from slot detail onto the rebuilt row.
    • The editQueuedMessage reducer records editRev on the row and refuses a frame whose editRev is lower than the one already applied. A frame with an equal revision still applies.
    • The editing tab's own response is not used for ordering. Frames reach each tab in server order on its one WS connection, so the frame alone sets the revision.
    • An unrevisioned frame is still applied, so an older gateway keeps working. Revisions count per entry, not per slot.

Example: tab B reloads and rebuilds the card from slot detail at revision 2. A delayed revision-1 frame then arrives. It is older than 2, so it is ignored and the card keeps the revision-2 text.

Backwards compatibility

Compatible: the frame and detail shapes gain one optional field, editRev. A client that ignores it behaves as today, and the reducer applies a frame without editRev exactly as before. The request and response shapes are unchanged.

Removes nothing: no field, route or reducer is removed or renamed.

Tests

  • test/test_queue_edit_revision.py: the revision advances on each edit and counts per entry, queue_entry_view serves it only when present (a boolean is refused), one test drives GET /api/chat/slots/{slot} end to end so the snapshot is covered, not just the serializer, and the revision survives a save and restore while a stored value that is not a positive integer is dropped.
  • test/test_queue_edit.py: two edits broadcast revisions 1 then 2, and the response carries no editRev. Two existing shape pins updated for edit_rev.
  • test/test_queue_drain_preserve_attachments.py: one frame-shape pin updated for editRev.
  • store/chat/queue.editRevision.test.ts: an older revision is ignored, an equal one applies with its attachments, a newer one applies, an unrevisioned frame applies, cards are ordered independently, and a row hydrated from slot detail keeps its revision and refuses an older frame.

Negative controls: changing the reducer guard to refuse an equal revision turns the equal-revision test red, and dropping edit_rev from _DURABLE_QUEUE_KEYS turns the restart test red.

Backend: every test matching queue, slot_detail or facade (10786 passed). The 2 failures and 2 errors in that run are in test_server_md_notebook_facade.py, test_onboarding_import_refactor_contract.py and test_mcp_stdio_wake.py, and they fail identically on the unmodified previous head in this environment. Frontend: every test file under src/store/chat, plus the hook and public-surface tests, 646 of 646. tsc, eslint on the changed files, black and flake8 are clean.

Manual verification

N/A for this draft: the ordering is a pure reducer decision and the wire shape is covered end to end by the endpoint and detail tests.

Screenshots / video

Why no screenshot: the frontend change is a reducer guard and a revision carried on refetch, and nothing on screen renders differently.

Related Issues

Part of #6825.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 8c692628fccdadd9152273c8bd1332058c51db0a via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check: the diff adds no visible control, label or state. Its frontend change is a reducer guard on queue-edit revisions plus one optional wire field (editRev), so no screenshot is needed.

[UX-REVIEWED] 8c69262

Description read

[DESCRIPTION-READ] ccd790fb328b881cee2d00a2e17fdc10eb9e857125777cbaee65101b7bc9b9c7

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 8c692628fccdadd9152273c8bd1332058c51db0a via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Each revision surface has one real reader (the client's ordering guard), and nothing in the repo already does this ordering.

What this change ships

Inventory (6 items) — 6 justified

Intent: when a queued message is edited in two places at once, its card ends up showing the text the agent will actually run. FIX (part of #6825).

  1. Every edit to a queued message now raises a revision number the server keeps for that message — justified
  2. The live edit update each tab receives now carries that revision — justified
  3. Reloading the chat (reconnect, slot switch, new tab) now gives each queued card its revision back — justified
  4. A queued message's revision now survives a gateway restart, so the next edit still counts as newer — justified
  5. A tab now ignores an edit update older than the one its card already shows; an update with no revision still applies — justified
  6. A reloaded card keeps the revision it was served, so a late older update is refused — justified

[FIRST-PRINCIPLES-REVIEWED] 8c69262

Description read

[DESCRIPTION-READ] 830984b60f9386b5c5fcd04039e85b9ee380715246214416bf11aaab2977c0e1

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 8c692628fccdadd9152273c8bd1332058c51db0a via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: a per-entry revision assigned by the server is the right way to order edits, it is kept across restarts and refetches, and gateways that send no revision still work.

Notes

  • The optimistic local edit (useQueuedMessageActions.ts:335) has no revision, so the editing tab briefly shows its own text even when an equal-or-newer frame already arrived from another tab. The tab's own frame corrects it soon after, so this is fine, but it is the remaining window where the card shows text the queue does not hold.

[DESIGN-REVIEWED] 8c69262

Description read

[DESCRIPTION-READ] b4b3432c2e243eb7c8cc491b2ee4dcc665c0c441a2401ffa625199f0e1a6ef43

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 8c692628fccdadd9152273c8bd1332058c51db0a via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8c69262

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 8c692628fccdadd9152273c8bd1332058c51db0a via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8c69262

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 20, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from 4827129 to f354060 Compare October 20, 2026 21:08
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 20, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from f354060 to b539683 Compare October 21, 2026 11:30
@rnoack1 rnoack1 changed the title feat(chat): name and order each queue edit so a client can tell its own echo apart feat(chat): order queue edits by a server revision so a stale echo cannot overwrite a newer edit Oct 21, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 21, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from b539683 to bde150a Compare November 4, 2026 13:57
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 4, 2026
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 4, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch 2 times, most recently from b5078aa to 98f178d Compare November 4, 2026 18:19
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 4, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from 98f178d to c035e2b Compare November 4, 2026 18:40
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 4, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 4, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from c035e2b to a82dc43 Compare November 5, 2026 21:35
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 5, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from a82dc43 to 64510be Compare November 9, 2026 15:30
@rnoack1
rnoack1 marked this pull request as ready for review November 9, 2026 15:30
@rnoack1
rnoack1 requested review from a team and KiroCrewCaptain as code owners November 9, 2026 15:30
@rnoack1
rnoack1 requested a review from tim-finnigan November 9, 2026 15:30
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 9, 2026
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from 64510be to d08455e Compare November 11, 2026 05:01
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 11, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

Each queue entry now gets a server-assigned revision that goes up by one on every edit. The revision rides on the queue_edit frame, slot detail, resume and the saved queue, so it survives a restart and is kept only if it is a positive integer. The client reducer refuses only a frame whose revision is lower than the one it already holds; frames without a revision, and the editing tab's own optimistic update, still apply. Every reader and writer is consistent: the slot-detail snapshot, queue_entry_view, the resume queue_view calls, normalizeQueueEntries, the hydrateQueuedBubbles meta, and the useWebSocket pass-through. The saved revision is not a trust input, since it only orders the display. Tests cover the server counter, the wire shape end to end, the save and restore round trip, and every reducer branch. Spec drift is the only gap, and it does not change behaviour.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit d08455eebd · 243 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 11, 2026
…nnot overwrite a newer edit

A queue edit now gets a server-assigned `edit_rev`, sent on the `queue_edit` frame and served on
slot detail, so a late echo of a superseded edit is ignored.
@rnoack1
rnoack1 force-pushed the split/queue-edit-revision-protocol branch from d08455e to 8c69262 Compare November 12, 2026 12:47
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 12, 2026

@bolichen97 bolichen97 left a comment

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.

Approve at 8c69262. I read the whole product diff: the queue edit route, slot detail, queue_entry_view, the slot queue repository, and the web store's queue.ts and wire.ts.

queue_edit_by_id bumps a per-entry edit_rev on every stored edit. The queue_edit frame, the slot-detail queue and queue_entry_view carry it as editRev. editQueuedMessage then drops an echo whose editRev is below the one the row already shows, so a stale frame can no longer overwrite a newer edit. A frame with no editRev, or a row without one, applies as before.

edit_rev joins _DURABLE_QUEUE_KEYS, and sanitize_restored_queue keeps it only as a positive non-bool int. A restart then keeps the next edit above what a tab already holds, and a hand-edited value can't smuggle in anything but a number.

No regex, no new refusal, and all 94 checks are green.

Optional nit: prompt_queue.py and slot_detail.py check isinstance(edit_rev, int) without the not isinstance(edit_rev, bool) that the other two sites use. The repository never writes a bool there, so this doesn't block.

@bolichen97
bolichen97 merged commit b85ae9b into kirodotdev:main Nov 12, 2026
94 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 2026
@rnoack1
rnoack1 deleted the split/queue-edit-revision-protocol branch November 14, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants