Skip to content

fix(chat): hold a queued message while its card's editor is open - #30549

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/fix-queued-message-edit
Nov 6, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/fix-queued-message-edit

Conversation

@buluoray

@buluoray buluoray commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A queued message that is being edited when the running turn ends is sent with the edited words, not the original ones.

A user opens the pencil editor on a queued card while a turn is running and starts typing. If the turn ends before they save, the queue drains the entry as it was: the agent receives the unedited message, the card disappears, and the save then targets an entry that is already gone (404, swallowed). The user sees their edit lost and the old text sent.

Why it matters

Editing a queued message is exactly what people do while waiting on a long turn, so the window where the turn ends mid-edit is common. When it hits, the agent acts on words the user was in the middle of changing, which can send it in the wrong direction with no warning.

Not a goal

What changed (motivation → approach → change)

Symptom → cause. The queue's only record of an edit is the PATCH sent when the editor commits. Nothing tells the server an editor is open, so _start_next_queued_turn (chat_turn/queue_drain.py) pops slot._queue[...]["content"] at turn end with the pre-edit text. The later PATCH finds no entry (api_chat_slot_queue_edit returns 404, and useQueuedMessageActions.onEdit swallows it).

Approach. Tell the server while the editor is open, and reuse the drain's existing user hold instead of adding a new drain path.

  • src/kiro_crew/dashboard/queue_edit_hold.py (new): POST /api/chat/slots/{slot}/queue/{queue_id}/editing with {"editing": true|false}. true stamps the in-memory entry with _edit_hold_until (monotonic, 300 s, never persisted: underscore keys are outside _DURABLE_QUEUE_KEYS). false releases it. A release on an idle slot starts the drain under slot._lock, the same guard responsive_chat.accept uses. The deadline releases the hold on its own via call_later.
  • One check, queue_edit_hold.edit_hold_blocks_user_turn, is asked by every path that starts a user turn. Only a card's Run now passes it.
  • chat_turn/queue_drain.py: hold_users is also true while any entry is held, whatever picked the entry (a turn's end, a responsive send's promotion, a queued arrival, a restored card). User entries stay queued and system injections still drain, as with the sub-agent hold. A held queue is never auto-promoted, so a promoted entry cannot park a system injection.
  • chat_api/chat_send.py: a send on an idle slot while an entry is held joins the queue behind it, steer or not, instead of being answered ahead of the earlier queued messages.
  • chat_utils_injected_rows._dequeue_next_system_message: skips a held entry, so a requeued steer (which passes the sub-agent hold) also waits while its card is open.
  • chat_api/prompt_queue.api_chat_slot_queue_edit: releases the hold after the edit is stored, so the drain starts with the new words.
  • Website: QueueStack reports onEditOpen(queueId, true) when the pencil opens the editor and false on cancel, on an unchanged/empty commit (those route to cancel), when switching to another card's editor, and on unmount. It sends no release beside a save: a release that reached the server before the PATCH would drain the old words. useQueuedMessageActions maps it to the new API call, and the two hosts (ChatPane, ChatPage via busyTurnControls and ComposerDockView) pass it through.

builder-security checked: the new route sits on the existing dashboard listener behind the same auth middleware, and applies the same deny_app_slot_access(..., "slot_queue_edit") gate as the PATCH. No new listener, bind, or auth change.

Backwards compatibility

Compatible: the new route and the onEditOpen prop are additive. A client that never calls the route sees the old drain behaviour, and a hold always ends by save, close, unmount or deadline.

Removes nothing: no route, key, prop or behaviour is removed or tightened; the drain only waits while an editor is open.

Tests

  • test/test_queue_edit_hold.py: the drain leaves a held entry queued; open editor → turn end sends nothing → PATCH → the drained row is the edited text; close without a save → the original entry drains; input validation (400/404); deadline expiry; the dashboard registers the route.
  • website/src/test/QueueStack.test.tsx (QueueStack editor hold): open reports true, cancel reports false, a save sends no release, unmount with an open editor releases.

Proof: not provable -- other: prove.py's all-hunks mode cannot import the new module once reverted (INCONCLUSIVE); --per-hunk shows the drain-hold and PATCH-release hunks are caught by test_the_drain_leaves_a_held_entry_queued and test_saving_the_edit_sends_the_edited_words (head e477092). The frontend tests were checked by hand: removing the onEditOpen(queueId, true) call fails both QueueStack editor hold cases.

Also run, one file at a time with no -n: test_queue_edit.py, test_queue_drain_preserve_attachments.py, test_chat_handlers_composition_contract.py, test_chat_runner_composition_contract.py, test_chat_runner_coverage_queue.py, test_queue_reorder.py, test_queue_cancel.py, test_queued_user_text_display.py, test_dashboard_server_composition_contract_guards.py, test_flake_pattern_ratchet.py; vitest QueueStack.test.tsx, QueueStackReadOnly.test.tsx, useQueuedMessageActions.test.tsx.

Manual verification

Not run against a live gateway. The backend tests drive the real PATCH and hold handlers through aiohttp and the real _start_next_queued_turn, with only the turn spawn stubbed.

Screenshots / video

Why no screenshot: The queue card and its editor render exactly as before; the change only adds a request when the editor opens and closes.

Related Issues

Reported by a dashboard user: editing a queued message sends the unedited version once it can be sent.

Follow-up: #31300 (renew the edit hold's 300 s deadline while the editor stays open)
Follow-up: #31437 (per-editor holds for the same card in two tabs and fast switching between cards)

Sibling sweep

Swept: git grep -n "api.editQueuedMessage|sideQueueEdit" -- website/src
Sibling: website/src/pages/chat/SideChat.tsx -- not affected -- side chat queue uses its own server-authoritative /side/queue endpoints and drain
Sibling: website/src/hooks/useQueuedMessageActions.ts -- changed here

Pattern harvest

Not generalizable: the defect is specific to an editor that commits only on save while a background consumer can take the same record first.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 5, 2026 16:22
@buluoray
buluoray requested a review from iamwhatever November 5, 2026 16:22
@buluoray
buluoray enabled auto-merge (squash) November 5, 2026 16:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of b982ca80c2ff69be39db2a5197504b0c15ec89e7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks: no control, label or layout changes. The editor now sends an open/close signal to the server, and the queue waits while a card's editor is open.

Notes

  • When a card's editor is open on an idle slot, nothing tells the user the queue is waiting for them: the turn looks finished and the queued card just sits there. A muted inline hint in the editor, such as "Waiting for your edit", would explain the pause.
  • A message sent from the composer while a card is being edited now joins the queue behind that card instead of running, and nothing says why. The same hint would cover this case.
  • After 300 s with the editor still open, the original text is sent and the card disappears mid-edit without warning. Until Queued-card edit hold: renew the 300 s deadline while the editor stays open #31300 lands, say this in the editor, or at least keep what the user typed.

[UX-REVIEWED] b982ca8

Description read

[DESCRIPTION-READ] 0a4bd7656e8d7131e44d1865362a989f9fcb79f07df279cab0bb5fe7d72ef117

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 Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b982ca80c2ff69be39db2a5197504b0c15ec89e7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level blocker: the hold reuses the drain's existing user-hold path, lives only in memory, always ends at a deadline, and removes nothing.

Notes

  • If a tab is closed or crashes with an editor open, nothing sends a release (an unmount release does not run on tab close). Every user turn on that slot, including a fresh composer send on an idle slot, then waits up to 300 s with no on-screen reason. That is bounded and reversible, but Queued-card edit hold: renew the 300 s deadline while the editor stays open #31300 should cover it.
  • edit_hold_blocks_user_turn treats one held card as holding the whole queue, so an open editor on the last card also holds back the cards ahead of it. Holding only the entries from the held one onward would keep the edited text safe without stalling the earlier messages.

[DESIGN-REVIEWED] b982ca8

Description read

[DESCRIPTION-READ] 4585a3e1fdff32458ae76b9b7a8d48a0340dabb5437b1ef5c8990db889cdfc51

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 Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b982ca80c2ff69be39db2a5197504b0c15ec89e7 — 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: the hold reuses the drain's existing hold_users path. One rider holds back a fresh composer send, and the Goal does not need it.

Notes

  • Item 3 — rides along: or _edit_held in chat_api/chat_send.py holds back a new composer send on an idle slot for up to 300 s while any card's editor is open. The Goal is met without it, because the drain still checks edit_hold_blocks_user_turn when that send's turn ends, so the held card still waits for its save. Subtraction: delete the _edit_held term from the send-time condition and keep the hold on the drain paths only.

What this change ships

Inventory (8 items) — 4 justified

Intent: when a turn ends while someone is editing a queued message, the edited words are sent, not the old ones. This is a FIX.

  1. Opening a queued card's editor holds that message: a turn that ends mid-edit no longer sends it — justified
  2. Saving the edit releases the hold, and the edited text then runs — justified
  3. A composer send on an idle slot waits behind an open card editor — rides along
  4. A queued steer whose card is open waits instead of draining — justified
  5. A release keeps the hold for 2 s, so moving straight to another card's editor never drains — undeclared
  6. Cancelling the held card releases its hold — undeclared
  7. Switching slots remounts the queue stack (key=slot), which releases an open editor's hold — undeclared
  8. The client sends a card's open, save and release in order, and releases the hold when a save fails — justified

[FIRST-PRINCIPLES-REVIEWED] b982ca8

Description read

[DESCRIPTION-READ] 3b1c690dd7db541d7888873e836b1211a94223ed6143c2a8cf65c5f08154fefe

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed b982ca80c2ff69be39db2a5197504b0c15ec89e7 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b982ca8

Verdict parsed from the review's SHA-scoped output markers for commit b982ca80c2ff69be39db2a5197504b0c15ec89e7.

False positive or not applicable? A repository writer can comment:
/ai-review override fable b982ca80c2ff69be39db2a5197504b0c15ec89e7 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ human override accepted

Human judgment by @buluoray overrides the GPT 6.1 finding for b982ca80c2ff69be39db2a5197504b0c15ec89e7; the recorded reason is authoritative for this commit.

[GPT-OVERRIDE] b982ca8

This comment is updated in place on each push.

The model was not re-run because an authorized human decision supersedes it.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b982ca80c2ff69be39db2a5197504b0c15ec89e7 false-positive: <reason, 20 to 500 characters>

@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from e477092 to 8b9d2f9 Compare November 5, 2026 20:11
@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for head 8b9d2f9 (findings raised on e477092).

Static Ratchet Gate (test_error_code_contract) — fixed. The two new error responses in queue_edit_hold.py carry code (invalid_field_type, queue_entry_not_found); the test pins both. Await Fast Gate and Coverage Gate were red only because this gate skipped the test lanes.

Opus — release drain skips the sign-in hold — fixed. drain_if_idle now gates on idle_slot_admits_drain(state, slot) (sign-in hold, task done, admission reservation, stop state) plus not queue_edit_held(slot), in place of the hand-written subset. Pinned by test_a_release_on_a_slot_held_for_sign_in_starts_nothing.

GPT F1 — cancelling a held entry strands the queue — fixed. api_chat_slot_queue_cancel calls release_and_drain on the removed entry. Pinned by test_cancelling_the_held_entry_sends_the_one_behind_it. Swept the same class (a hold left behind with no release): the other queue_remove_by_id callers remove recovery replays, stale admissions inside the drain itself, or sub-agent completions, none of which shows a pencil. A save the server refuses (400/409) or never receives also left the hold for the deadline (Design note): useQueuedMessageActions.onEdit now releases the hold when the save fails, pinned in useQueuedMessageActions.test.tsx.

GPT F2 — an opening POST landing after its close — not changed; the adjudication downgraded it. It needs two POSTs from one tab to arrive in reverse order inside one body read, and the result is a hold that clears itself at the 300 s deadline, with no wrong text sent. A per-card request chain to rule it out costs more than the harm.

Design note — a killed tab keeps its hold for 300 s — deferred, as the note says; recorded in the shortcut: comment.

UX note — no sign the queue is waiting on the open editor — out of this PR's goal; the editor being open on screen is the sign today.

builder-security checked: no new listener; the route keeps the PATCH's auth and deny_app_slot_access gate.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 5, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 8b9d2f9 to 00d5b7a Compare November 5, 2026 20:46
@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for head 00d5b7a (GPT findings raised on 8b9d2f9).

F1 — a session switch leaves the outgoing queue held — fixed. Both hosts key QueueStack by slot (ChatPane: key={slotKey}, ComposerDockView: key={activeSlot}), so a switch remounts the stack and its unmount releases the hold through the outgoing slot's callback. Pinned by releases through the outgoing slot when a slot key change remounts it in QueueStack.test.tsx.

F3 — feature map — fixed. The Sessions row of docs/feature-map/README.md names dashboard/queue_edit_hold.py and POST /api/chat/slots/{slot}/queue/{queue_id}/editing.

F2 — editor handoff to another card can drain that card first — not changed; the adjudication downgraded it. It needs merging on, the turn ending while the first editor is open, and a click straight onto another card's pencil. What goes out is the person's own queued words as written, the same as before this PR, and the later save fails visibly. An acknowledged handoff across blur, PATCH and release is a new client/server ordering contract for that one path.

@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 and removed readiness: action required A blocking check or review needs attention labels Nov 5, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 00d5b7a to 456348c Compare November 5, 2026 21:10
@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 5, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 456348c to 46ebdf6 Compare November 5, 2026 21:37
@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 5, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 390cb51 to 010cd05 Compare November 6, 2026 11:01
@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 6, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 010cd05 to 53cbfe8 Compare November 6, 2026 12:40
@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 Nov 6, 2026
A turn that ended while the person was still typing in a queued card's
editor drained the entry as it was: the agent got the unedited words and
the save then landed on an entry that was already gone.

Opening the editor now places a short server-side hold on the entry
(POST .../queue/{queue_id}/editing). While it is held the drain keeps
user entries queued, the same way the sub-agent hold does, and system
injections still flow. Saving the edit releases the hold after the text
is stored, closing the editor without a save releases it, and a
300-second deadline releases it on its own; each release starts the
drain on an idle slot.
@buluoray
buluoray force-pushed the crew/slack/fix-queued-message-edit branch from 53cbfe8 to b982ca8 Compare November 6, 2026 13:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@buluoray

buluoray commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt b982ca8 deferred #31437: Needs two editors open on the same queued card while the slot is idle, then one closed. The worst case equals behaviour before this PR (no hold at all): the original words send and the card visibly disappears. Per-editor hold identity is tracked in #31437.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

AI-review override not recorded: issue #31437 is not a tracked deferral. What is missing:

  • no deferred-finding label
  • no assignee (owner)
  • no due date (add a 'Due: YYYY-MM-DD' line to the issue body, or a milestone with a due date)

Fix the issue, then re-issue the command.

@buluoray

buluoray commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt b982ca8 deferred #31437: Needs two editors open on the same queued card while the slot is idle, then one closed. The worst case equals behaviour before this PR (no hold at all): the original words send and the card visibly disappears. Per-editor hold identity is tracked in #31437.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a deferred release (class deferred) for the gpt AI finding on b982ca80c2ff69be39db2a5197504b0c15ec89e7.

Needs two editors open on the same queued card while the slot is idle, then one closed. The worst case equals behaviour before this PR (no hold at all): the original words send and the card visibly disappears. Per-editor hold identity is tracked in #31437.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@buluoray
buluoray dismissed iamwhatever’s stale review November 6, 2026 17:13

The requested follow-up is open as #31300; this review was on an older head (800a460).

@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.

Approving b982ca8.

What I checked on this head:

  • All checks are green and none is pending, including PR Readiness, CodeQL, E2E, Integration, Coverage Gate and the Design, First Principles, Opus and UX lanes. The GPT lane shows a human override with a recorded reason and a tracked follow-up. The cancelled entries in the gate list are older duplicate runs, and each has a newer run that passed.
  • The fix matches the problem: the server now learns that a queued card's editor is open, and the drain treats that entry like the sub-agent hold. User entries wait, system injections still pass, a save, a close, a cancel or the 300 s deadline releases it, and a release on an idle slot starts the drain. Run now is the only path that skips the hold, and a held queue is never auto-promoted.
  • The new route POST /api/chat/slots/{slot}/queue/{queue_id}/editing is registered next to the PATCH and DELETE on the same queue entry and checks what a slot route should: it looks up the slot, checks app slot access with deny_app_slot_access, reads the body with the bounded JSON reader, requires a boolean editing, and returns coded 400 and 404 errors. The hold lives only in memory and is never persisted, so a restart does not restore it.
  • It adds no restriction: the default behavior for a queue with no open editor is unchanged.
  • No regex in the added product code.

I did not set auto-merge, because it is already set on this PR.

@buluoray
buluoray merged commit d4b20d0 into main Nov 6, 2026
100 of 111 checks passed
@buluoray
buluoray deleted the crew/slack/fix-queued-message-edit branch November 6, 2026 18:11
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 2026
bolichen97 pushed a commit that referenced this pull request Nov 9, 2026
)

A turn that ended while the person was still typing in a queued card's
editor drained the entry as it was: the agent got the unedited words and
the save then landed on an entry that was already gone.

Opening the editor now places a short server-side hold on the entry
(POST .../queue/{queue_id}/editing). While it is held the drain keeps
user entries queued, the same way the sub-agent hold does, and system
injections still flow. Saving the edit releases the hold after the text
is stored, closing the editor without a save releases it, and a
300-second deadline releases it on its own; each release starts the
drain on an idle slot.

Backport note: the conflicts were context only. The feature-map Sessions
row and the ComposerDockView destructuring line carry unreleased wording
and props (composerPresence), so they keep release's text and gain only
this fix's additions.

(cherry picked from commit d4b20d0)
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.

3 participants