Skip to content

fix(chat): hold a signed-out slot's queue per entry, not per queue - #28329

Open
rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:fix/signout-queue-provenance
Open

rnoack1 wants to merge 1 commit into
kirodotdev:mainfrom
rnoack1:fix/signout-queue-provenance

Conversation

@rnoack1

@rnoack1 rnoack1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A prompt sent while the CLI is signed out is never lost, and the first send after signing in resumes the queue in order.

When a turn hits a signed-out CLI, _requeue_auth_retry puts back only runner-authored, synthesis and sub-agent input. A person's own prompt that ran into the failure, whether drained from the queue or sent straight from the composer, is gone from the post-login resume. And on top of #22224, a send made after signing in that queues behind a pending conversation discard is stranded when the discard lands, because the release reads the sign-in failure flag, which only a turn that runs can clear.

Why it matters

Anyone whose sign-in expires mid-session loses the prompts they typed during the outage, with no sign that they were dropped. The stranded post-sign-in send looks like a hung chat until the person sends again.

Not a goal

What changed (motivation → approach → change)

Telling a held prompt apart from a send made after the failure cannot be done later from the slot's state, because both leave it looking the same. So the turn that hits the failure records it, at the moment it holds the queue.

Piece What it does
Put back The failing turn puts the person's input back at the queue head, as the same entries, so each keeps its origin, channel and actor stamps. Their parked admission work ended when the turn ran, so they drop it and are admitted afresh. A typed send from the composer or a linked thread gets one entry, carrying the turn's own stamps and the row's author; a linked thread's entry keeps reaching the model as typed, as its direct turn did. A composed prompt, like the OpenAI-compatible endpoint's, is not put back: its client was told the request failed. Nothing goes back once the model reported the input used.
One row A put-back run keeps the transcript row it ran under, matched as that row rather than by its text, and drains again as the same run. It is never written a second time. A /prompts get turn puts back what the person typed, not its expansion.
No edit A put-back entry already has its row, so the queue edit route refuses it with 409 queue_item_already_sent. Cancel withdraws a put-back entry, leaving its row unanswered; cancelling one member of a merged run frees the rest from that row.
Order A person's idle send made while held prompts wait is queued behind them, not run ahead, from the composer, a Bot DM's responsive send and a linked Slack thread alike. A queued thread message keeps the row the route wrote, so the drain writes no second row, and its model input is the text as typed, as on the direct thread path; the row stays redacted. Sending a held prompt's words again queues a second copy, and both run in order. Only /usage, /context and /help, which start no model turn, still run at once, from the composer or a linked thread; every other message starting with / waits like any send.
Mark Right after, the failing turn marks every queued entry as held.
Release signout_hold_active holds the queue until an unmarked person send is queued, anywhere in it. Then the queue tries again in order. A failed try puts everything back and marks it again, so it loses nothing. Only a person's send triggers a try: app, cron, crew and sub-agent arrivals do not, and no parked-queue drain starts a held slot until one does. While held prompts wait and a sub-agent runs, only a person's send at the queue head runs past the child, from the composer or a linked thread, and every held prompt runs before the send that released them; an app, MCP or cron entry at the head waits for it.

Every drain site that read _last_turn_auth_required reads signout_hold_active instead: the discard release in session_reset.py, the turn-end hand-off and both stop hand-offs in queue_cycle.py and turn_stop.py, and the completion hint in chat_utils_completion.py. The failing turn's put-back and mark run in turn_failures.py, the sign-in arm. The new names are bound on the chat_utils, chat_runner and chat_handlers facades. queue_drain.py hands each turn the entries it drained, through a new _run_chat parameter carried on turn_locals.py; slot_queue_repository.py gains queue_restore, bound on the slot in state_parts/; responsive_chat.py reuses a put-back entry's row and reports it as already written; slash_commands.py hands the nested /prompts get turn its row, drained entries and typed flag. The linked-thread route in slack/handler_runtime/inbound.py hands its turn the redacted row it wrote, and turn_locals.py carries the typed flag to the sign-in arm. PUT_BACK_KEY lives in slot_queue_repository.py, read by the merge in chat_utils_injected_rows.py. _send_binds_agent moves unchanged from chat_send.py to a new chat_api/send_binding.py, bound on the chat_handlers facade, only to keep chat_send.py within the 2000-line cap.

Backwards compatibility

Compatible: a slot that never hits a sign-in failure takes every path it took before. The signature tests are updated for the new optional _run_chat and _start_next_queued_turn keywords.

Accepted limit: the put-back group and row link live only in memory, so after a gateway restart a held run may write its user row a second time, and the restored queue drains without waiting for a new send. Before this PR the prompt was lost.

Removes nothing: no key, field, route or public function is removed or renamed; the new queue-entry keys are process-local.

Tests

  • test_signout_put_back.py: put-back of drained, merged and composer input; app and tagged input left alone; exactly one user row after a fail-then-drain cycle, for a single entry, a merged run and a composer send; a put-back entry does not merge with a later send; a /prompts get from the composer or the queue goes back as typed and writes one row; a put-back entry counts as written; a composed prompt is not put back; a redacted thread send goes back under its own row and reaches the model as typed; a composer send is charged to its author; drained entries drop their ended admission work; with held prompts queued, a person's send at the head passes a running sub-agent and an entry with no person origin does not; held prompts in separate groups all run before the send that released them; an open editor on that entry still holds it.
  • test_signout_release.py: the hold check, including a send behind retained entries (the head-only failure); the failing turn marks its queue; a post-sign-in send behind a discard drains when it lands; a landed discard with only retained entries drains nothing; cron and crew sends do not release the hold, and a cron send to the idle held slot starts nothing; the turn-end hand-off and the completion hint read the hold.
  • test_signout_release_stop.py: both stop hand-offs and the held-synthesis drain resume a post-failure send.
  • Four existing tests queue an unmarked entry to stand for a held prompt; each now marks it. The two boundary-fence tests from fix(chat): route every queue drain through one derived queue-held gate #22224 are unchanged and pass.
  • test_dashboard_chat_handlers_coverage.py: editing an entry put back under a merged row returns 409; cancelling one frees the rest from that row.
  • test_signout_slack_route.py: a linked thread's turn gets the redacted row the route wrote; a thread message waits behind held prompts, writes one user row when it drains, and reaches the model as typed while its row stays redacted; a resend there runs after the held copy; a thread send after sign-in starts a held prompt past a running sub-agent.
  • test_signout_resend.py: an idle send waits behind held prompts; sending a held prompt's words again runs both in order; a refused resend leaves the held prompt queued; /usage runs past held prompts, while /prompts get, /compact and a path like /var/log/syslog wait; with a sub-agent running, a composer send after sign-in starts a person's held head but not an app's.
  • test_responsive_chat.py: a responsive resend of a held prompt queues behind the held copy.
  • test_dashboard_chat_handlers_coverage.py: a lone put-back entry can be cancelled.
  • Each guard, removed one at a time, turns its test red.

Proof: not provable -- other: the new tests import names the fix adds, so a run with every hunk reverted fails at collection; each guard was instead removed one at a time and its test went red

Manual verification

N/A: the sign-out state is reached by AcpAuthRequired, which the tests raise through the real _run_chat; a real signed-out CLI was not used.

Related Issues

Closes #23145

Builds on #22224 (merged).

Sibling sweep

Swept: git grep -n "_last_turn_auth_required" -- src/
Sibling: src/kiro_crew/dashboard/chat_turn/queue_cycle.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_api/turn_stop.py -- changed here
Sibling: src/kiro_crew/dashboard/kiro_readiness.py -- not affected -- it reports sign-in state for a rerun, not whether the queue may drain
Sibling: src/kiro_crew/dashboard/chat_turn/session_reset.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_utils_completion.py -- changed here

Pattern harvest

Not generalizable: the distinction rests on one handler knowing which entries it held, specific to the sign-in failure path.

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

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 2, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 566a1cb to 7c82ea8 Compare November 2, 2026 17:03
@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 2, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 7c82ea8 to 51f1630 Compare November 3, 2026 21:04
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 3, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 51f1630 to ac5f549 Compare November 3, 2026 22:05
@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 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 2b9de0dcf3965d8063d249a98bf20749898be845 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 2b9de0dcf3965d8063d249a98bf20749898be845 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: every drain gate that read _last_turn_auth_required now reads signout_hold_active, and nothing is taken away. _send_binds_agent is still re-exported from the chat_handlers facade.

Notes

  • The linked-thread route stamps PUT_BACK_KEY with a fresh uuid on a send that was never put back, so it can reuse its row and drain alone. PUT_BACK_KEY now means two things that withdrawable_put_back and the cancel route treat the same. A separate "row already written" key would keep the sign-in put-back meaning clean.
  • The hold now depends on four process-local queue-entry keys (_signout_retained, _signout_put_back, _signout_shared_row, _model_input_as_typed), read in queue_drain, responsive_chat and chat_utils_injected_rows. The PR changes the queue behaviour that docs/system-specs/modules/session.md and task.md describe, but updates no spec. Recording the hold and release contract in its owning spec would stop the next drain site from missing it.

[DESIGN-REVIEWED] 2b9de0d

Description read

[DESCRIPTION-READ] 7906837d33b54d1c91b3ba183c045fc140811665d134f09863c0f0cac38914ae

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 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of 2b9de0dcf3965d8063d249a98bf20749898be845 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: the fix sits at mechanism level, and it converts all 7 drain gates that read _last_turn_auth_required. Two of the items it adds are second spellings of things the repo already has.

Notes

  • Item 6 — duplicate: signout_gate hard-codes {"/usage", "/context", "/help"} as the "starts no model turn" list. That is a third hand-kept list next to _DASHBOARD_SERVED_SLASH_COMMANDS (chat_utils.py:283) and KAS_LOCAL_INSPECT_COMMANDS (kas_local_commands.py:67), and the three will drift apart. Subtraction: delete the literal and read membership from one of the existing sets.
  • Item 4 — inherited: withdrawable_put_back makes an exception to the cancel refusal. That refusal was put there because "removing only the queue entry would leave the message there and hand the text back to the composer, where sending it again writes a second copy" (prompt_queue.py:49-51), and a put-back entry still has that problem. The helper also never uses its slot argument and has one caller. Subtraction: delete withdrawable_put_back, so put-back entries take the existing 409.

What this change ships

Inventory (8 items) — 6 justified

Intent: prompts typed while signed out are kept and run in order after the person signs in. FIX.

  1. A person's prompt that hit a signed-out CLI goes back to the head of the queue with its stamps — justified
  2. A put-back run reuses its transcript row and writes no second copy — justified
  3. Editing a put-back entry is refused with 409 — justified
  4. A put-back entry can be cancelled, and its row stays unanswered — inherited, overrides a recorded refusal
  5. A person's idle send waits behind held prompts (composer, Bot DM, linked thread) — justified
  6. /usage, /context and /help skip the hold — duplicate of _DASHBOARD_SERVED_SLASH_COMMANDS
  7. The queue is held until a person's new send releases it; cron, app and crew arrivals do not release it — justified
  8. _send_binds_agent moves to send_binding.py, as the line cap requires — justified

[FIRST-PRINCIPLES-REVIEWED] 2b9de0d

Description read

[DESCRIPTION-READ] 8cccd0a594a4aad3a58ac3ad4275474df297fd61ccf5a7660f20241dbd479257

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 2b9de0d

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[GPT-REVIEWED] 2b9de0d

@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 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🔴 BLOCK (blocking)

Which legitimate operations does ac5f5493ecafa91238dd9e0b81183b8a88cc7d3e newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

the review scope was never resolved: the generate job did not finish (it timed out, failed or was cancelled), so no leg ran; its log names the step that stopped

No [SCOPE-REVIEWED] marker for this head was produced, so the model's text is withheld: it cannot be shown to describe this revision. See the job logs.

@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from ac5f549 to 9a5b297 Compare November 4, 2026 00:22
@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 4, 2026
@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 5, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 06182f5 to c41d67d Compare November 9, 2026 14:53
@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 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 fix/signout-queue-provenance branch 2 times, most recently from bf044e9 to 454454c Compare November 9, 2026 20:43
@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 9, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 454454c to 4a24d89 Compare November 10, 2026 04:27
@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 10, 2026
@rnoack1
rnoack1 force-pushed the fix/signout-queue-provenance branch from 4a24d89 to b995d56 Compare November 11, 2026 01:37
@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 11, 2026
@KiroCrewCaptain

KiroCrewCaptain commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 22% chance that this change introduces a defect, above the 12% limit for approving on its own.

Fixes lost prompts during a sign-in outage. The failing turn puts the person's drained entries (or a direct composer/thread send) back at the queue head, marks the queue held, and a later unmarked person send releases it in order. I checked every drain site that read _last_turn_auth_required: all switched to signout_hold_active, except kiro_readiness, which correctly still reads the old flag. A repeat failure re-marks the queue without looping. A slot that never hit a sign-in failure takes the same paths as before, because the new branches need retained or put-back keys. App, composed and regenerate turns are excluded from put-back. MODEL_AS_TYPED is set only where the direct thread path already sends raw text to the model. Cancel and edit semantics have tests. Tests are extensive, CI is green and the AI review lanes pass; the Security Scope BLOCK was on an earlier head and only reports a job timeout. No concrete failing path found.

Tier: 2, held for a person: 39 files, more than 20.

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 1e6db39126 · 1539 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

This changes behaviour users already rely on, so it needs a design sign-off from a maintainer before it can merge. A maintainer will post the decision here.

To propose a design, follow the request-for-change process in CONTRIBUTING.md (docs/request-for-change/).

The review found no blocking defect on this head. Every drain site that read _last_turn_auth_required now reads signout_hold_active. The failing turn marks its held entries through mark_signout_retained. Put-back restores the same queue dicts with their stamps and row link, so a re-run does not write a second user row. The tests drive the real _run_chat and _start_next_queued_turn, and most gates are tested on both sides. Doing it this way, instead of re-enqueueing text, is a good choice.

The decision for a maintainer is the new ordering. After a sign-in failure, a person's idle send from the composer, a Bot DM or a linked thread now waits behind the held prompts. So does every slash command except /usage, /context and /help. Issue #23145 says "the person's own send after signing in still runs". On main that send runs at once. Recording the choice on #23145 would help. MODEL_AS_TYPED_KEY exists only because of this rule. It lets queued linked-thread entries and channel put-backs reach the model without redaction. That matches main's direct thread path, but it widens which queued entries skip redaction, so please weigh it with the ordering decision.

Optional:

  • recovery.py:931: no test covers the if not _consumed_reported: guard, so deleting it reds nothing, and a consumed prompt would run twice after sign-in. The consumed keyword on _signed_out in test/test_signout_put_back.py is never used. Adding a consumed case would cover the guard.
  • queue_drain.py:966: if row reuse misses, the unredacted next_msg becomes the transcript row. Keeping a redacted copy for slot.append would close that gap. A test that pins inbound.py and recovery.py as the only setters of MODEL_AS_TYPED_KEY would stop a later route from copying it.
  • No spec changed. learn-cron-dashboard.md (near line 3422) could state the per-entry mark, the release on a person's send, the /usage, /context and /help exception, and the limit after a gateway restart.

A sign-in failure puts the person's prompts back and marks what it holds; a send made after it lets the queue try again.

This branch has not been deployed

No deployments
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) readiness: checking Automated validation is still running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hold queued prompts on a signed-out slot per entry, not per queue

2 participants