← Back to PRs

#6466: fix(gateway): add handshake timeout and connection error handling

by jarvis-raven open 2026-02-01 17:50 View on GitHub →
gateway
Adds timeout handling for agent CLI connections to prevent hanging when the gateway is unreachable or slow to respond. ## Changes - Added handshake timeout for connection establishment - Improved error handling for connection failures - Clearer error messages when connection times out ## Testing Tested locally with various network conditions. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds faster failure behavior for gateway CLI connections by: - Setting a WebSocket `handshakeTimeout` in `GatewayClient` to prevent hanging during connection establishment. - Plumbing a new `onConnectError` path through `callGateway` so connection failures surface as clearer CLI errors with connection details. These changes fit into the existing gateway client lifecycle (`GatewayClient.start()` wiring and `callGateway`’s promise-based connect/request flow) and should improve operator UX when the gateway is unreachable or slow. <h3>Confidence Score: 4/5</h3> - This PR is reasonably safe to merge and is a focused improvement to connection failure behavior. - Changes are small and localized to gateway connection setup and error plumbing; the new `handshakeTimeout` is a standard ws option and the new callback is guarded to avoid double-settle. The main concern is message formatting consistency (literal `\\n`), not runtime correctness. - src/gateway/call.ts (error message formatting), src/gateway/client.ts (ensure handshakeTimeout aligns with desired CLI timeout behavior) <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs