fix(agent): drop a silent controller connection and reconnect #1290
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 342 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1290"
general
weight: 0.35
nicotsx
Fixes #1285.
Problem
The controller pings every 15 seconds and drops an agent after 45 seconds without a pong (
heartbeat_timeout). The agent has no check in the other direction: it only answers pings and its socket has no keepalive. When the network path breaks silently (VPN restart, mesh path change), the controller drops the session while the agent keeps a half-open connection that the operating system still reports as established. The agent never reconnects and every backup on it fails withFailed to send backup command to agentuntil the container is restarted.We hit this on three agents in production over three days. In each case
ssinside the agent container showed the connection to the controller asESTAB, while the reverse proxy in front of the controller had no connection from that host.Fix
onclosepath then reconnects.terminate(). A close handshake never completes on a dead connection: with Bun 1.4.4,ws.close()against a silent peer fired nocloseevent within 8 seconds, whileterminate()fired it immediately with code 1006.close()stays as a fallback whenterminateis not available.No protocol change: the agent reacts to the existing
heartbeat.pingmessages, so it works with any controller of the same protocol version.Tests
apps/agent/src/__tests__/controller-session.test.ts: a silent controller connection is terminated after the timeout, and a connection that keeps receiving pings is kept.bun fmt --check,bun checkand the agent test suite pass (219 passed, 1 skipped).<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Silent controller connections are now terminated after 90 seconds without messages, helping prevent inactive sessions from remaining connected.
Active connections that continue sending heartbeats remain connected.
When timer processing is delayed, a brief grace period helps avoid ending a connection if a heartbeat arrives shortly afterward.
* Failed message delivery now terminates the connection more reliably, allowing the session to close cleanly.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->