fix: reduce cloud sync heartbeat interval from 30s to 60s#409
Conversation
| heartbeatInterval: config.heartbeatInterval | ||
| || (process.env.AGENT_RELAY_HEARTBEAT_INTERVAL ? parseInt(process.env.AGENT_RELAY_HEARTBEAT_INTERVAL, 10) : 0) | ||
| || 60000, // 60 seconds (reduced from 30s to lower cloud API load) |
There was a problem hiding this comment.
🟡 Negative or very small env var value bypasses || fallback, causing rapid-fire heartbeats
If AGENT_RELAY_HEARTBEAT_INTERVAL is set to a negative value (e.g., "-5000"), parseInt returns -5000, which is truthy and passes through the || chain without falling back to the 60000 default. When passed to setInterval at cloud-sync.ts:202-204, Node.js clamps values ≤ 0 to 1ms, causing heartbeats to fire ~1000 times/second — the exact opposite of this PR's goal of reducing API load.
Root Cause
The || operator on line 122-124 only guards against falsy values (0, NaN, undefined). Negative numbers are truthy in JavaScript:
heartbeatInterval: config.heartbeatInterval
|| (process.env.AGENT_RELAY_HEARTBEAT_INTERVAL ? parseInt(process.env.AGENT_RELAY_HEARTBEAT_INTERVAL, 10) : 0)
|| 60000,If the env var is "-1000", parseInt("-1000", 10) returns -1000 (truthy), so the final || 60000 is never reached. Similarly, a very small positive value like "10" (10ms) would also pass through, causing excessive API calls.
Impact: An operator misconfiguring the env var with a negative or very small value would cause the daemon to flood the cloud API with requests, potentially causing a denial of service on the cloud server — which is the very problem this PR aims to mitigate.
| heartbeatInterval: config.heartbeatInterval | |
| || (process.env.AGENT_RELAY_HEARTBEAT_INTERVAL ? parseInt(process.env.AGENT_RELAY_HEARTBEAT_INTERVAL, 10) : 0) | |
| || 60000, // 60 seconds (reduced from 30s to lower cloud API load) | |
| heartbeatInterval: config.heartbeatInterval | |
| || Math.max(10000, (process.env.AGENT_RELAY_HEARTBEAT_INTERVAL ? parseInt(process.env.AGENT_RELAY_HEARTBEAT_INTERVAL, 10) : 0)) | |
| || 60000, // 60 seconds (reduced from 30s to lower cloud API load) |
Was this helpful? React with 👍 or 👎 to provide feedback.
Allows overriding the default 30s heartbeat interval via env var without code changes. This enables per-deployment tuning from the workspace Dockerfile or provisioner config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1ee3c70 to
c7754d9
Compare
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
AGENT_RELAY_HEARTBEAT_INTERVALenv var for per-deployment tuning without code changesImpact
Test plan
AGENT_RELAY_HEARTBEAT_INTERVAL=30000overrides back to 30s🤖 Generated with Claude Code