#10636: fix: setTimeout integer overflow causing server crash
gateway
agents
stale
Cluster:
Timeouts and Memory Management Fixes
Fixes #10626
Prevents server crashes caused by setTimeout integer overflow on low-memory instances (AWS a1.large, 4GB RAM, ARM64).
## Problem
`NO_TIMEOUT_MS` was set to 30 days (2,592,000,000 ms), exceeding Node.js 32-bit limit (2,147,483,647 ms). This caused `TimeoutOverflowWarning` with silent fallback to 1ms, leading to rapid retry loops and memory exhaustion.
## Changes
- Add `MAX_SAFE_TIMEOUT_MS` constant and `clampTimeout()` helper in `src/agents/timeout.ts`
- Add defensive clamp in `src/gateway/call.ts`
## Testing
- [x] `pnpm build` passes
- [x] Tested locally
## AI Disclosure
- [x] AI-assisted (Claude/Gemini)
- [x] Lightly tested
- [x] I understand what the code does
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Introduces a `MAX_SAFE_TIMEOUT_MS` constant plus a `clampTimeout()` helper to ensure timeouts stay within Node’s 32-bit `setTimeout` limit.
- Updates agent timeout resolution to use a safe “no timeout” sentinel value and to clamp computed values.
- Adds a defensive timeout clamp in the gateway client call path to prevent `TimeoutOverflowWarning` and runaway retry loops on large timeouts.
<h3>Confidence Score: 4/5</h3>
- This PR is largely safe to merge, with one correctness/perf concern around a per-call dynamic import in a hot path.
- The timeout clamping logic addresses a real Node.js limit and is applied consistently in resolveAgentTimeoutMs and callGateway. The main issue is that `callGateway` now awaits a dynamic import each call, which is unnecessary overhead and could affect high-frequency callers; switching to a static import would remove that risk.
- src/gateway/call.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11416: fix: clamp timeout values to avoid 32-bit overflow warning
by seojoonkim · 2026-02-07
87.5%
#12477: fix(agents): prevent TimeoutOverflowWarning when timeout is disabled
by skylarkoo7 · 2026-02-09
85.4%
#9114: Fix: Reduce NO_TIMEOUT_MS to 24 days to avoid Node.js overflow warning
by vishaltandale00 · 2026-02-04
84.0%
#11752: fix(heartbeat): clamp setTimeout delay to 2^31-1 to prevent Timeout...
by kjaylee · 2026-02-08
79.6%
#6302: fix: Add timeouts to prevent indefinite hangs (issues #4954, #4956,...
by batumilove · 2026-02-01
79.1%
#6466: fix(gateway): add handshake timeout and connection error handling
by jarvis-raven · 2026-02-01
77.8%
#6268: fix: add timeout to compaction retry to prevent session lockout
by batumilove · 2026-02-01
77.4%
#13055: fix: prevent cron RPC stalls with timeout and caching (#13018)
by trevorgordon981 · 2026-02-10
77.3%
#11874: fix: handle fetch rejections in provider usage withTimeout
by Zjianru · 2026-02-08
77.2%
#7810: fix: add fetch timeouts to prevent memory indexing hangs (#4370)
by Kaizen-79 · 2026-02-03
77.2%