Skip to content

ui-react: keep uncertain-save and pending-bind draft states in the device-local snapshot #1214

Closed

Description

@schlessera

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

  1. An uncertain first save. A first PUT whose answer was lost leaves the draft at host: 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), and restoreLocal would 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.
  2. 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.

Refs #1014, #951

Scope

  • Persist uncertain (only when true) and a pending bind in the stored draft record written by storeDraft, and parse them back in parseDraft, 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, no bind) parses as uncertain: false, bind: null, exactly as it is restored today. The record stays v: 1.

Out of scope

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 malformed bind is 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 in local-work-runtime.test.ts if 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 uncertain from storeDraft again and watch the uncertain-reload test fail; drop bind and watch the bind-reload test fail. Restore and record both in the PR.
  • tsc --noEmit for packages/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

  1. added
    type: fix
    area: ui-react
    priority: p3
    agent-ready
    on Oct 7, 2026
  2. schlessera commented on Oct 23, 2026

    @schlessera
    OwnerAuthor

    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.

  3. self-assigned this
    on Nov 3, 2026
  4. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming (token wi-1214-c0384d). Branch fix/1214-draft-snapshot-states from epic/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.

  5. added this to the 0.45.0 milestone on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-reactpriority: p3type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions