Skip to content

feat(ui): edit a queued chat message in place - #121692

Merged
vyctorbrzezowski merged 4 commits into
mainfrom
feat/queue-edit
Aug 11, 2026
Merged

vyctorbrzezowski merged 4 commits into
mainfrom
feat/queue-edit

Conversation

@vyctorbrzezowski

@vyctorbrzezowski vyctorbrzezowski commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Related: #121667
Was stacked on #121682, which landed as 1d989027cf6; this PR is rebased onto main and reviews on its own.

What Problem This Solves

Fixing a typo in a queued chat message costs the whole message. The only action on a queued row is discard, so an operator who spots a mistake has to throw the row away and retype it — and every image they attached is gone with it. Attachment payloads are released on discard, so a queued screenshot cannot be recovered; the operator has to take it again.

Why This Change Was Made

A pencil sits directly on the queued row, next to the discard X; double-clicking the row does the same thing. The message and its attachments move into the composer, and a small pencil marker with an X to cancel appears beside the input, so the operator always knows they are rewriting a queued message rather than composing a new one.

The row itself stays in the queue, in its own slot, marked Editing. That is what makes the return-to-the-same-position contract self-evident: the operator can see where the corrected message will land instead of being told. It also makes cancel free — the row never left, so cancelling touches storage not at all.

Sending hands the original row's position to the replacement, reusing the operator-owned queue position from #121682 rather than introducing a second ordering concept. If the queue drained during the edit, that position is simply the only one and the message sends as a normal turn, with no special case.

The original is retired by the same store write that admits its replacement, never before it. Admission carries the id of the row it replaces, and the store writes the queue once with the source filtered out and the replacement in it (composer-persistence.ts, chat-queue.ts). A rejected write therefore changes nothing at all: the original is still queued, the replacement was never stored, no attachment was released, and the edit is still open on the row that is still there — which is exactly what cancelling already promises. Retiring first and admitting second would leave a rejected write having consumed both copies, in the one failure the offline queue exists to survive. Filtering before the stored-queue cap also keeps a replacement admissible on a full queue.

Resuming an edit is now the composer submit's business rather than every pending enqueue's. enqueuePendingSendMessage builds pending rows for the reset-command sender too, so reading the edit token inside it meant a /new typed over an abandoned edit would retire the operator's queued row and hand its slot to the reset message. The submit path passes the resumed position and the replaced id explicitly; the reset path passes neither, so an open edit is simply left alone.

An edit belongs to the scope it started in, and an outbox is scoped by session and agent. A raw global session keeps its key while the selected agent changes underneath it, so the token records the agent that owned the row and the single accessor compares the whole scope through visibleSessionMatches, the helper the queue and delivery paths already share. A send after an agent switch cannot retire a row in the outbox it left behind.

While an edit is open, the drain refuses that row. A reconnect must not deliver the text the operator is visibly rewriting, and the queue behind it waits — the same contract the row's held position already promises. This sits next to the existing unconfirmed guard in chat-outbox-drain.ts.

That hold is read across every pane, not just the one holding the composer. Panes share an outbox and its drain lane, and a session event makes any of them resume every stored outbox, so a hold only its own pane could see would let the other pane deliver the superseded text. It stays derived from each pane's own scope-validated edit rather than stored a second time at the owner: a stored hold would need releasing on cancel, on send, on pane close and on agent switch, and one that outlived its edit would stall the queue with nothing on screen explaining why. Derived, it releases by construction — a closed pane leaves the owner's set, and a switched agent makes that pane's edit inactive.

Two deliberate boundaries. Editing requires an empty composer, matching the existing rule that newer composer input is never overwritten (chat-send-composer.ts), and it reports that instead of silently clobbering a draft. Routing the pane to another session drops the edit, alongside the in-progress title-edit cleanup that already lives there.

Every reader goes through that one accessor — the row badge, the composer marker, the drain block, and the send. A pane showing another session, or the same global session after an agent switch, sees no edit, so no lifecycle hook has to remember to clear one — which is why the retained-pane rework on main did not leave a hole here.

Non-goal: queued slash commands. They take a different enqueue path that cannot carry a resumed position, so they keep the discard-and-retype flow and are excluded from the action rather than half-supported.

Row anatomy holds in every state

A queued row is always the same five slots — handle, status, text, pencil, discard — and a row never loses a slot because of the state it is in. An open edit makes the slots it owns inert, not absent, so no column moves while the operator retypes:

  • the edited row keeps its handle, dimmed, because it is holding its place rather than offering a drag;
  • so do its neighbours: an edited row blocks the drain, so it splits the queue for reordering exactly like an in-flight row, and a segment of one has nowhere to go;
  • every pencil waits, because only one edit runs at a time;
  • only the edited row's X goes inert — discarding a different queued row stays safe and stays live.

Editing is an active state, not a failure, so the row tint, the badge, and the composer marker use the informational family. --accent is the brand red in every shipped theme and sits directly on top of --danger (see the --run token note in base.css), which is exactly why a neutral state must not borrow it.

The composer row aligns by construction

The composer's input row bottom-aligns its children so it can follow a growing textarea, which only reads as one axis while every child is the same height. That was an unwritten rule each control happened to satisfy, so the marker — the first genuinely small child — landed low.

The row now owns the rule: --chat-composer-control-height (36px, 44px on touch layouts) is declared once on .agent-chat__input, .agent-chat__composer-input-row > * claims that box, and the attach button and textarea read the token instead of repeating the literals. The marker needs no align-self or margin nudge, and neither will the next child added to this row.

User Impact

An operator can correct a queued message — text and attachments — and it goes back to the same place in the queue. Cancelling leaves the queued message exactly as it was.

Evidence

Row anatomy, light and dark

Light Dark

Handle, status dot and badge sit on the same x on all three rows while the middle one is being edited; the Editing badge and the row outline read informational, never danger.

Composer row in edit mode

Light
Dark

A pencil glyph and a cancel X beside the input, on the same axis as the attach button, the text and the send controls. The queued row already names the state, so the composer only says which mode it is in and how to leave it.

The whole flow — queued row, pencil, editing, send, cancel

Six steps: the queued row with its pencil; the row held in place marked Editing with the composer marker; the rewritten text; the message back in the same slot; a second edit being abandoned; and the queue restored untouched.

Light Dark

Stepped stills of the same six frames, if the animation is too quick to read:

Light
Dark

Recorded from the mocked Control UI E2E harness (headless Chromium, mock Gateway, no live credentials); frames are not committed.

Tests (Blacksmith Testbox, Linux, Node 24)

  • Full Control UI lane: node scripts/run-vitest.mjs ui/src — 565 files, 8338 passed, 0 failed.
  • Browser round-trip: ui/src/e2e/chat-flow.queue-edit.e2e.test.ts queues three messages offline, double-clicks the middle row, asserts the row stayed in place carrying the Editing badge while the composer took the text, then edits and sends it and asserts it replaced the same slot. A second case drives the pencil and the composer's cancel, asserting the queue comes back untouched.
  • Segment proof: chat-composer-queue.test.ts asserts that while a row is edited every handle stays in its column and every one of them is inert, because the edited row splits the queue. queued-message-edit.test.ts asserts a stale edit from another session neither marks a row nor locks the composer.
  • Alignment proof in the rendered DOM: the same e2e case measures the vertical centre of the attach button, the edit marker, the textarea and the send controls while the marker is on screen, and asserts they agree within 1px.
  • Render proof for the anatomy rule: ui/src/pages/chat/chat-composer-queue.test.ts asserts every row keeps its handle, pencil and discard button while an edit is open, that each one is disabled exactly where it should be, and that a live X on another row still discards.
  • Storage-boundary proof: ui/src/pages/chat/queued-message-edit.test.ts covers the attachment lift with the row held in storage, cancel leaving the queue byte-identical, the resumed send replacing the same slot, one edit at a time, the empty-composer requirement, the refused row kinds, and the edit not following a session switch. The send cases drive the real handleSendChat path, so the admit/retire ordering itself is what is under test rather than the pieces.
  • Failure-ordering regression: keeps the original queued when the replacement's stored write is rejected queues three rows offline, edits the middle one, then makes the store refuse any write that would grow it — exactly how quota behaves — and asserts the original row, the open edit, the restored draft and the visible storage error. On the pre-fix ordering it fails with expected [ 'message 1', 'message 3' ] to deeply equal [ 'message 1', 'message 2', 'message 3' ]: the operator's message is simply gone.
  • Scope regression: cannot retire a row in the outbox a global agent switch left behind queues a row in one agent's global outbox, edits it, switches the selected agent, and asserts each outbox keeps its own row. On the pre-fix token it fails at the switch (expected true to be false) and the send retires the previous agent's row.
  • Cross-pane regression: holds a row being edited against a drain owned by another pane, in ui/src/pages/chat/chat-send.test.ts's existing two-pane harness. One pane edits a queued row, the other runs the real retryReconnectableQueuedChatSends. With a pane-local hold it fails with a chat.send on the wire; with the shared read no request is issued and the row stays in the stored outbox.
  • Payload regression: releases only the images the replacement dropped stages two images in the payload store, drops one during the edit and sends. Reading the retired row's attachments after the write fails (expected null, received "data:image/png;base64,…") because the write already retired the row everywhere; reading them from the edit token releases the dropped image and keeps the retained one.
  • node scripts/run-tsgo.mjs -p tsconfig.ui.json, node scripts/run-oxlint.mjs ui/src, pnpm check:import-cycles (0 runtime value cycles), and oxfmt --check on every touched file — all clean.
  • Codex autoreview (gpt-5.6-sol, high) on the branch diff: no accepted or actionable findings.

Size

Against main, counted with test and production separated: production +441 / -30 (net +411), tests +471 / -1, docs +1. This is a feature, so the growth is capability rather than a bug-fix delta: the pencil affordance, the edit-mode composer, the row anatomy rules, and the queue-edit state itself.

Where it could be absorbed, it was. The composer's queue-edit wiring is grouped into one queuedEdit shape, which keeps chat-view.ts under the max-lines cap without a suppression. Leaving the row in the queue removed the re-admit path and its storage-failure branch that the earlier revision needed. The edit-mode surface shrank across revisions: the full-width banner and its six CSS rules are gone, replaced by the inline marker. The alignment fix is close to LOC-neutral — one token and one shared rule replace three hardcoded control heights.

The cross-pane hold and payload-ownership revision is production +41 / -9 (net +32) with tests +66 / -1; fourteen of those production lines are the comments recording why the hold is derived rather than stored, and the new surface is anyPane on the outbox owner plus anyChatOutboxPaneMatches.

The ordering repair before it is production +68 / -23 (net +45) with tests +77 / -5. Thirty-one of those added lines are the JSDoc and inline comments recording the two invariants, and roughly eleven more are oxfmt re-wrapping a call and an object literal that already existed. It is a reshape rather than an addition: consumeQueuedMessageEdit was replaced, not supplemented, and the remove-then-admit ordering is deleted. About ten lines are genuinely new — isDurableQueuedMessage, the replacesId parameter through two layers, the queue filter that replaces the queue read, and the send-path guard. isDurableQueuedMessage is the one addition carrying capability rather than safety: without it an edit could not be sent at all in a browser with no session storage.

Main is red independently of this PR

ui/src/pages/chat/components/chat-thread.measure.test.ts > "rebinds guarded transcript images when the gateway rotates its auth token" fails on origin/main. It runs in the core-runtime-media-ui shard, which is why checks-ui, check-lint, check-dependencies, and four checks-node-compact-* jobs all go red together. Two managed-media browser tests fail alongside it: chat-flow.media-files.e2e.test.ts > "evicts and refetches managed image Blob URLs after the cache reaches capacity" and managed-media-base-path.e2e.test.ts > "keeps origin-root managed-media APIs outside the UI base path".

A second, independent breakage sits in checks-node-compact-small-11: src/cron/service.stream-trigger.test.ts, src/cron/service.stream-validation.test.ts, and src/cron/service/timer.timeout-watchdog.test.ts all expect the old failure-alert payload shape and now receive the generic "Automation ... failed N times" text.

A third: pnpm check:test-types fails on src/gateway/managed-image-actions.e2e.test.ts:125 (unknown passed where string | URL is expected) and ui/src/pages/chat/components/chat-message.test.ts:4590,4595 (missing download property, empty tuple index).

Unrelated PR #121686 shows the same failing set, so none of this comes from this branch, and nothing here touches the transcript-image, managed-media, or cron paths. The one failure from #77017 that landed in this PR's own lane — the hardcoded cursor: pointer on .chat-image-action — is fixed here.

@vyctorbrzezowski vyctorbrzezowski self-assigned this Aug 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: L maintainer Maintainer-authored PR labels Aug 10, 2026
@vyctorbrzezowski
vyctorbrzezowski marked this pull request as ready for review August 10, 2026 18:28
@vyctorbrzezowski vyctorbrzezowski changed the title feat(ui): edit a queued chat message without losing it feat(ui): edit a queued chat message in place Aug 10, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 10, 2026
@clawsweeper

clawsweeper Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 12:52 AM ET / 04:52 UTC.

ClawSweeper review

What this changes

This PR lets Control UI operators edit a queued chat message in place, retaining attachments and returning a sent replacement to its stored queue position.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The implementation is technically coherent and covers the prior durability and cross-pane concerns, but it intentionally pauses later shared-outbox deliveries during an edit; that user-visible policy needs maintainer acceptance before merge.

Priority: P2
Reviewed head: b2a9ca447958f8b8834ebc4aa812d72317df306a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong mocked-browser and owner-boundary coverage supports a coherent patch, with the remaining question being deliberate delivery policy.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its supplied mock-Gateway browser E2E evidence still directly exercises the visible flow.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its supplied mock-Gateway browser E2E evidence still directly exercises the visible flow.
Evidence reviewed 8 items Edit ownership: The edit token is scope-validated by session and agent, and the shared owner can observe an edit held by another pane.
Delivery policy: The drain returns blocked for an edited row, thereby pausing that row and all later rows in its shared outbox.
Durable replacement: Replacement admission filters the source before capacity checking and writes the replacement/source swap together, preserving the original if storage rejects the write.
Findings None None.
Security None None.

How this fits together

Control UI stores queued messages in a session-and-agent-scoped browser outbox that can be rendered and drained by multiple panes. This change lifts one queued row into a pane-local composer while coordinating replacement and delivery blocking through the shared outbox owner.

flowchart LR
  Operator[Operator edits queued row] --> Composer[Pane-local composer]
  Composer --> Replacement[Durable replacement admission]
  Replacement --> Outbox[Shared session outbox]
  Outbox --> Drain[Outbox delivery drain]
  Composer --> Hold[Edited-row delivery hold]
  Hold --> Drain
  Drain --> Gateway[Gateway chat delivery]
Loading

Decision needed

Question Recommendation
Should editing one queued Control UI message pause delivery of that row and all later rows in its shared outbox until the operator sends or cancels? Accept the shared-outbox barrier: Keep the documented held-position contract so no later pane can send text the operator is visibly rewriting.

Why: Code cannot determine the UX tradeoff between never delivering visibly superseded text and delaying later queued work across panes.

Before merge

  • Resolve merge risk (P1) - An open edit deliberately blocks delivery of its row and every later row in the shared outbox, including delivery started from another pane; this preserves no-superseded-delivery semantics at the cost of potentially delayed queued work.
  • Complete next step (P2) - A maintainer must choose the intended delivery semantics; there is no narrow mechanical repair to dispatch.
Agent review details

Security

None.

PR surface

Source +420, Tests +485, Docs +1. Total +906 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 19 450 30 +420
Tests 4 486 1 +485
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 937 31 +906

Review metrics

Metric Value Why it matters
Production versus test delta production/docs +421/-29; tests +485/-1; support +31/-1; 24 files The +392 production/docs delta is feature capability growth across the queue, persistence, rendering, and documentation surfaces, so maintainer review should assess the delivery-policy change rather than raw size alone.

Stored data model

Persistent data-model change detected: migration/backfill/repair: ui/src/e2e/chat-flow.queue-edit.e2e.test.ts, serialized state: ui/src/pages/chat/queued-message-edit.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #121667
Summary: This PR is the candidate implementation for the queued-message editing portion of the canonical Control UI queue request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Confirm the shared-outbox hold (recommended)
    Accept the documented behavior that later queued messages wait while an earlier row is being edited.
  2. Redesign delivery ordering
    Require a revised invariant and updated browser and cross-pane tests before merge if later messages must continue delivering.
  3. Pause the feature
    Close or defer this feature if the delivery delay is not acceptable for the default queue workflow.

Technical review

Best possible solution:

Retain the single scope-validated edit hold and land it only if maintainers accept that it pauses later delivery in the shared outbox.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a feature request; the supplied mock-Gateway browser E2E and owner-boundary tests demonstrate the intended edit, send, and cancel flows.

Is this the best way to solve the issue?

Technically yes: durable replacement is owned by the outbox write and the cross-pane hold reads the shared owner; whether the pause is the best product behavior remains a maintainer choice.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c5b7b8e33c99.

Labels

Label changes:

  • add proof: 🎥 video: Contributor real behavior proof includes video or recording evidence. This member-authored PR is exempt from the external-contributor proof gate; its supplied mock-Gateway browser E2E evidence still directly exercises the visible flow.

Label justifications:

  • P2: This is a bounded Control UI queue feature whose unresolved effect is delayed queued delivery, not an emergency regression.
  • merge-risk: 🚨 message-delivery: The shared drain intentionally blocks rows after an edited row until the operator resolves the edit.
  • merge-risk: 🚨 session-state: The feature coordinates a pane-local composer edit with session-and-agent-scoped durable queue state across panes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its supplied mock-Gateway browser E2E evidence still directly exercises the visible flow.
  • proof: 🎥 video: Contributor real behavior proof includes video or recording evidence. This member-authored PR is exempt from the external-contributor proof gate; its supplied mock-Gateway browser E2E evidence still directly exercises the visible flow.

Evidence

Acceptance criteria:

  • [P1] Review the documented shared-outbox pause against expected default queue behavior.
  • [P1] If accepted, run the focused queue-edit and cross-pane drain tests on the exact head.

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame identifies his recent work as the durable queue admission owner. (role: recent outbox architecture contributor; confidence: medium; commits: 8aa0376f27dc, 9a499d3c1be0; files: ui/src/pages/chat/composer-persistence.ts, ui/src/pages/chat/chat-outbox-owner.ts)
  • vyctorbrzezowski: Prior merged queue-order work and this feature's design both cover the Control UI queued-message lifecycle. (role: recent queued-message feature contributor; confidence: medium; commits: 1d989027cf6c; files: ui/src/lib/chat/chat-queue-order.ts, ui/src/pages/chat/components/chat-composer-queue.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the shared-outbox delivery-pause decision before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (7 earlier review cycles)
  • reviewed 2026-08-10T20:00:55.399Z sha 156e8178520b00aa58d1d7e82e09f738d5ac4234 :: found issues before merge. :: [P1] Preserve the original row until replacement admission succeeds
  • reviewed 2026-08-10T21:53:35.911Z sha f825727 :: found issues before merge. :: [P1] Retire the original row only after durable admission succeeds
  • reviewed 2026-08-10T23:54:03.838Z sha 88df4f19e69ad32ebb98d2605d0d290a581eead3 :: found issues before merge. :: [P1] Make edited-row replacement durable before removing the original
  • reviewed 2026-08-11T00:51:08.123Z sha c89bf909706204dac2ed2358eedaf61780b4db75 :: needs changes before merge. :: [P1] Retire the original only after replacement admission succeeds | [P1] Bind the edit token to the selected global agent
  • reviewed 2026-08-11T01:01:42.180Z sha 278c6cb :: found issues before merge. :: [P1] Commit the replacement before retiring the edited row | [P1] Bind the edit token to the selected global agent
  • reviewed 2026-08-11T02:01:06.112Z sha a8c8510 :: needs changes before merge. :: [P1] Centralize queued-edit ownership across panes | [P2] Retain dropped attachment payloads after an edit
  • reviewed 2026-08-11T03:06:00.911Z sha e68043c :: needs maintainer review before merge. :: none

@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Both P1 findings from the latest review are accepted. I traced each one through the code and they are real, so this PR is not landing until they are fixed — recording that here so nobody lands it on the strength of green CI. The base of the stack, #121682, landed separately as 1d989027cf6; this PR is now rebased directly on main.

[P1] Retire the original only after replacement admission succeeds — confirmed. The sequence is:

  1. enqueuePendingSendMessage calls consumeQueuedMessageEdit, which removes the durable source row and returns its orderKey (ui/src/pages/chat/chat-send-queue-state.ts).
  2. admitQueuedMessageForSession then attempts the durable write for the replacement (ui/src/pages/chat/chat-send-submit.ts).
  3. When that write is rejected and the row cannot be sent from memory, cancelChatDelivery restores the composer but removes only the new volatile row.

So a rejected durable write leaves the original gone and the replacement never persisted: after a reload the operator's message is lost, along with any attachment payload the replacement dropped, because consumeQueuedMessageEdit has already released those. That is silent data loss on the exact failure the queue exists to survive, and the review is right that it is the more serious of the two.

The related detail in the same finding also holds: removeVisibleOrScopedQueuedMessageWithoutReleasing can fail, and the function still clears chatQueuedEdit and returns the order key, which would admit a duplicate replacement while the original is still in the queue.

Repair shape: make it one scoped durable replacement rather than remove-then-admit. The source row and its payloads stay until exactly one durable replacement write for that scope succeeds; only then is the original retired and the dropped payloads released. If the write is rejected, the edit stays open and the row is still there, which is already what cancel promises.

[P1] Bind the edit token to the selected global agent — confirmed. QueuedMessageEdit records { id, orderKey, sessionKey }, and activeQueuedMessageEdit compares sessionKey alone. But the queue scope is (sessionKey, agentId) everywhere else — readChatQueueForScope and updateQueuedMessageForSession both take agentId — and a raw global session keeps sessionKey === "global" while the selected agent changes underneath it. So after an agent switch the previous agent's edit still reads as active, and sending would retire a row in the old agent's outbox while the pending replacement is scoped to the new one.

Repair shape: the token carries the source agent scope, and every reader validates the full scope rather than the session key alone. That is the same principle already applied to the session: the edit belongs to the scope it started in, and one accessor makes that true everywhere.

Both repairs land in one focused update at the queue owner boundary, with the two regressions the review names: a rejected durable write must leave the original row and its attachments intact, and a selected-global-agent switch must not let an edit cross outboxes.

CI on this head is green, but green CI does not cover either case — that is precisely the gap, and the regressions above are what close it.

The send retired the source row first and admitted the replacement second,
so a rejected store write left the operator with neither: the original gone,
the replacement never persisted, and the attachments it dropped already
released. Admission now carries the source id and swaps both rows in one
store write, so a rejected write changes nothing and the edit stays open on
the row that is still there, which is what cancelling already promises.
Filtering the source before the cap check also keeps a replacement
admissible on a full queue.

The edit token recorded only the session key, but an outbox is scoped by
session and agent, and a raw global session keeps its key while the selected
agent changes underneath it. The token now carries the agent that owned the
row and every reader validates the whole scope, so a send after a switch
cannot retire a row in the outbox it left behind.
@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Both accepted P1s are fixed at the owner boundary in a8c8510f7da, each with the regression the review named. The repair went where the invariant is owned rather than where the symptom showed.

[P1] Retire the original only after replacement admission succeeds

The remove-then-admit sequence is gone. Admission now carries the id of the row it replaces, and the store performs one write: admitStoredChatComposerQueueItem filters the source out of the queue it is about to write (ui/src/pages/chat/composer-persistence.ts:463), threaded through admitQueuedMessageForSession(host, sessionKey, item, replacesId) (ui/src/pages/chat/chat-queue.ts:276) from the one call site that resumes an edit (ui/src/pages/chat/chat-send-submit.ts:466). A rejected write now changes nothing at all: the original is still queued, the replacement was never stored, and no attachment was released.

consumeQueuedMessageEdit became retireEditedQueuedMessageSource (ui/src/pages/chat/queued-message-edit.ts:105), which runs after that write and only clears what the write left behind — the projection row and the payloads the replacement dropped. It refuses to retire a stored source when the write was rejected, which also closes the second half of the finding: the edit is no longer cleared, and no order key is handed out, when the source is still in the queue. The send then declines the memory fallback while an edit is still open (ui/src/pages/chat/chat-send-submit.ts:477), because a memory-only replacement beside a surviving stored original is the duplicate this ordering exists to prevent. A source that has no stored copy retires with its memory row, so the feature keeps working in a browser with no session storage at all.

Filtering before the cap check has a second effect worth naming: a replacement is now admissible on a queue already at MAX_STORED_QUEUE_ITEMS, where an admit-after-remove ordering would have failed.

[P1] Bind the edit token to the selected global agent

The token now records the agent that owned the row (ui/src/pages/chat/queued-message-edit.ts:72), and the single accessor validates the whole scope through visibleSessionMatches, the same helper the queue and delivery paths already use to compare (sessionKey, agentId) (ui/src/pages/chat/queued-message-edit.ts:43). Every reader — the badge, the composer marker, the drain block, and the send — goes through that accessor, so a raw global session that changed agent underneath the pane sees no edit, exactly as a pane routed to another session already did. The stalled outbox that a hidden token could leave behind goes with it.

Regressions (both fail on the pre-fix code, for the right reason)

  • keeps the original queued when the replacement's stored write is rejected — three rows queued offline, the middle one edited, then the store refuses any write that would grow it, exactly as quota does. Pre-fix: expected [ 'message 1', 'message 3' ] to deeply equal [ 'message 1', 'message 2', 'message 3' ] — the operator's message is simply gone. Post-fix the row is untouched, the edit is still open on it, the draft is back in the composer, and the storage error is visible.
  • cannot retire a row in the outbox a global agent switch left behind — a row queued in lily's global outbox, edited, then the selected agent switches to nova and the replacement is sent. Pre-fix the edit still reads active (expected true to be false) and the send retires lily's row while the replacement lands in nova's. Post-fix each outbox keeps its own.

Both drive the real handleSendChat path rather than the pieces, so the ordering itself is what is under test. The existing same-slot case was moved onto that path too, which removed a near-duplicate rather than adding one.

Size: production +68 / -23 for this repair, net +45, tests +77 / -5. That delta is mostly prose and formatter: 31 of the added lines are the JSDoc and inline comments recording the two invariants, and roughly 11 more are oxfmt re-wrapping a call and an object literal that already existed. The structural change is a reshape rather than an addition — consumeQueuedMessageEdit was replaced, not supplemented, and the remove-then-admit ordering is deleted. New code is about ten lines: isDurableQueuedMessage, the replacesId parameter through two layers, the one-line queue filter that replaces the queue read, and the send-path guard. isDurableQueuedMessage is the one addition carrying real capability — without it an edit could not be sent at all in a browser with no session storage.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 11, 2026
Panes share one outbox and one drain lane while composer state stays per
pane, so the hold that keeps a row from being delivered while it is rewritten
was invisible to the pane that drained it: a session event in a second split
pane resumed every stored outbox, saw no edit, and sent the original text.
The hold is now read across every pane subscribed to the outbox, which keeps
one source of truth — each pane's own scope-validated edit — and needs no
lifecycle of its own, so closing a pane or switching agent releases it by
simply no longer being an active edit.

The payloads an edit owns now travel with its token. The write that admits
the replacement retires the source row and tells every pane synchronously, so
by the time the send released the images the replacement had dropped, the row
holding them was already gone and nothing was released. That leaked the
payload and its object URL for the rest of the browser session.
@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Both new findings are real — I traced each one through the code before touching it — and both are fixed in e68043c8391, with the two regressions the review asked for. Thanks for catching them; the second one was mine, introduced by the ordering repair itself.

[P1] Centralize queued-edit ownership across panes

Confirmed, and worse than a guard gap: resumeStoredChatOutboxes maps over every stored outbox (ui/src/pages/chat/chat-outbox-drain.ts:586), so any pane taking a session.message or sessions.changed event drains outboxes it does not display, and a fresh drain lane simply takes whichever host got there first (ui/src/pages/chat/chat-outbox-drain.ts:553). The visible-owner preference at :531 only re-points an existing lane. So a second pane really could deliver the row being rewritten.

The hold now reads across every pane subscribed to the outbox: isQueuedMessageBeingEdited asks anyChatOutboxPaneMatches (ui/src/pages/chat/queued-message-edit.ts:55, ui/src/pages/chat/chat-queue.ts:50, ui/src/pages/chat/chat-outbox-owner.ts:238), which walks the panes the shared owner already tracks.

I deliberately did not add a hold registry to the owner. A second stored copy of the fact needs its own lifecycle — release on cancel, on send, on pane close, on agent switch — and a hold that outlives its edit is a queue stalled with nothing on screen explaining why, which is the worse failure of the two. Reading the fact from each pane's own scope-validated edit keeps one source of truth: closing a pane removes it from the owner's set, and switching agent makes that pane's edit inactive, so the hold releases by construction with no cleanup path to miss.

[P2] Retain dropped attachment payloads after an edit

Confirmed, and the mechanism is exactly as described. notifyStoredChatOutboxChanges is synchronous (ui/src/lib/chat/outbox-store.ts:103), so the admission's store write publishes and reconciles inside the admitQueuedMessageForSession call; reconcile then drops the retired source from every pane's projection because it is no longer durable and durableSeen already holds its id (ui/src/pages/chat/chat-outbox-owner.ts:141). By the time retirement looked the row up it was gone from both durable storage and the projection, so removed was null and the dropped image kept its payload and object URL for the rest of the session.

Rather than have the caller capture metadata around the write — ordering knowledge at the call site is what produced the first P1 — the payloads now travel with the edit token (ui/src/pages/chat/queued-message-edit.ts:22, released at :132). The token already records what the edit owns: the row, its scope, its position. Its payloads are the same kind of fact, and releasing from it needs no lookup that a successful write is guaranteed to defeat.

Regressions (both fail on the pre-fix code, for the right reason)

  • holds a row being edited against a drain owned by another pane — in ui/src/pages/chat/chat-send.test.ts, using the two-pane harness already there. One pane edits a queued row; the other runs the real retryReconnectableQueuedChatSends. Pre-fix it fails with expected [ [ 'chat.send', {…} ] ] to have a length of +0 but got 1 — the peer genuinely puts the superseded text on the wire. Post-fix no chat.send is issued and the row is still in the stored outbox.
  • releases only the images the replacement dropped — two images staged in the payload store, one dropped from the composer during the edit, then sent. Pre-fix the dropped payload survives (expected null, received "data:image/png;base64,…"); post-fix it is released and the retained one still resolves.

Size: this revision is production +41 / -9 (net +32), tests +66 / -1. Fourteen of the added production lines are the comments recording why the hold is derived rather than stored. anyPane on the outbox owner (7 lines) and anyChatOutboxPaneMatches (5 lines, comment included) are the new surface; the rest is the token field and the release it feeds.

Local: queued-message-edit.test.ts, chat-send.test.ts, chat-composer-queue.test.ts, chat-send-submit.test.ts, composer-persistence.test.ts, chat-queue-reorder.test.ts — 370 passed. tsgo for tsconfig.ui.json and the UI test project, run-oxlint.mjs ui/src/pages/chat, and oxfmt on every touched file are clean. Blacksmith Testbox is running the ui/src/pages/chat and ui/src/lib/chat lanes against this head; the previous head passed there at 568 files.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Aug 11, 2026
@clawsweeper clawsweeper Bot added the proof: 🎥 video Contributor real behavior proof includes video or recording evidence. label Aug 11, 2026
@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Maintainer decision: accept the documented shared-outbox barrier. While a queued row is actively edited, that row and later rows in the same outbox wait until the operator submits or cancels; this prevents another pane from delivering text that is visibly being rewritten.

Exact-head proof for b2a9ca447958f8b8834ebc4aa812d72317df306a:

This resolves the latest ClawSweeper decision item and its rank-up move. No actionable findings remain.

@vyctorbrzezowski
vyctorbrzezowski merged commit 9327c10 into main Aug 11, 2026
98 checks passed
@vyctorbrzezowski
vyctorbrzezowski deleted the feat/queue-edit branch August 11, 2026 04:59
@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
* feat(ui): edit a queued chat message in place

The pencil on a queued row, or a double-click, lifts the message and its
attachments into the composer. The row stays where it is, marked Editing,
so the position the corrected message will take is visible rather than
promised. The composer shows an edit banner with an X to cancel.

Cancelling touches storage not at all, because the row never left the
queue. Sending retires the original and hands its position to the
replacement, which lands in the same slot. While an edit is open the
drain refuses that row, so a reconnect cannot deliver the text the
operator is visibly rewriting; the queue behind it waits, which is the
same contract the held position promises.

* fix(ui): retire an edited queued row only with its replacement

The send retired the source row first and admitted the replacement second,
so a rejected store write left the operator with neither: the original gone,
the replacement never persisted, and the attachments it dropped already
released. Admission now carries the source id and swaps both rows in one
store write, so a rejected write changes nothing and the edit stays open on
the row that is still there, which is what cancelling already promises.
Filtering the source before the cap check also keeps a replacement
admissible on a full queue.

The edit token recorded only the session key, but an outbox is scoped by
session and agent, and a raw global session keeps its key while the selected
agent changes underneath it. The token now carries the agent that owned the
row and every reader validates the whole scope, so a send after a switch
cannot retire a row in the outbox it left behind.

* fix(ui): hold an edited queued row across every pane

Panes share one outbox and one drain lane while composer state stays per
pane, so the hold that keeps a row from being delivered while it is rewritten
was invisible to the pane that drained it: a session event in a second split
pane resumed every stored outbox, saw no edit, and sent the original text.
The hold is now read across every pane subscribed to the outbox, which keeps
one source of truth — each pane's own scope-validated edit — and needs no
lifecycle of its own, so closing a pane or switching agent releases it by
simply no longer being an active edit.

The payloads an edit owns now travel with its token. The write that admits
the replacement retires the source row and tells every pane synchronously, so
by the time the send released the images the replacement had dropped, the row
holding them was already gone and nothing was released. That leaked the
payload and its object URL for the rest of the browser session.

* fix(ui): release attachments from cancelled queue edits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant