Skip to content

fix: treat a 404 on session close as a completed close - #14834

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/14823-close-slot-404
Sep 29, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/14823-close-slot-404

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Closing a chat session the server has already deleted succeeds quietly instead of showing a "not found" error.

When a session is closed twice, for example from a second tab still showing it or by a repeat click while a slow first close is in flight, the second DELETE /api/chat/slots/<key> returns HTTP 404 {"error": "not found"}. The dashboard treats that like any failure: it puts the close back in doubt, refetches the slot list and raises an error report, even though the session is gone.

Why it matters

The user sees an error for an action that worked. It suggests the session is still there or that something broke, and it lands in the dashboard's error reports as noise. Nothing is wrong server-side.

Not a goal

  • Changing what the server returns for a missing slot, or the App Kit ownership 404s in api_chat_slot_delete.
  • Deduplicating the second DELETE itself (cross-tab coordination or disabling the close control while a close is in flight).
  • Other deleteChatSlot callers: the ones in chatSlice.ts already swallow errors, and ArtifactDetailPage.tsx already treats a 404 as "already archived".

What changed (motivation → approach → change)

A second close of the same session showed an error. The cause is the deleteSlot thunk in website/src/store/chatSlice.ts: its catch around api.deleteChatSlot(key) releases the close hold, refetches slots and throws save failed for every rejection, and a 404 from that endpoint is a rejection. For a dashboard caller the server only answers 404 when the slot is no longer in state._slots, which is the end state the close asked for.

deleteSlot now reads the rejection with the existing isNotFoundError helper from website/src/api/apiError.ts. A 404 resolves the close instead of throwing save failed. Because this request closed nothing, and the close that did pop the key can still fail and put the slot back, the rest of the 404 path matches the failure path:

  • it drops its close hold instead of confirming it, so a restored row is not hidden behind this request's tombstone;
  • before the release it pairs every fetchSlots still in flight with the key in staleSlotFetches (new optional distrustInFlight on releaseCloseHold in website/src/store/dashboardSlice.ts, the same pairing the removed branch of sseSlotPatch records), because such a reply may predate the pop and would otherwise re-add the row whichever order it lands in;
  • it still dispatches the recovery fetchSlots() after that pairing, so the post-pop list is trusted and shows the row again if the popping close restored it;
  • its fulfilled action carries meta.alreadyGone (through fulfillWithValue), and deleteSlot.fulfilled skips evictSlotState for it, so the tab keeps that slot's in-memory view state until an authoritative list (reconcileSlotResidue on the next slots frame, or a slot_patch removed key) settles it.

The payload is still the key, so unwrap() callers are unchanged. The close-hold paragraph in docs/system-specs/modules/learn-cron-dashboard.md now describes the 404 path and says why it differs from the other already-answered removal sites, which arm a confirmed hold. Every other status keeps the current failure path.

Backwards compatibility

Compatible: only a 404 from this one DELETE changes outcome, from a false failure to success, with the same hold release and refetch as before; every other status and the success path behave as before.

Tests

  • website/src/test/ChatSliceCoverage.test.tsx, treats a 404 on DELETE as a completed close: a 404 rejection resolves deleteSlot as fulfilled, leaves no close hold and keeps the row removed. Fails on origin/main (expected 'chat/deleteSlot/rejected' to be 'chat/deleteSlot/fulfilled').
  • Same file, refetches after a 404 close so a pre-close slot list cannot keep the row: a fetchSlots already in flight at click time answers with the closed row after the 404, and the recovery refetch's post-pop list removes it again. Fails on 4ce79ce (no second chatSlots call, row stays).
  • Same file, drops a pre-close slot list that lands after the 404 close's recovery refetch: the in-flight reply lands last with the closed row and is filtered for that key. Fails on dc1ac59 (row comes back).
  • Same file, trusts the recovery refetch when the popping close restored the slot: a recovery list that still carries the key shows the row, and the late pre-close reply does not remove it.
  • Same file, keeps the slot's view state on a 404 close and evicts it on a real one: after a 404 close slotMessages for the key survives; after a successful close it is evicted. Fails on 4ce79ce.
  • Same file, shows a slot the server restores after a 404 close: after a 404 close, a slot list that still carries the key shows the row.
  • Same file, still fails the close on a non-404 status: a status-500 rejection still rejects and still refetches slots.

Run locally on head 370512a4f (base origin/main 2e09b1030):

  • npx vitest run src/test/ChatSliceCoverage.test.tsx: 114 passed.
  • SCOPED_TESTS_BASE_REF=$(git merge-base HEAD origin/main) scripts/run_scoped_tests.py --surface frontend: 352 files, 10565 tests passed.
  • tsc -b, tsc -p tsconfig.app.json --noEmit, eslint on the three changed source files, npm run jscpd (0 clones), scripts/docs_lint.py: clean.

Manual verification

N/A: unit coverage sufficient. The change is a branch inside the store thunk, and the tests drive that thunk with the same rejection shape the API client produces for a 404.

Screenshots / video

Why no screenshot: no component, layout or string changes; the store stops raising an error in a two-close race, which the unit tests cover.

Related Issues

Closes #14823

Pattern harvest

Not generalizable: the other DELETE-slot callers already treat 404 as done (ArtifactDetailPage.tsx) or ignore errors, so this was the one caller left.

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

@jeeshofone
jeeshofone requested a review from a team September 28, 2026 21:46
@jeeshofone
jeeshofone requested a review from a team as a code owner September 28, 2026 21:46
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

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

UX-Verdict: PASS

Nothing to check.

[UX-REVIEWED] 370512a

Description read

[DESCRIPTION-READ] a87c6d5f93f53a38d14384ed50d3c883612314df4f02c05683abc4fe8b3ebdd0

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 .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 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 370512a

Description read

[DESCRIPTION-READ] a0211c6bbc035f69a0a6e5b55a17fa0b711ff0ee9886890cab3ce1313bfa9d02

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 28, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 370512a4f243cbcad1b77f45bd1a76e6e1bd4650 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: PASS

Verify the server-side premise: a close that popped the key can still fail and restore the slot — it alone justifies the hold-release/distrust/alreadyGone machinery over a two-line "treat 404 as success".

That premise is client-untestable here; if the pop is actually irrevocable, items 3–5 guard a state that cannot occur and the simple confirmCloseHold path was the smaller fix. Everything else checks out against the base tree: isNotFoundError is reused, not duplicated (website/src/api/apiError.ts:61); the pairing reuses markStaleSlotFetches, the same call the removed branch of sseSlotPatch makes (dashboardSlice.ts:892); the sibling count in "Pattern harvest" is accurate — the three other deleteChatSlot call sites in chatSlice.ts (3626, 3637, 3672) swallow all errors and ArtifactDetailPage.tsx:1408 already treats 404 as archived, so zero unfixed siblings. Provenance is a linked issue (#14823) plus tests stated to fail on base. Deduplicating the second DELETE is the deeper cause and is declared out of goal, so this sits at mechanism level with the residue named.

What this change ships

Inventory (6 items) — 6 justified

Intent: closing a session the server already deleted succeeds quietly instead of raising an error — a FIX.

  1. A second close of an already-gone session completes quietly instead of erroring — justified
  2. After a 404 close the dashboard refetches the slot list once — justified
  3. Slot-list replies in flight at the 404 can no longer re-add the closed row — justified
  4. A slot the server restores after a 404 close reappears instead of staying hidden — justified
  5. A 404-closed slot keeps its tab view state until an authoritative list settles it — justified
  6. The close-tombstone spec paragraph now describes the 404 path — justified

[FIRST-PRINCIPLES-REVIEWED] 370512a

Description read

[DESCRIPTION-READ] 386f457d9423e7f09e26fbf22088e4262b32edaf6e6beb2524575cf5909412d5

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 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 370512a

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

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

Review details

No blocking issues; one advisory gap in the new 404 branch.

FINDING — website/src/store/chatSlice.ts:3771 — the new if (alreadyGone) branch declares the close complete but returns without gcSessionStorage(key), its only call site in the app, so ChatSidebar's cleanup loop (for (const key of res.keys) dispatch(deleteSlot(key)), every DELETE 404ing because api_chat_slots_cleanup already popped those keys from state._slots) leaves all N archived sessions' vc_heights_* / scroll-anchor / mc-panel-tabs:* entries in localStorage until the next page boot runs gcOrphanedStorage (App.tsx:3294) → Fix: hoist gcSessionStorage(key) above the if (alreadyGone) split — the server holds the slot in neither case and the call is idempotent and best-effort.

[OPUS-REVIEWED] 370512a

@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 28, 2026
@jeeshofone
jeeshofone force-pushed the fix/14823-close-slot-404 branch from 9e0d2d5 to 4ce79ce Compare September 28, 2026 23:49
@jeeshofone

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: a 404 close releases its close hold instead of confirming it

  • a 404 can precede rollback of an in-flight close

fixed in 4ce79ce: legitimate. A 404 means another close already popped the key (close_slot pops before save_slot_off_loop), and that close can still fail and restore the slot.
The 404 path in deleteSlot now dispatches releaseCloseHold rather than confirmCloseHold, and skips gcSessionStorage, so no tombstone holds the restored row out of view; the next authoritative slot list decides.
No server change: this request closed nothing, so it has no outcome of its own to confirm or await.
Regression: shows a slot the server restores after a 404 close in website/src/test/ChatSliceCoverage.test.tsx fails on 9e0d2d5 and passes on 4ce79ce.

@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 Sep 29, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Status on head 4ce79ce, not yet fixed on a new head.

Both line-lane findings on the 404 branch of deleteSlot in website/src/store/chatSlice.ts are legitimate, and they pull in opposite directions:

  • Opus (the BLOCKING at line 3751): releasing the close hold on a 404 without the fetchSlots() the old catch path dispatched lets a fetchSlots reply serialized before the server popped the key re-add the closed row, with no later list guaranteed to remove it.
  • GPT (the BLOCKING at line 3743): the 404 path still resolves deleteSlot, and deleteSlot.fulfilled runs evictSlotState, so if the close that did pop the key fails and restores the slot, this tab has dropped that slot's in-memory view caches.
  • Opus FINDING: the close-hold paragraph in docs/system-specs/modules/learn-cron-dashboard.md does not describe the 404 path.

Planned fix for the next head: on a 404, keep releaseCloseHold, restore the fetchSlots() recovery refetch the pre-change catch path already did (so the only behavioural change from main is that no error is thrown), mark the fulfilment as "already gone" through the thunk's fulfilled meta so deleteSlot.fulfilled skips evictSlotState for it, and update that spec paragraph. That leaves the authoritative slot list to decide whether the row stays gone or comes back, which is the premise of the first fix.

Separately, Backend Tests (Windows) (4) fails test_pid_reader_ratchet.py::test_pid_reader_sites_match_the_recorded_count_exactly (161 sites, recorded 160). That is main-side: this diff touches no Python, the same test fails on bare origin/main 22284b7 (the base this CI run merged onto), and main fixed it in 9932337 (#14883). A rebase clears it.

@jeeshofone
jeeshofone force-pushed the fix/14823-close-slot-404 branch from 4ce79ce to dc1ac59 Compare September 29, 2026 02:06
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Dispositions for the Opus 5 Review of 4ce79ce, fixed on head dc1ac59 (rebased onto origin/main 7610731).

  • BLOCKING website/src/store/chatSlice.ts:3751 (404 branch releases the hold without a recovery refetch, so a pre-pop fetchSlots reply re-adds the closed row)

fixed: legitimate. The 404 branch keeps releaseCloseHold and now dispatches fetchSlots() right after it, the same pair the failure path uses, so the post-pop list removes a row that a pre-pop reply put back once the hold was gone. I took the second of your two options rather than armConfirmedCloseHold: a confirmed hold would hide the row if the close that did pop the key fails and restores the slot, which is the case the first fix exists for. Parity note: the two HTTP replies are unordered, so a pre-pop reply that lands AFTER the recovery reply is still re-applied, exactly as on main before this PR (main's 404 took the same catch path).
Regression: refetches after a 404 close so a pre-close slot list cannot keep the row in website/src/test/ChatSliceCoverage.test.tsx fails on 4ce79ce (one chatSlots call, row stays) and passes on dc1ac59.

  • FINDING docs/system-specs/modules/learn-cron-dashboard.md:2802 (close-hold paragraph does not describe the 404 path)

fixed: the paragraph now covers a DELETE answered 404. It says the path resolves the thunk, takes releaseCloseHold + recovery fetchSlots instead of confirmCloseHold / armConfirmedCloseHold and why, and that fulfilled carries meta.alreadyGone so the chat slice skips evictSlotState.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Disposition for the GPT 5.6 Review of 4ce79ce (security-fenced F1), fixed on head dc1ac59.

  • BLOCKING website/src/store/chatSlice.ts:3743 (a raced 404 fulfils deleteSlot, and deleteSlot.fulfilled evicts the client state of a slot the popping close may restore)

fixed: legitimate, and implemented the suggested fix. deleteSlot now declares fulfilledMeta: { alreadyGone: boolean } and returns fulfillWithValue(key, { alreadyGone }). deleteSlot.fulfilled returns early when action.meta?.alreadyGone is set, so neither evictSlotState nor the active-slot clear runs for a 404 close. The payload is still the key, so unwrap() callers are unchanged.
Absence is confirmed by an authoritative list: the 404 path dispatches the recovery fetchSlots(), and every live sseSlots frame runs reconcileSlotResidue (chatSlice.ts, addCase(sseSlots), which evicts the residue of a key the list no longer carries, as does a slot_patch removed key. gcSessionStorage still runs only on a successful DELETE.
Regression: keeps the slot's view state on a 404 close and evicts it on a real one in website/src/test/ChatSliceCoverage.test.tsx fails on 4ce79ce (slotMessages.doomed evicted by the 404 close) and passes on dc1ac59.

Closing a chat session the server already deleted (a second tab, or a
repeat close racing a slow first one) got a 404 from DELETE
/api/chat/slots/<key>, and deleteSlot treated it like any failure:
released the close hold, refetched slots and showed 'save failed'.

A 404 there means the slot is gone, which is the requested end state,
so deleteSlot now resolves on it instead of rejecting. Everything else
on that path matches the failure path, because this request closed
nothing and the close that did pop the key can still fail and restore
the slot:

- it drops its close hold rather than confirming it, so a restored row
  is not hidden behind this request's tombstone;
- before releasing, it pairs every fetchSlots still in flight with the
  key in staleSlotFetches (releaseCloseHold's distrustInFlight), since
  such a reply may predate the pop and would otherwise re-add the row
  whichever order it lands in;
- it still dispatches the recovery fetchSlots after that pairing, the
  trusted post-pop list that shows the row again if it was restored;
- its fulfilled action carries meta.alreadyGone, and the chat slice
  skips evictSlotState for it, leaving the slot's view state to the
  authoritative slot-list writers.

The close-hold paragraph of the dashboard spec now describes the 404
path. Other statuses keep the failure path.

Closes kirodotdev#14823
@jeeshofone
jeeshofone force-pushed the fix/14823-close-slot-404 branch from dc1ac59 to 370512a Compare September 29, 2026 02:48
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Disposition for the GPT 5.6 Review of dc1ac59 (fenced F1, upheld), fixed on head 370512a (rebased onto origin/main 2e09b10).

  • BLOCKING website/src/store/chatSlice.ts:3763 (a pre-close fetchSlots that resolves after the recovery refetch re-adds the closed row)

fixed: legitimate, implemented the suggested fix. releaseCloseHold in website/src/store/dashboardSlice.ts takes an optional distrustInFlight; when it is set, every request in slotFetchesInFlight is paired with the key through the existing markStaleSlotFetches before the hold is dropped, the same pairing the removed branch of sseSlotPatch records. The 404 branch of deleteSlot passes it, then dispatches the recovery fetchSlots(), which is therefore not paired and still shows the row if the popping close restored the slot. fetchSlots.fulfilled filters a paired key out of a late reply (keeping an on-screen row for it), and settleSlotFetch clears the pairing. The failure path does not pass the flag: the slot still exists there, so no pre-pop reply is wrong.
Regressions in website/src/test/ChatSliceCoverage.test.tsx: drops a pre-close slot list that lands after the 404 close's recovery refetch fails on dc1ac59 (row comes back) and passes on 370512a; trusts the recovery refetch when the popping close restored the slot pins that the recovery list is not distrusted.
The dashboard spec's close-hold paragraph describes the pairing.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 29, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Disposition for the Opus 5 Review advisory FINDING on 370512a (website/src/store/chatSlice.ts:3771, 404 branch skips gcSessionStorage).

hold position, deliberate: the observation is accurate. The sidebar cleanup loop (ChatSidebar.tsx:4490, for (const key of res.keys) dispatch(deleteSlot(key))) 404s on every key and leaves each one's per-tab storage in place. But the skip is the same rule as the evictSlotState skip this head adds: a 404 means this request closed nothing, and the close that did pop the key can still fail and restore the slot, so this tab must not drop that slot's UI state. The residue is bounded and self-heals: gcOrphanedStorage(liveIds) at App.tsx:3294 clears keys no live slot carries on the next boot. Telling "popped by the server's cleanup" apart from "popped by a racing close that may still roll back" needs the caller to say so, which is out of scope for #14823. Leaving it for a follow-up unless the maintainer wants it folded in.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed on behalf of the maintainers (readiness sweep 2026-09-29): readiness passed, the required PR Readiness check is green on this head, no live CHANGES_REQUESTED, no open blocking review threads; where the PR's files also moved on main since its merge-base, the PR's own tests were run on the main+PR merge tree and passed. Approving and squash-merging.

@bolichen97
bolichen97 merged commit 922a6d5 into kirodotdev:main Sep 29, 2026
100 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 29, 2026
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.

dashboard: closing an already-deleted session shows a 404 'not found' error instead of succeeding

2 participants