Skip to content

Fix dropped replies on remote-host iMessage channels - #413

Merged
promptclickrun merged 1 commit into
mainfrom
fix/imessage-remote-reply-reliability
Nov 30, 2026
Merged

promptclickrun merged 1 commit into
mainfrom
fix/imessage-remote-reply-reliability

Conversation

@promptclickrun

Copy link
Copy Markdown
Owner

Problem

When an iMessage channel on a Mac is bound to a primary agent on another paired host (e.g. a Linux VPS), inbound messages arrive and run on the remote host, but replies often stop making it back to the iMessage thread—especially on turns that wait for tool approval or take more than a few seconds.

Root Cause

  1. desktop/desktop/channels/remote-bridge.mjs had no retry/backoff on TEAMWORK_OFFLINE ("The computer or profile service is temporarily unreachable.") across peers.hosts(true), channel.submit, or channel.status. A single transient 429, relay blip, or peer fetch timeout immediately aborted runTurn(), leaving the remote agent to finish in its local chat while the Mac never polled again or sent the reply.
  2. Aggressive polling: remote-bridge.mjs polled channel.status every 350ms (ramping to 1000ms), and imsg_node polled job.submit every 1500ms (with 150ms job status polls), triggering profile.botkins.app rate limits (60 req / 60s per IP) and transient TEAMWORK_OFFLINE errors.
  3. FIFO queue drift in desktop/desktop/channels/index.mjs: handleTurnFinished blindly shifted the head of remoteTurnQueue without checking which remote turn(s) belonged to the finished run, allowing manual UI turns or joined/steered multi-message turns to mis-correlate or hang.

Fix

  • desktop/desktop/channels/remote-bridge.mjs: Retry TEAMWORK_OFFLINE with bounded exponential backoff (1.5s -> 15s) across host resolution, idempotent channel.submit (same turn UUID), and channel.status polling until completion, cancellation, or overall timeout, matching remote-teamwork.mjs. Non-offline errors still fail immediately. Ease default polling cadence to 1000ms -> 2500ms.
  • desktop/desktop/channels/index.mjs: Tag remote turns with clientMessageId: payload.id in workspace.submit and correlate handleTurnFinished by clientMessageId (handling joined/steered runs cleanly and preventing manual host chat turns from stealing remote turn rows).
  • desktop/desktop/channels/adapters/imessage.mjs: Add TEAMWORK_OFFLINE retry/backoff to createNodeChannelBridge and ease default imsg_node polling (1500ms -> 4000ms) and job polling (150ms -> 500ms).
  • desktop/test/channels-imessage.test.mjs: Add regression tests covering transient TEAMWORK_OFFLINE recovery across hosts, channel.submit, and channel.status, immediate failure on non-offline errors, and clientMessageId correlation for manual and joined turns.

Verification

  • Ran node --test test/channels-imessage.test.mjs test/channels-core.test.mjs test/channels-telegram.test.mjs test/channels-slack.test.mjs test/channels-discord.test.mjs test/remote-teamwork.test.mjs — 37/37 passed.

When an iMessage channel on a Mac is bound to a primary agent on a remote paired host, any single transient TEAMWORK_OFFLINE error (profile service 429, relay blip, or peer timeout) during hosts(), channel.submit, or channel.status caused remote-bridge.mjs to abandon polling immediately. The remote agent still finished its turn in its local chat, but the reply was never fetched or sent back to iMessage.

Changes:
- desktop/desktop/channels/remote-bridge.mjs: retry TEAMWORK_OFFLINE errors with bounded exponential backoff across host resolution, idempotent channel.submit (reusing the same turn UUID), and channel.status polling, matching remote-teamwork.mjs. Ease default poll cadence from 350ms..1000ms to 1000ms..2500ms to avoid hammering findHost/relay/profile.
- desktop/desktop/channels/index.mjs: pass clientMessageId=payload.id to workspace.submit and correlate finished runs in handleTurnFinished by clientMessageId so joined/steered multi-message turns resolve once without hanging and manual UI messages or cancelled stops cannot steal queued remote turns.
- desktop/desktop/channels/adapters/imessage.mjs: add TEAMWORK_OFFLINE retry/backoff to createNodeChannelBridge and ease default imsg_node poll interval (1500ms -> 4000ms) and job poll (150ms -> 500ms) to stay well within profile.botkins.app IP rate limits.
- desktop/test/channels-imessage.test.mjs: add regression tests for transient TEAMWORK_OFFLINE recovery, fail-fast on non-offline errors, and clientMessageId correlation with manual turns and joined runs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@promptclickrun
promptclickrun merged commit d4bc291 into main Nov 30, 2026
8 checks passed
@promptclickrun
promptclickrun deleted the fix/imessage-remote-reply-reliability branch November 30, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant