Repository navigation
fix(gateway): distinguish reachable-but-errored from unreachable in probe diagnostics - #93948
Conversation
…robe diagnostics When the WebSocket handshake is accepted but closed before hello-ok (protocol mismatch, auth failure, timeout), the probe left connectLatencyMs null, making downstream code treat it as unreachable. This caused doctor to show "Gateway not running" while the port-scan panel correctly identified the gateway PID — a contradiction reported on both Windows and Linux. - probe.ts: set connectLatencyMs when onClose fires without connectError (WebSocket was accepted), so downstream distinguishes reachable-but-errored from truly unreachable (ECONNREFUSED) - doctor-gateway-health.ts: use isGatewayTransportError to show close reason instead of generic "Gateway not running" for accepted-then-closed connections - doctor-gateway-daemon-flow.ts: same pattern - doctor-gateway-health.test.ts: mock isGatewayTransportError Fixes openclaw#79099 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
d553f04 to
c7af08b
Compare
|
Land-ready verification:
Known gap: broad local |
|
Codex review: needs maintainer review before merge. Reviewed June 19, 2026, 6:54 AM ET / 10:54 UTC. Summary PR surface: Source +35, Tests +121. Total +156 across 10 files. Reproducibility: yes. at source level. Current main settles a pre-hello close before setting connectLatencyMs, so downstream probe and doctor diagnostics can classify an accepted-but-errored gateway as unreachable or not running. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this focused PR after normal required checks, keep the linked issue open until merge, then close it as fixed by this PR. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main settles a pre-hello close before setting connectLatencyMs, so downstream probe and doctor diagnostics can classify an accepted-but-errored gateway as unreachable or not running. Is this the best way to solve the issue? Yes. Carrying validated transport state from GatewayClient into probe and doctor diagnostics is the narrow owner-boundary fix; timeout bumps or port-scan heuristics would not distinguish auth, protocol, and TLS validation cases cleanly. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 92d1f04de340. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +35, Tests +121. Total +156 across 10 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…nclaw#93948) Distinguish validated gateway reachability from pre-open and TLS-validation failures, and sanitize close diagnostics before terminal output. Fixes openclaw#79099. Co-authored-by: xialonglee <[email protected]>
Root Cause
Two independent gaps produced the same symptom —
doctorreporting "Gateway not running" while the gateway listener was actually alive:probe.ts—connectLatencyMsnever set for pre-hello close:probeGatewayonly setsconnectLatencyMsafteronHelloOk. When the WebSocket connects but the handshake fails (protocol mismatch, auth rejection, version skew),onClosefires beforeonHelloOk, leavingconnectLatencyMs === null. Downstream,isProbeReachablechecksconnectLatencyMs != nulland returnsfalse, making the probe indistinguishable from a TCP-level unreachable.doctor-gateway-health.ts/doctor-gateway-daemon-flow.ts—"gateway closed"check always renders "Gateway not running": Both health check functions catch errors fromcallGatewayand testmessage.includes("gateway closed"). When true, they unconditionally print "Gateway not running", even when the WebSocket was connected and the close was a server-side rejection (protocol mismatch, etc.). The port-scan panel correctly shows the gateway PID, creating a contradiction.Summary
doctoroutput even when the gateway listener was alive.settleProbe({ ok: false, ... }), check whether the transport ever connected (connectError == null). If the WebSocket was accepted but closed before the hello completed, setconnectLatencyMsso downstream code can tell the transport was reachable (tri-state: unreachable / reachable-but-errored / healthy).isGatewayTransportError(err) && err.kind === "closed"guard to distinguish a connected-then-closed WebSocket from a never-connected transport. When connected, render the specific close code and reason instead of "Gateway not running."isGatewayTransportErrorwithkind === "closed"so the daemon flow shows the close reason when the listener is alive.isGatewayTransportError: vi.fn(() => false)mock to keep existing tests passing.Fixes #79099
Verification
pnpm test src/gateway/probe.test.ts src/commands/doctor-gateway-health.test.ts src/commands/doctor-gateway-daemon-flow.test.ts— 145 tests passed across 4 test files and 2 Vitest shardspnpm check:changed— passingReal behavior proof
Behavior addressed:
doctorno longer falsely reports "Gateway not running" when the gateway listener is alive but the probe/health RPC fails due to handshake error (protocol mismatch, auth rejection, version skew). Probe diagnostics now properly distinguish three states: unreachable / reachable-but-errored / healthy.Real environment tested: Linux x86_64, Node 24, branch
fix/issue-79099-gateway-probe-tristate, commitd553f04279, OpenClaw 2026.6.2 built from sourceExact steps or command run after this patch:
Evidence after fix:
Observed result after fix: Three distinct gateway states now clearly distinguishable:
Connect: ok (60ms) · Read probe: okcallGateway)GatewayTransportError: gateway closed (1008): unauthorized...Connect: failed - connect ECONNREFUSEDBefore the fix, state 2 would match
message.includes("gateway closed")→ "Gateway not running". After the fix,isGatewayTransportError(err) && err.kind === "closed"preserves the close code (1008) and reason, enabling accurate tri-state diagnostics indoctor.The probe's
connectLatencyMsis set for pre-hello close when the transport was previously connected, enabling the tri-state downstream.What was not tested: Protocol version mismatch (requires older gateway binary). Token mismatch and auth rejection were verified via live gateway. The unit-test suite (145 tests) covers the
connectLatencyMsset path and doctor rendering logic with proper mocking.