fix(remote): keepalive WS Ping so the /acp tunnel doesn't idle-flap - #54
Merged
Conversation
Cloudflare's tunnel idle-closes a WebSocket with no traffic (~100s) and tokio-tungstenite never pings on its own, so an idle /acp connection was flapping ~every 2 min: 8 reconnects in 45 min with 0 prompts, each a fresh session/new channel (diagnosed from the oab-prod-orca logs). Harmless while idle, but once chatting a >~100s quiet stretch would idle-close mid-turn and — until session/resume lands — reconnect into a new channel, losing agent context. Add a 45s tokio interval branch to run_once's select! loop that sends a WS Ping directly on the write half (the send() helper only frames JSON Text). 45s is well inside the ~100s idle window; the ping counts as traffic and keeps the tunnel open. The read arm already ignores inbound Ping/Pong, so this composes with the existing loop without touching the inbound path. Skip missed-tick behaviour avoids a burst of pings after any busy stretch. Diagnosed with Jellyfish (ECS log analysis). session/resume (so a real drop also preserves context) is a separate Part B item. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Emit an `app-log` info line on every keepalive tick so the operator can see in the Activity tab that the tunnel is being kept warm between prompts (not just infer it from the absence of reconnects). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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
Jellyfish's read of the
oab-prod-orcalogs: the/acpconnection flaps ~every 2 min — 8 reconnects in 45 min, 0 prompts, each ~100–125 s long, and each reconnect opens a freshsession/newchannel (notsession/resume).Root cause: Cloudflare's tunnel idle-closes a WebSocket with no traffic (~100 s), and tokio-tungstenite never pings on its own. openab doesn't idle-evict; Studio doesn't self-disconnect → the close comes from the CF edge idle-timing an idle WS.
Impact: harmless while idle (reconnect, no data lost), but once chatting a >~100 s quiet stretch idle-closes mid-turn and — until
session/resumelands — reconnects into a new channel, losing agent context.Fix
Add a 45 s
tokio::time::intervalbranch torun_once'sselect!loop that sends a WS Ping directly on the write half (thesend()helper only frames JSON Text). 45 s is well inside the ~100 s idle window; the ping is traffic and keeps the tunnel open between prompts.Ping/Pong/Frame(=> continue), so this composes with the loop without touching the inbound path.MissedTickBehavior::Skipavoids a burst of pings after any busy stretch.Scope
Keepalive only (止血).
session/resume— so even a genuine drop preserves agent memory — is a separate Part B item, not in this PR.Verification
Local Rust build OOMs this workspace (per project constraint); relies on CI (
build-test+bundle-macos). Change is transport-level and self-contained.Diagnosed with Jellyfish (ECS log analysis); implemented by Orca.