Skip to content

fix(gateway): refresh health after runtime inspection failure - #127174

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-182-health-cache
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-182-health-cache

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #127167

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where operators or monitoring scripts running openclaw health --json or openclaw gateway health --json would receive a stale healthy snapshot and exit code zero when live channel-runtime inspection failed and health collection could not refresh that snapshot.

Why This Change Was Made

The documented cache contract permits reuse only when a fresh snapshot is verified unchanged against live channel runtime. Treat an inspection failure as an unverified cache and reuse the existing foreground passive refresh: successful collection returns fresh data, while failed collection returns the existing typed UNAVAILABLE Gateway request error. This changes one production token without adding a branch, protocol field, fallback, retry, configuration, or dependency.

User Impact

Both machine-readable health commands now report a structured gateway_request_error and exit nonzero if the Gateway cannot produce a verified health snapshot. If collection succeeds despite the unavailable runtime snapshot, callers receive the fresh health snapshot. Verified cache hits, background refreshes, explicit probes, account/lifecycle invalidation, and successful health collection remain unchanged.

Evidence

  • Before the fix, both new owner-boundary cases failed in both Gateway test projects: the response was respond(true, { ok: true, ... }, undefined, { cached: true }) instead of the existing UNAVAILABLE error or newly collected snapshot.
  • After the fix, the complete cache-freshness describe block, runtime-snapshot health-state case, and both CLI error-route cases passed across three Vitest shards (35 passing assertions/tests).
  • The complete Gateway health-state suite and both CLI health suites passed across three Vitest shards (83 passing tests).
  • Existing coverage preserves verified cached success, background-refresh throttling, stale-cache refresh, explicit admin probes, runtime lifecycle changes, added/removed accounts, and successful collector behavior after runtime inspection failure.
  • Focused formatter check and the repository-owned changed-file gate cover the three changed files.
  • Fresh independent structured code review reported no actionable P0/P1 findings.
  • Isolated Blacksmith Testbox: tbx_01m0j12s2rh7xc41hc3h6xkrx1; prepared run: https://github.com/openclaw/openclaw/actions/runs/32477121136.
  • A deliberately broader legacy Gateway suite exposed two unrelated existing exec-approval failures; the affected cache suite and all relevant state/CLI suites pass when scoped to their documented owners.
  • The cached-health QA scenario and live Gateway proof were intentionally not run because this repair explicitly prohibits starting or touching any live Gateway/service/operator state.
  • Production LOC: +1/-1 (net 0); regression tests: +79/-0.
  • AI-assisted; no transcript included.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 21, 2026
@steipete
steipete marked this pull request as ready for review August 21, 2026 11:49
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 7:55 AM ET / 11:55 UTC.

ClawSweeper review

What this changes

The PR treats failed live runtime inspection as an unverified Gateway health cache, then adds Gateway and JSON CLI regression coverage for fresh success or structured failure.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still marks a runtime-inspection failure as an unchanged cache and can return stale success, while this branch forces the existing foreground refresh/error path. No actionable patch defect found; exact-head CI and rebase confirmation remain before merge. Likely related people: steipete (high) and Vincent Koc (medium).

Priority: P1
Reviewed head: 2935549c5d87b9546a66c310c90aa7743eb673dd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow owner-boundary repair with focused regression coverage and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused after-fix Gateway and CLI test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused after-fix Gateway and CLI test evidence.
Evidence reviewed 6 items Current-main defect: Current main catches a runtime-snapshot exception and sets the cache-difference flag to false, allowing the subsequent fresh-cache branch to return cached success.
Owner-boundary repair: The branch changes only that catch outcome to true, so it falls through to the existing refresh path and its existing UNAVAILABLE response on collection failure.
Documented cache contract: The CLI documentation permits cached health only when it is fresh and unchanged from live channel runtime state.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw health --help

Result: PASS (completed)

pnpm openclaw health --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127174-oZ80gW/target$ pnpm openclaw health --help
$ node scripts/run-node.mjs health --help
pnpm openclaw health --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 108.17 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 14.5s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4376ms (slowest: built plugin control-plane loads 3608ms)
│
◇

OpenClaw 2026.8.1 (2935549) — All your chats, one OpenClaw.

Usage: openclaw health [options]

Fetch health from the running gateway

Options:
  --debug         Alias for --verbose (default: false)
  -h, --help      Display help for command
  --json          Output JSON instead of text (default: false)
  --timeout ‹ms›  Connection timeout in milliseconds (default: "10000")
  --verbose       Verbose logging (default: false)

Docs: docs.openclaw.ai/cli/
… output truncated …

Assertions:

  • PASS expect_output: --json

How this fits together

Gateway health compares its cached status with the live channel runtime before replying to health RPC callers. The routed CLI commands render that RPC result as JSON and use its success or failure for their process exit status.

flowchart LR
  A[Health CLI command] --> B[Gateway health RPC]
  B --> C[Cached health snapshot]
  C --> D{Live runtime inspection}
  D -->|Verified unchanged| E[Return cached health]
  D -->|Changed or unavailable| F[Collect fresh health]
  F --> G[Fresh snapshot or typed unavailable error]
  G --> H[JSON output and exit status]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub currently reports the branch as behind main; rebase or refresh the merge result and require green checks for the exact resulting head before merge.
  • Complete next step (P2) - Let the maintainer-owned PR rebase or refresh as needed and complete exact-head CI; no separate automated repair is indicated.
Agent review details

Security

None.

PR surface

Source 0, Tests +79. Total +79 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 2 79 0 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 80 1 +79

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +1/-1 (net 0); tests +79/-0 The bug fix changes one cache-decision token while adding owner-boundary and CLI error-contract coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #127167
Summary: This PR is the candidate repair for the linked Gateway health cache bug.

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
    Retain the fail-closed cache decision at the health-handler owner boundary, then merge only after the rebased exact head preserves the focused Gateway and CLI contracts.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the fail-closed cache decision at the health-handler owner boundary, then merge only after the rebased exact head preserves the focused Gateway and CLI contracts.

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

Yes, from source: with a fresh cached snapshot, make runtime inspection throw and make refresh reject; current main returns cached success while the branch returns UNAVAILABLE.

Is this the best way to solve the issue?

Yes. The health handler owns the cached-versus-refresh decision, and marking failed inspection as unverified reuses its existing foreground refresh and typed-error contract without new surface area.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: A fresh cached health response can otherwise make operator monitoring report success while health collection is unavailable.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused after-fix Gateway and CLI test evidence.

Label justifications:

  • P1: A fresh cached health response can otherwise make operator monitoring report success while health collection is unavailable.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless records focused after-fix Gateway and CLI test evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Available history records the recent health-cache refresh, health reporting, and read-only CLI work under this path. (role: recent Gateway and CLI contributor; confidence: high; commits: bdc595d1bd56, b233ea79575e, bbe22082b0d3; files: src/gateway/server-methods/health.ts, src/cli/gateway-cli/health-route.ts)
  • Vincent Koc: Path history records the health-owner-boundary and health snapshot-collection refactors under this subsystem. (role: health-owner-boundary refactor contributor; confidence: medium; commits: 4278fdfd5ede, 0211407d8a2c; files: src/gateway/server-methods/health.ts)

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.

@steipete
steipete merged commit 4984713 into main Aug 21, 2026
303 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway health returns stale cached success when runtime inspection and refresh fail

1 participant