Repository navigation
fix(imessage): prevent missed messages after gateway crashes - #110409
Conversation
There was a problem hiding this comment.
💡 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".
| const adoptAll = async () => { | ||
| for (const lifecycle of lifecycles) { | ||
| await lifecycle.onAdopted(); | ||
| } |
There was a problem hiding this comment.
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 👍 / 👎.
… 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.
a207387 to
7c5fe5e
Compare
|
Land-ready at exact head 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:
Known proof gap: no destructive live gateway-crash injection against a personal Messages database; durable crash boundaries have focused integration coverage. No unresolved finding. |
|
Merged via squash.
|
There was a problem hiding this comment.
💡 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" }; |
There was a problem hiding this comment.
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 👍 / 👎.
* 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
…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
Refs #109657
What Problem This Solves
Fixes an issue where iMessage users could permanently miss inbound messages when the gateway crashed after
imsg watchadvanced 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
imsgexposes every message row's own ROWID and GUID inSources/imsg/OutputModels.swift, whileSources/IMsgCore/MessageWatcher.swiftyields 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
origin/main(4e0cc187a21c).node scripts/run-vitest.mjs extensions/imessage— 46 test files and 798 tests passed after the lint-fix rebase.oxlintandoxfmt --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.imsgrow contract and catchup cursor failure gate.