Skip to content

fix(cli): gateway health JSON connects before loading presentation code - #115244

Merged
steipete merged 9 commits into
mainfrom
codex/gateway-cli-readiness-latency
Jul 28, 2026
Merged

steipete merged 9 commits into
mainfrom
codex/gateway-cli-readiness-latency

Conversation

@steipete

@steipete steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #115243

What Problem This Solves

openclaw gateway health --json spent seconds in local CLI startup before opening its first socket, even when the live Gateway answered the health RPC quickly. This made machine-readable health probes feel unusably slow on a loaded host.

Why This Change Was Made

The successful JSON path does not need Commander registration or text health presentation modules. It now uses a JSON-only routed command, while text output and unsupported argument shapes continue through Commander.

Profiling also showed that routing alone was not enough: the route still ran the generic startup config/state guard, then the Gateway call performed the config work it actually owns. The routed JSON health command now follows the existing routed gateway-status ownership pattern and lets the call path perform that single config read. This removes duplicated startup initialization without changing the Gateway, its readiness, the RPC handshake, authentication, payloads, or the text command.

User Impact

Machine-readable Gateway health probes open their connection about a second earlier and complete roughly twice as fast in the measured loaded-host scenario. Text output, invalid-argument handling, local-port projection, authentication diagnostics, and structured transport errors retain their existing paths.

Release note: reduce startup latency for gateway health --json by routing machine-readable probes before duplicate CLI config and presentation initialization.

Evidence

  • Live OpenClaw 2026.7.2 Gateway over an SSH tunnel, using installable Package Acceptance tarballs and ten alternating samples per package after two excluded warmups:
    • pre-route package cd9895adf0c06422cadaaaf1f90e1f59c423482e: min 2792.8 ms, p50 3521.4 ms, p90 5103.8 ms
    • exact-head package cf967a9c3c91d6cb31096151df6070f7a676600d: min 1375.0 ms, p50 1624.3 ms, p90 2347.0 ms
    • p50 improved by 1897.1 ms / 53.9%; top-level JSON output shape was identical
  • The route-only package was explicitly rejected before the final fix: under the same alternating method it improved p50 by only 16.7 ms / 0.7%.
  • Node startup/socket instrumentation on the installable packages:
    • pre-route first socket.connect: 1891.5 ms
    • exact-head first socket.connect: 876.3 ms
    • exact-head routed phase: 960.4 ms; total traced CLI time: 1098.4 ms
  • Authentication/error parity against the same reachable Gateway with a synthetic invalid token:
    • both packages exited 1 with gateway_transport_error, WebSocket code 1008, the same top-level JSON keys, and no stdout corruption
  • Exact-head text gateway health completed successfully, confirming Commander fallback remains intact.
  • Live agent-turn check on the same loaded Gateway confirmed the turn path was already healthy once warm and remained out of scope:
    • queue wait: 0 ms
    • pre-model setup: 588 ms
    • Gateway agent duration: 4318 ms
    • exact PERF_OK_4 response with 38,656 prompt-cache read tokens
  • Node/V8 investigation before the fix:
    • 3795.1 ms process profile with 3723.3 ms idle while startup/import I/O completed
    • direct essential RPC path: 271.1 ms module import, 297.0 ms RPC, 6 ms Gateway work
  • Exact-head hosted CI: https://github.com/openclaw/openclaw/actions/runs/30383886438 — success.
  • Exact-head Package Acceptance: https://github.com/openclaw/openclaw/actions/runs/30383932857 — package source SHA cf967a9c3c91d6cb31096151df6070f7a676600d; package integrity and smoke acceptance succeeded.
  • git diff --check: clean.
  • Final Codex branch autoreview: clean, no accepted/actionable findings (0.87 confidence).

AI-assisted: yes, with Codex. The investigation used live Gateway and agent-turn timings, V8 CPU profiling, first-socket instrumentation, exact-package A/B runs, focused regression tests, exact-head hosted CI, and full caller/callee inspection. Two plausible fixes were rejected by measurement before the final config-owner boundary produced a stable improvement.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete steipete self-assigned this Jul 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 12:36 PM ET / 16:36 UTC.

ClawSweeper review

What this changes

This PR adds a route-first path for openclaw gateway health --json so it opens the Gateway RPC before loading health diagnostics and terminal presentation code used only by error or text output.

Merge readiness

⛔ Blocked until real behavior proof is added - 4 items remain

Keep this PR open. The proposed JSON-only route appears to preserve the normal text path while removing presentation imports from the successful machine-readable health path, but the current head still lacks the required after-fix live behavior proof and has an unresolved production-typecheck failure in the supplied check state.

Likely related people

  • steipete — medium confidence; authored the recent gateway-health routing work represented by this PR’s commits.

Priority: P2
Reviewed head: 15ca695815dbba91715d3ee05791fbb06c0f7097

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation and tests provide useful signal, but missing current-head real behavior proof prevents merge readiness.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The body contains detailed pre-fix measurements and mock coverage, but no redacted after-fix live output, timing artifact, runtime log, or terminal transcript for the current head. Add real Gateway CLI proof and redact endpoints, tokens, IP addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body contains detailed pre-fix measurements and mock coverage, but no redacted after-fix live output, timing artifact, runtime log, or terminal transcript for the current head. Add real Gateway CLI proof and redact endpoints, tokens, IP addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Route-first JSON path: The PR adds a gateway-health routed-command id and dispatches JSON health arguments to runGatewayHealthJsonRoute, separating machine-readable health output from the normal presentation-oriented command implementation.
Presentation loading remains conditional: The proposed normal registration path calls the Gateway first, loads diagnostic/config helpers only after an RPC failure, and loads health formatting/styling only for successful non-JSON output.
Regression coverage: The PR adds route and registration tests asserting that a successful JSON health response does not invoke the presentation loaders, alongside parser coverage for accepted JSON health argument shapes.
Findings None None.
Security None None.

How this fits together

The CLI command catalog identifies routable commands before the usual Commander command registration finishes loading. For machine-readable Gateway health probes, this PR sends parsed connection options to a small route module, which calls the Gateway and emits JSON; unsuccessful calls and non-JSON output still use the existing diagnostic and presentation paths.

flowchart LR
  A[CLI arguments] --> B[Command catalog]
  B --> C[JSON health route parser]
  C --> D[Gateway health route]
  D --> E[Gateway RPC]
  E --> F[JSON result]
  E --> G[Diagnostic error handling]
  F --> H[Script or monitor]
  G --> H
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body contains detailed pre-fix measurements and mock coverage, but no redacted after-fix live output, timing artifact, runtime log, or terminal transcript for the current head. Add real Gateway CLI proof and redact endpoints, tokens, IP addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The new early route bypasses the usual command-registration load path for a supported CLI invocation, so a real current-head run is needed to confirm that connection, authentication, error projection, and JSON output remain correct outside mocks.
  • Resolve merge risk (P1) - check-prod-types is currently failing and the branch is behind main; until the failure is resolved and the current head is refreshed, merge safety is not established.
  • Complete next step (P2) - This PR needs contributor-supplied current-head real behavior proof and a resolved production-typecheck result; no discrete mechanical code defect is established for an automated repair lane.
Agent review details

Security

None.

PR surface

Source +171, Tests +227. Total +398 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 177 6 +171
Tests 4 228 1 +227
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 405 7 +398

Review metrics

Metric Value Why it matters
New routed command 1 JSON-only command route added It changes the initialization boundary for a supported CLI command, so a live route proof matters in addition to mocked loader assertions.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115243
Summary: This PR is the candidate implementation for the linked report about eager presentation imports delaying JSON Gateway health probes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the focused route-first implementation, add a redacted after-fix exact-head Gateway health transcript or timing artifact that demonstrates earlier connection and unchanged JSON/error behavior, then resolve the production typecheck failure against current main.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the focused route-first implementation, add a redacted after-fix exact-head Gateway health transcript or timing artifact that demonstrates earlier connection and unchanged JSON/error behavior, then resolve the production typecheck failure against current main.

Do we have a high-confidence way to reproduce the issue?

No high-confidence reproduction was independently run in this review. The linked report gives a concrete loaded-host, SSH-tunneled Gateway scenario and the proposed source path clearly explains how eager imports can delay the first connection.

Is this the best way to solve the issue?

Yes, provisionally. Routing the already-supported JSON health invocation before presentation loading is narrower than changing Gateway readiness or agent runtime behavior, but it still needs real after-fix proof because it introduces a separate CLI initialization path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a88c4283ad48.

Labels

Label justifications:

  • P2: This is a bounded CLI health-probe latency repair affecting scripts and operator monitoring, without evidence of data loss, security impact, or unavailable core runtime.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body contains detailed pre-fix measurements and mock coverage, but no redacted after-fix live output, timing artifact, runtime log, or terminal transcript for the current head. Add real Gateway CLI proof and redact endpoints, tokens, IP addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Route-first JSON path: The PR adds a gateway-health routed-command id and dispatches JSON health arguments to runGatewayHealthJsonRoute, separating machine-readable health output from the normal presentation-oriented command implementation. (src/cli/program/routed-command-definitions.ts:116, 15ca695815db)
  • Presentation loading remains conditional: The proposed normal registration path calls the Gateway first, loads diagnostic/config helpers only after an RPC failure, and loads health formatting/styling only for successful non-JSON output. (src/cli/gateway-cli/register.ts:680, 15ca695815db)
  • Regression coverage: The PR adds route and registration tests asserting that a successful JSON health response does not invoke the presentation loaders, alongside parser coverage for accepted JSON health argument shapes. (src/cli/gateway-cli/health-route.test.ts:9, 15ca695815db)
  • Proof remains absent at the current head: The PR body documents pre-fix live measurements and mock-based regression tests, but says exact-head hosted CI and exact-package live timing "will be added"; the preceding ClawSweeper review also required after-fix real Gateway CLI evidence. (15ca695815db)
  • History and current contributor: The feature path was developed across five PR commits, culminating in the route-before-Commander change; this makes steipete the available recent area contributor, though current-main history could not be independently inspected in this read-only environment. (src/cli/program/routes.test.ts:197, 15ca695815db)
  • Current merge gate state: The supplied PR checks show check-prod-types completed with failure and multiple required checks still in progress; no failure log is supplied, so the cause cannot be treated as an actionable patch finding yet. (15ca695815db)

Likely related people:

  • steipete: Authored the five commits that narrowed the change from general one-shot CLI startup to the current Gateway health JSON route and its tests. (role: recent area contributor; confidence: medium; commits: 500eeab6cbc1, 21e23662d9b9, 15ca695815db; files: src/cli/gateway-cli/register.ts, src/cli/program/routed-command-definitions.ts, src/cli/gateway-cli/health-route.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach a redacted current-head terminal transcript or timing artifact showing the JSON health probe’s after-fix connection/output behavior.
  • Resolve check-prod-types and refresh the branch against current main before relying on the proposed route.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-28T15:15:28.735Z sha 500eeab :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T16:03:29.312Z sha cd9895a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T16:21:34.346Z sha a119037 :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS and removed gateway Gateway runtime size: S labels Jul 28, 2026
@steipete steipete changed the title fix(gateway): CLI calls stall before connecting under load fix(cli): gateway health JSON connects before loading presentation code Jul 28, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit ba8bccb into main Jul 28, 2026
125 checks passed
@steipete
steipete deleted the codex/gateway-cli-readiness-latency branch July 28, 2026 18:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
…de (openclaw#115244)

* fix(gateway): start one-shot CLI clients immediately

Closes openclaw#115243

* fix(cli): defer gateway health presentation imports

* style(cli): format gateway health loader

* test(cli): match gateway health call shape

* perf(cli): route gateway health JSON before Commander

* fix(cli): preserve routed health output contract

* test(cli): match routed JSON indentation

* fix(cli): guard routed health config resolution

* perf(cli): avoid duplicate health config bootstrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway health JSON loads presentation code before connecting

1 participant