Skip to content

fix(imessage): prevent missed messages after gateway crashes - #110409

Merged
steipete merged 5 commits into
mainfrom
claude/ingress-imessage
Jul 18, 2026
Merged

steipete merged 5 commits into
mainfrom
claude/ingress-imessage

Conversation

@steipete

@steipete steipete commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Refs #109657

What Problem This Solves

Fixes an issue where iMessage users could permanently miss inbound messages when the gateway crashed after imsg watch advanced its chat.db ROWID cursor but before OpenClaw finished dispatching the row. On restart, the advanced cursor caused that never-dispatched message to be skipped.

Why This Change Was Made

The iMessage monitor now journals each raw row before advancing the recovery cursor, mirroring Telegram's offset-after-spool contract. The durable queue uses the message GUID as its event ID and a per-chat lane, then carries claims through deferred debounce, merged fan-out adoption, gated settlement, restart recovery, and the legacy catchup path.

Completed queue tombstones replace the retired persistent GUID guard with the same 4-hour / 10,000-entry parity. There is intentionally no migration for the retired guard namespace: it was a transient dedupe cache, its existing entries expire on their own, and the layering policy requires cache state to be dropped/rebuilt rather than preserved through a compatibility path. The existing age fence and the 2-hour / 500-row recovery caps are unchanged.

Legacy catchup rows carry provenance through the durable journal so their configured catchup age window remains authoritative instead of the tighter live Push-flush fence. The documented live-fence/catchup overlap is accepted: tombstoning live-fence suppressions keeps restart replay deterministic, while the overlap requires the narrow combination of downtime Push-flush backlog and legacy catchup being enabled.

Twin verdict: tapbacks remain distinct events. Upstream imsg exposes every message row's own ROWID and GUID in Sources/imsg/OutputModels.swift, while Sources/IMsgCore/MessageWatcher.swift yields and advances by each row's ROWID, including reaction rows. GUID event IDs therefore do not collapse tapbacks into their parent messages.

AI-assisted implementation; maintainer-reviewed behavior and contracts.

User Impact

iMessage ingress now survives a crash between receipt and dispatch without silently losing the message. Replayed live and catchup rows share one durable admission path, duplicates are suppressed by durable GUID tombstones, and existing backlog age limits remain in force.

Evidence

  • Rebased onto current origin/main (4e0cc187a21c).
  • node scripts/run-vitest.mjs extensions/imessage — 46 test files and 798 tests passed after the lint-fix rebase.
  • Targeted oxlint and oxfmt --check — passed on all four CI-fallout files.
  • node scripts/check-deadcode-exports.mjs — production, full-tree, and script scans passed with 0 entries.
  • node scripts/check-deadcode-unused-files.mjs — production and full-tree scans passed with 0 entries.
  • git diff --check origin/main...HEAD — passed.
  • Fresh uncommitted autoreview of the lint-fix — clean, with no accepted/actionable findings; full branch review also verified the upstream imsg row contract and catchup cursor failure gate.

@openclaw-barnacle openclaw-barnacle Bot added channel: imessage Channel integration: imessage size: XL maintainer Maintainer-authored PR labels Jul 18, 2026
@steipete steipete self-assigned this Jul 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a207387418

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +173 to +176
const adoptAll = async () => {
for (const lifecycle of lifecycles) {
await lifecycle.onAdopted();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ensure every merged ingress claim is adopted

When a debounced/URL-merged flush contains multiple durable claims and one onAdopted() rejects, for example because the queue tombstone write has a transient SQLite failure or the claim was lost, this loop stops before invoking the later lifecycles. Since the merged lifecycle has already marked the handoff as taken, the later abandon() path is a no-op, leaving the remaining constituent claims deferred until timeout/restart even though their merged turn was already dispatched. Please attempt all lifecycles and then report any collected error so every row gets a terminal callback.

Useful? React with 👍 / 👎.

steipete added 5 commits July 18, 2026 05:45
… append

The chat.db watcher advanced its ROWID cursor after yielding rows to an
in-memory pipeline; a crash between read and dispatch skipped those messages
forever. Raw rows now journal durably (event_id = message GUID, lane per
chat) at the monitor chokepoint, and the cursor advances only after the
durable append — mirroring Telegram's offset-after-spool contract. Dispatch
runs through the core drain with deferred claims, merged fan-out adoption,
and gated settlement; legacy catchup enters the same raw path. The
transitional GUID replay guard is deleted per the layering contract with
4h/10k tombstone parity; the permanent age fence and recovery caps are
untouched. Twin verdict: tapbacks are distinct rows with their own
ROWID/GUID; fresh-GUID stale backlog remains age-fence territory (upstream
imsg source cited in PR).

Autoreview blocked by codex sandbox network in the build stage; full manual
review performed. Part of the #109657 fleet adoption program (wave 2).
…ge fence

Landing review caught real message loss: legacy catchup accepts rows up to
its configured maxAge (120min default), but the unified durable path ran them
through the 15-minute live Push-flush fence — suppressing AND tombstoning
any catchup row older than 15 minutes, permanently losing history the
operator explicitly asked to replay. Catchup rows now carry provenance
through the journal payload and skip the live fence; the catchup query's own
maxAge window is their age gate. Regression test proves provenance survives
the durable round trip.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 18, 2026
@steipete
steipete force-pushed the claude/ingress-imessage branch from a207387 to 7c5fe5e Compare July 18, 2026 04:46
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at exact head 7c5fe5ed0630c247e17f1aff9ee1491b2631106c.

Work complete: durable GUID admission now precedes ROWID cursor advancement across live watch and catchup; per-chat lanes, deferred/fan-out lifecycle ownership, deterministic fence tombstones, and transient-cache no-migration policy are documented and reviewed.

Proof:

  • node scripts/run-vitest.mjs extensions/imessage — 46 files / 798 tests passed after the final rebase.
  • Targeted oxlint and oxfmt --check passed on the four lint-fallout files.
  • Both hard-zero dead-code gates passed; git diff --check passed.
  • Fresh uncommitted autoreview: no accepted/actionable findings.
  • Hosted CI run 29631109241: openclaw/ci-gate success on the exact head.

Known proof gap: no destructive live gateway-crash injection against a personal Messages database; durable crash boundaries have focused integration coverage. No unresolved finding.

@steipete
steipete merged commit b2ea69c into main Jul 18, 2026
98 checks passed
@steipete
steipete deleted the claude/ingress-imessage branch July 18, 2026 04:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c5fe5ed06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
const repairedMessage = await repairMessageConversationAnchor(message);
if (!repairedMessage) {
return { kind: "completed" };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep anchor repair failures retryable

When an anchorless iMessage row (chat_id 0 / empty chat identifiers, the #104136 path) cannot be repaired because chats.list or messages.history is temporarily unavailable or the exact history row is not visible yet, repairMessageConversationAnchor() returns null and this branch completes the durable claim. Since onDurableEnqueue has already advanced the recovery cursor for that ROWID, the completed GUID tombstone prevents a restart replay, turning a transient repair miss into a permanently dropped inbound message; before this change the row was not claimed/advanced until after repair, so restart recovery could retry it.

Useful? React with 👍 / 👎.

steipete added a commit that referenced this pull request Jul 18, 2026
* fix(imessage): adopt durable ingress drain with cursor advanced after append

The chat.db watcher advanced its ROWID cursor after yielding rows to an
in-memory pipeline; a crash between read and dispatch skipped those messages
forever. Raw rows now journal durably (event_id = message GUID, lane per
chat) at the monitor chokepoint, and the cursor advances only after the
durable append — mirroring Telegram's offset-after-spool contract. Dispatch
runs through the core drain with deferred claims, merged fan-out adoption,
and gated settlement; legacy catchup enters the same raw path. The
transitional GUID replay guard is deleted per the layering contract with
4h/10k tombstone parity; the permanent age fence and recovery caps are
untouched. Twin verdict: tapbacks are distinct rows with their own
ROWID/GUID; fresh-GUID stale backlog remains age-fence territory (upstream
imsg source cited in PR).

Autoreview blocked by codex sandbox network in the build stage; full manual
review performed. Part of the #109657 fleet adoption program (wave 2).

* fix(imessage): exempt operator-requested catchup rows from the live age fence

Landing review caught real message loss: legacy catchup accepts rows up to
its configured maxAge (120min default), but the unified durable path ran them
through the 15-minute live Push-flush fence — suppressing AND tombstoning
any catchup row older than 15 minutes, permanently losing history the
operator explicitly asked to replay. Catchup rows now carry provenance
through the journal payload and skip the live fence; the catchup query's own
maxAge window is their age gate. Regression test proves provenance survives
the durable round trip.

* test(imessage): resolve ingress rebase mocks

* docs(imessage): document the fence-suppression vs catchup overlap tradeoff

* fix(imessage): satisfy durable ingress lint gates
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…w#110409)

* fix(imessage): adopt durable ingress drain with cursor advanced after append

The chat.db watcher advanced its ROWID cursor after yielding rows to an
in-memory pipeline; a crash between read and dispatch skipped those messages
forever. Raw rows now journal durably (event_id = message GUID, lane per
chat) at the monitor chokepoint, and the cursor advances only after the
durable append — mirroring Telegram's offset-after-spool contract. Dispatch
runs through the core drain with deferred claims, merged fan-out adoption,
and gated settlement; legacy catchup enters the same raw path. The
transitional GUID replay guard is deleted per the layering contract with
4h/10k tombstone parity; the permanent age fence and recovery caps are
untouched. Twin verdict: tapbacks are distinct rows with their own
ROWID/GUID; fresh-GUID stale backlog remains age-fence territory (upstream
imsg source cited in PR).

Autoreview blocked by codex sandbox network in the build stage; full manual
review performed. Part of the openclaw#109657 fleet adoption program (wave 2).

* fix(imessage): exempt operator-requested catchup rows from the live age fence

Landing review caught real message loss: legacy catchup accepts rows up to
its configured maxAge (120min default), but the unified durable path ran them
through the 15-minute live Push-flush fence — suppressing AND tombstoning
any catchup row older than 15 minutes, permanently losing history the
operator explicitly asked to replay. Catchup rows now carry provenance
through the journal payload and skip the live fence; the catchup query's own
maxAge window is their age gate. Regression test proves provenance survives
the durable round trip.

* test(imessage): resolve ingress rebase mocks

* docs(imessage): document the fence-suppression vs catchup overlap tradeoff

* fix(imessage): satisfy durable ingress lint gates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: imessage Channel integration: imessage maintainer Maintainer-authored PR rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant