Repository navigation
fix(chat): load a restored row's window off the loop before reading its queue marks - #39971
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Small, well-placed fix: the window loads off the loop before the same-tick snapshot, and pages with no queue still leave the window unloaded. Notes
[DESIGN-REVIEWED] c45adf5 Description read[DESCRIPTION-READ] 376585775372ea92c5749da394d1846444c5684c4d8b098888666755680ce18a 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) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One await moves a transcript read that already had to happen off the event loop. It reuses the existing Notes
What this change shipsInventory (2 items) — 2 justifiedIntent: when someone opens a restored chat tab that has waiting messages, the gateway should not stall every other request while it reads the transcript. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] c45adf5 Description read[DESCRIPTION-READ] c817bb39230a969d37b25e0c74216437826a205fc7ce8fce427e51c8cc960e80 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: |
Code change approver recommendation: A person should decideWhy: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed. Before its same-tick snapshot, slot_detail now awaits load_window_off_loop whenever the slot has waiting messages, so written_queue_ids no longer reads slot.messages (a full transcript load) on the event loop for a restored, not-yet-loaded row. Both _present_row and _restored_row read slot.messages, so guarding on any queued entry is the right width. load_window_off_loop returns immediately when no window is pending. The await comes before the queue copy, refused_durable_ids and written_queue_ids, which still run with no await between them. Bounded pages with an empty queue still leave the window unloaded (the existing test still covers this). The new regression test would fail without the fix. Tier: pending: being reviewed. 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 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved. On this head the review confirmed that a bounded open of a still-pending restored row with a waiting entry loads its transcript window inline on the event loop on main. Here that load runs off the loop before the queue snapshot, and the queue copy, refused_durable_ids and written_queue_ids are still read in one tick. The new test fails with the production file reset to the merge-base (the on-loop warning is logged) and passed 10 of 10 repeats on this head. Changing the guard to if True: reds both cases of the existing bounded-page test, so the "a page with no queue stays unloaded" goal is pinned too.
Done well: the fix reuses the existing load_window_off_loop seam, and the test asserts the gateway's own on-loop warning, not a stand-in.
Optional:
- The
## Backwards compatibilityline says only where the read runs changes. A pending row whose queue holds only live entries (no restored key and no_responsive_row) now also loads its window off the loop, which main left unloaded. You could reword the line. Keep the guard asif slot._queue:, because a guard on the restored key alone would leave the_present_rowread ofslot.messageson the loop. - The sibling sweep grep also matches
src/kiro_crew/dashboard/chat_api/resume.py:568. That site is safe (a freshly hydrated slot, or the live path throughresume_live.py:107), so you could add it to the list.
Problem / Motivation
Goal: Opening a restored chat tab that has waiting messages never reads its transcript on the gateway's event loop.
A restored sidebar row keeps its transcript window unloaded until something needs it. A bounded slot-detail request (
?limit=or?before=) serves its page without loading that window, on purpose. The same request then works out which waiting messages are already written (written_queue_ids). For a message restored from disk, that check readsslot.messages, which loads the whole window right there, on the event loop. The gateway logsLoading the transcript window of ... on the event loopwhen this happens.A review lane flagged this on #39598. The code is on main as well.
Why it matters
While that read runs, every other chat request and background task on the gateway waits. A large transcript makes the stall longer.
Not a goal
What changed (motivation → approach → change)
slot_detailnow awaitsload_window_off_loop(slot)when the slot has waiting messages, before it takes its snapshot of the slot's fields. The transcript read runs on a worker thread. The laterwritten_queue_idscall then finds the window loaded and reads nothing from disk. The load sits before the snapshot so the queue copy and its marks are still read in the same tick, as the code there requires.Backwards compatibility
Compatible: the response is the same; only where the transcript read runs changes.
Removes nothing: no field, route or setting goes away.
Tests
test/test_lazy_open_slot_restore.py::test_a_bounded_open_with_a_restored_queue_loads_the_window_off_the_looprestores a pending row, gives it one restored waiting message, and opens it with?limit=3. On main it fails: the gateway logsLoading the transcript window of chat-1-alpha on the event loop; the reader did not await load_window_off_loop first. With the fix there is no such log and the queue entry is still returned. The existingtest_a_bounded_open_reads_the_page_and_leaves_the_window_unloadedstill passes, so a page with no queue keeps the window unloaded.Proof: PROVEN test/test_lazy_open_slot_restore.py::test_a_bounded_open_with_a_restored_queue_loads_the_window_off_the_loop (head c45adf5)
Determinism: the new test passed 20 of 20 runs alone with
-n0, and the whole file passes with-n4. The slot-detail test files, and the restore and queue test files that open/api/chat/slots/, pass.test/test_flake_pattern_ratchet.py, flake8, isort, mypy and the repo semgrep rules pass.Manual verification
N/A -- the unit test drives the real aiohttp route against a really restored pending row.
Real-machine verification
N/A -- the defect is where a read runs, not what the user sees; the gateway's own on-loop warning is the signal, and the test reads it.
Related Issues
Part of #39959
Found by the review on #39598.
Sibling sweep
Swept:
git grep -n "written_queue_ids\|row_already_written" -- src/Sibling: src/kiro_crew/dashboard/chat_api/slot_detail.py:1342 -- changed here
Sibling: src/kiro_crew/dashboard/chat_api/resume_live.py:132 -- not affected -- it awaits
load_window_off_loopat line 107Sibling: src/kiro_crew/dashboard/chat_api/prompt_queue.py:48 -- tracked in #39959
Sibling: src/kiro_crew/dashboard/handlers/members_thread_turns.py:252 -- tracked in #39959
Pattern harvest
Rule candidate: any async route that reads a slot's queue marks must await
load_window_off_loopfirst. The other callers that skip it are listed in #39959.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits