Repository navigation
Description
Context
Found in the second adversarial review of #1014 (PR #1209). The device-local snapshot keeps each draft's text, images and last acknowledged host revision, but not two of the reconciliation states #951's draft client relies on. The in-memory draft carries both (uncertain, bind, packages/ui-react/src/stores/draft-state.ts:77-80); the stored record (storeDraft, packages/ui-react/src/lib/local-work.ts:169-180) and its parser (parseDraft, packages/ui-react/src/lib/local-work.ts:136-147) carry neither, and the restored draft starts from blank() with neither set (restoreLocal, packages/ui-react/src/stores/draft-state.ts:496-519).
- An uncertain first save. A first
PUTwhose answer was lost leaves the draft athost: null, uncertain: true(saveFailed,packages/ui-react/src/stores/draft-state.ts:741-744). If the reader then empties the draft, the snapshot drops the empty record because it has no host copy (packages/ui-react/src/lib/local-work.ts:345-347), andrestoreLocalwould drop it again (packages/ui-react/src/stores/draft-state.ts:500-501). After a reload the host refresh restores the cleared text instead of reconciling it through the uncertain-save path. - A pending bind. After a new chat's first message is accepted while a newer unbound save is outstanding, the draft carries
bind: { sessionId, requestId }. The snapshot drops it. After a reload the draft reads clean, so the client neither binds it nor reads its revision, and the host keeps an unbound draft that the session no longer shows.
Both are narrow timing windows on a host that keeps drafts (#979). Without #1014, a reload lost the whole in-memory draft in the same windows. This work belongs to #578's device-local persistence outcome.
Scope
- Persist
uncertain(only when true) and a pendingbindin the stored draft record written bystoreDraft, and parse them back inparseDraft, validating their shapes like the other untrusted fields. - Keep an emptied, host-null draft in the snapshot while it is
uncertain(its possible host copy is still owed a reconciliation), alongside the existing "deletion still owed" rule. - Restore both states in
restoreLocal, including the emptied-uncertain case, so the draft client's existing uncertain-save and bind paths run after a reload. - A record written before this change (no
uncertain, nobind) parses asuncertain: false, bind: null, exactly as it is restored today. The record staysv: 1.
Out of scope
- Any redesign of the draft client's reconciliation, rotation or conflict rules (ui-react: retain and restore a separate composer draft per session #951); this only stops the two states being lost across a reload.
- Attachment upload ids, which deliberately re-upload after a reload.
- The attachment-error publication repair in ui-react: an attachment rejection disappears in an empty composer #1245.
- Host-side draft storage (ui-server: persist and synchronize session composer drafts and attachments #979) and any server or protocol change.
Acceptance criteria
- An emptied draft whose first save is uncertain survives a reload as uncertain, and the draft client reconciles it (deleting the host's copy if it exists) rather than restoring the cleared text.
- A draft with a pending bind survives a reload with its bind, and the client completes the bind (or rotates per ui-react: retain and restore a separate composer draft per session #951's rule) after reload.
- A stored record without the new fields restores exactly as before (
uncertain: false,bind: null), and a malformedbindis ignored rather than rejecting the whole draft, each proven by a unit test. - Each of the first two cases has a test shown failing on the tree before the change, for the assertion it names.
Verification
bun run test packages/ui-react/tests/draft-store.test.ts packages/ui-react/tests/draft-client.test.ts packages/ui-react/tests/local-work-runtime.test.ts(draft-store/draft-client unit level is enough; add a runtime cell inlocal-work-runtime.test.tsif the reload ordering matters).- Failing-first receipts: each new reload test fails on main for the named assertion (cleared text restored; bind lost), not on a load error.
- Mutation: drop
uncertainfromstoreDraftagain and watch the uncertain-reload test fail; dropbindand watch the bind-reload test fail. Restore and record both in the PR. tsc --noEmitforpackages/ui-react.
Contract impact
None. The stored draft is an internal device-local record (StoredDraft, packages/ui-react/src/lib/local-work.ts:121); LocalDraft and storeDraft are not exported from @schlessera/brain-ui-react. No CLI --json, MCP, HTTP or schema_version change. Older records stay readable.
2026-10-24: completed the task template (Scope, Out of scope, Verification, Contract impact) and gave every source reference a line-numbered anchor on main a6b945bd9; defect and acceptance criteria unchanged apart from the legacy-record criterion.
Activity
schlessera commentedon Oct 23, 2026
2026-10-24 restructuring: attached to #578. Its whole deliverable, keeping uncertain-save and pending-bind draft state through reload, serves that epic's device-local persistence outcome.
schlessera commentedon Nov 3, 2026
Claiming (token
wi-1214-c0384d). Branchfix/1214-draft-snapshot-statesfromepic/578-offline-transitions(5abcc42). Collision check on the cited files: closure-level overlap only (shared ui-react test closure with ~38 open PRs), no path collision.fix(ui-react): keep uncertain-save and pending-bind draft states in t…