Repository navigation
fix(ui): retire drafts after authoritative session deletion - #125665
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 5:36 AM ET / 09:36 UTC. ClawSweeper reviewWhat this changesCentralizes confirmed session-deletion handling so Control UI removes stale composer drafts from sessionStorage and IndexedDB while preserving drafts recreated after deletion confirmation. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessNo blocking correctness findings. Current main still has request-local draft retirement and no app-shell consumer for Gateway deletion facts, so this repair remains necessary; exact-head CI and a behind-base refresh remain before merge. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherControl UI receives session deletions from direct requests and Gateway events. The app shell passes those authoritative facts to browser-local draft stores, which retire stale text and attachments before a recreated session can restore them. flowchart LR
A[Direct session deletion] --> C[Confirmed deletion fact]
B[Gateway deletion event] --> C
C --> D[Control UI app shell]
D --> E[Draft retirement runtime]
E --> F[Session storage draft]
E --> G[IndexedDB draft]
F --> H[Recreated composer]
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +325, Tests +594, Docs 0. Total +919 across 23 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one confirmed-deletion consumer in the app shell, preserve its revision fence across both browser stores, then merge after a current-base refresh and exact-head checks are green. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: current main handles only direct deletion cleanup, while the PR's real Chromium mocked-Gateway scenario exercises an authoritative external deletion that leaves stale draft data without this consumer. Is this the best way to solve the issue? Yes—the app-shell fact consumer is the right owner because it covers both direct and event producers; retaining request-local cleanup would leave the event path divergent. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b8ff4fe3d7d6. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
290baf0 to
a2e6cfa
Compare
|
@clawsweeper re-review The confirmation-boundary finding and both rank-up moves are addressed on |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready proof for Local owner proof
Exact-head hosted proof
Chromium before / after
Review / size
|
|
Merged via squash.
|
…#125665) * fix(ui): retire drafts on authoritative session deletion * fix(ui): fence drafts after deletion confirmation * test(ui): type post-confirm draft replacement * test(ui): wait for durable attachment drafts * test(ui): reject indexeddb readiness errors * perf(ui): lazy-load deleted-session cleanup * perf(ui): trim draft cleanup startup path * refactor(ui): keep outbox types private
Related: #125332, #125330
What Problem This Solves
Fixes an issue where browser-persistent composer drafts could outlive their session when the session was deleted outside the current request path. The original restart-persistence feature also swept seven-day expiry only inside the currently opened credential scope, repeated browser-storage work for batch deletion, and could let asynchronous deletion cleanup erase a newer draft after the same session key was recreated.
Why This Change Was Made
Session deletion reconciliation now publishes timestamped authoritative deletion facts from both request and event paths. The app host consumes each fact-array identity once and delegates the batch to one lazy retirement runtime, which performs one sessionStorage update and one IndexedDB transaction while preserving same-key drafts written after deletion began. First IndexedDB open now sweeps expired records across abandoned credential owners, active expired records become revision fences, and expired tombstones are removed.
The obsolete request-local retirement path and its request-owner test are removed. Attachment restore cleanup now belongs to
NewSessionAttachmentDraft.restore, which releases only displaced payload IDs while preserving shared or incoming owners. The read-only outbox projection moved tooutbox-store-projection.tsto keep the storage owner below the max-lines ratchet without a suppression.ClawSweeper's exact-head review found that the first version timestamped direct deletions before the delete RPC was confirmed. That finding was accepted: direct and batch timestamps now originate only after a successful deletion response. The Chromium regression separately proves that an edit made while deletion is in flight is retired and that a replacement written after confirmation survives.
Production LOC is +585/-262 (net +323), including the approximately 160-line moved read-only projection. The remaining growth pays for global retention enforcement, authoritative cross-source deletion cleanup, one batch runtime, the replacement fence, and the attachment owner boundary. Snapshot invalidation, once-only failure reporting, and draft cleanup share the deletion-only lazy boundary so the current-main tree stays inside the Control UI startup budget. Tests/test support are +674/-78; docs are +1/-1. No changelog, version, tag, release, or package publication is included.
User Impact
Deleting a session now retires its browser draft even when deletion arrives from another client or authoritative Gateway event. Recreating the same session key no longer resurfaces stale text, while a genuinely newer replacement remains intact. Browser-wide seven-day retention also applies to abandoned credential scopes, and cleanup failures show an actionable site-data message instead of failing silently.
Evidence
Real Chromium + mocked Gateway
The same user flow ran against exact pre-fix parent
1c3e512096bc57b34f9379b1992912c3d18729c7and this PR head2347e177044478d132ff475a968978876cbdc697: type text and attach a synthetic file through the composer, close/reopen the page to prove both are durable, receive an authoritative external deletion, recreate the same key, then open it from the sidebar.Before: the recreated session restores stale text.
After: the recreated session opens with an empty composer.
Known visual-proof limitation: the synthetic file was visibly restored after the pre-deletion page restart in both runs, but exact pre-fix code's legacy pane-deletion lifecycle independently releases that attachment before the recreated key is opened. Therefore the final before frame can honestly show the stale text but not the stale file. No DOM injection or storage mutation was used to fake the final state. The Chromium owner regression below directly verifies that authoritative external deletion retires both sessionStorage and IndexedDB records, including attachments, while preserving siblings, no-ops, and newer replacements.
Mocked-Gateway verdict: before = stale text restored; after = empty text and zero attachments; the seed text and file survived a real page restart before deletion in both runs.
Exact local proof
node scripts/run-vitest.mjs ui/src/app/app-host.deleted-session.test.ts ui/src/lib/chat/outbox-store.test.ts ui/src/lib/sessions/index.event-refresh.test.ts ui/src/pages/new-session/draft-submission-flow.test.ts— 4 files, 43 tests passed on the rebased head.node scripts/run-vitest.mjs ui/src/e2e/composer-draft-store.e2e.test.ts ui/src/e2e/session-management.delete.e2e.test.ts ui/src/e2e/new-session-page.draft-handoff.e2e.test.ts— 3 files, 6 Chromium tests passed on the rebased head.pnpm tsgo:ui— passed on the rebased head.pnpm tsgo:core:test— passed after the CI-reported E2E test-shape correction.pnpm tsgo:test:ui— passed after adding an explicit durable-readiness assertion to the attachment lifecycle E2E.pnpm ui:build— passed at 335.3 KiB startup JS gzip against a 336.3 KiB limit.node scripts/check-deadcode-exports.mts— production, full-tree, and script scans passed with zero entries after privatizing owner-only outbox types.git diff --check origin/main...HEAD— passed.0f3fc97985289c516e30c8081e2365bb028e4b80across rebase.The patch-identical pre-rebase commit also passed the full
pnpm test:uisuite (686 files, 9,822 passed, 1 skipped),pnpm build, and the complete changed-file gate after removing one reported unused import. The final changed-file rerun with only the already-completed dead-export scan skipped passed every remaining gate.AI-assisted; the implementation and evidence were reviewed before publication. No agent transcript is attached.