Repository navigation
fix(imessage): prevent duplicate messages after delayed sends - #110853
Conversation
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 1:22 PM ET / 17:22 UTC. ClawSweeper reviewWhat this changesRaises the iMessage outbound RPC timeout floor to 180 seconds and prevents a configured probe timeout from shortening an ordinary send below that floor. Merge readinessKeep this PR open for the protected maintainer review: current main still applies a short configured probe timeout to outbound sends, while the proposed floor removes the timeout/result ambiguity that can prompt a duplicate retry. The patch is technically sound from the inspected OpenClaw path and the supplied real-process proof, but merging intentionally changes failure latency for installations that configured a value below 180 seconds. Priority: P1 Review scores
Verification
How this fits togetherThe bundled iMessage plugin sends outbound messages through the flowchart LR
A[Agent or channel send] --> B[iMessage send path]
B --> C[Resolve account and timeout]
C --> D[imsg RPC helper]
D --> E[Bridge or AppleScript fallback]
E --> F[Delivery result]
F --> G[Caller retry decision]
C --> H[Pending echo lifetime]
Decision needed
Why: This is a deliberate compatibility and operator-latency tradeoff, not a mechanical correctness choice: the fix removes a duplicate-delivery trigger but changes the failure deadline for existing configured installations. Before merge
Agent review detailsSecurityNone. PR surfaceSource -2, Tests +29. Total +27 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the timeout floor only if maintainers accept delivery certainty over the changed short-timeout behavior for configured installs; retain explicit per-call timeouts as the opt-in route for callers that genuinely need a shorter send deadline. Do we have a high-confidence way to reproduce the issue? Yes. The supplied current-main real-process helper-boundary transcript reports a 158-second successful reply as an Is this the best way to solve the issue? Yes, subject to the stated compatibility decision. Flooring the timeout at the OpenClaw RPC owner boundary is narrower and safer than duplicating AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8b994fc9e170. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
bfc7851 to
fce7399
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Yigtwxx
left a comment
There was a problem hiding this comment.
The 150 → 180 bump reads correct to me, and I checked the new test is load-bearing rather than just asserting the literal: on revert to 150_000 the mock's reject timer fires at 150s before the 158s resolve, and since "hello" carries no approval binding, shouldRecoverApprovalPromptGuid is false and the error rethrows — so it fails on behavior. Two notes on the comment rewrite.
Also verified as non-issues while I was in here, in case it saves you the check: the echo-dedup store is bounded and pruned (IMESSAGE_SENT_ECHOES_MAX_ENTRIES = 256 plus a 12h TTL with isLiveEntry filtering on every read/write), so the indirect 155s → 185s TTL bump via resolvePendingPersistedEchoTtlMs doesn't grow anything unboundedly; and the failure path still calls forgetPersistedIMessageEchoKey, so a timed-out send won't leave a stale pending echo suppressing a real inbound.
| // back to AppleScript and spend up to 8s verifying the persisted row. The outer | ||
| // RPC timeout must outlive both stages; matching imsg's 150s deadline turns a | ||
| // successful fallback into an ambiguous timeout that callers may retry. | ||
| export const DEFAULT_IMESSAGE_SEND_TIMEOUT_MS = 180_000; |
There was a problem hiding this comment.
The rewrite drops two facts the old comment was carrying: the observed ~124s macOS 26 stall upper bound, and the #69193 BlueBubbles cross-reference. The new text only justifies why 180 > 150, so a future reader could reasonably conclude "imsg's deadline is 150s plus an 8s verify, 160s is plenty" and ratchet it back below the stall headroom this constant originally existed for.
It has now been tuned twice; one clause preserving the observed stall bound would keep both reasons visible to whoever tunes it third.
There was a problem hiding this comment.
Still open as of 256d9c3 — the constant's comment carries the two-stage 150s + 8s derivation, but not the ~124s observed stall bound or the #69193 cross-reference that the 150s number originally came from. Not a blocker, and it may well be deliberate now that the deadline is derived from imsg's contract rather than from the stall measurement. Flagging only because the floor added in 256d9c3 gives the value a second reason to exist, and neither reason is written down next to it.
|
Maintainer proof decision: I accept ClawSweeper option 2, the bounded dependency-contract risk, for this PR. The production incident establishes the 150-second collision, direct imsg source establishes the 150-second bridge deadline plus verifier window, and the deterministic 158-second regression proves the OpenClaw-owned boundary. I am deliberately not forcing a live Messages stall because that fault injection can create real duplicate deliveries. The additional 30-second failure latency is an accepted delivery-versus-latency tradeoff. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper approve |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@omarshahine The review's remaining blocker assumes the delayed-fallback path can only be proven with fake timers, because forcing a real bridge stall risks duplicate delivery. That assumption doesn't hold here: I ran it against your head and the pre-PR base. The only stand-in is the Helper holds the
The second row is the PR's actual thesis measured end to end: on base, a fallback that succeeds at 158s is reported to the caller as a timeout at exactly 150.0s — the ambiguous outcome that invites the retry. On head the same successful fallback is returned as a success. The first row is the Scope, to be explicit about what this does and does not show: the helper models imsg's timing contract (a late reply), not macOS's private-bridge internals. It proves the OpenClaw-side deadline arithmetic and RPC plumbing behave as claimed across the boundary at real time — which is the part this diff changes. Whether ~124s/150s is the right characterization of the bridge stall still rests on your incident data. Harness (two files, both dropped after the run)
import { createInterface } from "node:readline";
const delayMs = Number(process.env.IMSG_PROOF_DELAY_MS ?? "158000");
const guid = process.env.IMSG_PROOF_GUID ?? "p:0/imsg-delayed-fallback";
const reply = (payload) => process.stdout.write(`${JSON.stringify(payload)}\n`);
createInterface({ input: process.stdin }).on("line", (line) => {
const trimmed = line.trim();
if (!trimmed) return;
const req = JSON.parse(trimmed);
if (req.method !== "send") {
reply({ jsonrpc: "2.0", id: req.id, result: {} });
return;
}
// Models the private-bridge stall: the send does succeed, just late.
setTimeout(() => reply({ jsonrpc: "2.0", id: req.id, result: { guid } }), delayMs);
});
import { IMessageRpcClient } from "./extensions/imessage/src/client.js";
import { sendMessageIMessage } from "./extensions/imessage/src/send.js";
const delayMs = Number(process.env.IMSG_PROOF_DELAY_MS ?? "158000");
const probeTimeoutMs = process.env.IMSG_PROOF_PROBE_TIMEOUT_MS
? Number(process.env.IMSG_PROOF_PROBE_TIMEOUT_MS)
: undefined;
const cfg = {
channels: {
imessage: {
accounts: { default: probeTimeoutMs === undefined ? {} : { probeTimeoutMs } },
},
},
};
const client = new IMessageRpcClient({ cliPath: process.execPath });
await client.start();
const started = Date.now();
const elapsed = () => `${((Date.now() - started) / 1000).toFixed(1)}s`;
try {
const result = await sendMessageIMessage("chat_id:42", "delayed fallback proof", {
config: cfg as never,
client,
});
console.log(`[harness] RESOLVED after ${elapsed()} messageId=${result.messageId}`);
} catch (error) {
console.log(`[harness] REJECTED after ${elapsed()} error=${String(error)}`);
} finally {
await client.stop();
}Run: Transcript: Note: Happy to turn this into a committable test-support helper if you'd rather have it in the tree than in a comment. |
|
@clawsweeper re-review |
|
@omarshahine The one rank-up item still standing is "rebase onto current Merge is clean, and the drift under the patch is real but unrelated. Merging current Unit suite on the merged tree: Delayed-fallback proof, rerun on the merged head. Same setup as before: real
The right-hand column is the control, and it is the current shipping behavior measured through the same harness, not the pre-PR base I measured on July 18 — so the 13 days of drift changed neither the failure nor the fix. Row one is the PR's thesis end to end: a fallback that succeeds at 158s is still handed to the caller as a timeout at exactly 150.0s, which is the ambiguity that invites the retry. Row two is the |
|
Merged via squash.
|
* origin/main: (26 commits) fix(update): return failure when dirty checkout blocks update (#117452) fix(auto-reply): apply mixed chat directives in one session transaction (#117542) refactor(ui): unify channel status and setup controls (#117499) fix(doctor): preserve surviving lint selections (#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (#112464) refactor(channels): consolidate lightweight plugin discovery (#117541) fix(imessage): prevent duplicate messages after delayed sends (#110853) refactor(memory): unify authoritative dreaming state and presentation (#117538) refactor(agents): consolidate main-session recovery ownership (#117383) fix(proxy-capture): make path-based session cleanup atomic (#98852) refactor(agents): consolidate compaction and context-engine ownership (#117482) fix(gateway): preserve Responses usage details (#117533) perf(gateway): skip empty session recovery stores (#117498) fix(ci): update canonical Kova performance pin (#117508) fix(system-agent): emit the wizard cancel hint once per message (#113731) refactor: dedupe secrets runtime snapshot fixtures (#117502) test(google): cover ready callback close precedence test(openai): dedupe realtime voice fixtures (#117503) fix(google): flush lazy prompts on provider readiness fix(gateway): keep canonical hooks on pristine startup path (#117493) ...
* origin/main: (35 commits) fix(update): return failure when dirty checkout blocks update (openclaw#117452) fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542) refactor(ui): unify channel status and setup controls (openclaw#117499) fix(doctor): preserve surviving lint selections (openclaw#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464) refactor(channels): consolidate lightweight plugin discovery (openclaw#117541) fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853) refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538) refactor(agents): consolidate main-session recovery ownership (openclaw#117383) fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852) refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482) fix(gateway): preserve Responses usage details (openclaw#117533) perf(gateway): skip empty session recovery stores (openclaw#117498) fix(ci): update canonical Kova performance pin (openclaw#117508) fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731) refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502) test(google): cover ready callback close precedence test(openai): dedupe realtime voice fixtures (openclaw#117503) fix(google): flush lazy prompts on provider readiness fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493) ...
* origin/main: (491 commits) feat(gateway): advertise chat attachment limits on hello-ok (#116188) fix(ui): preserve full graphemes in session owner initials (#117350) refactor(tui): consolidate runtime ownership (#117368) fix(update): return failure when dirty checkout blocks update (#117452) fix(auto-reply): apply mixed chat directives in one session transaction (#117542) refactor(ui): unify channel status and setup controls (#117499) fix(doctor): preserve surviving lint selections (#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (#112464) refactor(channels): consolidate lightweight plugin discovery (#117541) fix(imessage): prevent duplicate messages after delayed sends (#110853) refactor(memory): unify authoritative dreaming state and presentation (#117538) refactor(agents): consolidate main-session recovery ownership (#117383) fix(proxy-capture): make path-based session cleanup atomic (#98852) refactor(agents): consolidate compaction and context-engine ownership (#117482) fix(gateway): preserve Responses usage details (#117533) perf(gateway): skip empty session recovery stores (#117498) fix(ci): update canonical Kova performance pin (#117508) fix(system-agent): emit the wizard cancel hint once per message (#113731) refactor: dedupe secrets runtime snapshot fixtures (#117502) test(google): cover ready callback close precedence ...
* origin/main: (325 commits) fix(skills): preserve profile in ClawHub command hints (#117555) fix(cli): explain filtered plugin policy without unsafe recovery (#117556) fix(irc): strip markdown from outbound text (#112961) refactor(plugins): consolidate registry snapshots (#117561) fix(plugins): fail blocked enable commands (#117536) test(secrets): dedupe runtime state fixtures (#117563) feat(gateway): advertise chat attachment limits on hello-ok (#116188) fix(ui): preserve full graphemes in session owner initials (#117350) refactor(tui): consolidate runtime ownership (#117368) fix(update): return failure when dirty checkout blocks update (#117452) fix(auto-reply): apply mixed chat directives in one session transaction (#117542) refactor(ui): unify channel status and setup controls (#117499) fix(doctor): preserve surviving lint selections (#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (#112464) refactor(channels): consolidate lightweight plugin discovery (#117541) fix(imessage): prevent duplicate messages after delayed sends (#110853) refactor(memory): unify authoritative dreaming state and presentation (#117538) refactor(agents): consolidate main-session recovery ownership (#117383) fix(proxy-capture): make path-based session cleanup atomic (#98852) refactor(agents): consolidate compaction and context-engine ownership (#117482) ... # Conflicts: # extensions/xai/realtime-voice-bridge.ts
…aw#110853) * fix(imessage): outlive imsg send fallback * test(imessage): prove delayed fallback resolves once * fix(imessage): preserve the send timeout floor --------- Co-authored-by: Omar Shahine <[email protected]>
* origin/main: (26 commits) fix(update): return failure when dirty checkout blocks update (openclaw#117452) fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542) refactor(ui): unify channel status and setup controls (openclaw#117499) fix(doctor): preserve surviving lint selections (openclaw#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464) refactor(channels): consolidate lightweight plugin discovery (openclaw#117541) fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853) refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538) refactor(agents): consolidate main-session recovery ownership (openclaw#117383) fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852) refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482) fix(gateway): preserve Responses usage details (openclaw#117533) perf(gateway): skip empty session recovery stores (openclaw#117498) fix(ci): update canonical Kova performance pin (openclaw#117508) fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731) refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502) test(google): cover ready callback close precedence test(openai): dedupe realtime voice fixtures (openclaw#117503) fix(google): flush lazy prompts on provider readiness fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493) ...
* origin/main: (35 commits) fix(update): return failure when dirty checkout blocks update (openclaw#117452) fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542) refactor(ui): unify channel status and setup controls (openclaw#117499) fix(doctor): preserve surviving lint selections (openclaw#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464) refactor(channels): consolidate lightweight plugin discovery (openclaw#117541) fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853) refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538) refactor(agents): consolidate main-session recovery ownership (openclaw#117383) fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852) refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482) fix(gateway): preserve Responses usage details (openclaw#117533) perf(gateway): skip empty session recovery stores (openclaw#117498) fix(ci): update canonical Kova performance pin (openclaw#117508) fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731) refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502) test(google): cover ready callback close precedence test(openai): dedupe realtime voice fixtures (openclaw#117503) fix(google): flush lazy prompts on provider readiness fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493) ...
* origin/main: (491 commits) feat(gateway): advertise chat attachment limits on hello-ok (openclaw#116188) fix(ui): preserve full graphemes in session owner initials (openclaw#117350) refactor(tui): consolidate runtime ownership (openclaw#117368) fix(update): return failure when dirty checkout blocks update (openclaw#117452) fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542) refactor(ui): unify channel status and setup controls (openclaw#117499) fix(doctor): preserve surviving lint selections (openclaw#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464) refactor(channels): consolidate lightweight plugin discovery (openclaw#117541) fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853) refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538) refactor(agents): consolidate main-session recovery ownership (openclaw#117383) fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852) refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482) fix(gateway): preserve Responses usage details (openclaw#117533) perf(gateway): skip empty session recovery stores (openclaw#117498) fix(ci): update canonical Kova performance pin (openclaw#117508) fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731) refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502) test(google): cover ready callback close precedence ...
* origin/main: (325 commits) fix(skills): preserve profile in ClawHub command hints (openclaw#117555) fix(cli): explain filtered plugin policy without unsafe recovery (openclaw#117556) fix(irc): strip markdown from outbound text (openclaw#112961) refactor(plugins): consolidate registry snapshots (openclaw#117561) fix(plugins): fail blocked enable commands (openclaw#117536) test(secrets): dedupe runtime state fixtures (openclaw#117563) feat(gateway): advertise chat attachment limits on hello-ok (openclaw#116188) fix(ui): preserve full graphemes in session owner initials (openclaw#117350) refactor(tui): consolidate runtime ownership (openclaw#117368) fix(update): return failure when dirty checkout blocks update (openclaw#117452) fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542) refactor(ui): unify channel status and setup controls (openclaw#117499) fix(doctor): preserve surviving lint selections (openclaw#117543) fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464) refactor(channels): consolidate lightweight plugin discovery (openclaw#117541) fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853) refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538) refactor(agents): consolidate main-session recovery ownership (openclaw#117383) fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852) refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482) ... # Conflicts: # extensions/xai/realtime-voice-bridge.ts
What Problem This Solves
Fixes an issue where an iMessage send could complete through
imsg's AppleScript fallback after a private-bridge stall, while OpenClaw reported a timeout to the calling agent. The agent then retried the apparently failed send, producing duplicate messages.Why This Change Was Made
The dedicated send timeout is increased from 150 seconds to 180 seconds. This lets the outer RPC outlive
imsg's 150-second bridge deadline plus its fallback verification window, while leaving the 10-second probe timeout unchanged.This is intentionally a boundary fix rather than a second delivery-verification implementation in OpenClaw. In the observed incident, the delivered rows stored their text in
attributedBody, so OpenClaw's plainmessage.textrecovery path could not reliably identify them.imsgalready owns that verification.User Impact
Users should receive one message instead of duplicates when the private iMessage bridge stalls but the fallback send succeeds.
Evidence
Redacted live failure timeline before the fix
One cron session issued three sends of the same text to the same chat:
Recipient and message text are omitted. The matching timeout and persistence timestamps show that the first two sends completed at the point the 150-second outer timer rejected them.
Dependency and caller contract
imsgassigns send actions a 150-second bridge deadline, which its bridge client enforces.sendMessageIMessageand passes it to the single RPC request. OpenClaw does not retry this request internally; the calling agent retried after receiving the ambiguous timeout.Deterministic delayed-boundary proof
The focused regression test models
imsgreturning successfully at 158 seconds, after the old outer deadline but within the new one. It asserts that the send resolves with the fallback message GUID and that OpenClaw makes exactly one RPC request.Command:
pnpm exec vitest run extensions/imessage/src/send.test.tsLive patched-build proof
The branch was rebased onto current
main, built, and run through Lobster's exclusive iMessage dev-gateway proof workflow. A temporary copy of the morning context-question cron was triggered once with an explicit private destination:The recipient, message text, and GUID are omitted. The unique output persisted as exactly one outgoing row. This live run completed through the normal fast bridge path; the 158-second fallback boundary is covered deterministically above because forcing a real bridge stall would require restarting Messages with a stale readiness marker and would introduce an avoidable delivery race.
After proof, the temporary dev cron was removed, the dev gateway stopped, and production was restored healthy on port 18789 with exactly one
imsg rpcprocess.Additional validation:
main.oxfmt --checkandgit diff --checkpass.AI-assisted: diagnosis, implementation, test updates, and independent review were performed with Codex under maintainer supervision.