Repository navigation
Fix dropped replies on remote-host iMessage channels - #413
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
desktop/desktop/channels/remote-bridge.mjshad no retry/backoff onTEAMWORK_OFFLINE("The computer or profile service is temporarily unreachable.") acrosspeers.hosts(true),channel.submit, orchannel.status. A single transient 429, relay blip, or peer fetch timeout immediately abortedrunTurn(), leaving the remote agent to finish in its local chat while the Mac never polled again or sent the reply.remote-bridge.mjspolledchannel.statusevery350ms(ramping to1000ms), andimsg_nodepolledjob.submitevery1500ms(with150msjob status polls), triggeringprofile.botkins.apprate limits (60 req / 60sper IP) and transientTEAMWORK_OFFLINEerrors.desktop/desktop/channels/index.mjs:handleTurnFinishedblindly shifted the head ofremoteTurnQueuewithout 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: RetryTEAMWORK_OFFLINEwith bounded exponential backoff (1.5s->15s) across host resolution, idempotentchannel.submit(same turn UUID), andchannel.statuspolling until completion, cancellation, or overall timeout, matchingremote-teamwork.mjs. Non-offline errors still fail immediately. Ease default polling cadence to1000ms->2500ms.desktop/desktop/channels/index.mjs: Tag remote turns withclientMessageId: payload.idinworkspace.submitand correlatehandleTurnFinishedbyclientMessageId(handling joined/steered runs cleanly and preventing manual host chat turns from stealing remote turn rows).desktop/desktop/channels/adapters/imessage.mjs: AddTEAMWORK_OFFLINEretry/backoff tocreateNodeChannelBridgeand ease defaultimsg_nodepolling (1500ms->4000ms) and job polling (150ms->500ms).desktop/test/channels-imessage.test.mjs: Add regression tests covering transientTEAMWORK_OFFLINErecovery acrosshosts,channel.submit, andchannel.status, immediate failure on non-offline errors, andclientMessageIdcorrelation for manual and joined turns.Verification
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.