Skip to content

fix(watch): preserve companion messages and replies across app restarts - #137463

Merged
steipete merged 2 commits into
mainfrom
codex/watch-companion-delivery-journal
Sep 3, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/watch-companion-delivery-journal

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #136617

Related: #135808 (standalone realtime voice; separate work).

What Problem This Solves

Fixes an issue where users sending companion Apple Watch chat or quick replies could lose saved work or its result across app suspension, disconnection, or restart. An interactive WatchConnectivity acknowledgment could precede application admission, and a completed request could be retired before its reply reached the Watch. Retrying an ambiguous Gateway send is not safe evidence that it never executed.

Why This Change Was Made

Give each side one durable delivery owner: the Watch commits its original command before transport, and iPhone commits admission, dispatch state, accepted run identity and the result receipt before acknowledging or forwarding them. Reconnects replay commands still awaiting custody or saved receipts; they do not automatically repeat uncertain execution. This replaces the Watch-specific UserDefaults outbox rather than adding another queue beside it.

The app-local SQLite design, migration, retention and deletion choices were explicitly approved in #136617. The phone uses its existing client-state database; the Watch uses existing native SQLite primitives. No new dependency, setting, Gateway shared-state/per-agent schema change, or Gateway protocol-version bump is included. The new companion command/receipt/ACK family requires updated phone and Watch apps. This is durable companion messaging, not realtime audio or a local model runtime.

User Impact

Saved messages keep their exact Gateway, route generation, agent, session, text and original 48-hour deadline. Results remain available after the short spoken-reply window. The iPhone's Apple Watch settings expose Message Delivery, including completed receipts and legacy text that needs review. Dismiss hides a completed card without deleting its acknowledgment authority or allowing another send; Discard applies only to non-dispatchable legacy text.

Only work known not to have been dispatched is automatically sent. Known Gateway acceptance survives a temporarily failed local state write without another send; an app exit before that commit produces the documented uncertain state. Forget invalidates the exact routing generation and removes its journal rows. Hash-only legacy import receipts survive targeted Forget to prevent old Defaults data from resurrecting deleted text; Full Reset removes them. Legacy text without trustworthy ownership is never silently sent to the currently selected agent.

Current landing status

Current candidate: e3edb92d4f871c2003e6861a39ce05c3b37838f6, rebased once onto main 9acf0d48294c86c09dbb0016b914f75eca567290 after the native merge gate refused an obsolete canceled PR-event check. Both commits are patch-identical by git range-diff; all 35 affected production, test and documentation files remain byte-for-byte identical to the reviewed/tested e77fdc8 candidate. Only main's CI and native string inventory compose.

Canonical pull-request CI, attempt 3 is successful on this head, and the enforced PR-event gate passed. Native prepare/merge can now use the canonical event without a bypass. The earlier manual result remains separately labeled below.

The exact Mac test job checked out merge e7aeeec0 (this head into the pinned main base), then passed the Kit 1,627-test run and Mac 2,013-test run, with their explicitly recorded native opt-in skips and separate XCTest/health/AppState results. The unchanged Windows retry passed the original source/config transform case in 91.327 seconds under its existing 120-second limit. The next Mac attempt failed only at GitHub DNS resolution during checkout; one targeted same-head retry passed. Successful siblings were retained. No source, test assertion, timeout, or global runner-policy workaround was used. Physical Watch/iPhone proof remains outside this CI result.

Evidence

Native regression, UI, stable-reader compatibility and real-provider verification passed on head 36bc00e7c312c9603fb75d9d984110a1cab439e0. Follow-up e77fdc826b21bdcc607fea048541967b5e289c35 removes unused helpers and corrects a test wait, as described below. Exact-head hosted CI has passed, as recorded below.

Verified on the current candidate: all 38 shared journal/Watch-store test methods (67 cases) and all 248 iPhone coordinator methods pass. The delayed-route regression failed on the old claim with the actual stale outbound message, then passed on the command-bound claim; the write-failure and ambiguous-dispatch controls also pass. Coverage includes admission, Dismiss identity, receipt acknowledgment, original expiry, interrupted imports, targeted Forget/re-pair, offline accepted quick replies, transient storage warning recovery and failed dispatch-state writes. An actual signed stable v2026.8.2 reader was exercised in a v8 → candidate → v8 open/use/Forget → candidate sequence, with all four phases and 33 guarded fact groups passing.

The native app and UI-test targets build successfully. The UI test opens Message Delivery through Apple Watch settings, expands the saved reply, dismisses it and verifies that Needs review remains; its three inspected, synthetic-only screenshots are attached below. node scripts/check-changed.mjs --staged passes, including configured Swift lint, repository/schema guards and 20 Vitest files/1,077 tests. A final two-line test-callback compiler correction was subsequently compiled and exercised by the native runs, with formatting checked separately.

The isolated real-provider test passed after normal device pairing: Watch SQLite enqueue → phone admission → actual Gateway/provider reply → independent phone SQLite readback → Watch reopen → phone operator reconnect and receipt replay → typed Watch ACK. Fifteen runtime facts passed; canonical history held exactly one correlated user turn, and command replay preserved the claim, run, receipt and original deadline. The first attempt reached its connection deadline while awaiting node-role pairing approval and sent no command; the unchanged test passed on retry. The full test Gateway then closed normally, its owned process group exited, and temporary credentials and state were removed with zero retained exact credential matches. Hardware discovery finds no physical paired iPhone/Watch, so Simulator and direct-delegate coverage must not be mistaken for background WatchConnectivity, microphone/speaker, radio handoff, battery or endurance proof.

The broader native run completed 313 selected methods: 311 passed and two native SDK opt-ins were skipped. An explicit isolated, unpaired SDK run with the required live-test flag then passed all 14 gate methods/21 cases, including both skipped cancellation methods, with zero skips or runtime warnings. The broader run emitted existing audio-session main-thread warnings during app-model tests; these are retained and being traced separately, not counted as delivery failures or silently suppressed.

The owner refactor removes duplicate Watch queue/recent-ID policy and adds durable command/result recovery and its UI. Current diff accounting is 26 production files, +3,495/−1,047 lines (net +2,448), and seven test/test-support files, +3,219/−911 (net +2,308); docs, generated native strings and CI wiring are counted separately. The growth implements the approved two-sided custody/receipt capability and migration, rather than a retry wrapper around the old queue.

CI repair and final local proof

The first hosted run failed two Periphery checks on four unused helpers left by the owner refactor. The follow-up removes those helpers rather than suppressing the checks. Existing tests now check real route admission after import rollback and use the structural decoder used by production; an obsolete predicate-only delayed-refresh test is removed while its stronger command-result/replacement tests remain.

The same hosted run had one shared-library test failure: the ownerless reconnect test observed creation of the replacement socket before its connect frame existed. It now waits for that frame under the existing deadline, then retains all credential-isolation assertions. No production credential or networking behavior changes in this repair.

The exact eight-file follow-up passed independent review with no actionable findings, 117 native shared-library methods/156 cases, and 31 native Watch operation methods/46 cases. Its initially gated native speech test was then explicitly enabled and passed, proving replacement/Stop playback state. The repository changed gate passed again with pinned Swift tools and all 1,077 selected tooling tests. Temporary native process groups and the cleanup Watch Simulator were retired. The earlier real-provider and UI proof remains bound to 36bc00e7; this follow-up changes only unused production code and test observations, not the proven delivery path. Exact-head hosted CI has now passed.

Earlier manual hosted CI

CI run 33802556208, attempt 2 passed on exact commit e77fdc826b21bdcc607fea048541967b5e289c35: 201 jobs succeeded, one unselected Docker job skipped, and the required openclaw/ci-gate succeeded. The Mac Swift/release, iOS and Watch tests/release, native screenshots and Android families all passed. This run checks the literal PR commit, not a virtual merge with newer main.

The first attempt failed only while downloading an upstream native dependency (ECONNRESET before tests). One failed-job retry, with no dependency or source workaround, passed 33 files and 581 tests; five Mac-packaging cases are intentionally skipped on that Linux shard. Previously successful native jobs were retained rather than rerun. The obsolete original queued run was cancelled after this replacement passed.

Native UI evidence

Synthetic fixtures only. Before and after refer to the Dismiss interaction in the new Message Delivery screen.

Before Dismiss Saved reply expanded After Dismiss
Completed and Needs review cards Saved reply expanded Needs review remains after Dismiss

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: ios App: ios size: XL maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 18:05
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 5:50 PM ET / 21:50 UTC.

ClawSweeper review

What this changes

The PR replaces volatile Apple Watch companion-message handling with durable phone and Watch journals so commands and receipts survive restart or disconnection.

Warning

SQLite table change

This PR modifies persisted SQLite tables in apps/shared/OpenClawKit/Sources/OpenClawChatUI/ClientDatabases+WatchMessages.swift. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 3 items remain

No blocking defect was found in the durable Apple Watch message/reply repair. The recorded maintainer acceptance resolves the prior storage-design decision; current main lacks this implementation, so the PR remains necessary pending its normal exact-head CI gate.

Priority: P2
Reviewed head: e3edb92d4f871c2003e6861a39ce05c3b37838f6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-bound durable-state repair with strong real-flow evidence, while the sizeable migration still needs the final required CI gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR evidence exercises Watch SQLite persistence through phone admission, a real Gateway/provider reply, phone readback, Watch reopen, receipt replay, and acknowledgement; physical background WatchConnectivity endurance remains a stated scope limit rather than a missing proof of this repair.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR evidence exercises Watch SQLite persistence through phone admission, a real Gateway/provider reply, phone readback, Watch reopen, receipt replay, and acknowledgement; physical background WatchConnectivity endurance remains a stated scope limit rather than a missing proof of this repair.
Evidence reviewed 6 items Current-main necessity: Fetched current main does not contain the added phone journal source; resolving the path at this revision reports that it exists locally but not in main.
Durable owner boundary: The phone journal persists route ownership and generation, admits a command before work starts, and uses claim-bound terminal settlement and typed receipt acknowledgement.
Migration and Forget cleanup: The v9 client-state migration creates the journal and indexes, retains legacy-import receipts separately, and removes journal rows when Forget reaches its irreversible phase.
Findings None None.
Security None None.

How this fits together

Apple Watch chat and quick replies travel through WatchConnectivity to the iPhone, which admits work to the Gateway and returns a result. This change adds app-local durable state around those handoffs so recovery can replay custody or receipts without resending uncertain work.

flowchart LR
  A[Watch chat or quick reply] --> B[Watch delivery journal]
  B --> C[WatchConnectivity transport]
  C --> D[iPhone admission journal]
  D --> E[Gateway chat request]
  E --> F[Saved result receipt]
  F --> G[Watch receipt replay and acknowledgment]
Loading

Before merge

  • Resolve merge risk (P1) - This app-local SQLite migration changes restart and upgrade behavior; matching updated Watch and iPhone apps are required for the durable delivery contract.
  • Resolve merge risk (P1) - Exact-head required CI remains incomplete, so landing should wait for its normal merge gate despite the reviewed source and real-flow evidence.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Docs +127, Config +12, Other +4813. Total +4952 across 37 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 2 134 7 +127
Config 1 12 0 +12
Generated 0 0 0 0
Other 34 6778 1965 +4813
Total 37 6924 1972 +4952

Review metrics

Metric Value Why it matters
Production versus test delta production +3,495/−1,047; tests +3,219/−911 The durable-state implementation replaces volatile queues with owner-bound custody and receipts; its migration makes upgrade validation material before merge.

Stored data model

Persistent data-model change detected: database schema: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ClientDatabases+WatchMessages.swift, unknown-data-model-change: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ClientDatabases+WatchMessages.swift. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Wait for required CI on the final head while retaining the reviewed migration and old-reader upgrade guarantees.
  2. Pause if upgrade validation fails
    Pause the PR if final CI exposes a migration, old-reader, or restart-recovery failure that invalidates the documented contract.

Technical review

Best possible solution:

Land after exact-head required CI is green while preserving the documented v8-reader, migration, Forget, and receipt-replay guarantees.

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

Yes, from source and reviewed regression coverage: the former acknowledgement/volatile-queue boundary can separate accepted work from durable custody; this reviewer did not execute native tests.

Is this the best way to solve the issue?

Yes: per-device journals give admission and result delivery one durable owner while explicit uncertainty prevents unsafe resend of ambiguous work; the old Defaults queues are migrated rather than retained as runtime fallbacks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 194b7f2a1619.

Labels

Label justifications:

  • P2: This repairs companion-message restart safety with a bounded Apple client blast radius rather than an active core-runtime outage.
  • merge-risk: 🚨 compatibility: The app-local client-state migration and required two-app update can affect existing installations and downgrade behavior.
  • merge-risk: 🚨 session-state: The change persists admission, dispatch, and receipt state across restarts, so incorrect migration or recovery behavior could mis-associate delivery state.
  • 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 (terminal): The PR evidence exercises Watch SQLite persistence through phone admission, a real Gateway/provider reply, phone readback, Watch reopen, receipt replay, and acknowledgement; physical background WatchConnectivity endurance remains a stated scope limit rather than a missing proof of this repair.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR evidence exercises Watch SQLite persistence through phone admission, a real Gateway/provider reply, phone readback, Watch reopen, receipt replay, and acknowledgement; physical background WatchConnectivity endurance remains a stated scope limit rather than a missing proof of this repair.

Evidence

Acceptance criteria:

  • [P1] Complete exact-head required CI before landing.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-03T18:41:50.396Z sha e77fdc8 :: blocked before merge. :: none
  • reviewed 2026-09-03T21:29:35.967Z sha e77fdc8 :: blocked before merge. :: none

@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Recording the maintainer decision already given in the originating task: the accepted implementation is the app-local journal design in #136617, including the exact migration, retention, Forget and downgrade terms now implemented in this PR.

That approval covers the iPhone v9 journal and route-generation column, the Watch-local v1 journal, the nullable command fingerprint, permanent hash-only legacy-import receipts, and receipt-preserving Dismiss. Legacy-import hashes survive targeted Forget to prevent old data from resurrecting; full reset clears them. New commands and results retain their original 48-hour deadline. There is no Gateway shared-state/per-agent schema change or protocol-version bump. The production growth is accepted for replacing the split queues with one durable admission/result owner on each device, not for adding a second delivery path.

The actual signed stable v8 → candidate → stable v8 open/use/Forget → candidate compatibility run passed, as did the isolated real-Gateway/provider journal flow described in the body. Physical background WatchConnectivity remains explicitly unverified.

CI is still a required gate. On e77fdc8, both Periphery workflows now pass, but the full CI run has an Android reconnect-test failure under investigation. Its tested merge contains newer main commit #137389; the failing test is absent from the literal PR head. No merge is being attempted while that gate is red.

@steipete

steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Update: the candidate is now e3edb92d4f871c2003e6861a39ce05c3b37838f6. Native landing correctly refused the obsolete cancelled PR-event gate; a successful manual aggregate refresh did not replace it. One clean rebase generated fresh canonical PR CI, which must pass before merge. Both commits and all affected production/test/doc bytes are unchanged; only main CI and native-string inventory compose. No merge or bypass occurred.

Previous candidate evidence:

Ready for native landing of the companion delivery journal at e77fdc826b21bdcc607fea048541967b5e289c35. The app-local migration and retention decision is recorded above; no Gateway or per-agent schema changes are included.

Exact-head CI attempt 2 and the required gate are green. The only retry was an upstream native-dependency download failure before tests; unchanged source then passed 581 tests in 33 files, with five Linux-inapplicable Mac-package cases skipped. Mac, iOS/Watch, Android and screenshot successes were retained.

Local proof includes node scripts/check-changed.mjs --staged (1,077 selected tests plus Swift/schema guards), signed native shared and Watch tests, the stable v8 upgrade/downgrade/use/reopen sequence, Settings → Message Delivery UI interaction, and the isolated real-Gateway/provider receipt-replay flow. Independent review has no accepted actionable findings. Earlier full delivery/UI/live proof and the exact-head unused-code/test-wait follow-up remain distinguished in the PR body.

Physical paired-Watch background transport and audio/endurance testing remain unverified; this PR does not claim standalone realtime voice, which remains in #135808.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 3, 2026
Replace volatile companion queues with an app-local SQLite journal. Commit
admission before acknowledging Watch custody, retain typed result receipts
until Watch acknowledgment, and fence retries by immutable route ownership.

Recover accepted quick replies offline without sending again. Preserve
ambiguous sends for review instead of assuming Gateway deduplication is durable.
Add recovery settings, legacy import receipts, and hash-only command identity
that survives Dismiss until the original receipt deadline.

The app-local v9 schema and retention design were explicitly approved in
@steipete
steipete force-pushed the codex/watch-companion-delivery-journal branch from e77fdc8 to e3edb92 Compare September 3, 2026 21:32
@steipete steipete self-assigned this Sep 3, 2026
@steipete
steipete merged commit ef9be3d into main Sep 3, 2026
396 of 405 checks passed
@steipete
steipete deleted the codex/watch-companion-delivery-journal branch September 3, 2026 23:00
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
…ts (openclaw#137463)

* feat(ios): persist Watch message custody and delivery receipts

Replace volatile companion queues with an app-local SQLite journal. Commit
admission before acknowledging Watch custody, retain typed result receipts
until Watch acknowledgment, and fence retries by immutable route ownership.

Recover accepted quick replies offline without sending again. Preserve
ambiguous sends for review instead of assuming Gateway deduplication is durable.
Add recovery settings, legacy import receipts, and hash-only command identity
that survives Dismiss until the original receipt deadline.

The app-local v9 schema and retention design were explicitly approved in

* fix(watch): remove obsolete delivery helpers and stabilize reconnect proof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 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.

Apple Watch: persist companion chat admission and reply receipts across app restarts

1 participant