Repository navigation
fix(dashboard): hand off the queue when a turn holder never starts - #23029
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: each exit that never starts its turn marks itself, and one owner hands off the queue. It is gated on the same floor and slot checks as the synthesis launch. Notes
[DESIGN-REVIEWED] 0fc41cb Description read[DESCRIPTION-READ] da556ecbe8627ca08ab9e25ae0fcb299e93e27a6d12f107e626dae8389d5cb96 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 |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix carries two small riders, the refusal log and the reworded card. Both have a stated harm, and neither needs a recorded product decision. Notes
What this change shipsInventory (5 items) — 3 justifiedIntent: when a dashboard turn never starts, a message queued behind it still runs and its chat still gets the end-of-turn frame. FIX (closes #23015; the new tests fail on base).
[FIRST-PRINCIPLES-REVIEWED] 0fc41cb Description read[DESCRIPTION-READ] bbe914fe0a6947575d1453d902adcf1768ec0789c772416db1187489fad6d3a7 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
|
Could a maintainer re-run Fork Security Scope Review run 39728732843? It was cancelled before any leg reported, and PR Readiness is waiting on that lane. Every other check on 44e2768 has finished green. |
A send that arrives while a dashboard turn holds the slot queues behind it, and that turn's tail hands the queue off. Two holders end without entering _run_chat: a monitor wake refused at its pre-runner authorization, and an unattended turn whose wait for a background-turn permit gives up or is cancelled. Neither ran a tail, so the queued message waited for the next send, indefinitely on an app-owned slot, and the cycle sent no chat_done. The abandoned wait also showed the turn-ceiling card for a turn that never started. Both exits mark the turn unstarted, and spawn_guarded_turn's done callback hands the queue off in its place: a one-shot task takes slot.task and runs the tail's no-outcome hand-off, so the queue drains or the cycle ends with done and chat_done. The cap's wait raises BackgroundTurnAbandoned, a TimeoutError reported with its own card. A refused dashboard wake logs one INFO line naming its reason. Closes kirodotdev#23015
44e2768 to
0fc41cb
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Recommendation: APPROVE at 0fc41cb6fb92549acd22ada75939e7f11a95683f.
The fix is sound. The two exits that hold slot.task without entering _run_chat (a monitor wake refused before its runner, and an unattended turn whose background-permit wait times out or is cancelled) now mark the turn unstarted (fire, permit wait). spawn_guarded_turn's done callback then hands the queue off through one owner (hand-off gate). The gate requires that the ended task still owns slot.task under the marked generation, no send holds the admission reservation, the slot is still the registered, open, local one, and the gateway is not shutting down. The cycle-end task takes slot.task synchronously, so a concurrent send queues behind it instead of racing. BackgroundTurnAbandoned stays a TimeoutError with the same message, so the nudge fire still settles BUSY and the Issue Radar catch still renders its own card; finish_turn_task checks it before the ceiling branch (card). The new tests in test_unstarted_turn_queue_handoff.py drive the real fire path, run_background_turn and /api/chat, and assert the queued send runs and chat_done is sent.
All five AI lanes PASS on this head; every check is green (newest run per name); base is main; the head merges cleanly with current main; no change requests.
AI findings judged non-blocking
- Design Review (note): nothing forces a future
slot.taskholder to callmark_turn_unstarted. This is a suggestion for a future pinning test. Both current exits are marked and tested (mark). - First Principles (note): the refusal INFO log is a rider outside the goal. It is diagnostics only, does not change which wakes are refused, and is small (refusal).
— crew-pr-reviewer (r134)
Problem / Motivation
Goal: A message queued behind a dashboard turn that never starts still runs, and its chat gets the end-of-turn frame.
A message sent to a dashboard chat while a turn holds the slot waits in the queue, and the end of that turn starts it. Two holders end without starting a turn, and neither starts the queued message:
nudge_dashboard_fire._run_dashboard_turn): slot replaced or closing, crew/member mode refused, memory not persistent, or the wake's claim revoked;DashboardState.run_background_turn).The queued message then waits for the next send. On an app-owned session with no other sender, it never runs. The chat gets no
chat_donefor that cycle either. The abandoned wait also shows the turn-ceiling card ("This turn hit the 4-hour limit and was stopped ... raise Turn Time Limit") for a turn that never started.Why it matters
App-owned sessions (crews, app workers) are the ones with no person to send again, so their queued work stops for good when the fleet sits at the background-turn cap or a monitor wake is refused. The wrong card points the operator at the turn-limit setting, which cannot help.
Not a goal
spawn_guarded_turnand renders its own no-permit card.What changed (motivation → approach → change)
The queue is handed off only by
_end_turn_tail, which every_run_chatexit runs (#16279). These two holders return or raise before_run_chat, so no tail runs, andturn_dispatch.finish_turn_taskonly reports the task's exception, treating the abandonment's plainTimeoutErroras the turn ceiling.turn_dispatch.mark_turn_unstarted(slot)records the generation of the turn a dispatch did not start (_ChatSlot._unstarted_generation). The refused-wake return and bothrun_background_turnexits (timeout and cancellation) call it.spawn_guarded_turn's done callback, after writing the dispatch's own card, callsqueue_cycle._hand_off_unstarted_turn, the one owner of this drain. It acts only while the ended task still holdsslot.taskunder the marked generation, no send has reserved the floor, the slot is still the registered, open, local one, and the gateway is not shutting down. It takesslot.taskwith a one-shot cycle-end task, as_launch_synthesisdoes, so a send arriving meanwhile queues behind it. That task runs the tail's no-outcome hand-off: the memory-preparation and sign-in holds, then_hand_off_queue. The queue drains, or the cycle ends with itsdonerow andchat_done. It consumes no reset, retires no wait and does not re-arm AutoNudge: the fire settles its own result.run_background_turnraisesBackgroundTurnAbandoned, aTimeoutErrorsubclass with the same message, so the structured fire still settlesBUSY.finish_turn_taskreports it with its own card: the turn never started._authorize_dashboard_turnlogs one INFO line per refused wake naming the reason. A revoked claim and a replaced slot logged nothing.The exits mark themselves rather than the callback inferring "no tail ran": an inferred trigger also fires for every
_run_chattest double, since a double skips the tail, and it changed the outcome of three unrelated suites.docs/system-specs/modules/learn-cron-dashboard.mddocuments the hand-off, the abandonment card and the refusal log.Backwards compatibility
Compatible: the abandoned wait still raises a
TimeoutErrorwith the same message, so every caller that catches one keeps doing so, and nothing refused today is admitted.Removes nothing: the change adds a hand-off after two exits and replaces one card with an accurate one; no path, record, key or function is removed.
Tests
test/test_unstarted_turn_queue_handoff.py; the first four fail onmain:test_a_wake_refused_before_its_runner_hands_off_the_queued_send: a send queued while the wake authorizes runs once the claim is refused, and the INFO line names the revoked claim.test_a_wake_refused_for_a_replaced_slot_logs_why: the replaced-slot refusal is logged.test_a_turn_that_never_gets_a_permit_hands_off_the_queued_send: with a 0.05 s permit wait, the entry queued behind the abandoned turn runs.test_a_chat_send_abandoned_at_the_cap_is_not_a_turn_timeout: an app send through/api/chatabandoned at the cap shows the never-started card and no turn-ceiling card, and its cycle ends withdoneandchat_done.test_the_hand_off_is_owed_only_to_a_holder_that_never_started(unmarked, reserved, replaced, closing, remote, successor) andtest_the_hand_off_takes_the_floor_before_it_yields: the gate, and the floor taken before the first await.test/test_slot_running_readers.pylists the new reader andslot.taskpublisher, andtest/test_state_parts_facade.pythe new slot default.Manual verification
N/A — both exits need a full background-turn cap or a refused monitor claim to reach; the tests drive the real fire path,
run_background_turn,spawn_guarded_turnand the/api/chatroute against a realDashboardState.Related Issues
Closes #23015
Pattern harvest
Rule candidate: review-prompt
Pattern: a task published as
slot.taskthat can end without running_run_chatmust hand off the slot's queue, or a send queued behind it is stranded until the next send.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.