Skip to content

fix(cli): preserve shared state when gateway commands are offline - #125102

Merged
steipete merged 1 commit into
mainfrom
steipete/compassionate-poitras-34d64c
Aug 17, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/compassionate-poitras-34d64c

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #101290
Follow-up to #123674

What Problem This Solves

Fixes an issue where operators running Gateway health, suspend, or resume commands against an unreachable Gateway could create or mutate the shared SQLite database before the connection failed. A clean isolated reproduction created openclaw.sqlite, a 32 KiB SHM file, and roughly 1.7–2 MiB of WAL despite the target being offline.

Why This Change Was Made

Gateway-owned suspension RPCs now use non-observing config validation, and all affected health and suspension transports use read-only shared-state access. Health fallback config reads also avoid plugin metadata observation. Process-level regressions cover root health, text and JSON Gateway health, suspend, and resume with both absent and pre-existing state.

User Impact

Health and cooperative suspension commands still report the normal connection failure when a Gateway is unreachable, but they no longer initialize or alter shared Gateway state. Existing database, WAL, and SHM bytes remain unchanged.

Evidence

  • Pre-fix reproduction on fc677bcc3c26e058636fee24e366280cff17fd77: unreachable suspend created a 4 KiB database, 32 KiB SHM, and 1,730,432-byte WAL; root/Gateway health and resume reproduced the same class.
  • Regression red phase: src/cli/gateway-backed-exit.process.test.ts failed 5 new cases while preserving the expected transport errors; each failure showed newly created SQLite/SHM/WAL artifacts.
  • Focused Vitest proof: 108 tests passed across command policy, startup policy, Gateway process, health route/registration, and health command suites.
  • node scripts/check-changed.mjs passed all selected core/coreTests gates locally after remote workload routing was unavailable due provider capacity: core and test typechecks, changed-file lint/format, dead-export scan, database-first guards, import cycles, and boundary ratchets.
  • Black-box built-CLI validation: 10/10 absent/seeded cases passed against dist/entry.js; absent state stayed absent and seeded shared-state inventories plus SHA-256 file digests remained byte-identical.
  • Codex autoreview: clean, no accepted/actionable findings.
  • Production LOC: +36/-23 (net +13). Tests: +143/-40.

AI-assisted: yes. The maintainer inspected the implementation, reproduced the failure, verified the regression red phase, and ran the final source-aware and source-blind proof.

Gateway health, suspend, and resume now preserve shared SQLite state when the target is unreachable.

Related: #101290

Follow-up to #123674
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 17, 2026 06:18
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 2:25 AM ET / 06:25 UTC.

ClawSweeper review

What this changes

The PR makes offline Gateway health, suspend, and resume commands validate configuration without observing state and use read-only shared-state access so they cannot alter Gateway SQLite files.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking correctness findings. This maintainer-labeled PR is a focused extension of the shared-state ownership repair; likely related people: steipete (high confidence) and VACInc (medium confidence).

Priority: P1
Reviewed head: b0fbb9e2e1ce00674ebab683647ab25a89a0782b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong process-level evidence supports a focused state-safety repair, with common-transport authentication compatibility as the remaining review focus.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless includes built-CLI after-fix artifact and digest 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 outside the external-contributor proof gate; its body nevertheless includes built-CLI after-fix artifact and digest evidence.
Evidence reviewed 6 items Current-main failure path: Current main loads health fallback configuration through the observing best-effort reader and sends health without a read-only shared-state mode.
Read-only owner boundary: The client contract turns read-only mode into no-create identity loading and no-op device-token writes, preventing a second CLI process from becoming a shared-state writer.
PR transport repair: The branch applies read-only shared-state mode to the common Gateway CLI transport and to root health.
Findings None None.
Security None None.

How this fits together

CLI Gateway commands validate local configuration, then connect to the Gateway over its RPC transport. The Gateway owns shared SQLite state, so a separate offline CLI process must not initialize identity, token, WAL, or SHM state before reporting a connection failure.

flowchart LR
  A[Operator CLI command] --> B[Startup policy]
  B --> C[Non-observing config validation]
  C --> D[Read-only Gateway transport]
  D --> E{Gateway reachable?}
  E -->|Yes| F[Gateway RPC result]
  E -->|No| G[Connection error and unchanged state]
Loading

Before merge

  • Resolve merge risk (P1) - The common Gateway CLI helper also serves raw calls, usage-cost, and diagnostics, so merging changes their device-identity and token-persistence behavior as well as the intended health and suspension routes.
  • Resolve merge risk (P1) - Production code grows by 13 lines; the explicit health configuration boundary is justified only insofar as it remains the single owner preventing observing/plugin metadata reads.
  • Complete next step (P2) - The active maintainer-labeled repair should receive exact-head CI and common-transport authentication review rather than automated cleanup.
Agent review details

Security

None.

PR surface

Source +13, Tests +103. Total +116 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 4 36 23 +13
Tests 6 143 40 +103
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 179 63 +116

Review metrics

Metric Value Why it matters
Startup-policy changes 2 commands changed to validation-only Suspend and resume retain invalid-config rejection while avoiding state migration during a separate CLI process.
Production versus regression coverage production +36/-23; tests +143/-40 The production growth creates explicit non-observing/read-only boundaries, while the test growth covers the real offline artifact invariant.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #101290
Summary: This PR extends the one-shot CLI shared-state ownership repair to the remaining health and cooperative suspension commands.

Members:

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

Merge-risk options

Maintainer options:

  1. Confirm common-transport auth compatibility (recommended)
    Verify first-use and stored device-auth behavior for the other callers of the shared Gateway CLI helper while preserving its no-write state contract.
  2. Narrow the helper policy if needed
    If a remaining caller must persist device-auth state, pass read-only mode only from the health and suspension routes rather than changing that caller's behavior.

Technical review

Best possible solution:

Keep one canonical read-only transport policy for one-shot Gateway RPCs and retain the process regression matrix proving offline commands preserve both absent and existing state artifacts.

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

Yes. Current main exposes the observing configuration and writable transport paths, and the branch adds a concrete isolated offline-Gateway process matrix; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, with one compatibility check remaining. Repairing configuration and transport at their shared ownership boundaries is preferable to cleaning up artifacts afterward; verify the broader helper's device-auth behavior before merge.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: Normal CLI health and suspension commands can otherwise create or mutate Gateway-owned SQLite artifacts during an offline failure path.
  • add merge-risk: 🚨 session-state: The PR changes how existing installations access the shared SQLite database, WAL, and SHM artifacts.
  • add merge-risk: 🚨 auth-provider: Read-only transport changes device-identity and stored-token writes for all callers of the common Gateway CLI helper.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 outside the external-contributor proof gate; its body nevertheless includes built-CLI after-fix artifact and digest evidence.

Label justifications:

  • P1: Normal CLI health and suspension commands can otherwise create or mutate Gateway-owned SQLite artifacts during an offline failure path.
  • merge-risk: 🚨 session-state: The PR changes how existing installations access the shared SQLite database, WAL, and SHM artifacts.
  • merge-risk: 🚨 auth-provider: Read-only transport changes device-identity and stored-token writes for all callers of the common Gateway CLI helper.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 outside the external-contributor proof gate; its body nevertheless includes built-CLI after-fix artifact and digest evidence.

Evidence

What I checked:

  • Current-main failure path: Current main loads health fallback configuration through the observing best-effort reader and sends health without a read-only shared-state mode. (src/commands/health.ts:252, 2915e563d673)
  • Read-only owner boundary: The client contract turns read-only mode into no-create identity loading and no-op device-token writes, preventing a second CLI process from becoming a shared-state writer. (src/gateway/client.ts:58, 2915e563d673)
  • PR transport repair: The branch applies read-only shared-state mode to the common Gateway CLI transport and to root health. (src/cli/gateway-cli/register.ts:116, b0fbb9e2e1ce)
  • PR validation boundary: The branch gives suspend and resume validation-only startup policy, matching the existing node/device RPC approach without state migration. (src/cli/command-catalog.ts:247, b0fbb9e2e1ce)
  • Behavior-level regression coverage: The added process matrix asserts both absent and seeded shared-state artifacts remain byte-identical for root health, Gateway health, suspend, and resume while retaining expected offline errors. (src/cli/gateway-backed-exit.process.test.ts:340, b0fbb9e2e1ce)
  • Feature-history provenance: Current affected lines and the read-only client policy trace to the recent CLI/Gateway work by steipete; the earlier merged node/device repair supplies the adjacent precedent. (src/cli/gateway-cli/register.ts:116, 3bf3acbee5a8)

Likely related people:

  • steipete: Current-main blame attributes the affected command catalog, Gateway CLI helper, health path, and shared-state client policy to this contributor; they also authored this focused repair. (role: recent area contributor; confidence: high; commits: 3bf3acbee5a8, b0fbb9e2e1ce; files: src/cli/command-catalog.ts, src/cli/gateway-cli/register.ts, src/commands/health.ts)
  • VACInc: The merged prior repair established read-only one-shot Gateway RPC handling for node and device commands, which this PR extends to health and suspension paths. (role: adjacent repair author; confidence: medium; commits: ab9b40daa333; files: src/cli/nodes-cli/rpc.ts, src/cli/devices-cli.runtime.ts)

Rank-up moves

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

  • Confirm first-use and stored device-auth behavior for the additional callers covered by the common Gateway CLI helper.

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

Copy link
Copy Markdown
Contributor Author

Land-ready proof for b0fbb9e2e1ce00674ebab683647ab25a89a0782b:

  • Rebased cleanly onto current origin/main; git diff --check origin/main...HEAD passed and the diff remained limited to the intended 10 files.
  • node scripts/run-vitest.mjs src/cli/command-path-policy.test.ts src/cli/command-startup-policy.test.ts src/cli/gateway-backed-exit.process.test.ts src/cli/gateway-cli/health-route.test.ts src/cli/gateway-cli/register.option-collisions.test.ts src/commands/health.test.ts: 108 passed across 3 shards, including 11/11 process cases.
  • Exact-head pull-request CI run https://github.com/openclaw/openclaw/actions/runs/32001093788 completed green; openclaw/ci-gate succeeded on the exact head.
  • Pre-publication proof already completed on this patch: regression red phase failed 5 new offline process cases specifically because SQLite/SHM/WAL artifacts were created; local changed gates passed after remote workload routing was unavailable due provider capacity; Codex autoreview reported no actionable findings.
  • Built-CLI black-box proof passed 10/10 absent/seeded cases. Absent shared state stayed absent; seeded database/WAL/SHM inventories and SHA-256 digests remained byte-identical.
  • Production LOC: +36/-23 (net +13), justified by one explicit non-observing health-config owner and canonical read-only one-shot Gateway transport. Tests: +143/-40.

ClawSweeper rank-up move: skipped an additional reachable first-use device-auth live test. Stored device credentials are exercised through the shared read-only client owner and seeded-state proofs, and explicit token/password auth bypasses origin device-auth persistence. These one-shot read-only queries have no contract to create or rotate credentials. Proof gap: reachable first-use credential issuance was not live-tested; the change was verified through the real built CLI against an unreachable target plus exact-head CI.

No ClawSweeper correctness finding remains; the reviewed head matches this exact SHA.

@steipete
steipete merged commit a3eb878 into main Aug 17, 2026
284 checks passed
@steipete
steipete deleted the steipete/compassionate-poitras-34d64c branch August 17, 2026 06:29
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 17, 2026
Direct gateway calls and diagnostic probes now preserve shared SQLite ownership instead of creating or mutating state during read-only operations.

Related: #101290
Follow-up to #125102
steipete added a commit that referenced this pull request Aug 17, 2026
Direct gateway calls and diagnostic probes now preserve shared SQLite ownership instead of creating or mutating state during read-only operations.

Related: #101290
Follow-up to #125102
steipete added a commit that referenced this pull request Aug 17, 2026
* fix(cli): keep gateway diagnostics read-only

Direct gateway calls and diagnostic probes now preserve shared SQLite ownership instead of creating or mutating state during read-only operations.

Related: #101290
Follow-up to #125102

* fix(cli): keep required status probes read-only
SemonCat pushed a commit to SemonCat/openclaw that referenced this pull request Aug 17, 2026
Gateway health, suspend, and resume now preserve shared SQLite state when the target is unreachable.

Related: openclaw#101290

Follow-up to openclaw#123674
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
Gateway health, suspend, and resume now preserve shared SQLite state when the target is unreachable.

Related: openclaw#101290

Follow-up to openclaw#123674
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
* fix(cli): keep gateway diagnostics read-only

Direct gateway calls and diagnostic probes now preserve shared SQLite ownership instead of creating or mutating state during read-only operations.

Related: openclaw#101290
Follow-up to openclaw#125102

* fix(cli): keep required status probes read-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant