Repository navigation
fix: avoid false Gateway failures during cold starts - #153063
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 20, 2026, 2:40 AM ET / 06:40 UTC (Revision 10). ClawSweeper reviewWhat this changesGateway diagnostics share a readiness deadline, distinguish ongoing startup from failure, and cancel provider usage requests when their allowance expires. Merge readiness⛔ Blocked before merge - 3 items remain This PR remains useful: current main still has the initial cold-start diagnostic failure. The prior cancellation finding is resolved, the maintainer has accepted the startup-result compatibility tradeoff, and this review found no remaining actionable defect. Priority: P2 Review scores
Verification
How this fits togetherDoctor, health, and status commands inspect the Gateway and report its condition to operators. The shared readiness owner combines service identity, listener ownership, and Gateway responses before allowing further diagnostic requests. flowchart TD
A[Diagnostic command] --> B[Shared deadline]
B --> C[Local or remote target]
C -->|Local| D[Service and startup checks]
C -->|Remote| E[Gateway and provider probes]
D -->|Ready| E
D -->|Still starting| F[Startup progress result]
D -->|Failed| G[Diagnostic failure]
E --> H[Health and status report]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the accepted best-effort startup contract through the shared readiness owner, with bounded probes, visible pending results, and cancellation at existing transport boundaries. Do we have a high-confidence way to reproduce the issue? Yes: current-main Doctor still makes the initial one-shot status request, and the captured installed-package matrix demonstrates failure during delayed startup. This read-only review did not execute a fresh reproduction. Is this the best way to solve the issue? Yes: reusing the existing readiness owner removes competing polling while preserving target selection, ownership checks, and bounded requests; the output compatibility choice is explicitly accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d0192ed506c8. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
0d147b4 to
736eefb
Compare
78dd342 to
59bd2b0
Compare
Use shared progress-aware readiness for Doctor, health, status, and channel status. Preserve authentication, target selection, update identity checks, and remaining request budgets while reporting pending startup separately. Remove Doctor's duplicate restart polling and keep RPC timeout values in integer milliseconds. Regression tests and isolated package proof cover slow startup, genuinely down Gateways, and published-updater compatibility. Repair two stale config imports that blocked the baseline build/typechecks. Reported by @Suidge in #152970.
Pass the remaining readiness budget into provider usage instead of relying on its unrelated default. Keep aggregate and synthetic usage collection under one deadline and preserve visible provider timeout outcomes. Retain exact Commander routing assertions and cover default, explicit, remaining, and exhausted budgets with a simulated clock.
aba308f to
9f7d3b8
Compare
|
Merged via squash.
|
Avoid false Gateway timeout and unreachable reports during slow cold starts. Doctor, health, and status diagnostics now reuse the existing readiness owner and one monotonic deadline, preserve observed startup progress, and leave a Gateway that is still starting alone. Remove Doctor's duplicate restart polling loop. Provider usage consumes the remaining allowance, reports Timeout before dispatch when exhausted, and cancels active usage work on expiry. Preserve explicit timeouts, target/auth selection, and real process/version/build failures. Health and channel-status JSON can return a documented non-failing starting payload; consumers that need a complete snapshot must distinguish it and rerun after startup. No new configuration, flags, dependencies, or stored-data migration. Validation: 592 cases across 37 files on isolated Linux Testbox; installed-package cold-start/down-Gateway matrix and unmodified 2026.9.5 updater-to-candidate Doctor proof; focused command/transport regressions and changed-file gates. The existing independent review is scoped-clean, and ClawSweeper reports no actionable correctness finding. Thanks to @Suidge for the report and startup measurements. Fixes openclaw#152970.
What Problem This Solves
Fixes false Gateway timeout and unreachable reports when Doctor, deep status, or channel status runs during a slow cold start.
Fixes #152970. Thanks to @Suidge for the report and startup measurements.
User Impact
Local startup diagnostics use the shared 60-second readiness allowance, report the observed startup phase, and leave a Gateway that is still starting alone. Existing explicit timeouts remain bounded. Provider usage receives the remaining shared budget; aggregate and synthetic usage collection consume one deadline. Exhaustion reports
Timeoutwithout new auth or usage requests, and expiry cancels active usage requests. A genuinely unreachable Gateway still reports failure. Remote targets and credential diagnostics retain their existing selection and authentication paths.Why This Change Was Made
The initial probes used one-shot request limits, while the longer polling behavior only covered restart paths. A refused connection returns immediately, so changing a numeric timeout alone cannot fix the pre-listener case. The commands now use the existing
waitForGatewayHealthyRestartreadiness owner, consume the remaining budget for their requests, and preserve startup as a separate outcome through text and JSON status. Doctor's duplicate post-restart polling loop is removed.Startup HTTP data does not override process/listener ownership, generation changes, or observed version/build/plugin/channel failures. No new configuration, CLI flags, dependencies, database schema, or service mutations are introduced.
Evidence
Landing review dispositions (2026-09-20)
The latest ClawSweeper review covers
9f7d3b88b140165f74cdd978ebbff493b59319d4and reports no actionable correctness or security finding. Its remaining merge-readiness requests are resolved as follows:{ "status": "starting", "startupPhase": "…" }from health or channel status. This is an intentional best-effort diagnostic outcome, documented in both CLI guides. Consumers requiring a complete snapshot must distinguish this payload and rerun after startup; exit 0 alone does not promise a complete snapshot. Genuine unreachable/process/version/build failures retain their failure reporting. The installed Linux and published-updater matrix below supports the intended operational contract, not arbitrary external consumer compatibility.--timeoutremains bounded. Remote and explicit-URL targets retain target/auth selection while consuming the same monotonic deadline. Operators that need the earlier bound can retain an explicit timeout.Release-note context: avoid false Gateway failure reports during slow cold starts by sharing the readiness deadline across Doctor, health, and status diagnostics, preserving startup progress and cancelling usage work when its remaining allowance expires. Thanks to @Suidge for the report and startup measurements.
Exhausted usage budget: fixed at
03f761445e78885b5f0f510c62415948ab4f932aThe confirmed P2 started provider work before racing the remaining allowance, then returned
Timeoutwithout cancelling that producer.Rank-up dispositions:
03f761445e78885b5f0f510c62415948ab4f932a.src/infra/provider-usage.load.ts:114returns providerTimeoutsnapshots before fetch setup or auth dispatch when the allowance is exhausted. Active work receives an abort signal from the usage timeout owner; ordinary fetches, ClawRouter, configured OpenRouter transports, and the Codex client all consume it. Auth helpers and late auth results check cancellation before further work. Completed sibling snapshots remain available.03f761445e78885b5f0f510c62415948ab4f932a. Eight real-loader regressions failed against the original usage owner; three Codex cancellation cases failed against the original request owner. The tests use simulated clocks and controlled promises, with real loader/timeout code. They cover initial and synthetic follow-up exhaustion, no auth/fetch dispatch, fetch abortion, caller-signal preservation, late auth, and cancellation before/during client acquisition or a request.Final regression names include
returns Timeout without auth or fetch dispatch for an exhausted budget (synthetic: %s),cancels the usage fetch (%s signal, caller abort: %s),does not dispatch usage after auth completes beyond the deadline,rejects a retained %s auth helper after the usage deadline,does not acquire a usage client after its owner has aborted, andaborts usage %s when the outer deadline expires.Validation: 592 passing tests across 37 files on isolated Linux Blacksmith Testbox, Node 24.19.0, including the six Commander usage-routing cases and the status, Doctor, readiness, usage/auth, and transport siblings. The native wrapper ran
corepack pnpm install --frozen-lockfile, verified 86 source/package SHA-256 checksums, then ranCI=1 node scripts/run-vitest.mjswith the 37 focused files. Testbox run 35485042520, leasetbx_01m2ybj7tz3vb277shhj5n8z8b:passed 9 Vitest shards,exitCode: 0,runStatus: succeeded; the owned lease was stopped after success. Locally, the real usage/auth suites passed 81 cases and all five transport suites passed 94 cases. Fresh P1 autoreview is scoped-clean; the SDK surface check passed without baseline changes.node scripts/check-changed.mjspassed every preceding gate, including all four typecheck lanes, core lint, Doctor contracts, and dead-export scans, then stopped at the documented nested-checkout extension-lint artifact (Declaration input escapes checkoutthrough ancestornode_modules). The prescribed directoxlint --tsconfig test/tsconfig/tsconfig.extensions.test.jsonsubstitute passed all ten changed extension files; every remaining planned guard also passed, including schema, database-first, media, runtime-sidecar, import-cycle, webhook, and both pairing checks. CI remains the authority for extension boundary preparation.The local full status run hit the existing 120-second limit in the unchanged snapshot-sharing fixture (129.7 seconds observed; 106.6 seconds in the earlier green run). The identical fixture passed on Linux in 7.817 seconds; the fixture, its 120-second limit, and all assertions remain unchanged. The first Testbox invocation failed before allocating a lease because explicit environment forwarding is unsupported by Blacksmith; removing that invocation-only setting allowed the successful run above.
This repair changes production +116/−70 (net +46), tests +289/−7 (net +282), and docs +14/−1 (net +13) across 18 files. The redundant unsupported-provider wrapper was removed. Necessary growth carries cancellation across the existing transport boundaries; no new configuration, CLI options, environment controls, dependencies, schema changes, or larger timeouts were introduced. Shared credential refresh remains auth-owned and tracked; cancellation stops further usage work after it settles instead of interrupting a shared credential writer. The prior published-updater evidence below is retained as historical proof. This repair stops after publication to the PR; it does not land or wait for CI.
Latest CI repair at
b7e6ec709e1730eb60c1055aa59538e4ce52121b: both reported failures came from whole-modulegateway/calltest fixtures that omittedisImplicitLocalGatewayTarget, newly used by diagnostic readiness. Doctor's missingisGatewayCredentialsRequiredErrorwas a secondary error in its catch path; the channel route fell back before its expected RPC. Both fixtures now spy only oncallGateway, leaving readiness and hosted routing real. No mocked exports were added and no assertions were removed. The hosted test additionally asserts authenticated success and the initial numeric budget; the channel test retains its exact RPC/JSON assertions and both cold-import guards. With a simulated clock, the actual probe allowance is 60,000 ms, derived from the shared restart-health default instead of the stale 10,000/30,000 ms expectations.Pristine
origin/mainatc5ad7506abae9a2e88f1492065204523f31d82a1passed both unchanged files (6/6 cases) in a detached physical checkout with a separate frozen dependency install. The repaired pair also passed 6/6. Unmodified local branch attempts hit collection/late worker-compilation limits; the saved exact-head CI logs provide the missing-export and zero-RPC assertions. No test timeouts or production budgets were increased.Final follow-up validation: 385 passing cases across 24 files, including all six usage-routing cases. After replacing an unsafe test call-array index with the equivalent type-safe first-call matcher, the affected pair passed again (6/6).
node scripts/check-changed.mjspassed for the full PR scope. Fresh independent P1 review of the test-only diff is scoped-clean. This follow-up changes production +0/−0; tests +29/−15 (net +14) acrosssrc/commands/doctor-hosted-gateway.test.tsandsrc/cli/channels-status-cold-imports.test.ts. CI attachment: run 35476688095, confirmed for this exact head by the native watcher. This was an attachment-only precheck; its one-second completion phase timed out and CI completion was not awaited. Failed CI jobs were not rerun; the new head received its own CI. This PR remains open and unmerged.Review finding disposition at
59bd2b0444018564c10379acbaf9d8527b635565: accepted and fixed. Remote and explicit-URL targets skipped local readiness, leaving no shared deadline and granting later probes fresh allowances. Both status entry points now create one monotonic deadline before awaited work; internal scan/runtime/usage contracts require it. Scan results no longer carry or reconstruct the deadline. Local readiness receives the same deadline, including authentication preparation and settling. The common health/channels/Doctor adapter also starts its deadline before target/auth resolution and derives its remainder from the clock, rather than readiness-only elapsed time.The remote
status --usage --deepregression failed before the repair: usage received 60,000 ms after the initial probe consumed 22,000 ms. Text, Commander JSON, and fast JSON now assert 60,000 → 38,000 → 30,000 → 25,000 ms for the initial probe, usage, health, and heartbeat. Four additional failing-before cases proved that target/auth preparation must count even when readiness is deferred or reports a shorter elapsed time. Fractional timing still produces schema-valid integer RPC timeouts. Existing update, Tailscale, and native-service bounds remain separate and unchanged.Rebased onto
a8c423006e100cfc65967c6f2da97f6e6d549630to clear the CI precheck conflict. The real-socket fallback test retains main’s deterministic startup/request coordination and verifies the remaining 100 ms allowance. Installed dependencies were refreshed from the unchanged frozen lockfile after main’sfs-safeupdate.Final validation on that rebased candidate: 379 passing cases across 22 files, including the six usage-routing budget cases, remote command regressions, scan/projection/runtime siblings, readiness/auth/settling owners, and health/channels/Doctor paths.
node scripts/check-changed.mjspassed on the full PR scope; fresh P1 autoreview is scoped-clean. Two unchanged channel-fixture helpers were extracted from the oversized status suite to satisfy its existing line-count ratchet; no assertions, baselines, or suppressions were removed or weakened.The prior deadline repair changed production +207/−170 (net +37), tests/support +500/−188 (net +312), and docs +1/−1. CI attachment: run 35469468829, confirmed for this exact head by the native watcher precheck. Completion is left to the landing workflow; this PR has not been merged.
The following Testbox evidence covers the original implementation at
0d147b44e3b3dbaa9cfc6eb6123c1ed11983d08f, before this rebase and usage repair; it was not rerun for the follow-up.Linux Blacksmith Testbox: run 35453572906, lease
tbx_01m2x6brkd3svwp10epv8q7csp, Node 24.19.0. All runtime state and ports were isolated. Startup delay used an existing plugin service withactivation.onStartup, without a production delay option.gateway timeout after 10000ms; deep status exited 1 with the same timeout; channels reported unreachable. The same Gateway subsequently became ready.Gateway reachable.startup-sidecarsand succeeded after about 25–26 seconds.--no-restart, returnedstatus: ok, and ran candidate Doctor with successful exit/IPC observations. Installed build metadata exactly matched the candidate tarball.The final candidate matrix and published-updater payloads exited successfully with their assertions, and the owned lease was stopped after proof. The linked Actions run tracks the Testbox lease lifecycle.
Candidate tarball SHA-256:
b31a6b2979b1a7a606dec27220629eded7157fcff0a49c0aa9b0cfd945f70702.Simulated-clock regressions were demonstrated failing before their fixes: delayed readiness, pending versus unreachable output, auth deferral, and preservation of process/version/build failures. The actual channel request validator also rejected fractional remaining time before the integer-millisecond fix.
Original validation: 513 command/flow cases, 376 follow-up cases, 317 owner/budget cases, and the final 105 Doctor/health/channel cases passed (overlapping focused runs). The final status suite passed 30 cases. Changed-file guards/typechecks and full changed-source lint/format passed; P1 autoreview is scoped-clean. The full changed-file run was followed by a scoped rerun for the final rounding/private-export fixes and full-scope lint, preserving the same gates.
Current PR numstat: production +834/−371 (net +463), tests/support +1630/−327 (net +1303), docs +30/−5 (net +25). Production growth exceeds the initial net-zero estimate because startup state, ownership checks, and remaining budgets must reach the existing diagnostic/rendering boundaries; removing the duplicate Doctor loop offsets only part of that work.
Probe inventory before this change
10000, unlike fast-route omitted defaultsShort post-readiness diagnostic limits now respect the remaining startup/probe deadline. Doctor retains its established adaptive post-status channel/exporter diagnostics. Generic non-diagnostic RPC defaults, native service-manager checks, standalone multi-target Gateway discovery, Doctor memory inspection, and direct provider capability probes retain their separate contracts.