Skip to content

fix(ui): retire drafts after authoritative session deletion - #125665

Merged
steipete merged 8 commits into
mainfrom
steipete/persistent-drafts-cleanup
Aug 18, 2026
Merged

steipete merged 8 commits into
mainfrom
steipete/persistent-drafts-cleanup

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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 to outbox-store-projection.ts to 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 1c3e512096bc57b34f9379b1992912c3d18729c7 and this PR head 2347e177044478d132ff475a968978876cbdc697: 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.

Before: stale deleted-session draft restored

After: the recreated session opens with an empty composer.

After: recreated session has 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.
  • Current-main 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.
  • Fresh branch-mode P1 autoreview — clean, no accepted/actionable findings.
  • Fresh P1 autoreview of the ClawSweeper follow-up — clean, no accepted/actionable findings.
  • The initial cleanup commit retained stable patch ID 0f3fc97985289c516e30c8081e2365bb028e4b80 across rebase.

The patch-identical pre-rebase commit also passed the full pnpm test:ui suite (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.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: XL maintainer Maintainer-authored PR labels Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 06:40
@steipete steipete self-assigned this Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 5:36 AM ET / 09:36 UTC.

ClawSweeper review

What this changes

Centralizes confirmed session-deletion handling so Control UI removes stale composer drafts from sessionStorage and IndexedDB while preserving drafts recreated after deletion confirmation.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No 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
Reviewed head: 2347e177044478d132ff475a968978876cbdc697

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong browser proof and focused owner-boundary coverage support a good patch; current-base refresh and remaining exact-head checks are still needed.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The PR body supplies before/after Chromium screenshots and describes an after-fix mocked-Gateway browser flow covering stale-draft removal and post-confirmation replacement preservation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The PR body supplies before/after Chromium screenshots and describes an after-fix mocked-Gateway browser flow covering stale-draft removal and post-confirmation replacement preservation.
Evidence reviewed 7 items Current-main gap: Current main still schedules composer-draft retirement only from the direct deletion mutation; it has no centralized consumer for externally observed deletion facts.
Confirmed deletion producers: The PR publishes retirement facts only after a successful direct deletion response and batches confirmed deletions before publishing state.
Event-path coverage: Gateway session deletion events now publish the same timestamped fact, while matching create events clear the transient deletion marker.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs ui/src/e2e/session-management.delete.e2e.test.ts

Result: FAIL (partial) — step 2 expect_output retires confirmed single and batch drafts in both stores: expected terminal output was not visible within 30 seconds: "retires confirmed single and batch drafts in both stores"

node scripts/run-vitest.mjs ui/src/e2e/session-management.delete.e2e.test.ts
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-125665-CPDsdP/target$ node scripts/run-vitest.mjs ui/src/e2e/session-management.delete.e2e.test.ts
[test] starting test/vitest/vitest.ui-e2e.config.ts
[test] preflight test/vitest/vitest.ui-e2e.config.ts
node scripts/run-vitest.mjs ui/src/e2e/session-management.delete.e2e.test.ts
[ui-e2e] Using system Chromium at /usr/bin/chromium-browser.
Downloading FFmpeg (playwright ffmpeg v1011) from https://cdn.playwright.dev/dbazure/download/playwright/builds/ffmpeg/1011/ffmpeg-linux.zip
|                                                                                |   0% of 2.3 MiB
|■■■■■■■■                                                                        |  10% of 2.3 MiB
|■■■■■■■■■■■■■■■■                                                                |  20% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■                                                        |  30% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                                |  40% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                        |  50% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                |  60% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                        |  70% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                |  80% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■        |  90% of 2.3 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 100% of 2.3 MiB
FFmpeg (playwright ffmpeg v1011) downloaded to /tmp/clawsweeper-live-proof-125665-CPDsdP/profile/cache/ms-playwright/ffmpeg-1011

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-125665-CPDsdP/target






























Assertions:

  • FAIL expect_output: retires confirmed single and batch drafts in both stores

How this fits together

Control 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
Loading

Before merge

  • Resolve merge risk (P1) - The repair is net +323 production lines across two persistent browser stores; exact-head CI should finish before merge.
  • Resolve merge risk (P1) - GitHub reports the branch behind main, so a rebase or merge-ref refresh should confirm the session lifecycle still integrates cleanly with current main.
Agent review details

Security

None.

PR surface

Source +325, Tests +594, Docs 0. Total +919 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 14 588 263 +325
Tests 8 671 77 +594
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 1260 341 +919

Review metrics

Metric Value Why it matters
Production versus test delta production +585/-262 (net +323); tests/test support +674/-78; docs +1/-1 The added browser-storage lifecycle is substantial for a bug fix, though the extraction of the 164-line read-only projection and deletion of the request-local path keep the owner boundary coherent.

Stored data model

Persistent data-model change detected: serialized state: ui/src/app/app-host.deleted-session.test.ts, serialized state: ui/src/e2e/composer-draft-store.e2e.test.ts, serialized state: ui/src/e2e/session-management.delete.e2e.test.ts, serialized state: ui/src/e2e/session-management.test-support.ts, serialized state: ui/src/lib/chat/outbox-store.test.ts, serialized state: ui/src/lib/sessions/index.event-refresh.test.ts, and 7 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head storage validation (recommended)
    Refresh against current main and require the remaining exact-head checks to pass while retaining the cross-store replacement-fence coverage.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This repairs stale browser-local draft state after session deletion, with bounded Control UI impact.
  • merge-risk: 🚨 session-state: The PR changes retirement and revision-fence behavior for persistent drafts in sessionStorage and IndexedDB.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR body supplies before/after Chromium screenshots and describes an after-fix mocked-Gateway browser flow covering stale-draft removal and post-confirmation replacement preservation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies before/after Chromium screenshots and describes an after-fix mocked-Gateway browser flow covering stale-draft removal and post-confirmation replacement preservation.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body supplies before/after Chromium screenshots and describes an after-fix mocked-Gateway browser flow covering stale-draft removal and post-confirmation replacement preservation.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the merged durable composer-draft feature and the current lifecycle repair. (role: merged feature author and recent area contributor; confidence: high; commits: 6b72d65ffe4f, 2347e1770444; files: ui/src/lib/chat/composer-draft-store.runtime.ts, ui/src/lib/chat/outbox-store.ts, ui/src/lib/sessions/session-mutations.ts)
  • Jacqueline Henriksen: Git blame ties the current-main direct-only deletion helper to this contributor's commit. (role: baseline lifecycle contributor; confidence: medium; commits: 5dcc91df998f; files: ui/src/lib/sessions/session-mutations.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase or validate the merge ref against current main, then let the remaining exact-head checks complete.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-08-18T06:48:46.221Z sha e75ecb8 :: found issues before merge. :: [P2] Timestamp retirement after deletion confirmation
  • reviewed 2026-08-18T07:06:10.295Z sha d055bd5 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T07:34:38.485Z sha 0344800 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T07:56:54.156Z sha d916e11 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T08:46:46.490Z sha 290baf0d7edf7768f6aa830eb3e76ef731e855ae :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T09:05:10.888Z sha a2e6cfa :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete
steipete force-pushed the steipete/persistent-drafts-cleanup branch from 290baf0 to a2e6cfa Compare August 18, 2026 08:57
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The confirmation-boundary finding and both rank-up moves are addressed on 2347e177044478d132ff475a968978876cbdc697: direct/batch fences are captured only after confirmed deletion, the Chromium regression now retires an in-flight edit and preserves a post-confirmation replacement, exact-head CI is green, and the cleanup remains consolidated under the single app-shell/lazy-runtime owner.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 2347e177044478d132ff475a968978876cbdc697:

Local owner 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 passed.
  • 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 ui/src/e2e/chat-attachment-read-lifecycle.e2e.test.ts — 4 Chromium files / 10 passed.
  • pnpm tsgo:ui and pnpm tsgo:test:ui — passed.
  • pnpm ui:build — passed; startup JS 335.3 KiB gzip / 336.3 KiB limit.
  • node scripts/check-deadcode-exports.mts — production, full-tree, and script scans passed with zero entries.
  • git diff --check origin/main...HEAD — passed.
  • Fresh final branch-mode P1 autoreview — clean, no accepted/actionable findings.
  • Patch-identical pre-rebase broad proof: full pnpm test:ui passed 9,822 tests in 686 files with one skip; pnpm build and changed-file gates passed.

Exact-head hosted proof

  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32121731143 — green after one bounded failed-job rerun. The three unchanged flaky files passed individually before rerun (chat-send 301/301, session sidebar 11/11, cloud dispatch 1/1).
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 125665 completed with gate mode hosted_exact_or_recent_parent and verified the remote/local head at 2347e177044478d132ff475a968978876cbdc697 (2026-08-18T09:53:43Z). No separate Testbox provider, lease, or run URL was created because exact hosted gates were reused.

Chromium before / after

Review / size

  • ClawSweeper's confirmation-boundary finding and both rank-up moves were applied: in-flight edits are retired, only post-confirmation replacements survive, and cleanup stays under the single app-shell/lazy-runtime owner. Re-review requested at fix(ui): retire drafts after authoritative session deletion #125665 (comment); the publisher is currently reviewing the exact head.
  • LOC: production +585/-262 (net +323), tests/test-support +674/-78, docs +1/-1. The approximately 164-line projection is moved read-only logic; remaining growth implements global expiry, authoritative batched cleanup, confirmation fences, failure visibility, and attachment ownership.
  • No CHANGELOG, release, tag, version, npm, or package publication action.

@steipete
steipete merged commit f32da28 into main Aug 18, 2026
264 of 268 checks passed
@steipete
steipete deleted the steipete/persistent-drafts-cleanup branch August 18, 2026 09:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant