Repository navigation
refactor(dashboard): route chat recovery replays through one ledger - #17067
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that [DESIGN-REVIEWED] e38028f Description read[DESCRIPTION-READ] 2813cf38da6ee436b2ec4d66a27aa8a790da02e7f945d56a090216a88c5fea74 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) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: one rule decides when a Stop, a rebind or a newer message cancels every self-queued recovery replay. This is a FIX-shaped refactor.
[FIRST-PRINCIPLES-REVIEWED] e38028f Description read[DESCRIPTION-READ] 7e4ac605c20cfd85c0d1a91532c322b8821c73352f240a774544f502daf35bb5 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
17a77db to
942c06e
Compare
|
|
|
942c06e to
7cfa31f
Compare
|
|
|
|
Re-ran job 112045813315 (Backend Tests (Windows) (2)) once. Its only failure, |
The dashboard re-queues a turn for itself after five recoverable failures (model-access swap, lost-session reconnect, image-history recovery, content-filter retry, auto-continuations). Each family kept three to five private attributes on _ChatSlot and its own copy of the "cancel on Stop, rebind or newer message" rule at the queue drain, the dispatch match, the consume seam and eight arm sites. dashboard/recovery_replays.py is the new deep module behind slot.replays: arm, claim (the drained-alone rule; one entry can carry two families), sweep, a pure revalidate over a LiveSlot view, and one policy table for the per-family notices, refunds and record lifetime. chat_turn/recovery.py keeps the two seam appliers, so every chat_runner patch target still reaches them. _run_chat takes one _replay frozenset in place of four booleans. Behaviour is unchanged apart from two ruled log-only differences: the lost-session drain step no longer logs a duplicate "Suppressing re-queue" line, and cancel log lines print ReplayRevocation(...). Part of #16536
7cfa31f to
e38028f
Compare
|
|
|
Reviewed for merge triage, not approving from my side: ~1.7k added / ~1k removed lines routing chat recovery replays through one ledger. Replay decides what history a recovered session re-sends, and at this size it needs a maintainer's own review. Auto-merge is already on, so a single approval merges it; please make sure a maintainer reviews it directly. CI is green. |
Problem / Motivation
Goal: A dashboard chat's self-queued recovery replays are recorded, claimed and cancelled through one ledger on the slot, so a Stop, a rebind or a newer message cancels every replay family by the same rule.
The dashboard re-queues a turn for itself after five kinds of recoverable failure: the model-access swap, the lost-session reconnect, the image-history recovery, the content-filter retry and the auto-continuations. Each kind kept its own three to five private attributes on
_ChatSlot, and the "drop it if the user stopped, moved or replaced it" rule was written out again for each kind at the queue drain, the dispatch match, the consume seam and eight arm sites. The lost-session copy had already drifted into its own re-implementation of the shared rule.Why it matters
A replay that slips past this rule re-runs a request the user cancelled: it can repeat a destructive tool call or answer into the wrong session. With the rule spread across about twenty sites in a file that changes daily, a new replay kind needed six coordinated edits, and missing one clause (the in-flight Stop, the session-scoped count, the rebind) failed silently. One module with one rule and one family registry makes that clause impossible to forget: a new replay kind becomes a
ReplayFamilymember, aPOLICIESrow (its position is the drain's re-check order, itsconsume_phasethe consume-seam slot) and the arm site that queues it.Not a goal
ReplayRevocation(...)instead of_ReplayRevocation(...). Every family keeps its notices, refunds, ordering and timing._model_access_fallback_used,_poisoned_reset_used,_session_not_found_retry_used,_refusal_fallback_attempted,_promise_only_retries,_compaction_continue_retries) stay on the slot; the ledger only names which one a cancellation re-arms._refusal_fallback_session_key) stays owned bychat_turn/model_fallback.py; the content-filter record copies it at arm._run_chator_start_next_queued_turnbeyond their replay sites.What changed (motivation → approach → change)
Every replay family had the same shape (an entry id, a session binding, two Stop counts) and the same question to answer twice, so the shape and the question move into one deep module,
dashboard/recovery_replays.py, owned byslot.replays.POLICIESis the one registry of families: whether one queue entry identifies a family, where the consume seam checks it, its notice wording, which one-shot a cancellation refunds and whether an accepted replay keeps its record are fields of its row, andENTRY_FAMILIESis derived from it in declared order. The continuation notice's trigger-priority wording stays incancel_notice._ChatSlotreplays: RecoveryReplayschat_runner.py)slot.replays.arm(family, ...)_start_next_queued_turn)_forget_swept_replays+_drop_revoked_replaysslot.replays.claim(consumed)_run_chat_replay: frozenset[ReplayFamily]_replay_vetoed_at_consume(state, slot, claimed, phase), phase read from the policy_purge_superseded_continuationswith its own snapshot readsThe ledger never reads the slot itself: a re-check takes a
LiveSlot(binding, Stop counts, Stop in flight, waiting user input) thatchat_turn/recovery.pyreads, so the rule is a pure function. The appliers stay in that composed owner because_purge_superseded_continuationsmust keep thechat_runner._should_suppress_requeuepatch target working; the other two appliers need no patched runner name and moving them out is a logged follow-up. The owner imports the ledger from its own module, andchat_runnerre-exports one ledger name for live importers (SESSION_NOT_FOUND_CANCELLED_TEXT, which tests import from the runner).Interface (
slot.replays: RecoveryReplays):arm(family, *, entry_id, session_key, stop_gen, session_stop_gen)entry_iddisarms an entry family; never raisesclaim(consumed) -> frozenset[ReplayFamily]revalidate(family, live) -> ReplayRevocationsweep(live_ids, families) -> [(family, entry_id)]sweep_refundsarmed/entry_id/disarmreplays_of(slot)AttributeError(fail closed)POLICIES/ENTRY_FAMILIES/consumed_in(phase)Configuration: none. Ordering: the drain re-checks families in registry order (
ENTRY_FAMILIES, pinned by a test); the consume seam checks the lost-session and image families before the turn-start allowance refresh and the model-access and content-filter families after it, as each row'sconsume_phasesays.Deletion test: delete
recovery_replays.pyand the 19 attributes return to_ChatSlot, the revocation rule returns as two implementations plus three inline copies, the drained-alone match returns four times in the drain, the per-family notices and refunds return to eight functions inchat_turn/recovery.py, and_run_chatregains four parameters: five families times the drain, dispatch and consume seams, plus eight arm sites.Intentional log-only differences (ruled): the lost-session drain step no longer logs a second "Suppressing re-queue" line right after the continuation purge logged the same line; the revocation repr inside cancel log lines reads
ReplayRevocation(...)instead of_ReplayRevocation(...).Docs:
learn-cron-dashboard.mdlists the ledger among the slot's components, notes it as the one slot-owned container behind its own interface, and itsrecoveryrow gives the recipe for a new family; of the three citations of deleted names inerror-handling.mdandmodel-fallback.md(coordinator grant), two now nameRecoveryReplays.revalidateand one names_run_chat's_replay.Backwards compatibility
Compatible: every removed name is private to the dashboard turn runtime, and its only producers and readers are migrated in this diff.
SESSION_NOT_FOUND_CANCELLED_TEXTstill imports fromkiro_crew.dashboard.chat_runner.Reader: src/kiro_crew/dashboard/chat_runner.py:_start_next_queued_turn -- chat -- the only producer of
_run_chat's replay flags now passes_replay(test_recovery_replays.py::test_the_drain_claims_a_replay_that_may_run)Reader: src/kiro_crew/dashboard/chat_runner.py:_run_chat -- chat -- the consume seam reads
_replay(test_recovery_replays.py::test_the_consume_seam_vetoes_a_stopped_replay_before_the_provider)Reader: src/kiro_crew/dashboard/chat_turn/model_fallback.py:_restore_refusal_fallback -- chat -- reads
_refusal_fallback_session_key, which stays on the slot (test_dashboard_chat.py::TestRunChatRefusalFallback::test_restore_dropped_when_slot_rebound)Reader: src/kiro_crew/dashboard/chat_regenerate.py:api_chat_slot_edit_resend -- chat -- its shallow slot copy shares
replaysbut only appends rows (test_chat_regenerate_cov80.py)Reader: src/kiro_crew/dashboard/chat_rewind.py:api_chat_slot_rewind -- chat -- same shallow copy, same rows-only use (test_dashboard_chat_rewind.py)
Tests
test/test_recovery_replays.py(new, 89 tests)POLICIESrow, entry families in pinned drain order, each in exactly one consume phase, every refund names a real_ChatSlotslot); one row per family: arm then claim alone vs merged, two families on one entry, Stop moved / Stop in flight / rebind / user input, the recorded vs live session count, sweep and its refund, notices,replays_offailing closed; and both seams through a real slot (drain drop + refund, drain claim, consume veto + refund, accepted record kept only for the content filter)test_dashboard_chat.py,test_model_access_fallback_interactive.py,test_chat_session_not_found_recovery.py,test_refusal_replay_consume_abort_chat_done.py,test_promise_only_recovery.py,test_cross_surface_stop_gate.py: private attribute writes becomeslot.replays.arm(...), reads becomearmed()/entry_id()/revalidate()assertions;TestRunChatRefusalFallbackgains an end-to-end refuse -> swap -> enqueue -> relink -> drain test and a rebind check on the requeue carry, pinning both content-filter arm sitestest_chat_runner_composition_contract.py_AWAIT_FREE_PHASES; the_run_chatsignature pin names_replayReplaced, not layered: the two direct unit tests of
_refusal_replay_vetoed_at_consumenow drive_replay_vetoed_at_consume, the seam every family shares. Mutation proofs: 22 mutations, each turning a named test red. They break the rebind clause, the empty-binding rule, the drain-head sweep, the drained-alone claim, each family's session-count key, the content-filter record's lifetime, the model-access refund, the in-flight Stop, user input, the session-scoped count, the consume seam, a continuation arm, the two-family claim, the await-free drain, the binding at both content-filter arm sites, the registry's keyed flag, consume phase and order, a refund naming a missing slot, andreplays_offailing closed.Evidence, recorded on this exact base:
logsfield only).scripts/local-gate.py --dry-runselects 1,973 backend files, so per the campaign capacity rule the related set runs in CI.Manual verification
N/A — unit coverage sufficient: the change is internal to the turn runtime and both seams are driven through real
_ChatSlots in the tests and the differential.Related Issues
Part of #16536
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)