Repository navigation
fix(chat): leave a resume prefetch that has started running on a focus change - #33768
jeeshofone wants to merge 1 commit into
Conversation
…s change A focus change or blur cancelled the socket's pending resume prefetch at any point, so a cancel landing after the debounce killed a runtime whose session/load had already succeeded, logged as a failed setup. Only a prefetch still debouncing is cancelled now; one already starting finishes and is reaped by the unclaimed-prefetch TTL and population cap. A cancelled setup's kill now says cancelled session setup cleanup. Fixes kirodotdev#33711
59c92ce to
fc8a912
Compare
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix stops focus changes from cancelling prefetches that have started, and the TTL and population cap that already exist still limit what those prefetches hold. Notes
[DESIGN-REVIEWED] fc8a912 Description read[DESCRIPTION-READ] 6bd07575fcfd079fad05ed40e6e24754e14b71f158171b1472190641024567a2 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 |
Opus 5.5 Review (fork) — 🔴 changes requested (blocking)Reviewed Blocks: prefetches that keep running after the user leaves a slot now hold both places in the eager-spawn limit (the semaphore allows two), so the slot the user actually settles on gets skipped and cold-starts. BLOCKING — src/kiro_crew/dashboard/ws.py:72 Notes:
|
GPT 6.1 Review (fork) — 🔴 changes requested (blocking)Reviewed Adjudication upheld 1 of 1 blocking finding(s); those must be resolved before merging. BLOCKING -- src/kiro_crew/dashboard/ws.py:710 -- Returning focus still cancels the preserved prefetch
[BLOCK-MERGE] fc8a912 Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — UPHOLD. Harm rung: MEDIUM. Hiding and revealing a tab is a common path. When it happens during resume setup, the prefetch this PR means to preserve gets killed and restarted. That is recoverable but costs a full restart and session load. Confirmed conditions: on blur the task is not cancelled, but the handler returns Fix cost: small and local. On focus, reuse the slot's own pending task once it is past the debounce. That is one extra check in the guard, with no new state, no change to the binding-change signals, and nothing new for later readers to carry. |
|
This PR and #33898 both close #33711. Both change |
|
#33898 fixes the same issue and also covers two cases this PR misses:
The only thing #33768 adds is the |
Problem / Motivation
Goal: Moving between dashboard chats no longer kills a resume prefetch that has already started loading its session.
_handle_slot_focusedcancelled the socket's pending resume prefetch on every focus change and blur, whatever stage it had reached. A cancel landing after the 1.5 s debounce went through the start'sexcept BaseExceptioncleanup, which killed a runtime whosesession/loadhad often already succeeded, and logged it asfailed session setup cleanup.Why it matters
Clicking through a few resumable chats after a gateway restart threw away runtimes 2 to 17 s old, each costing a full start (the agent process plus its MCP servers). The cancel also read in the log as a setup failure.
Not a goal
failed init handshake cleanupreason inruntime_spawn_launch.py.schedule_eager_spawnon a newer slot signal or fromstop_eager_spawnsat shutdown.What changed (motivation → approach → change)
Symptom: focus or blur killed a started prefetch. Root cause: the focus path cancelled at any stage, not only during the debounce it exists to collapse. Change:
chat_turn/eager_spawn.pyrecords a speculative start once its debounce ends.eager_spawn_debouncing(task)reports whether it is still debouncing, andchat_runnerre-exports it like the other eager-spawn entry points.ws._handle_slot_focusedcancels the previous prefetch only while it is still debouncing. A prefetch already starting finishes, and the existing unclaimed-prefetch TTL and population cap reap it if no turn claims it. Rapid tab flipping still leaves at most one debouncing prefetch per socket.providers/acp_runtime_start.pynames a cancelled setup's killcancelled session setup cleanup.Backwards compatibility
Compatible: no input, key or API is narrowed; a started prefetch is kept instead of cancelled, and one kill reason string gains a cancelled variant.
Removes nothing: no path, record, key or function is removed.
Tests
test_eager_spawn_slot_frames.py::test_focus_change_and_blur_leave_a_started_prefetch_running: a prefetch past its debounce survives a focus change and a blur. Fails on main'sws.py(assert not True).test_acp_provider.py::test_a_cancelled_setup_kills_its_runtime_as_cancelled_not_failed: a cancelled setup kills with the cancelled reason.Proof: PROVEN test/test_acp_provider.py::TestStartKiroRuntimeResume::test_a_cancelled_setup_kills_its_runtime_as_cancelled_not_failed (head 59c92ce)
Manual verification
N/A — the focus-path decision and the kill reason are both covered by unit tests; no live gateway run.
Related Issues
Fixes #33711
Sibling sweep
Swept: git grep -n "prev_task.cancel|_eager_spawn_task" -- src/
Sibling: src/kiro_crew/dashboard/chat_turn/eager_spawn.py -- not affected -- schedule_eager_spawn cancels on a newer signal for the same slot, whose bindings changed
Sibling: src/kiro_crew/dashboard/chat_turn/eager_spawn.py -- not affected -- stop_eager_spawns cancels at gateway shutdown, where the kill is wanted
Pattern harvest
Not generalizable: the debounce-only cancel is specific to the focus prefetch signal.
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.