Repository navigation
fix(dashboard): hold a closing session out of the sidebar until the server omits it - #11225
iamwhatever merged 2 commits into
Conversation
…erver omits it Closing a session removed its row, then a slots frame serialized before the server-side pop put it back, then the post-pop frame removed it again. dashboardSlice now keeps a per-key close tombstone, armed on chat/deleteSlot/pending and released by the first authoritative list that omits the key, by rejection, by a same-key recreate, or after a bounded number of post-confirmation straggler frames. Fixes kirodotdev#11224
UX Review (Fable 5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Verify a slow, refused close reads acceptably: the row now stays hidden up to 30 s before the recovery refetch silently restores it. [UX-REVIEWED] 7205834 |
First Principles Review (Fable 5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
Sibling count for the record: What this change shipsInventory (10 items) — 9 justifiedIntent: FIX — stop a closed session's sidebar row from vanishing, reappearing, and vanishing again (#11224).
[FIRST-PRINCIPLES-REVIEWED] 7205834 |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsFINDING -- website/src/store/dashboardSlice.ts:990 -- after reconnect clears |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the close gesture once on a live many-session dashboard — the race was only replayed in reducer tests, never rendered. [DESIGN-REVIEWED] 7205834 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
|
Both Design watch items at Deadline-less DELETE. The in-flight hold now expires on the wall clock: Refetch landing before |
9ec22ff to
518c08a
Compare
|
GPT F1 at Fix: the |
518c08a to
bbc2eb8
Compare
|
Both findings at GPT F1 (omission releases the hold; stale HTTP reply re-adds the row). Confirmed real — the reorder is exactly the one First Principles (two sibling |
bbc2eb8 to
f7e70f6
Compare
|
Both GPT findings at F1 (a pre-close F2 (attempt 1's late The two Windows backend shard failures at |
8e8a1da to
1a7d8cf
Compare
|
GPT F1 at Design's advisory (server-stamped monotonic list generation as the durable resolution of this staleness class) is recorded on #11255 as the preferred direction for that follow-up. |
1a7d8cf to
83b22b4
Compare
|
GPT F1 at Backend Tests (Windows) (8) at |
…ounded and prototype-safe Review hardening on the tombstone from the first commit: - deleteChatSlot has no deadline, so the in-flight hold expires on the wall clock (30s) and degrades to the pre-fix visible reappearance. - The failure path's fetchSlots reply can land before deleteSlot/rejected, so the thunk releases the tombstone in its catch before refetching. - Prototype keys are refused at every dynamic closingSlots access. - An omitting list no longer releases the hold: the HTTP and live writers are unordered, so a post-pop frame could release it and a pre-pop reply then re-add the row. The hold is retired by the close lifecycle instead: unconditional in flight, then a fixed budget of further lists plus every fetchSlots request that was in flight at the 200. - Holds are owned by the deleteSlot requestId, so a stale attempt's rejected cannot release a same-key retry's hold. Sibling removal sites without a hold are tracked in kirodotdev#11255.
83b22b4 to
7205834
Compare
|
Frontend Lint & Type Check — TS7006 on the stale-key filter ( GPT F1 (a stale reply's filter drops a same-key session recreated meanwhile) — fixed as suggested: for a distrusted key, |
|
On the First Principles item 5 at |
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: holds a closing session's sidebar row out of the list until an authoritative list omits it, fixing the row that reappeared mid-close (#11224); tests cover the tombstone lifecycle. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/learn-cron-dashboard.md. CodeQL is not applicable on this fork PR (default-setup emits no check-run); SAST coverage is Semgrep only, latest run success with 0 annotations.
…erver omits it (kirodotdev#11225) * fix(dashboard): hold a closing session out of the sidebar until the server omits it Closing a session removed its row, then a slots frame serialized before the server-side pop put it back, then the post-pop frame removed it again. dashboardSlice now keeps a per-key close tombstone, armed on chat/deleteSlot/pending and released by the first authoritative list that omits the key, by rejection, by a same-key recreate, or after a bounded number of post-confirmation straggler frames. Fixes kirodotdev#11224 * fix(dashboard): retire the close hold by the close's own lifecycle, bounded and prototype-safe Review hardening on the tombstone from the first commit: - deleteChatSlot has no deadline, so the in-flight hold expires on the wall clock (30s) and degrades to the pre-fix visible reappearance. - The failure path's fetchSlots reply can land before deleteSlot/rejected, so the thunk releases the tombstone in its catch before refetching. - Prototype keys are refused at every dynamic closingSlots access. - An omitting list no longer releases the hold: the HTTP and live writers are unordered, so a post-pop frame could release it and a pre-pop reply then re-add the row. The hold is retired by the close lifecycle instead: unconditional in flight, then a fixed budget of further lists plus every fetchSlots request that was in flight at the 200. - Holds are owned by the deleteSlot requestId, so a stale attempt's rejected cannot release a same-key retry's hold. Sibling removal sites without a hold are tracked in kirodotdev#11255.
Problem / Motivation
Closing a session from the Sessions sidebar (hover ✕ or row menu → Close) removes the row, brings it back a moment later, then removes it again. It is most visible with many open sessions and long-context chats, where the server-side close takes longer and slot pushes are frequent.
Why it matters
The sidebar is how you know what exists. A row that vanishes, returns and vanishes again at the exact moment you act on it reads as "did that take?", and the reflex is to click again — on a row that may already be gone, or on the neighbour that has shifted into its place. It also made a refused close and a flickering close look identical.
What changed (motivation → approach → change)
Symptom → cause.
deleteSlotremoves the row optimistically (removeSlotOptimistic) and then awaits theDELETE. On the server,_close_slotkeeps the slot instate._slotsacross several awaits (auto-nudge retirement under the AutoNudge lock, the app teardown hook, the history save) before popping it, andpush_slots_updatecoalesces on a 200 ms window that re-serializes at delivery time. So a slots frame listing the closing slot as live is ordinary, and an in-flightGET /api/chat/slotsreply assembled before the click says the same. Both authoritative writers (sseSlots,fetchSlots.fulfilled→applySlots) took membership at face value and re-inserted the row; the first post-pop frame removed it again.Approach. Fix it where both writers converge, on the client, with no wire change. #6807 attacks the same symptom with server-side incarnation / epoch / generation stamps across 22 files; that adds a protocol surface for a race that the client can already recognise on its own: it knows which key it is closing, and it knows when the server has stopped listing it.
Change.
dashboardSlicegainsclosingSlots: Record<string, number>, a per-key close tombstone:chat/deleteSlot/pending(same import-cycle-avoiding pattern as the existingcreateSlot.fulfilledmatcher).pendingis dispatched before the thunk body'sremoveSlotOptimistic, so the hold exists by the time the row leaves the list.applySlotsfilters held keys out of the list it applies. Everything else about the frame still lands — other rows,slotsGeneration, the unread drain — andreconcileSlotsstill sees the frame's full membership, so a held slot's sub-agent state is not evicted before the close is confirmed (the existing "a failed close leaves the slot live" invariant).fetchSlots.fulfilledalready documents that a reply can be older than live frames that arrived while it travelled — so a post-pop frame releasing the hold would let a pre-pop reply still in flight re-add the row. The tombstone is retired by the close's own lifecycle instead: by a same-keyaddSlotOptimistic/createSlot.fulfilled(a resume or fork under the closing key), and on failure byreleaseCloseHold, which the thunk dispatches in its catch before the recoveryfetchSlots—chat/deleteSlot/rejectedalso releases, but it fires only after the thunk's trailingawait navigation(an unbounded peer transcript load), so the refetch reply could otherwise be filtered by the very hold it exists to undo.confirmCloseHoldas soon asdeleteChatSlotresolves, not onfulfilled(which trails the unboundedawait navigation), so a successful close whose peer transcript load outlasts the in-flight cap is not expired as if it had stalled.deleteChatSlotcarries no deadline, so while the request is in flight the hold expires on the wall clock (CLOSE_IN_FLIGHT_MAX_MS, 30 s): a close the server never answers degrades to the pre-fix behaviour (the row visibly comes back), not to a session hidden until reload. Afterfulfilledit outlivesCLOSE_CONFIRMED_GRACE_FRAMES(3) further authoritative lists, listing the key or not (live pushes coalesce on 200 ms, so a frame serialized before the pop is among the first few after the 200), and everyfetchSlotsrequest that was already in flight at the 200:fetchSlots.pending/fulfilled/rejectedmaintainslotFetchesInFlight, thefulfilledmatcher snapshots it onto the hold'sawaitingFetches, and the hold is not retired until those have settled — a pre-pop HTTP reply can trail the pop by a whole round trip, which no frame budget bounds. The confirmed phase carries its own wall-clock cap (CLOSE_CONFIRMED_MAX_MS, 30 s) for the same reason the in-flight phase does:chatSlots()has no deadline, so a snapshotted fetch that never settles must not pin the tombstone until reload. Unlike the in-flight case the server has confirmed this close, so a reply from one of those fetches is known to be pre-pop: the ids still awaited at expiry go intostaleSlotFetches(request → closed keys) andfetchSlots.fulfilleddistrusts only those keys in such a reply (once the stream has delivered a snapshot): for each, the row currently on screen — if the key has since been recreated — is kept in place of the reply's pre-pop row, otherwise the key is dropped; the rest of the payload still applies, so an unrelated change it carries is not thrown away. Then it yields to membership, so a server that keeps listing a slot it claimed to close cannot hide a live session indefinitely.deleteSlotattempt'srequestId;fulfilled,rejectedandreleaseCloseHoldact only on the attempt that owns the hold. A same-key retry takes the hold over, so attempt 1'srejected(which trails an unbounded peer navigation) cannot release attempt 2's hold.Scope. Only
deleteSlotgets a hold. The other tworemoveSlotOptimisticsites —switchSlot's 404 eviction and the artifact companion-chat close — remove the row only after the server has already answered, so they have no in-flight window and are exposed to the post-confirmation straggler window alone; the general form needs the DELETE lifecycle that onlydeleteSlothas. Tracked separately in #11255.Every dynamic access to
closingSlotssits behind the slice's existingisUnsafeKeyguard (prototype keys are refused at thependingwriter rather than letting Immer throw and leave the DELETE undispatched), the same convention as the other per-slot maps in the slice.Row identity for untouched rows is preserved through the filter (the
applySlotsidentity contract chatSlice's 404 eviction leans on is unchanged).Tests
website/src/test/dashboardSlice.closeTombstone.test.ts(23 tests) drives the reducer with the exact action sequencedeleteSlotemits, interleaved withsseSlots/fetchSlots.fulfilledframes:rejected, so the refetch restores the row; and viareleaseCloseHoldwhen the refetch reply lands beforerejectedaddSlotOptimisticandcreateSlot.fulfilledfetchSlotsin flight at confirmation keeps the hold alive through six omitting frames until its stale reply lands, which is still filtered; a fetch started after confirmation is not waited for; a snapshotted fetch that never settles releases on the 30 s confirmed-phase cap, and when its reply finally lands — including when that reply is itself the first list after the cap — only the closed key is filtered out while an unrelated rename in the same reply still applies; a same-key session recreated before the stale reply lands keeps its on-screen row; a later fetch applies normally (fake timers, all mutation-checked)rejectedandfulfilledare ignored__proto__/constructor/prototype) are refused without throwing in any tombstone reducer — mutation-checked: without the guard Immer throwsObject.setPrototypeOf() cannot be used on an Immer draftwebsite/src/test/ChatSliceCoverage.test.tsxadds two thunk-level tests running the realdeleteSlot: one with a slow-but-successful DELETE and the peer navigation parked past the in-flight cap (the hold is confirmed at the 200, and a straggler frame at 40 s does not resurrect the row — mutation-checked by removing the thunk'sconfirmCloseHold), and one against a rejecting DELETE with the peer navigation parked: the recovery refetch restores the row and the tombstone is empty beforerejectedfires — mutation-checked: removing the catch-sidereleaseCloseHoldfails it.Neighbouring suites (156 files touching
dashboardSlice/sseSlots/deleteSlot, 3,220 tests),tscandeslintpass.Manual verification
N/A — the defect is a reducer-level race between two action streams and the unit tests replay exactly that interleaving. No new UI element, layout or copy; the only observable difference is that the closed row no longer comes back for one frame.
Related Issues
Fixes #11224
Related: #6807 (server-side approach to the same symptom), #10024 (close latency on the same gesture)
Pattern harvest
Rule candidate: review-prompt
Pattern: "optimistic removal followed by an authoritative full-list writer that treats membership as truth; the removed key needs a tombstone until the authority omits it"
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)