Skip to content

fix(chat): load a restored row's window off the loop before reading its queue marks - #39971

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/slot-detail-queue-off-loop
Nov 20, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/slot-detail-queue-off-loop

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

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 reads slot.messages, which loads the whole window right there, on the event loop. The gateway logs Loading the transcript window of ... on the event loop when 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

  • Loading the window for a bounded page with no waiting messages. That page still leaves the window unloaded.
  • Changing what the queue marks mean.

What changed (motivation → approach → change)

slot_detail now awaits load_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 later written_queue_ids call 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_loop restores a pending row, gives it one restored waiting message, and opens it with ?limit=3. On main it fails: the gateway logs Loading 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 existing test_a_bounded_open_reads_the_page_and_leaves_the_window_unloaded still 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_loop at line 107
Sibling: 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_loop first. The other callers that skip it are listed in #39959.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • 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

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 20, 2026 13:10
@buluoray
buluoray enabled auto-merge (squash) November 20, 2026 13:10
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of c45adf54c0df9b88d397947c2b8d51f899c28588 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • The guard if slot._queue: loads the window whenever any message is waiting. The description says only restored entries read slot.messages. If that holds, guarding on entries with RESTORED_QUEUE_KEY would keep bounded pages lazy when only live messages are waiting.
  • Two other callers still skip load_window_off_loop: prompt_queue.py and members_thread_turns.py. Both are tracked in Queue cancel, edit and fresh start read a restored row's window on the event loop #39959. A shared "load before reading queue marks" helper would stop each route from re-deriving this.

[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 .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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of c45adf54c0df9b88d397947c2b8d51f899c28588 — 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

One await moves a transcript read that already had to happen off the event loop. It reuses the existing load_window_off_loop, and the description names the two unfixed siblings and tracks them in #39959.

Notes

  • Item 1 — symptom-level: the fix guards one caller of written_queue_ids (src/kiro_crew/dashboard/responsive_chat.py:269), but the function itself still reads slot.messages. The description lists 2 more callers that skip the await: prompt_queue.py:48 and members_thread_turns.py:252. It says "tracked in Queue cancel, edit and fresh start read a restored row's window on the event loop #39959", so this is an accepted, deferred general fix and does not block.

What this change ships

Inventory (2 items) — 2 justified

Intent: 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.

  1. A bounded slot-detail request on a row with a queue now loads the transcript window on a worker thread before it snapshots the slot — justified
  2. A new test shows a restored queue entry opened with ?limit=3 no longer logs the on-loop transcript load — justified

[FIRST-PRINCIPLES-REVIEWED] c45adf5

Description read

[DESCRIPTION-READ] c817bb39230a969d37b25e0c74216437826a205fc7ce8fce427e51c8cc960e80

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed c45adf54c0df9b88d397947c2b8d51f899c28588 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c45adf5

Verdict parsed from the review's SHA-scoped output markers for commit c45adf54c0df9b88d397947c2b8d51f899c28588.

False positive or not applicable? A repository writer can comment:
/ai-review override fable c45adf54c0df9b88d397947c2b8d51f899c28588 false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of c45adf54c0df9b88d397947c2b8d51f899c28588 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c45adf5

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c45adf54c0df9b88d397947c2b8d51f899c28588 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 20, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 compatibility line 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 as if slot._queue:, because a guard on the restored key alone would leave the _present_row read of slot.messages on 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 through resume_live.py:107), so you could add it to the list.

@buluoray
buluoray merged commit 07375bd into main Nov 20, 2026
98 checks passed
@buluoray
buluoray deleted the crew/slack/slot-detail-queue-off-loop branch November 20, 2026 14:29
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants