Skip to content

fix(chat): re-read kept rows a link or reply change outdated - #15029

Closed
billygerhard wants to merge 1 commit into
kirodotdev:mainfrom
billygerhard:fix/warm-cache-over-ceiling
Closed

billygerhard wants to merge 1 commit into
kirodotdev:mainfrom
billygerhard:fix/warm-cache-over-ceiling

Conversation

@billygerhard

@billygerhard billygerhard commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A long chat you have scrolled back through no longer downloads its whole transcript into the open tab every time it reconnects, finishes a turn, or is switched back into.

#13203 bounded the background pane warm (warmSlotCache) to the rows the pane already holds, floor PANE_HYDRATE_LIMIT, ceiling SLOT_DETAIL_MAX_LIMIT (500). The open pane's refresh (refreshSlot) shares the same bound. But countMatchedFetchLimit answers undefined when the count is over the ceiling, and both callers treat undefined as "no limit". So a pane or view holding more than 500 rows (any long chat paged back through "load earlier") still asks the server for the entire transcript: the warm on every background turn end, the refresh on every reconnect and turn end of the open chat.

Measured against origin/main with a stubbed server, first request the warm makes:

rows in the pane's cache request
100 / 499 / 500 limit=100 / 499 / 500
501 / 600 / 2000 no limit (whole transcript)

refreshSlot behaves the same above its ceiling (REFRESH_LIMIT_CEILING, also 500); an existing test pinned that unbounded read on purpose.

#13236 and #16005 (merged since) gave refreshSlot, switchSlot and the background warm (warmSlotCache) their own bound: a window that misses the view or cache walks older one page at a time (walkWindowBackTo) instead of reading unbounded. This PR is rebased onto both and keeps that walk on all three paths; what it still adds is the staleness guard below, which the walk needs as much as any kept head: a walked window keeps the rows above its anchor verbatim, so a marked view or cache reads whole instead of walking, and a walked head still offering a sign-in link reads whole.

Why it matters

The chat most likely to hold more than 500 rows is exactly a long-running session: an always-on babysit or monitor loop that a user scrolls back through. For a 52 MB / 5,894-row session that is 52 MB fetched, redacted server-side and parsed into whatever tab is open, on every one of that session's turn ends, which is the renderer-kill described in #12907. It also puts the whole-corpus read and redaction back on the gateway's worker thread, which the comment above the warm names as the reason the bound exists.

Not a goal

  • Changing the ceiling value, or what the pane ends up holding after a warm or refresh.
  • Bounding the other deliberate unbounded paths: an empty view, a cache holding a row with no readable timestamp, and a coverage shortfall measured over rows the page would actually replace.
  • Making the unbounded handler branch report its total in collapsed units. The client now records which units a retained count is in instead (below); changing the server's count would move every other total consumer too.

What changed (motivation → approach → change)

Symptom (on the base this PR was opened against; #13236 and #16005 have since fixed it on main with the walk): a refresh or warm of a transcript over the ceiling is unbounded. Root cause: "no count-matched bound because the span exceeds the ceiling" and "no bound can be proven safe" share one undefined, and both callers give both the unbounded read.

Approach: the bound itself is now #13236's and #16005's clamp and walk, on all three readers. This PR adds only the guards that keep a stale or sign-in head from surviving them, and the units rule a wide chat's first bounded read needs:

  • refreshSlot, switchSlot and warmSlotCache all walk older on a coverage miss, as on main.
  • A marked view or cache (below) reads whole instead of walking, carrying the bounded read's total as comparableTotal.
  • A walked head still offering a sign-in link reads whole (below).
  • A background warm whose window anchors nothing in a cache with a raw retained count (below) reads whole once, so a remote clear is still read as a shrink.

Keeping a head is only sound while the server still serves those rows the way the view or cache holds them. Two changes break that: a redaction host allowed or revoked (workspace-wide, so every loaded session, in every tab), and a reply's variant switched (any loaded row of that session). A new markLoadedRowsChanged action marks the affected slots in slotHeadUnverified, valued by a loadedRowsEpoch counter: every loaded slot, the open one included, or only the named ones. While a slot is marked, its refresh accepts a count-matched page only where it spans the view and otherwise takes the whole read, its switch and warm read whole on a coverage miss instead of walking, so its next read re-serves every loaded row. That read clears the mark only if it saw the same epoch at dispatch, so a change landing mid-read keeps its mark. The open slot is marked rather than trusted to its re-read: switching away drops that re-read's answer and caches the view it would have replaced, and the mark then makes the switch back re-serve it. The mark is evicted with the slot's other per-slot state.

The slot switch had the same width-only case. slotSwitchFetchLimit clamps a cache over 500 rows to a 500-row window, and the coverage check then measured the WHOLE cache against it, so the shortfall was certain and every switch back into a long chat retried unbounded. The switch reducer already keeps every cached row above the window's first row as a head (the shared olderHeadAbovePage cut), so coverage is now measured only over the cached rows from that cut on, the rows the window actually replaces. No cut (the window moved past the whole cache, an ambiguous anchor) measures the whole cache as before.

The mark is driven by the server, not only by the tab that clicked. The dashboard status frame, sent on every connect and every 5 seconds, now carries redaction_hosts_gen: a value that moves with every input that conditions how rows are served (dashboard/serving_gen.py: one registry, SERVING_INPUTS, holding the allow list, the companion's exempt hosts and the operator's oauth_endpoints.json; an HMAC of them under a domain-separated use of the dashboard's persisted signing secret, as chat_tag_grants does, computed off the event loop (it stats the OAuth file) by the status funnel and the allow/revoke routes: keyed because the status frame reaches every socket, app tokens included, while the allow list is owner-only, so a plain hash would let a socket confirm guessed hosts; with a per-process boot value folded in, because the write counts below live in memory and restart at zero, so a list revoked back to its boot state after a restart would otherwise hash to the value a tab took before it; the cost is one re-read of what is on screen per gateway restart: the open chat and each pane showing (a split view tops out at a handful), never the background caches, which keep their mark and heal on their next read. A view holding more than one page ceiling of rows (older pages loaded by scrolling up) re-reads its whole transcript, since no bounded page re-serves every row it holds. A value from content alone would avoid this, but it reaches tabs on a polled frame, so a list written and written back between two polls would answer the value a tab already holds while that tab kept rows read in between. A gateway restarts rarely and each restart already drops every socket, so this rides a reconnect that re-reads the open chat anyway. It never returns to an earlier value within a process: the allow list's part counts writes and the OAuth file's carries its stat (mtime, the kernel-kept change time, size, device and inode, so even a backup restored with its old mtime moves it), so a list or file changed and changed back still reads as changed, and a render spanning both changes cannot vouch for its rows). Allow and revoke also answer with the value their write left. noteRedactionHostsGen is the one decision both feed: a status frame's first value is a baseline, a value that moved means mark every loaded slot and re-read the open one, and this tab's own write adopts its value, so the status frame carrying the same change afterwards is not handled a second time (and a write that changed nothing, such as re-allowing a host, moves nothing). So every tab heals, including one whose socket was down through the change and one where the change was made from Settings. A variant switch marks its own slot, which also covers a switch in a background session whose refresh cannot run. An older page (loadOlderMessages) read before such a change is dropped like a cancellation rather than prepended above rows the change's own re-read healed; the next climb reads it again. A tab that sees a chat_variant_switch frame applies it in place to the row the server rewrote (the newest assistant row carrying variants) where it holds that row, logged like any row patch (noteVariantSwitch), so a regenerate in a long chat keeps its re-read bounded; only a slot whose rewritten row it cannot find is marked. A tab whose socket was down through a chat_variant_switch frame learns of the switch from the slot list: each slot carries variant_seq, a revision of its switches (and of regenerated replies finalized as new variants): minted by mint_tags_revision (as each slot's tag revision is) when the slot is created and on every switch or variant attach, including a regenerate's terminal flush that sends no switch frame, so a gateway restart never hands back a value a tab already holds; it is patched on every change and sent in full on reconnect, so a switched row 500 rows back cannot survive a reconnect. A moved count marks that slot alone and re-reads it if it is open; so does a first count for a slot already holding rows (a resume, or a read that raced the first list), since nothing vouches those rows predate no switch; the live frame carries the same count, so the tab that saw the switch does not re-read it twice. The workspace-wide served value does not move for a switch, and it is read before any row of a transcript read, so a switch landing during a read can only make the value older than the rows. The owner's credential-redaction switch is reachable from the render but is not an input: it acts only inside owner_view(), which only the file viewer enters, and a test pins that no chat render can reach it.

The baseline is the value the tab's rows were served under, not whatever status frame arrives first. Every transcript read now reports redaction_gen, read before its rows are prepared (so a change landing mid-render leaves the rows newer than the value, never older), and the tab's first applied read seeds the baseline; a status frame only seeds it when no read has, and only for a document holding no rows yet: rows installed by a path that reports no value (a history resume) make the first status value a change, so a revoke landing before it cannot become the baseline. So a revoke landing between a tab's first read and its first status frame is still a change there. An unloaded list serves as empty (allowed_hosts_for answers nothing until the background load lands), so its value is the empty list's: rows served just after a gateway start compare unequal to the loaded list and heal as soon as the list loads. list_fingerprint lives in the kiro_crew.security package, whose measured line budget in test/test_security_gate_liveness.py is re-pinned for it and for exfil.oauth_extension_changes (34 lines together), with the reason written beside it. The invariant this rests on is pinned where rows are served (_prepare_messages in chat_utils.py): any new input that changes what already-served rows look like must move that value or mark loaded rows, or long chats keep stale rows above their newest page.

Handling a change re-reads the open chat; a background pane on screen (a split view, a member's panes) re-reads itself as soon as its slot is marked, and a cache no longer on screen keeps its mark and heals on its next read, so one click never fans out whole-transcript reads to every session opened this visit. If that re-read fails while the slot is still marked (slotHealFailed), the open chat or the pane shows its load error with a Retry, so a revoked link is never left clickable silently. A change this tab made from a redaction card in a background pane marks that pane (which re-reads itself) and still refreshes the open chat, whose rows the change outdates just as much (the status frame will not report it, since the write already adopted the value). A background pane's first read (its hydrate) that comes back served under an outdated value re-reads before installing. Every re-read, in warm, switch and hydrate alike (a refresh needs none: the mark drops it), goes through one helper (renewUntilCurrent): a re-read is checked again only when the value moved while it was in flight, so a revoke landing mid re-read re-reads again, while a re-read that disagrees with an unchanged value is the server's current answer and is kept (no loop right after a gateway restart). A refresh, warm or switch dispatched before a change that has since marked its slot (a variant switch, an allow or revoke) is dropped when it lands (slotRowsChangedAt + markedSince; a switch, which must finish, re-reads the whole transcript instead): reads carry no ordering, so a late one would otherwise reinstall the rows the change outdated after the change's own read had cleared the mark. It is capped at three re-reads, and a page still outdated once the cap is spent is refused (ObsoleteReadError), never installed: installs carry no ordering, so a late one could overwrite the fresh rows the newest change's own read already put on screen, and that read is what heals the view. A switch refused this way keeps the rows on screen rather than clearing them, and reports nothing. If a pane's hydrate re-read fails, the pane shows its usual load error with Retry (which re-runs the check) instead of a blank pane; the outdated rows are never installed. A marked switch also takes the whole read when its cache holds a persisted row with no readable timestamp (a row streamed this session): the coverage measure cannot place that row, so it cannot prove the window re-served it. A read that was already in flight when the change landed answers with rows the change outdated; the refresh, warm and switch each compare the read's redaction_gen with the document's current value and re-read instead of writing outdated rows over the fresh read the change asked for. A marked view also no longer counts a page as covering it when id-less durable rows (history read off disk without a mid) sit above the page's anchor: those rows would be kept verbatim, so the view takes the whole read.

One consequence needed its own fix. The unbounded handler branch counts raw rows (every per-turn done row) where a bounded read counts after collapsing them, and a wide chat's retained baseline came from unbounded reads until now. Its first bounded warm then read the smaller collapsed count as a server shrink and dropped the pane's live identity-less tail (the in-flight streaming row). retainServerTotal now records when a count came from a read that says it was unbounded (slotServerTotalRaw, cleared with the other per-slot maps on eviction); the settled background hydrate now says which read it was too, while a running hydrate's count stays refused as before. Against a raw baseline the warm reducer compares the payload's own raw total whenever it has one (an unbounded read, or the coverage retry), so a genuine truncation such as another client clearing the slot is still detected. Only a bounded page with no raw count declines the shrink and same-count checks: the same "no comparable count, keep the rescue" answer an absent baseline gets. The collapsed count then becomes the baseline.

A sign-in (mcp_oauth) row still offering its Authorize link is never kept above a bounded page: the server withdraws a dead child's link only as it serves the row, so a refresh, warm or switch whose kept head holds an open one reads the whole transcript instead (hasOpenOAuthRow, pinned per path in chatSlice.overCeilingRead). A settled link (completed, failed, superseded or expired) keeps the bounded read.

A whole read on the open chat takes as long as the transcript is big, so on a streaming slot a live chunk landing inside it is near-certain. Its rows predate that chunk and the fulfilled reducer rebuilds the view from them, so when the live-frame counter moved since dispatch, refreshSlot installs every read past its first page (the marked whole read, its unbounded retry, and the sign-in whole read) with the live tail carried over (withLiveTail): the view's rows after the newest row the read also holds, which the read lacks, and the view's streaming row in place of the read's older copy of it. Discarding the read instead would leave a revoked link clickable until the turn ends, which is what the read exists to stop. A patch to a row already on screen or cached (chat_message_update: a sign-in banner settling or retired, a tool row's result) moves no live-frame count, so every such patch, for any slot, is numbered into a capped log (rowPatchLog, store/chat/rowPatch.ts, withReplayedPatches) and the ones past dispatch are replayed onto every page a refresh installs (bounded pages included), and onto what a switch or a background warm installs, so a settled or retired Authorize link is not put back; a read that outlived the log's cap is refused as a failure, so a marked chat or background pane shows its "Couldn't refresh" notice with Retry rather than silently keeping the revoked link.

Costs this takes on knowingly, all bounded to what is on screen: any change to a serving input (an allow or revoke, a write to oauth_endpoints.json, including an editor save or a scheduled touch that only moves its stat, and the first status frame after any gateway restart) re-reads the open chat, and each pane on screen, whole once; more than three changes landing inside one switch refuse that switch's read, and the newest change's own refresh fills the chat instead. On Windows st_ctime is the creation time, so a restore can reproduce the file's whole stat; the value therefore also folds in exfil.oauth_extension_changes(), a count of changes to the endpoint set the loader has returned in this process, so rows rendered under a set since restored never share a value with the restored state on any host.

One trade a maintainer should decide: TestServingInputsArePinned's reach walk and PINNED_READS fail when code reachable from the render reads a module-level name the pin does not list, in one of the seven serving-state modules, or when a new module enters that chain; a read or module that drops out passes, so only a genuinely new read costs a judged re-pin (the regeneration command is in the test file). A constant those modules add but the render never reads passes too. Reviewers split on it: one asks to drop the walk and keep only the signature pins and the SERVING_INPUTS behaviour tests, another to extend it to method calls, which it does not follow today.

Today the only server-side changes to already-loaded rows' content are the registered serving inputs and a variant switch (which marks its slot); nothing else re-serves rows differently.

Backwards compatibility

Compatible: no persisted-state change; one additive status field (redaction_hosts_gen) and one additive response field (gen). (slotServerTotalRaw, slotHeadUnverified and loadedRowsEpoch are in-memory store state). The allow and revoke responses gain a gen field; a client that does not read it handles its own write exactly as before. A view or pane at or under the ceiling takes the identical request path as before (pinned by tests).

Tests

New website/src/test/chatSlice.overCeilingRead.test.ts (29 tests):

  • panes holding 501, 600 and 2000 rows warm with exactly one limit=500 read, and views of those sizes refresh with exactly one limit=500 read; afterwards each holds every original row plus the new ones, in order;
  • a warm page that moved past the whole cache walks older with bounded reads only and ends up with every row; a warm page missing a cached row below its anchor is settled with bounded reads only;
  • a pane or view holding exactly 500 rows keeps the count-matched read;
  • a raw baseline met by a bounded warm keeps the streaming tail and is replaced by the collapsed count; a bounded baseline with the same fall is still read as a shrink (control);
  • a raw baseline met by a remote clear (bounded probe anchors nothing, unbounded retry) is still read as a shrink, so the cleared rows do not survive in the pane;
  • an unbounded refresh records its count as raw, and the next bounded one clears it; a settled background hydrate is recorded raw only when it was unbounded;
  • a marked 600-row view's refresh takes one unbounded read and re-serves a changed older row and clears the mark, while an unmarked refresh of the same view stays bounded (control); a marked 100-row view keeps the count-matched read when its page spans the view, and retries unbounded when the page only overlaps it;
  • switching into a cache of 501, 600 and 2000 rows takes exactly one limit=500 read and ends with every row; a window that moved past the whole cache, or is missing a cached row below the cut, still retries unbounded;
  • markLoadedRowsChanged marks every loaded slot including the open one, or only the named slots; a marked 600-row cache's next switch and next warm each re-serve a changed older row and clear the mark; a second change landing while a read is in flight keeps its mark; a switch away that drops the open view's re-read leaves the view marked, and the switch back re-serves it.

ChatPageFollowup also pins that the "Allow for this host" reload marks another loaded session's cache. chatSlice.overCeilingRead pins noteRedactionHostsGen: a status frame's first value is a baseline and a moved one is handled once; this tab's write is handled once whichever of it and the status frame lands first; an empty value is unknown, but a write without one is still handled. UseWebSocketCoverage pins that a status frame whose redaction_hosts_gen moved marks a background cache and re-reads a 600-row open chat whole, while the first value and an empty one change nothing, and that a variant switch marks a background slot. Backend: test_redaction_handlers.py pins that allow and revoke answer with the value their write left, unmoved by a write that changed nothing; test_redaction_allow.py pins that the fingerprint of an unloaded list equals the empty list's, moves with every change, returns to its value when the list does, and shows none of the list; test_dashboard_status_snapshot.py pins that the status snapshot carries it. test_slot_detail_full_history.py pins the counting contract the units marker rests on, where the counting lives: the same transcript with per-turn done rows reports its raw count unbounded and its collapsed count on a bounded read. chatSlice.overCeilingRead also pins the read seeding: a first read's value makes a differing first status frame a change, a later read never moves a baseline, and a pane hydrate and a warm seed it too; test_slot_detail_full_history.py pins that both read branches report the value. chatSlice.overCeilingRead also pins that a change re-reads a mounted background pane, that a refresh, a warm and a switch whose read was served under an outdated list each re-read, and that a marked view with an id-less row above its oldest identified row takes the whole read. ChatPane.hydrateBound pins that a pane hydrate served under an outdated value re-reads instead of installing, and that a re-read answering the same value installs rather than looping; chatSlice.overCeilingRead pins that this tab's write from a background pane warms that pane and refreshes the open chat, pins that a marked switch holding a timestamp-less row takes the whole read, and pins renewUntilCurrent (re-reads when the value moves mid re-read, keeps an answer under an unchanged value, refuses a still-outdated page at the cap) and that a refused switch does not wipe the chat, and that a refresh or warm predating a variant switch is dropped; chatSlice.overCeilingRead, ChatPane.hydrateBound and ChatPageFollowup pin that a failed re-read of a marked slot shows the load error with a Retry that re-reads it (and that an unmarked slot's failure, or an outdated read refused, does not); TestServingInputsArePinned also pins that the published value is keyed by the persisted secret, not a plain digest; ChatPane.hydrateBound also pins a revoke landing during the hydrate's re-read. test_slot_detail_full_history.py::TestServingInputsArePinned fails when _prepare_messages or _prepare_messages_scoped gains a parameter or consults a new module helper, or when the set of project functions reachable from _prepare_messages at any depth changes (followed by name and through modules, mod.helper(), whether imported at module level or inside a function; methods are not followed and are left to review); the reached modules are pinned by name, and in the seven that hold or read serving state (dashboard.chat_utils, dashboard.state, security.redaction_allow, security.redaction_switch, security.exfil, config.loader, platform.context) the module-level state their reached code reads is pinned by name too (PINNED_READS, a readable list per module, not per-function hashes), so a helper that starts reading a new setting fails it, while renaming, splitting or adding a helper that reads nothing new passes untouched (both pins are printed for a judged re-pin by running the test file directly) (walked in a fresh interpreter, so test fixtures cannot skew it); it also pins that the served value moves with each registered input, so a new serving input cannot land without deciding how it invalidates kept heads. The same invariant is stated at the slot-detail handler's render and at the client's filterMessages, the two other places a serving change could be made. ChatPane.hydrateBound also pins that a failed re-read shows the load error and that Retry recovers.

UseWebSocketCoverage pins that a variant switch on a 600-row view takes one unbounded read, and ChatPageFollowup pins the same for the "Allow for this host" reload.

chatSlice.refreshSlotBound's "above the handler ceiling" test now pins the bounded request and that the view is not shrunk, instead of the unbounded read. That test pinned the unbounded read to guard one harm, a bounded page shrinking the view and dropping scrollback; the kept head keeps the rows above the page, so the intent stands and only the mechanism it pins changed.

Mutation checks, each reverting one piece: the refresh change (4 fail), the warm's marked whole read, its raw-baseline whole read and its sign-in head whole read (one test each fails, after the #16005 rebase), the units gate (the raw-baseline test fails), declining every raw-baseline comparison instead of using the retry's raw count (the remote-clear test fails), the coverage condition (the hole test fails), the raw-marker write and the hydrate's flag (their marker tests fail), the marked refresh's ceiling skip and its overlap refusal (one test each fails), the switch's coverage cut (3 fail), the unverified-head gate on the switch, on the warm, and on the page's mark dispatch (one test each fails), clearing a mark regardless of its epoch (the mid-read test fails), leaving the open slot unmarked (7 fail, including the switch-away race), the refresh's mark clear, the variant switch's mark, the status-token wiring, a missing baseline, and reading an empty token as a change (each fails its test), dropping the status value's dedup, its baseline, a value-less write, the status wiring, or the page reporting its write as a status (each fails its test), and a constant fingerprint or an empty status field (one test each fails).

Local gates on the rebased head: tsc -p tsconfig.app.json, npm run lint, jscpd, lint:i18n and i18n:check with I18N_BASE_REF=origin/main, theme-colors, phantom-classes, restyle-ratchet, the bundle-size gate, and the feature-map and decision-ledger gates all pass. All 83 store and chat-pane suites (src/store, src/test/chatSlice*, refreshSlot*, ChatPane*, switchSlot*) pass, including chatSlice.warmSlotCacheBound, chatSlice.boundedRefetchShrink and ChatPane.hydrateBound.

Manual verification

N/A: unit coverage drives the real store and reducers against a stubbed server at the request boundary, which is where the behavior lives. Nothing in the rendered UI changes.

Screenshots / video

The one new visible state: when the open chat's re-read after an allow or revoke fails, the chat says so with a Retry (heal-error) instead of leaving rows the change outdated on screen silently. Captured from the built SPA by website/scripts/capture-heal-failed-notice.mjs (the redaction card's own mc:redaction-hosts-changed event, with the transcript endpoint failing, then Retry with it healthy):

Light Dark
Notice, light Notice, dark
Repeat failure, light Repeat failure, dark
Retrying, light Retrying, dark
After a successful retry, light After a successful retry, dark
Split-view pane notice, light Split-view pane notice, dark
  • Row 1, the notice: "Couldn't refresh this session. Recent changes, like a removed link, may not show here yet.", with Retry. It names a removed link as its example because that is the one stake worth a user's attention (a just-revoked link could still be clickable in the rows on screen); "like" keeps it true when a reply variant switch raised it instead. A Retry that fails again says "Still couldn't refresh this session…", in words rather than only by the notice's re-entrance motion, and returns to the first wording once the notice clears; every Retry beside a pane's notice, including the one for a pane whose first read was outdated, shows "Retrying…" while it runs. It stays up while a Retry is in flight (the button reads "Retrying…", aria-disabled and aria-busy, meanwhile: still focusable, so a keyboard user keeps their place, and the re-mounted open-chat Retry takes focus back) and clears only once a re-read lands; in split view only the grid pane shows it, not a second banner above the grid; a Retry that fails again re-mounts the notice, so its role="alert" is announced again rather than the click reading as ignored.
  • Row 2, a Retry that fails again: the notice reads "Still couldn't refresh this session. Recent changes, like a removed link, may not show here yet.", with Retry (capture-heal-failed-notice.mjs keeps the endpoint failing through one Retry).
  • Row 3, retrying: while the Retry is in flight (the harness holds the response open), the notice stays and the button reads "Retrying…", busy.
  • Row 4, retried: after Retry, the notice is gone.
  • Row 5, split view: the same notice in a split-view pane beside the open chat (scripts/capture-heal-failed-pane.mjs), where the copy wraps beside its Retry; the harness asserts the notice sits inside the second pane. The whole second pane renders dimmed because it is the unfocused pane of the split; its Retry is enabled.

A background pane shows the same copy in its existing load-error slot (chat-pane-hydrate-error); its Retry re-runs that pane's warm (pinned by ChatPane.hydrateBound). Everything else changes how many rows a fetch requests; the panes render the same rows before and after.

Related Issues

Refs #12907. Follows #13203.

Pattern harvest

Rule candidate: review-prompt
Pattern: an undefined meaning "no safe bound" consumed as "no limit", where one of the declines (over a ceiling) has a safe bounded answer the caller never asks for.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

Contribution License Agreement

@billygerhard
billygerhard requested a review from a team September 29, 2026 14:50
@billygerhard
billygerhard requested a review from a team as a code owner September 29, 2026 14:50
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — 🟡 CONCERNS

UX-level review of 53acb3162fa25d77ccb57d1a651a31f494e6f9ce via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: CONCERNS

The failure notice never says what the risk is: a link you blocked may still be clickable. Nobody has done a first-time read of these screenshots.

Watch

  • The copy doesn't name the consequence. heal_failed says "Couldn't refresh this session. Recent changes, like a removed link, may not show here yet." The code fires this after an allow/revoke or a reply-variant switch. The danger the code comments name is "a revoked link would stay clickable", but the notice never says that. "Refresh" also reads as something the user asked for, and "removed link" isn't a term the blocked-link cards use. So in attachment-01 the reader has no reason to press Retry and can't tell what is unsafe to click meanwhile. Severity: low frequency, but it is the only warning on a safety-relevant state.
  • One failure, two layouts. In the main view (attachment-01), Retry sits inside the notice as a footer. In a split pane (attachment-09), Retry floats outside the red box at a different size. Users who meet both will see two different components for the same failure. Severity: low, cosmetic, happens on every split-view failure. Fix: pick one placement for both.
  • Two pane states are only shown in the main banner. The pane's "Still couldn't refresh…" and "Retrying…" states never appear in a pane screenshot (attachments 03–06 show them in the main banner only). They use the same strings, but nobody has seen them at the pane's narrower width.

Suggestions

  • Change heal_failed to "Couldn't reload this session after a link change. Links you blocked may still be clickable here." Make heal_failed_again the same with "Still couldn't reload…".

[UX-REVIEWED] 53acb31

Description read

[DESCRIPTION-READ] cff0052a34498e645fc303b48b3511a3e285640d35093411e96c2414c0ad780e

That sha256 names everything this verdict read: the PR description, plus the 13 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

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — 🔴 changes requested (blocking)

Reviewed 53acb3162fa25d77ccb57d1a651a31f494e6f9ce via the fork AI-review pipeline; updated in place on each push.

2 of 2 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- website/src/store/chatSlice.ts:987 -- Variant frames overwrite an unrelated earlier reply

if (m.role === 'assistant' && Array.isArray(m.variants) && m.variants.length) { target = m; break }
Regenerating a later turn while an earlier two-variant reply is loaded -> a permission-time _flush_segment broadcasts the new assistant before attaching its variants -> this scan patches the earlier reply instead; if that reply sits above the bounded refresh window, its corrupted content survives.
Anchor: residual/crash-data-loss-corruption
Fix: Carry the rewritten row’s mid in both variant emitters and patch only that identity; mark/re-read when it cannot be identified.

BLOCKING -- website/src/store/chat/slotRefresh.ts:109 -- Live-tail preservation discards recovered stream text

const kept = liveStreams ? rows.filter(m => m.role !== 'streaming') : rows
A disconnect loses chunk B, then chunk C reduces during reconnect refresh -> withLiveTail replaces the server’s complete ABC streaming snapshot with the incomplete local AC stream -> B remains missing after recovery, and the received sequence floor rejects its replay.
Anchor: residual/crash-data-loss-corruption
Fix: Reconcile streams using their generations and chunk sequences: retain snapshot-covered text and append only live chunks newer than the snapshot.

[BLOCK-MERGE] 53acb31
[GPT-REVIEWED] 53acb31

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 — website/src/store/chatSlice.ts:987: UPHOLD-FENCED. Server side, src/kiro_crew/dashboard/chat_runner.py:4264 sends chat_segment (the new reply, with no variants attached on the client yet) before chat_variant_switch at :4269. The client scan at patch line 3645 then picks the newest reply that already has variants, which is an earlier one. All this takes is a regenerate whose segment flushes mid-turn (a permission prompt) while an earlier reply has variants, which is an ordinary path, so I can't argue it is extreme. The wrong text is silent and lasts until a full read.

F2 — website/src/store/chat/slotRefresh.ts:109: UPHOLD-FENCED. Patch lines 2679–2681 swap the server's streaming row for the local one whenever any live frame moved during the read (liveMoved, patch line 2668). A reconnect that lost a chunk, with streaming still going on during the refresh, is exactly the recovery case this code is there for. That is common, not extreme, and the missing text gives no sign it is missing.

[ADJUDICATION] 53acb3162fa25d77ccb57d1a651a31f494e6f9ce total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 53acb3162fa25d77ccb57d1a651a31f494e6f9ce

[ADJUDICATION-FENCED] 53acb3162fa25d77ccb57d1a651a31f494e6f9ce fenced=2 flagged=0
UPHOLD-FENCED F1 website/src/store/chatSlice.ts:987 -- chat_runner.py:4264 finalizes the new reply before :4269 sends its variant frame, so the client scan patches an earlier variant reply on an ordinary regenerate-with-permission path, and the wrong text stays silently.
UPHOLD-FENCED F2 website/src/store/chat/slotRefresh.ts:109 -- any live chunk during a reconnect refresh makes withLiveTail swap the server's complete streaming row for the local one that lost a chunk, which is the common recovery case, and the loss is silent.
[GPT-ADJUDICATED-FENCED] 53acb3162fa25d77ccb57d1a651a31f494e6f9ce

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🔴 BLOCK

Premise-level review of 53acb3162fa25d77ccb57d1a651a31f494e6f9ce via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: BLOCK

The frozen Goal (stop whole-transcript downloads) is already met on main, by the PR's own account. Everything still shipped adds new whole-transcript reads.

Not justified as shipped

  • Item 1 — oversized: the description says "perf: walk slot windows older instead of unbounded re-reads #13236 and perf(chat): bound the background warm with the same window walk #16005 have since fixed it on main with the walk", yet the diff adds return finish(withLiveTail(await fetchSlotDetail(key))) (an unbounded read) on every marked view.
    Subtraction: when a slot is marked, drop the kept rows above the fresh bounded page and reset its paging cursor, instead of re-reading the whole transcript.
    Clears when: the whole-read branches are removed, or a human amends the Goal.
  • Item 2 — oversized: per serving_gen.py, after every gateway restart, an on-screen view holding more than one page ceiling of rows (older pages loaded) "re-reads its whole transcript". That brings back the Dashboard crash loop: long chat session freezes renderer, recovery reloads into the same slot #12907 renderer-kill the Goal cites.
    Subtraction: delete _BOOT, the stat stamp and the oauth_extension_changes counter.
    Clears when: these are removed, or a human amends the Goal.
  • Item 6 — rides along, undeclared: open sign-in rows force a whole read. This is a new trigger for whole reads.
  • Item 7 — rides along, undeclared: the row-patch replay log (ROW_PATCH_LOG_CAP 200).

What this change ships

Inventory (10 items) — 3 justified

Intent: keep long chats from re-downloading their whole transcript. Framed as a FIX; the diff ships staleness ADDITIONS.

  1. A marked view, cache or switch re-reads its whole transcript — oversized
  2. The status frame carries a keyed serving value that changes on each restart — oversized
  3. A variant switch is applied in place; the slot list carries variant_seq — justified
  4. A new "Couldn't refresh" notice with Retry in the chat and in panes — rides along
  5. An on-screen background pane re-reads itself when marked — rides along
  6. An open sign-in link in the kept rows forces a whole read — rides along, undeclared
  7. A row-patch replay log for reads in flight — rides along, undeclared
  8. Switch coverage is measured only over the rows the window replaces — justified
  9. Retained counts record whether they are raw or collapsed — justified
  10. Two screenshot scripts — rides along

Blockers

  • Framing contradicted by the diff. The Goal says a long chat "no longer downloads its whole transcript". The description admits main already does this. The new whole branches in slotRefresh.ts/slotSwitch.ts, the open-sign-in reads and the restart re-read each add whole-transcript downloads.
    Subtraction: the bounded drop-the-kept-rows form in Item 1, plus the deletions in Item 2.
    Clears when: the unbounded branches are removed, or a human amends the Goal and says why in a PR comment.

[FIRST-PRINCIPLES-REVIEWED] 53acb31

Description read

[DESCRIPTION-READ] 57e1345ef8515ab0d510792bc0b956abf730f844690e543b327e029cceba7d94

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

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — 🟡 CONCERNS

Design-level review of 53acb3162fa25d77ccb57d1a651a31f494e6f9ce via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The staleness guard adds back whole-transcript reads, the very thing the Goal line says to remove: a restart, allow/revoke or missed variant switch makes a >500-row view download its whole transcript.

Watch

  • New whole-transcript reads. The description says "a marked view or cache reads whole instead of walking" and "a view holding more than one page ceiling of rows… re-reads its whole transcript". _BOOT = secrets.token_hex(8) moves redaction_hosts_gen on every gateway restart, and self.variant_seq: str = mint_tags_revision() in _ChatSlot.__init__ gives every slot a new value at boot. So every restart or update marks every loaded slot, and an open long session the user scrolled back through fetches all of it (52 MB in the PR's own example). That is the Dashboard crash loop: long chat session freezes renderer, recovery reloads into the same slot #12907 renderer kill, now on a path where main's walk stays bounded. It is reversible, but it moves in the wrong direction for the stated Goal.
    Clears when: a marked view over the ceiling heals without an unbounded read (or the PR shows a measured restart against a >500-row view staying bounded)
  • The Goal no longer matches the diff. The description says perf: walk slot windows older instead of unbounded re-reads #13236/perf(chat): bound the background warm with the same window walk #16005 already deliver the Goal on main. What this PR adds is a staleness guard for walked heads plus a new status-frame field, slot-list field and HMAC registry. Reviewers are judging it against a Goal it neither delivers nor needs.
    Clears when: a maintainer confirms the frozen Goal still describes this PR, or the PR is re-scoped

Suggestions

  • On a mark, drop the kept head: cut the view to its newest bounded page and set has_more, so "load earlier" re-serves older rows under the current value. This heals stale links without ever reading the whole transcript.
  • Drop the per-slot variant_seq boot remint. The in-place noteVariantSwitch already covers a live tab, and a reconnect needs only a value that survives restart.

[DESIGN-REVIEWED] 53acb31

Description read

[DESCRIPTION-READ] 4c1c9c3921f91ec9603b7e341b88c5dca7e803c7878ac0fc344cde234389bb57

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

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — 🔴 changes requested (blocking)

Reviewed 53acb3162fa25d77ccb57d1a651a31f494e6f9ce via the fork AI-review pipeline; updated in place on each push.

BLOCKING: noteVariantSwitch can write a regenerated reply's text onto an older reply in the same chat.

BLOCKING — website/src/store/chatSlice.ts:985

for (let i = rows.length - 1; i >= 0; i--) { const m = rows[i]; if (m.role === 'assistant' && Array.isArray(m.variants) && m.variants.length) { target = m; break } }

Trigger: an earlier reply in the chat has already been regenerated (its row holds 3 variants). The user then regenerates a newer reply, and the new reply writes text before a tool call or permission prompt. That flushes a broadcast segment through _flush_segment. Its chat_message frame is built by _broadcast_chat_message from an explicit field list, so the new row reaches the client without variants. The chat_variant_switch frame that follows carries index: 1. The backward walk skips the new row (no variants) and stops at the older reply. Since 1 < 3, placed is true, and sseVariantSwitch overwrites the older reply's content and variant_idx. logRowPatch also records the overwrite, matched by mid. In a long chat, the bounded re-read leaves that row above the newest page, so it stays wrong. A background pane is never marked, so it keeps the wrong text until a reload. Before this change, the same frame only triggered refreshSlot.
Fix: in _flush_segment and api_chat_slot_switch_variant, add the rewritten row's mid to the chat_variant_switch frame. Match on that mid in noteVariantSwitch, and fall back to markLoadedRowsChanged({ slot }) when no row matches. A smaller fix also works: only accept the newest assistant row as the target.

[BLOCK-MERGE] 53acb31
[OPUS-REVIEWED] 53acb31

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from 89176ab to d3b0801 Compare September 29, 2026 20:53
@billygerhard billygerhard changed the title fix(chat): bound the warm of a pane over the page ceiling fix(chat): bound the refresh and warm of a transcript over the page ceiling Sep 29, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 29, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch 2 times, most recently from f589b5a to b0d8d85 Compare September 29, 2026 23:09
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 30, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch 2 times, most recently from 91d0381 to e2e427d Compare September 30, 2026 12:48
@billygerhard billygerhard changed the title fix(chat): bound the refresh and warm of a transcript over the page ceiling fix(chat): bound reads of a transcript wider than the page ceiling Sep 30, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from e2e427d to 6d9e7ab Compare September 30, 2026 13:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 30, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 30, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from 4ad9325 to 2b0505a Compare September 30, 2026 22:21
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 30, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from 2b0505a to 3fb26b8 Compare September 30, 2026 23:25
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 30, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from 3fb26b8 to c00e8b7 Compare October 1, 2026 00:30
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 1, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch from c00e8b7 to 37141aa Compare October 1, 2026 01:20
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 1, 2026
@billygerhard
billygerhard force-pushed the fix/warm-cache-over-ceiling branch 2 times, most recently from 7c3997d to 4bbabd2 Compare October 1, 2026 02:51
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 1, 2026
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thanks @billygerhard. Your diagnosis and measurements here are what showed that the background warm (warmSlotCache) still re-reads the whole transcript once a pane holds more than 500 rows.

Since #13236 has merged, which bounds refreshSlot and switchSlot with a window walk (walkWindowBackTo), we've applied that same walk to the warm path in #16005 so all three readers share one mechanism. You're credited as co-author on that commit (Co-authored-by: Billy Gerhard).

That covers the warm-bounding part of this PR. The heal-failed banner and Retry flow are separate and still yours to drive here. If you rebase onto main, the overlapping slotRefresh/slotSwitch changes should drop out and leave that UX on its own. Happy to review it once it's rebased.

Rebased onto kirodotdev#13236 and kirodotdev#16005, which bound refreshSlot, switchSlot and
warmSlotCache with a clamp plus an older-walking window. This keeps that walk
on all three and adds only what a kept head needs on top of it: a marked view
or cache (a serving change) reads whole instead of walking, since the walk
keeps rows above its anchor verbatim, a walked or overlapping head still
offering a sign-in link reads whole, and a background warm that anchors
nothing in a cache with a raw retained count reads whole once so a remote
clear is still read as a shrink. The refreshSlotBound over-ceiling test is
@billygerhard

Copy link
Copy Markdown
Contributor Author

Closing. The goal of this PR, stopping long chats from downloading their whole transcript (#12907), is now met on main by #13236, #16005 and #16017. What remained here healed stale rows kept above the newest page by re-reading the whole transcript, which reintroduces the unbounded read. The stale-row problem is tracked in #17023 with a bounded approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants