Skip to content

fix(remote): keepalive WS Ping so the /acp tunnel doesn't idle-flap - #54

Merged
brettchien merged 2 commits into
mainfrom
feat/acp-keepalive-ping
Aug 14, 2026
Merged

fix(remote): keepalive WS Ping so the /acp tunnel doesn't idle-flap#54
brettchien merged 2 commits into
mainfrom
feat/acp-keepalive-ping

Conversation

@brettchien

Copy link
Copy Markdown
Contributor

Problem

Jellyfish's read of the oab-prod-orca logs: the /acp connection flaps ~every 2 min — 8 reconnects in 45 min, 0 prompts, each ~100–125 s long, and each reconnect opens a fresh session/new channel (not session/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/resume lands — reconnects into a new channel, losing agent context.

Fix

Add a 45 s tokio::time::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). 45 s is well inside the ~100 s idle window; the ping is traffic and keeps the tunnel open between prompts.

  • The read arm already ignores inbound Ping/Pong/Frame (=> continue), so this composes with the loop without touching the inbound path.
  • MissedTickBehavior::Skip avoids a burst of pings after any busy stretch.
  • ~10 lines, no new deps, no signature changes.

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.

brettchien and others added 2 commits August 14, 2026 21:40
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>
@brettchien
brettchien merged commit ae92428 into main Aug 14, 2026
2 checks passed
@brettchien
brettchien deleted the feat/acp-keepalive-ping branch August 14, 2026 15:18
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