Repository navigation
fix: revalidate slot incarnation across a close - #6807
Conversation
|
👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated. Missing sections:
Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle. |
1 similar comment
|
👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated. Missing sections:
Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle. |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff changes no user-visible control, label or string. A [UX-REVIEWED] b532b8a Description read[DESCRIPTION-READ] 1f937ca2d4f94ad34ce38ad9dd7cc53405112800cabc054c825e85edcff31f63 That sha256 names everything this verdict read: the PR description, plus the 3 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The entry-time incarnation check is optional and fails closed. The only thing removed, Notes
[DESIGN-REVIEWED] b532b8a Description read[DESCRIPTION-READ] 2288f8aa9f938dcdab2426299024553787838377b1def353bfeae7daaca0fb0d 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The new entry check reuses the What this change shipsInventory (6 items) — 6 justifiedIntent: closing a session must never archive, or wipe the browser state of, a different session that has reused its key. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] b532b8a Description read[DESCRIPTION-READ] ed32d6a533b163a499fad9989a47ff1c38e6c621bb5d45ecfa02e618698cc689 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
2a639f8 to
f5e2257
Compare
|
@bolichen97 All three items from your review are fixed at head Entry-time incarnation mismatch (the blocking item). Your ordering analysis holds at this head: inside The fix rejects the mismatch before The regression is Mutation control, because the test needs to be able to fail for the stated reason: removing only the entry-time call at
Storage identity prose. No new commit was needed for this round, so the head above is unchanged from your last look apart from the rebase onto current main. |
Security Scope Review (fork) — 🔴 BLOCK (blocking)Which legitimate operations does no leg reported, and this was not the nothing-to-adjudicate short circuit No |
|
@bolichen97 Following up on my earlier note: the branch has moved twice since (a fix round plus a rebase onto current main), and two of the three coordinates I gave you have shifted. All three items are still fixed; these are the live line numbers at head Entry-time incarnation mismatch (the blocking item). Unchanged and still fixed. Re-verified at this head rather than carried over:
Storage identity prose — coordinate corrected. Previously 659-660, now The rebase was a clean replay — |
|
@bolichen97 — the blocking item is fixed at head Entry-time rejection. At the pinned sha the handler went straight from Regression. Mutation control, with one caveat I would rather state than gloss. Deleting the 5756 guard turns that test red, so it does detect the defect you named. But it reddens with Non-blocking items. Those two, and the stub completion, are held up by size rather than disagreement: I am holding this change to 1500 added lines and it is at 1497. I can fold them into the client change or a follow-up — whichever you prefer. |
|
@bolichen97 — both halves of your review, checked at the current head The entry-time validation is in. You were right about the revision you reviewed: try:
_reassert_same_incarnation()
await close_slot(state, slot, name, pre_pop_check=_reassert_same_incarnation)The ordering you described still holds at this head — nudge retire, then the app-close hook, then the pre-pop check — so the entry-time call is what keeps both seams out of reach. The regression test exists but is weaker than what you asked for, and I would rather say so than let it stand. The correction I have measured gives the fake the two lifecycle methods so the mutated path genuinely reaches the seams, and makes each spy fail at the seam with a named message. With the entry-time call removed it then fails at the test's own detection point rather than incidentally. That is not in this head yet; it follows separately so it does not reset the green on this one. |
|
Thank you @rnoack1 for this fix and the thorough write-up — the session-close flicker is a real problem and the mechanism was carefully done. Heads up on why this hasn't moved: main's #16427 ("compose the chat handlers from chat_api owners") relocated the slot-delete handler out of Bringing it current would be a re-author against the new |
PR triage (2026-10-05) — REBASE (re-author) + MERGE-DISCUSSIONChecked against Not on main / not superseded. Nothing this PR adds exists on main: no Re-author needed (agrees with the earlier maintainer note). Since #16427, Still overlapping open PRs: #6813 ( Fix these while re-authoring (not blocking):
I found no breaking wire change (all fields are additive and the query param is optional) and no P0 bug. |
bolichen97
left a comment
There was a problem hiding this comment.
[operator: bolichen97] My earlier change request is addressed on 68a1838. Approving to clear it; other open gates on this PR still apply.
iamwhatever
left a comment
There was a problem hiding this comment.
Request changes at d35dab7: one deferred cleanup has lost its tracking. After that, this still needs a human sign-off because it changes the session close path.
The fix itself looks sound. Each live slot gets a uuid4 incarnation (slot_session.py#L237). The DELETE re-checks it at entry and again before the pop, and an absent key counts as a normal overlapping close, not a 409 (slot_lifecycle.py#L1333-L1347). The app-teardown undo is gated on ownership (L1028). All checks are green and the branch merges cleanly with main.
Blocking:
gcSessionStoragenow has no production caller (storageGc.ts#L135), and its header still says it runs when a session is deleted (L10). The description leaves that decision to #6825, but #6825 and #6813 are both closed. Please either remove it with its tests here, or open an issue for it and link it in the description, and update Related Issues.
Reserved for a human after that: the PR changes what the close path kills and deletes. It adds new 409 refusals before the session is cancelled and archived, and it stops erasing a closed session's localStorage at close.
AI findings judged non-blocking:
- GPT 6.1 (downgraded BLOCK), nudge loop retired in a three-way race: the retire-by-key order is main's, and main archives the replacement outright, so this PR narrows the race (L928-L996).
- Design note 2, closed-session storage waits for the boot sweep: a documented trade-off, since the boot sweep covers the same prefixes (chatSlice.ts#L679).
- First Principles item 1, the motivation describes the flicker: description wording only; the Goal and tests name the real defect (slot_lifecycle.py#L1333).
- UX note, 409 shows the generic refusal notice: a rare race in which the close is correctly refused; wording polish only (L1347).
— crew-pr-reviewer (r138)
|
@bolichen97 Your September change request is fixed at
|
|
@iamwhatever Your blocking item is fixed at
The human sign-off on the close path is still yours to give. |
|
HOLD at 15087a2 for a human reviewer. This supersedes our change request at d35dab7. Our blocking item is fixed.
Every check and AI lane on this head is green, and the branch merges cleanly. What holds it: the session close path is reserved for a human reviewer. This PR changes what a close kills and archives: it adds 409 AI findings judged non-blocking:
This clears once a maintainer reviews the close-path changes. A new push will need a fresh review. — crew-pr-reviewer (r147) |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 1eff1ed, as the human sign-off on the session close path. Every dashboard close now sends the slot's incarnation with the delete, and the route checks it at entry and again before the pop. So closing a card can no longer archive a different session that reused the key, or wipe that session's browser state. An absent key is still a normal overlapping close. The deferred cleanup that iamwhatever's change request at d35dab7 asked about is resolved: gcSessionStorage and its delete-mode sweep are removed, and iamwhatever's hold confirms that point is fixed. No regex is added. The red entries are cancelled duplicate runs.
|
HOLD at I found no defect. This head rebases What holds it: the PR changes what a close kills and archives, and it stops erasing a closed session's AI findings judged non-blocking: Design (closed-session storage waits for the boot sweep; a documented trade-off) and First Principles (the motivation prose mentions the flicker; wording only). All checks are green and the branch merges cleanly. — crew-pr-reviewer (r149) |
|
@bolichen97 rebased onto main as |
A close revalidates the slot's incarnation, and the dashboard names the instance it meant, so a replacement that took the key is neither archived nor has its browser state erased.
bolichen97
left a comment
There was a problem hiding this comment.
Re-approving at b532b8a. I compared it with 1eff1ed, the head I approved before. Beyond the rebase, the change is smaller now:
- The mid-close re-check is gone:
_reassert_same_incarnation, thepre_pop_checkpassed from the DELETE handler, and its ownership-gated undo and tests. Main now does that job itself._close_slot'srefuse_if_replacedraisesslot_replacedwhen another slot holds the key after the close's awaits, andapi_chat_slot_deleteon main already maps that to 409. So a replacement that arrives during the close is still left alone, by main's code. - What this PR still adds is the entry check: a
?incarnation=that does not match_dashboard_card_identityanswers 409target_replacedbefore any teardown step.test_entry_mismatch_no_teardown.pypins that neither the nudge retirement nor the app hook runs. The check only applies when the caller names an instance, and a key-only DELETE behaves as on main (test_omitting_the_incarnation_leaves_a_pre_arrival_replacement_unprotected). - The dashboard passes the row's
incarnationfromdeleteSlotand from thecreateSlotrollbacks. gcSessionStorageand its tests are removed, so the close no longer leaves an uncalled cleanup behind. Closed-session storage is left to the boot sweep (gcOrphanedStorage).
The re use in test_slot_incarnation_identity.py is test-only, so it is out of scope for the regex rule. Every check that shows as cancelled has a newer passing run on this head.
@iamwhatever, the gcSessionStorage point from your review is addressed (removed along with its tests). Could you take another look?
|
HOLD at b532b8a. The session close path is reserved for a human reviewer, and @bolichen97 has approved this exact head. I found no defect. The DELETE now checks What holds it: the PR adds a refusal before the close kills and archives a slot, and it stops erasing a closed session's AI findings judged non-blocking:
Test nit, not blocking: in All five AI lanes pass. CI is green: 81 checks succeeded and 11 were skipped, and PR Readiness succeeded. The branch merges cleanly. A new push needs a fresh review. — crew-pr-reviewer (r150) |
|
@iamwhatever could you re-review, or clear your change request from d35dab7? It is still open and blocks the merge. Your 11-06 hold says its one blocking point is fixed: |
Problem / Motivation
Goal: Closing a chat session can no longer archive a different session that reused its key, or wipe that session's browser state.
The harm this PR removes. Slot keys are reusable, so a session can be resumed
under a key while a close of the old session is on its way. A key-only
DELETEthen resolves to the replacement and archives it, and the client's per-key
storage cleanup then wipes the replacement's reading position and panel state.
The rest of this section is background: the sidebar flicker below is why the
client needs an instance identity at all. Its client-side fix is a separate
change (see Not a goal), and this PR supplies only the identity it reads.
Closing a session (arrow menu → Close, or the ✕ on the card) selects the next
session and reloads the chat pane, but the card being closed lingers — and often
disappears, comes back, and disappears again.
The row is already removed optimistically. What puts it back is that every
authoritative slot-list writer —
sseSlotsandfetchSlots.fulfilled, boththrough
applySlots— takes server membership as the truth, and the server stilllists a slot whose
DELETEhas not finished.Two producers make such a frame ordinary rather than rare:
api_chat_slot_deleteretires the auto-nudge loop, runs the app-teardown hook, cancels the task and
saves history before popping
state._slots. Anypush_slots_update()inthat window serializes the slot as live — and pushes coalesce on a 200 ms
window whose trailing edge re-serializes at delivery time, so a coalesced
frame is a fresh read of a list that still contains the slot.
GET /api/chat/slotsanswers with a list assembled before the close began.
Each such frame reinstates the row; the next one after the pop removes it again.
That is the flicker.
Why it matters
The session list is how you know what exists, and a card that vanishes, returns,
and vanishes again makes it unreadable at the exact moment you are acting on it —
you cannot tell whether the close took, whether you hit the wrong row, or whether
the session is coming back. The reflex is to click again, on a row that may
already be gone or may be a neighbour that has shifted into its place.
It also hid the one case that genuinely needs attention: a flickering row and a
close the server refused looked identical, because both ended with the card back
on screen.
Not a goal
applySlotswithholding andcloseSeqretirement are a separate change. This PR supplies the wire identitythat change needs, and nothing that consumes it for the sidebar.
closingflag on slotrows, a
definitiveverdict on a close-failure reply, andincarnationon theresume and fork replies were all carried in an earlier revision and have been
removed: their only readers are in the client
change above, so they ship with it rather than becoming public fields with no
consumer here.
(slotsEpoch, slotsGeneration)stamp and theX-Slots-*headers are not here.?incarnation=mandatory. It stays optional, so a client store-misscannot turn an ordinary close into a hard failure.
gcOrphanedStorageis now the only collector ofper-session browser state, and this PR does not change it: not its prefix list,
not its liveness input, not when it runs.
What changed
Symptom. Closing a session could archive a different session, or erase its
browser state, when a session was resumed under the same key while the close was
still running.
Root cause. Slot keys are reusable:
api_chat_slot_resumerevives a sessionunder its own key and restores
created_atfrom the transcript metadata. Sonothing on the wire distinguished the instance a close targeted from a
replacement that had taken the key, and the close acted on whatever held it.
Change. Give each live slot object an identity, carry it on the wire, check
it at both ends of the close, and stop the close path from collecting storage it
cannot prove it owns.
Server (
src/kiro_crew/dashboard/):incarnationon main (fix(dashboard): keep a session reopened elsewhere from reading as a failed close #31929): the slot's_dashboard_card_identity, a uuid4 hex minted once per live_ChatSlotand neverrestored by any rehydrate path. This PR adds no wire field and mints no second id;
it makes the close act on that one identity.
DELETE /api/chat/slots/{key}accepts?incarnation=.chat_api/slot_lifecycle.pychecks it once, at ENTRY, and answers 409target_replacedwhen it does not name the slot holding the key. Nothing hasrun yet at that point, so a mismatch never reaches the nudge retirement or the
app-close hook, which was the blocking item in bolichen97's review.
close_slot'srefuse_if_replaced(fix(dashboard): refuse a slot close once a replacement holds the name #33188) answers 409slot_replacedaftereach wait. So this PR adds no second check at the pop.
Client (
website/src/):api.deleteChatSlot(slot, incarnation?). All six production call sites namethe instance, including the rollback in
pages/chat/startFromInitialPrompt.tsthat removes a session whose agent or project setup failed.
successful close used to call
gcSessionStorage(key). Naming the DELETE targetproves which instance the CALLER meant, not that no replacement took the key
before the reply arrived, so a close cannot establish ownership of key-scoped
localStorage: the server can pop the original, preserve a replacement sharingthe transcript, and answer 200, after which the erase takes the live
replacement's reading position and panel state. Gating the call on having named
an instance narrowed that window but did not close it.
gcOrphanedStorage,at boot and when a complete live slot list drops a key (fix: sweep closed sessions' localStorage on live slot lists #31773), is now the only
collector, which is correct because it is keyed on the live session list rather
than on one tab's view of one close.
gcSessionStorageis deleted fromutils/storageGc.ts, since that closecall was its only production caller. So is the
'delete'mode ofisReservedNameand thespareOnExplicitDeleteflag, which only it read.Tests that exercised the helper itself are removed. The two that pin
behaviour the boot sweep still owns now drive
gcOrphanedStorage: theScrollAnchorCacheprefix-coupling check, and theno-slotsentinel beingspared while a same-named slot's other state is collected.
One shape note a reviewer would otherwise have to reconstruct: this revision
is a re-author, not a rebase. Since PR 16427 the close path lives in
chat_api/slot_lifecycle.py,_ChatSlotinstate_parts/chat_slot.pywith its__init__instate_parts/slot_session.py, and the client'sdeleteChatSlotin
api/client/chat.ts. Thepatch that previously targeted
chat_handlers.pyandstate.pyno longerapplied, so each hunk was moved to the module that now owns the code rather
than resolved in place.
Backwards compatibility
Compatible: the one wire addition,
?incarnation=on the DELETE, is optional.A key-only DELETE behaves exactly as it does on main.
The close path TAKES AWAY one thing, deliberately: it no longer deletes a closed
session's own
localStoragekeys. Readers of that state, one line each:website/src/hooks/virtualizer/HeightCache.ts(vc_heights_) -- chatrow heights. Reclaimed by
gcOrphanedStorage; a stale entry for aclosed session is never read, because nothing resolves that session id again.
website/src/hooks/virtualizer/ScrollAnchorCache.ts(vc_anchor3_and the older
vc_anchor2_/vc_anchor_) -- scroll position. Samesweep, and this cache additionally reaps superseded prefixes itself when the
virtualizer loads.
website/src/pages/chat/sidePanelWidth.ts(
mc-side-panel-width:/mc-side-panel-height:) and themc-panel-tabs:,mc-activity-open:,mc-webpreview-*:,mc-busy-send-mode:andkirocrew:touched-files:families -- per-chat panel state. All are in thesame
SESSION_PREFIXESlist both collectors iterate (utils/storageGc.ts),so the orphan sweep covers exactly what the close pass used to.
The cost is that a closed session's keys survive until the next complete slot
list or startup instead of being collected at close. The quota pressure the
helper's docstring warns about is bounded by the orphan sweep rather than by the
close, and the alternative
is deleting a live replacement's state, which has no rebuild path beyond the
user scrolling and resizing again.
Tests
New, each written to fail first:
test/test_close_incarnation_revalidated.py(3). A matching incarnationcloses; a replacement under the reused key is refused 409
target_replacedand survives; and the remaining residual is pinned explicitly by
test_omitting_the_incarnation_leaves_a_pre_arrival_replacement_unprotected.test/test_entry_mismatch_no_teardown.py(1). Drives the real handler with astale
?incarnation=and spies the real seams (_retire_slot_nudge_loop,notify_slot_closed), asserting 409 with zero calls to either. A stubbedclose cannot detect this, which is why the spies are on the real functions.
test/test_slot_incarnation_identity.py(3). No path reassigns theincarnation, and the slot projection publishes it. Its
positive control asserts that something does restore
created_at, so thepin is not vacuous, and its scan is recursive because the slot now lives under
state_parts/.Updated: the fake requests in
test/test_slot_close_nudge_race.py,test/slot_close_recreation_race_helpers.pyandtest/test_conductor_close_closes_workers.pynow carry.query, andtest/test_ephemeral_sessions.pynames the instance it closes; thedeleteChatSlotarity inwebsite/src/test/closeKeepsPendingOpen.test.tsx, which main added after theprevious push; and in
website/src/test/ChatSliceCoverage.test.tsxthe close now pins that it namesthe instance AND that a successful close erases no key-scoped storage.
Measured at this head:
identity, fork, facade, error codes, turn golden and session control.
deleteChatSlot,storageGc,slotStorageSweep,incarnationorcloseWatch.no-slotfromRESERVED_NAMESfails exactly that test; restored, all 14 instorageGc.test.tspass. Swept by symbol rather than by textpattern: an earlier pattern-based pass missed
chatSlice.releaseLocally.test.ts, whose assertion usesexpect.objectContaining(...)instead of a quoted key.chat_api/slot_lifecycle.pyswapped formain's copy, the replacement test fails (
200 == 409) and the entry-mismatchtest fails; restored, all four pass.
black,isortandflake8clean;eslint --max-warnings 0clean on thechanged files;
tsc --noEmitreports no errors outsidesrc/stories.Manual verification
N/A, unit coverage sufficient: every behaviour here is a scheduled interleaving
of a close against a same-key resume, which the tests drive deterministically
and a manual run cannot reproduce reliably.
Screenshots / video
Why no screenshot: the production client files change an optional query
parameter, a thunk argument, a type field, and remove a storage-cleanup call, so
no panel, layout or theme renders differently.
Related Issues
No issue closes with this change. The two PRs an earlier maintainer audit named
as overlapping, 6813 and 6825, are both closed, so no landing order remains.
6825 was the one importer of
gcSessionStorage, which this PR now deletes.Builds on #31929, which put
incarnationon slot rows, and on #31773, whichruns
gcOrphanedStorageon live slot lists.Pattern harvest
Rule candidate: review-prompt
Pattern: a mutation targets a resource by a REUSABLE key across an await, so a
same-key replacement silently receives the mutation.
The shape generalizes past this close path. A key that can be reissued is not an
identity, and neither is a creation timestamp that a restore path rewrites. Any
check of the form "is this still the thing I was asked about" needs a value
minted per live object and never restored -- and where no such value is
reachable, as for storage keys shared across tabs, the honest answer is to stop
claiming ownership rather than to narrow the window. The prompt that would have
found it: "between reading this key and acting on it, could something else come
to hold it, and what would tell the difference?"
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement