Skip to content

refactor(imessage): keep echo and replay storage off the Gateway thread - #149605

Merged
steipete merged 3 commits into
mainfrom
codex/imessage-async-storage-host-compat-20260915
Sep 16, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/imessage-async-storage-host-compat-20260915

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146557

What Problem This Solves

iMessage echo suppression and restart replay currently perform SQLite bookkeeping on the Gateway thread.

User Impact

Current hosts move that bookkeeping to the existing state worker while preserving echo suppression, replay ordering, and failed-send cleanup. The declared OpenClaw 2026.9.4 peer and plugin API floor remains supported through its existing synchronous atomic updater. There are no configuration, schema, expiration, or retention changes.

Why This Change Was Made

Send, inbound, startup, and durable-ingress callers now await their echo and cursor operations. One pure cursor decision serves worker comparisons and the older host's transactional update callback, preserving monotonic advancement and rewinding only the expected row after a database replacement. The compatibility path is selected only when comparison methods are absent, before any wait; errors from available comparison methods never retry through synchronous storage. Remove that fallback only when the declared host floor excludes hosts without comparison support.

Reply-cache hydration remains with its existing owner because the synchronous action-authorization callback still requires first-read hydration. The affected tests use the existing process-based database-worker lane, await fixture shutdown, and signal request readiness without increasing deadlines.

Evidence

  • Eight real-SQLite cursor cases cover current and 2026.9.4 API-shaped stores, concurrent maximum advancement, durable rewinds, intervening writes, and modern comparison failures without synchronous fallback. The three older-host cases fail without the compatibility repair.

  • Eight monitor cases cover startup watermarks, remote replay, downtime recovery, cursor advancement after durable enqueue, and replaced or empty databases.

  • CI exposed one missed test-helper caller migration. The existing monitor behavior corpus now awaits cursor operations; all 17 selected recovery-cursor cases pass, along with scoped lint and extension-test types. A fresh P0–P2 review of that test-only completion is clean. Production code and the previously qualified rendering inputs are unchanged.

  • The selected changed-check plan is complete and independent P0–P2 review is clean. A fixture variable-shadowing lint finding was fixed; final lint/typechecks and all remaining planned guards passed. The published 2026.9.4 API and npm peer/plugin API declarations were inspected; version-shaped fixtures use the real SQLite owner, rather than a full historical-host installation.

  • Supporting predecessor proof is retained: 33 focused storage cases, 28 reply-cache cases, and 13 ingress cases. Cursor coverage is refreshed above. The unchanged rendering corpus passed a paired comparison at 9.005 seconds before migration and 11.034 seconds afterward under its unchanged 30-second deadline; earlier loaded concurrent runs exceeded that deadline. No rendering or full-suite repeat was added for this compatibility-only delta.

  • Rebase sanity preserved all qualified iMessage production/test file hashes and combined the documentation and worker-test roster with current main, including the landed Discord and ClickClack routes.

Proof uses synthetic state and transport fixtures; live Messages data and real channel sends were outside this validation.

  • A second CI failure exposed an old routing assertion that kept send.test.ts in the ordinary lane. The route contract now checks both send suites in the database-worker lane and an unaffected sibling in the ordinary lane. All 18 selected iMessage routing cases pass, with fresh P0–P2 review clean; production and roster bytes did not change.

The final main integration includes the canonical planner-fixture repair (#149726) and Goal read reuse (#149697). All qualified iMessage production/test bytes are unchanged; the worker roster is the exact union with current main. Sixteen cursor/monitor cases passed again with the current frozen dependency install. Fresh CI is attached to the integrated head.

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: imessage Channel integration: imessage size: L maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete force-pushed the codex/imessage-async-storage-host-compat-20260915 branch from d159492 to f9bb473 Compare September 16, 2026 02:39
@steipete
steipete marked this pull request as ready for review September 16, 2026 02:41
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 2:25 AM ET / 06:25 UTC (Revision 4).

ClawSweeper review

What this changes

Moves iMessage echo tracking and restart replay bookkeeping to asynchronous storage while retaining atomic cursor writes on supported older hosts.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still performs these iMessage operations synchronously, and the merged worker prerequisite does not complete this caller migration. No actionable introduced defect was found.

Priority: P2
Reviewed head: 2a069fac9256b17a666ffa24c1eb2e0eaf59a567

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, coherent refactor with meaningful ordering and compatibility coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor gate does not apply under the supplied maintainer context. Real-SQLite cursor tests and synthetic send/monitor fixtures support the changed storage ordering; they are not live Messages proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor gate does not apply under the supplied maintainer context. Real-SQLite cursor tests and synthetic send/monitor fixtures support the changed storage ordering; they are not live Messages proof.
Evidence reviewed 9 items Current main still needs the migration: The fetched main revision opens a synchronous recovery-cursor store; its persisted echo owner also uses openSyncKeyedStore. The merged prerequisite #146557 supplies worker-backed operations but leaves this caller migration distinct.
Atomic cursor updates: One decision function handles monotonic advancement and expected-row rewinds. Modern hosts retry explicit comparison conflicts; older hosts select the synchronous transactional updater before awaiting. Available comparison failures do not trigger synchronous fallback.
Published host compatibility: The v2026.9.4 API exposes asynchronous keyed operations and synchronous update, but no observe or compareAndApply methods. Its implementation executes the updater inside runWriteTransaction, supporting the retained fallback without changing the declared host floor.
Findings None None.
Security None None.

How this fits together

The iMessage plugin records outgoing messages to suppress reflected echoes and saves the last durably admitted incoming row for restart recovery. These records connect the Messages transport to OpenClaw’s durable inbound queue and agent dispatch.

flowchart TD
  A[Outgoing message] --> B[Persist provisional echo]
  B --> C[Messages transport]
  C --> D[Incoming message]
  D --> E[Durable admission and replay cursor]
  E --> F[Await echo lookup]
  F --> G[Suppress echo or dispatch]
  B --> H[Plugin state worker]
  E --> H
  F --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +67, Tests +254, Docs +16. Total +337 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 6 142 75 +67
Tests 10 452 198 +254
Docs 1 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 610 273 +337

Review metrics

Metric Value Why it matters
Production versus validation growth Net production +67 lines; tests/support +251; test routing +3 Production growth implements atomic cursor comparisons and the documented supported-host fallback; most growth validates preserved behavior.

Technical review

Best possible solution:

Keep one cursor decision across supported hosts, with durable admission and failed-send cleanup settled before reporting completion.

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

Not applicable as a discrete bug reproduction: source confirms synchronous bookkeeping on current main, but Gateway stalls were not measured during this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing worker API with a shared atomic decision and a published-host fallback preserves the established storage contract without adding another owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8ca8c40a35d5.

Labels

Label justifications:

  • P2: This is a bounded iMessage responsiveness improvement with focused storage and ordering changes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor gate does not apply under the supplied maintainer context. Real-SQLite cursor tests and synthetic send/monitor fixtures support the changed storage ordering; they are not live Messages proof.

Evidence

What I checked:

  • Current main still needs the migration: The fetched main revision opens a synchronous recovery-cursor store; its persisted echo owner also uses openSyncKeyedStore. The merged prerequisite feat: offload data-only keyed plugin state operations #146557 supplies worker-backed operations but leaves this caller migration distinct. (extensions/imessage/src/monitor/recovery-cursor.ts:24, 8ca8c40a35d5)
  • Atomic cursor updates: One decision function handles monotonic advancement and expected-row rewinds. Modern hosts retry explicit comparison conflicts; older hosts select the synchronous transactional updater before awaiting. Available comparison failures do not trigger synchronous fallback. (extensions/imessage/src/monitor/recovery-cursor.ts:89, 2a069fac9256)
  • Published host compatibility: The v2026.9.4 API exposes asynchronous keyed operations and synchronous update, but no observe or compareAndApply methods. Its implementation executes the updater inside runWriteTransaction, supporting the retained fallback without changing the declared host floor. (src/plugin-state/plugin-state-store.sqlite.ts:1041, 3a9d69db306c)
  • Admission ordering and shutdown: The iMessage callback awaits cursor advancement. The shared ingress owner serializes admission through that callback and joins admissionTail during shutdown, preserving completion ordering across the new storage waits. (src/channels/message/ingress-monitor.ts:632, 2a069fac9256)
  • Echo persistence and cleanup: Text and attachment sends await provisional persistence before transport and deletion before reporting failure. Inbound matching awaits persisted results; account/conversation scopes, matching rules, and expiration values remain unchanged. (extensions/imessage/src/send.ts:994, 2a069fac9256)
  • Focused validation and its limits: The inspected tests cover concurrent maximum advancement, replacement-database rewinds, intervening writes, comparison failures, and send/rollback ordering. The captured PR body reports passing SQLite and monitor cases and explicitly identifies synthetic transports and version-shaped hosts; it does not claim live Messages or a full historical-host installation. This review executed no tests. (extensions/imessage/src/monitor/recovery-cursor.test.ts:61, 2a069fac9256)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Yuval Dinodia: 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 (3 earlier review cycles)
  • reviewed 2026-09-16T02:47:34.468Z sha f9bb473 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T02:56:38.315Z sha 5857b44 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T05:08:01.884Z sha 8fd56a43276decb61e025797426552dd22872ffd :: needs maintainer review before merge. :: none

Move echo bookkeeping and recovery cursor operations onto the existing async
state API, preserving pending-send rollback and durable-ingress ordering.
Keep atomic cursor updates for the declared 2026.9.4 host contract when
comparison methods are absent; current hosts retain the worker comparison path.

Related: #146557
@steipete
steipete force-pushed the codex/imessage-async-storage-host-compat-20260915 branch from 8fd56a4 to 2a069fa Compare September 16, 2026 06:08
@steipete
steipete merged commit 4152c53 into main Sep 16, 2026
153 checks passed
@steipete
steipete deleted the codex/imessage-async-storage-host-compat-20260915 branch September 16, 2026 06:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…ad (openclaw#149605)

* refactor(imessage): await echo and recovery cursor storage

Move echo bookkeeping and recovery cursor operations onto the existing async
state API, preserving pending-send rollback and durable-ingress ordering.
Keep atomic cursor updates for the declared 2026.9.4 host contract when
comparison methods are absent; current hosts retain the worker comparison path.

Related: openclaw#146557

* test(imessage): await recovery cursor behavior fixtures

* test(imessage): align send routing with database worker owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: imessage Channel integration: imessage docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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