Skip to content

feat(ui): preserve composer drafts across restarts - #125332

Merged
steipete merged 12 commits into
mainfrom
steipete/persistent-drafts-and-images-65b66d
Aug 18, 2026
Merged

steipete merged 12 commits into
mainfrom
steipete/persistent-drafts-and-images-65b66d

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #125330

AI-assisted: yes

What Problem This Solves

A browser or app restart currently loses unsent Control UI text and staged image/file attachments in both existing-session and New Session composers. Users must reconstruct the message and select the attachments again before they can continue.

Why This Change Was Made

A browser-local IndexedDB owner now stores composer text and native attachment Blobs atomically. It reuses the existing session scope and compare-and-swap semantics, isolates records by the exact Gateway credential recovery scope and session, agent, or New Session target, excludes Incognito, bounds retained storage, and clears durable data only at the lifecycle owner boundaries for successful send or session creation, attachment removal, and session deletion.

The final lineage repair starts New Session writes before teardown while preserving atomic compare-and-swap behavior. CAS accepts only the committed revision/write ID or a known in-flight local predecessor ID; missing nonzero predecessors and unrelated same-revision writers still conflict. Completed local IDs leave the lineage set, and an authoritative missing record clears stale lineage before the still-current edit is re-snapshotted. Incognito remains memory-only until a real normal-mode edit, and oversized text-only fallback keeps the committed lineage identity.

This is device-local browser persistence, not cross-device or server syncing. There are no Gateway API, SQLite, protocol, config, or dependency changes.

Owner decision: Peter requested image draft restart persistence and accepts bounded browser-local retention (7 days / 20 scopes / 25 MiB); no server sync.

The production growth is the new durable browser-storage capability: attachment Blob ownership, compare-and-swap fences, and separate lifecycle owners for existing-session and New Session composers cannot be expressed as a smaller extension of the prior memory-only path.

User Impact

Control UI drafts and attachments now return after browser or app restarts in the same browser profile, login, and session or New Session target. Drafts expire after 7 days, retain at most 20 scopes per owner, and cap attachments at 25 MiB per draft. Clearing site data and using Incognito/private profiles still loses drafts by design.

When a draft's attachments exceed the durable cap, the browser preserves the exact text and omits only attachment payloads that cannot be persisted, with a visible warning in the current tab.

Release-note context: Control UI drafts and attachments now survive browser/app restarts in the same browser profile.

Evidence

Before the final repair, New Session could defer a newer attachment snapshot behind an earlier IndexedDB write, allowing page teardown before the newer transaction was registered. Commit 0fd719f967d starts each transaction immediately and preserves strict atomic local-lineage CAS.

Validation:

  • pnpm test:ui — 685 files; 9,766 passed / 1 skipped.
  • All draft E2E files passed; the focused lineage, teardown, and New Session set passed 18/18, with repeated stress runs green.
  • pnpm check:architecture — passed with 0 runtime cycles and 0 Madge cycles.
  • pnpm docs:check-mdx — passed.
  • pnpm check:changed — complete proportional coreTests, ui, and docs lanes passed.
  • git diff --check — passed.
  • Source-blind behavior validation — passed for text restoration, Incognito exclusion, session isolation, and session-creation cleanup.
  • .agents/skills/autoreview/scripts/autoreview --mode local --max-priority P1 — final fresh review clean; no accepted/actionable findings.

LOC classification: Production +1,680/-92; Tests +1,050/-38; Docs +4/-2.

The browser proof uses a mocked Gateway with real Chromium. No live Gateway was needed because this change has no Gateway surface.

Restored after restart — New Session

Restored after restart

Cleared after successful submission/removal — New Session

Cleared after successful submission/removal

Restored after restart — existing session

Restored after restart

Cleared after successful submission/removal — existing session

Cleared after successful submission/removal

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 17, 2026 15:45
@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 17, 2026
@steipete steipete closed this Aug 17, 2026
@steipete steipete reopened this Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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: 🦐 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 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 8:53 PM ET / August 18, 2026, 00:53 UTC.

ClawSweeper review

What this changes

Adds scoped browser-local IndexedDB persistence so Control UI composer text and staged attachments survive a restart and are retired after their owning lifecycle events.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding was found. This maintainer-labeled PR remains the active candidate for the paired draft-recovery feature and needs maintainer approval plus completion of exact-head checks before landing.

Priority: P2
Reviewed head: 0fd719f967d222b795b2695771c98578cb5ffc46

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A substantial but coherent browser-state feature with focused lifecycle coverage and visible after-fix evidence.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): The PR body supplies before/after screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.
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 screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.
Evidence reviewed 7 items Durable owner boundary: The new store keys records by gateway owner, credential recovery scope, and composer scope; reads reject mismatched scope records before restoration.
Lifecycle integration: Existing-session persistence excludes Incognito, restores only for a connected credential scope, and retires the durable record when Incognito is selected.
Visible behavior coverage: The browser E2E uses fresh pages to verify session-isolated restoration, attachment restoration, send cleanup, and attachment-removal cleanup.
Findings None None.
Security None None.

How this fits together

Control UI chat and New Session composers collect unsent text and attachments. This PR derives a credential-and-session scope, stores the draft locally in IndexedDB, restores it after restart, and retires it after send, creation, removal, deletion, or Incognito transitions.

flowchart LR
A[Composer text and attachments] --> B[Gateway credential and session scope]
B --> C[Browser-local draft store]
C --> D[Restart or route restore]
D --> E[Composer restored]
A --> F[Send, remove, delete, or Incognito]
F --> G[Durable draft retired]
Loading

Before merge

  • Resolve merge risk (P1) - Merging makes up to seven days of unsent text and attachment blobs durable in the browser profile; the documented credential scoping, expiry, size cap, and retirement paths are therefore a session-state and privacy contract.
  • Complete next step (P2) - The protected maintainer-labeled PR needs a human merge decision on its accepted local-retention contract; no bounded automated repair is indicated.
Agent review details

Security

None.

PR surface

Source +1588, Tests +1012, Docs +2. Total +2602 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 18 1680 92 +1588
Tests 11 1050 38 +1012
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 2734 132 +2602

Review metrics

Metric Value Why it matters
Production versus test growth production +1,680/-92; tests +1,050/-38; docs +4/-2 The feature adds a durable browser-state owner, Blob hydration, CAS fencing, and lifecycle cleanup; this deliberate production growth warrants continued owner review.

Stored data model

Persistent data-model change detected: serialized state: ui/src/lib/chat/composer-draft-store.runtime.ts, serialized state: ui/src/lib/sessions/session-deletion-draft-retirement.test.ts, serialized state: ui/src/lib/sessions/session-mutations.ts, serialized state: ui/src/pages/chat/durable-composer-persistence.ts, unknown-data-model-change: ui/src/lib/sessions/session-deletion-draft-retirement.test.ts, vector/embedding metadata: ui/src/pages/chat/attachment-payload-store.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #125330
Summary: This PR is the active implementation candidate for the paired composer-draft recovery feature request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land the bounded local-retention design (recommended)
    Accept the documented browser-profile retention policy and merge once the exact head has completed required checks.
  2. Reduce retained draft scope
    If browser-local attachment retention is not acceptable for this surface, narrow the retention contract before landing.

Technical review

Best possible solution:

Keep one browser-local, credential-scoped draft owner with the documented retention bounds and lifecycle retirement, then land after maintainer approval and exact-head checks complete.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main lacks the three durable-draft modules, and focused real-Chromium E2Es exercise fresh-page restart restoration and cleanup at the owning UI boundary.

Is this the best way to solve the issue?

Yes. Device-local, credential-scoped storage solves restart recovery without introducing Gateway, protocol, server-storage, or configuration surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3dd95d7bf790.

Labels

Label changes:

  • add P2: This is a bounded Control UI resilience feature for unsent work, without an active runtime outage or security bypass.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR body supplies before/after screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.
  • remove P1: Current review triage priority is P2, so this older priority label is no longer current.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded Control UI resilience feature for unsent work, without an active runtime outage or security bypass.
  • merge-risk: 🚨 session-state: The patch adds persisted composer state and retirement behavior across restart, submission, removal, deletion, and Incognito transitions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies before/after screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body supplies before/after screenshots and real-Chromium mock-Gateway E2E evidence for restoration and cleanup; the changed behavior has no live Gateway dependency.

Evidence

What I checked:

Likely related people:

  • steipete: The PR records Peter's acceptance of the browser-local retention policy, and the current head's lineage repair is authored by steipete. (role: feature owner and recent area contributor; confidence: high; commits: 0fd719f967d2; files: ui/src/lib/chat/composer-draft-store.runtime.ts, ui/src/pages/new-session/draft-persistence.ts, docs/web/control-ui.md)

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 (2 earlier review cycles)
  • reviewed 2026-08-17T20:43:10.156Z sha 6cfddd6 :: needs changes before merge. :: [P1] Start New Session writes before teardown
  • reviewed 2026-08-17T20:57:06.301Z sha 6cfddd6 :: needs changes before merge. :: [P1] Start New Session writes before teardown

@steipete

steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased head 9909e727c5d3a8ac27ca41bbd8cdcb4b3b81fb30 now addresses every completed ClawSweeper finding. Oversized drafts preserve exact text while omitting only unpersistable attachment payloads, the retention/scope/disposal contract is documented, and existing-session Incognito state is carried into the durable owner so any queued Blob write is fenced by a serialized tombstone and cannot restore after restart. Peter accepts the bounded browser-local policy. No Before merge or rank-up item is skipped.

Exact post-rebase/post-fix proof:

  • node_modules/.bin/oxfmt --check — 29,123 files passed.
  • pnpm test:ui — 685 files; 9,766 passed / 1 skipped.
  • pnpm test:ui:e2e -- ui/src/e2e/composer-draft-store.e2e.test.ts ui/src/e2e/chat-attachment-read-lifecycle.e2e.test.ts ui/src/e2e/new-session-page.prompt-attachments.e2e.test.ts — 3 files, 21/21 passed. The first combined run had one transient pre-existing New Session cleanup timing failure; the exact file passed 15/15 and the bounded combined rerun passed 21/21 without code changes.
  • New Session restart full-file proof — 3 consecutive runs, 45/45; attachment lifecycle — 3 consecutive runs, 12/12; affected five-file shared-browser set — 37/37; New Session visibility/restart set — 31/31.
  • pnpm test ui/src/pages/chat/composer-persistence.test.ts ui/src/pages/chat/chat-pane-state.test.ts — 2 files, 64/64 passed.
  • Focused final owner proof including deletion retirement — 3 files, 66/66 passed.
  • pnpm ui:build — passed; durable IndexedDB work is lazy-loaded and startup JS is 339,078 B, below the 339,585 B baseline and 340,641 B enforced limit.
  • pnpm build — passed, including dynamic-import topology, runtime postbuild, plugin SDK, and Control UI performance checks.
  • pnpm docs:check-mdx — 776 files passed.
  • node scripts/check-changed.mjs -- <all PR paths> — coreTests, ui, and docs lanes passed.
  • git diff --check — passed.
  • .claude/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean; no accepted/actionable findings.

LOC classification: production +1,564/-71; tests +739/-8; docs +4/-2 across 27 files. Positive production growth is the new durable browser-storage capability, Blob hydration and CAS fencing, and the lifecycle owners needed to retire data after send/create/removal/deletion/Incognito transitions.

The behavior is entirely browser-local. Real Chromium with a mocked Gateway exercises the owning boundary; there is no Gateway API, SQLite, protocol, config, dependency, or cross-device surface requiring a live Gateway.

@clawsweeper clawsweeper Bot added proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Aug 17, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

checks-ui exposed a real order dependency: this test's module mock was unsafe in the shared isolate:false UI suite. The test now exercises the actual IndexedDB boundary, verifies confirmed deletion does not await cleanup and a no-op schedules nothing, then settles the pending open request so no module state leaks.

Head: 5d1a96360e09045940136d420ac296493652952f

  • Focused test: 2/2 passed.
  • Full pnpm test:ui: 678 files; 9,697 passed / 1 skipped.

This is a test-only correction; production behavior is unchanged.

Separately, GitHub's major outage affected CI availability, but it did not cause this real test failure.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. labels Aug 17, 2026
@steipete steipete self-assigned this Aug 17, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Aug 17, 2026
@steipete steipete closed this Aug 17, 2026
@steipete steipete reopened this Aug 17, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Aug 17, 2026
@steipete steipete closed this Aug 17, 2026
@steipete steipete reopened this Aug 17, 2026
Accept the committed predecessor or a known in-flight local write ID atomically so New Session writes can start before teardown without spurious local-lineage conflicts.

Reset cached lineage when authoritative storage is missing and re-snapshot the still-current edit.
@steipete

Copy link
Copy Markdown
Contributor Author

Latest P1 resolved in 0fd719f967d, now the exact PR head. New Session transactions start before teardown, while CAS atomically accepts only the committed predecessor or a known in-flight local predecessor; authoritative missing records reset stale lineage and re-snapshot the still-current edit.

Proof: full UI 685 files / 9,766 passed / 1 skipped; all draft E2E green; focused lineage/teardown/New Session 18/18 with repeated stress green; architecture, docs, and check-changed green; final fresh P1 autoreview clean. All Before merge items and rank-up moves are addressed. The PR remains open and unmerged; no re-review requested.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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.

[Feature]: Preserve Control UI composer drafts across restarts

1 participant