Skip to content

fix(cli): keep gateway calls and diagnostics read-only - #125178

Merged
steipete merged 2 commits into
mainfrom
steipete/gateway-readonly-auth-proof
Aug 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/gateway-readonly-auth-proof

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #101290
Follow-up to #125102

What Problem This Solves

Fixes three remaining cases where one-shot Gateway diagnostics could touch shared SQLite state even though the command only reads or calls the running Gateway:

  • a reachable gateway call could run observing startup/config work before reaching the read-only transport;
  • gateway diagnostics export could initialize SQLite during startup, while its generic connectivity probe also used writable identity and token readers.
  • gateway status --require-rpc made a writable status call before its read-only connectivity probe.

This could create or change openclaw.sqlite, WAL, and SHM artifacts during ordinary diagnostics.

Why This Change Was Made

Direct Gateway RPC commands now share one validation-only startup policy, while the diagnostics command group owns one corrupt-config-safe cold policy. Generic Gateway probes enforce their existing non-mutating contract with read-only identity/token access and a read-only client lifecycle, and the required status RPC now carries that same lifecycle mode. This preserves the status connectivity snapshot rather than disabling it.

The cleanup also removes the duplicate loadDeviceIdentityIfPresentReadOnly API; the canonical loadDeviceIdentityIfPresent already provides the same non-creating, artifact-preserving behavior. Internal helper names now state the read-only and non-observing boundaries directly.

User Impact

Operators can run raw Gateway calls, required status probes, and diagnostics exports without the CLI joining the Gateway's SQLite write lifecycle. Reachable explicit and stored authentication continue to work, diagnostics still records status and health snapshots, and existing shared-state bytes remain unchanged.

Evidence

  • Red proof, raw call: the RPC authenticated and completed, then the process assertion found newly created/changed SQLite WAL and SHM artifacts before the validation-only startup policy was added.
  • Red proof, diagnostics export: absent and seeded commands both exited successfully and wrote valid non-empty zip files, but absent state gained SQLite/SHM/WAL and seeded state gained SHM/WAL. After the diagnostics startup policy fix, the seeded case still exposed writable token access in the generic probe.
  • Owner proof: making probeGateway use canonical read-only identity/token readers plus sharedStateMode: "read-only" preserved the connectivity snapshot and made both export cases byte-identical.
  • Sibling proof: ClawSweeper identified the required status RPC that precedes the generic probe. That call now carries sharedStateMode: "read-only"; real-process cases prove both absent and seeded shared-state artifacts remain byte-identical after a successful gateway status --require-rpc.
  • Vacuity proof: removing only the common helper's read-only mode made reachable explicit/stored process cases fail for state creation/mutation after successful RPC authentication.
  • Focused post-rebase tests: 489 passed across Gateway call/client/probe, device identity, daemon status probe, CLI process, command policy, registration, health route, and health command suites.
  • Environment ratchet: node --import tsx scripts/check-env-var-count.mts --base origin/main passed at 501/501. The ratchet repair is owned by merged PR fix(ci): restore environment variable count ratchet #125185 and none of its budget/config/baseline files are included here.
  • Main-owned build gate: the unrelated Control UI startup-budget failure was repaired by merged PR fix(ui): refresh startup budget baseline #125200; this branch rebases onto that fix without including its protected baseline file.
  • Main refresh: the final conflict resolution preserved main's new gateway restart validation policy; main already contained the identical preaction expectation, so Git dropped that redundant commit.
  • node scripts/check-changed.mjs passed all selected core and coreTests gates, including core/test typechecks, changed-file lint/format, dead-export scan, database-first guards, and import-cycle checks.
  • pnpm build passed on the original owner-boundary patch with no ineffective dynamic-import failure; exact-head CI rebuilds the final sibling repair.
  • Built-CLI behavior: explicit first-use gateway call health succeeded without state; invalid auth failed without state; diagnostics export produced status/health entries and no state when absent; export over existing unpaired state remained byte-identical and recorded the expected pairing-required snapshot. Stored-origin reachable success is covered by the real process fixture because live noninteractive pairing was unavailable to the source-blind validator.
  • Codex autoreview: clean after the ClawSweeper status-path repair, with no accepted/actionable findings; the final rebase was range-diff identical.
  • Production LOC: +38/-42 (net -4). Tests: +283/-36.

AI-assisted: yes. The maintainer inspected the owner boundaries, rejected broader performance/API abstractions, verified red phases, ran the final source-aware and built-product proof, and reviewed the complete diff.

@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 08:47
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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, 6:56 AM ET / 10:56 UTC.

ClawSweeper review

What this changes

The PR makes one-shot Gateway CLI calls, required status probes, and diagnostic exports avoid creating or mutating shared SQLite state.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking patch defect found. This maintainer-owned state-safety repair should remain open until exact-head checks complete.

Priority: P2
Reviewed head: 5748fa196d117dee0f81c7e343a247706c05b8b1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has strong stated process proof and no source-level defect found; exact-head CI remains the merge gate.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR includes process-level artifact-preservation evidence; an external-contributor proof gate does not apply.
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 includes process-level artifact-preservation evidence; an external-contributor proof gate does not apply.
Evidence reviewed 6 items Read-only lifecycle owner: The branch makes the Gateway client facade enforce non-creating identity lookup and no-op token writes whenever its caller supplies read-only state mode.
Required status RPC: The previously writable status RPC now receives read-only state mode before the subsequent connectivity probe.
Process-level regression coverage: New isolated CLI cases exercise reachable explicit/stored authentication, required status RPC, and diagnostics export while comparing absent and seeded state artifacts before and after.
Findings None None.
Security None None.

How this fits together

Gateway CLI diagnostics resolve startup, credentials, and a client connection before querying a running Gateway. These paths should return health and connectivity information without entering the shared SQLite write lifecycle.

flowchart LR
  A[CLI diagnostic command] --> B[Startup policy]
  B --> C[Gateway client lifecycle]
  C --> D[Read-only identity and token lookup]
  D --> E[Running Gateway]
  E --> F[Status or diagnostic output]
Loading

Before merge

  • Resolve merge risk (P1) - Diagnostics now intentionally skip global config validation at startup; exact-head CI should confirm this remains limited to the read-only diagnostics path while artifact preservation and authentication continue to work.
  • Complete next step (P2) - No repair is requested: this maintainer-labeled PR needs its exact-head checks to finish, then normal maintainer merge review.
Agent review details

Security

None.

PR surface

Source -4, Tests +247. Total +243 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 9 38 42 -4
Tests 9 283 36 +247
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 321 78 +243

Review metrics

Metric Value Why it matters
Production versus test LOC production +38/-42 (net -4); tests +283/-36 The repair reduces production code while adding process-level regression coverage for the shared-state invariant.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #101290
Summary: This is a focused follow-up candidate for the CLI shared-state mutation problem; the earlier merged repair handled offline paths, while this branch covers reachable calls and 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. Finish exact-head verification (recommended)
    Allow the running exact-head checks to confirm state preservation and the intentional diagnostics startup behavior before merging.

Technical review

Best possible solution:

Land after exact-head CI confirms that authentication, status snapshots, and diagnostics remain available while absent and existing SQLite artifacts remain unchanged.

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

Yes—source and the added process harness define a high-confidence path: run reachable calls, required status RPCs, and diagnostics export with absent or seeded state and compare artifacts before and after.

Is this the best way to solve the issue?

Yes—the patch carries read-only mode through the shared Gateway call, client, and probe boundaries rather than suppressing diagnostics or adding downstream cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: Diagnostics now bypass the prior global startup-validation path to remain usable for local diagnostics.

Label justifications:

  • P2: This is a bounded repair for CLI diagnostics that can mutate shared Gateway state.
  • merge-risk: 🚨 session-state: The changed client lifecycle controls reads and writes to shared SQLite identity and token state.
  • merge-risk: 🚨 compatibility: Diagnostics now bypass the prior global startup-validation path to remain usable for local diagnostics.
  • 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 includes process-level artifact-preservation evidence; an external-contributor proof gate does not apply.

Evidence

What I checked:

  • Read-only lifecycle owner: The branch makes the Gateway client facade enforce non-creating identity lookup and no-op token writes whenever its caller supplies read-only state mode. (src/gateway/client.ts:58, 5748fa196d11)
  • Required status RPC: The previously writable status RPC now receives read-only state mode before the subsequent connectivity probe. (src/cli/daemon-cli/probe.ts:126, 5748fa196d11)
  • Process-level regression coverage: New isolated CLI cases exercise reachable explicit/stored authentication, required status RPC, and diagnostics export while comparing absent and seeded state artifacts before and after. (src/cli/gateway-backed-exit.process.test.ts:629, 5748fa196d11)
  • Canonical identity reader: The retained identity reader already guarantees missing-state reads do not create the database or coordinator artifacts, so removing its duplicate alias does not remove behavior. (src/infra/device-identity.test.ts:356, 5748fa196d11)
  • Regression provenance: Current main's required-status call lacks the lifecycle mode at the exact call site; blame attributes that new helper line to the merged change for pull request 125054. (src/cli/daemon-cli/probe.ts:125, 8c2d5f914719)
  • Current-main comparison: The branch remains a substantive focused delta from current main; it is not already implemented there. (src/gateway/probe.ts:294, 5748fa196d11)

Likely related people:

  • steipete: Blame assigns the current required-status path to this author, who also authored the predecessor offline repair and both commits in this PR. (role: introduced and recently maintained the affected Gateway CLI lifecycle; confidence: high; commits: 8c2d5f914719, a3eb8787ffc1, 1b237b1c3586; files: src/cli/daemon-cli/probe.ts, src/gateway/probe.ts, src/gateway/client.ts)

Rank-up moves

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

  • Let exact-head CI complete after the final force-push.

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 (4 earlier review cycles)
  • reviewed 2026-08-17T08:53:53.942Z sha 7753b53f3da8f5232d4e346db8118f555a09a3ac :: needs changes before merge. :: [P2] Keep the required status RPC read-only
  • reviewed 2026-08-17T09:02:54.256Z sha 8fabe2d66b658d7df8bc87c0a5738d394bedc30d :: found issues before merge. :: [P2] Keep the required status RPC read-only
  • reviewed 2026-08-17T09:28:27.282Z sha f941c3dd49b19ae096a3616665b31fe2c60b5617 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-17T09:42:00.291Z sha a36a1d6 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/gateway-readonly-auth-proof branch from 8fabe2d to f941c3d Compare August 17, 2026 09:21
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete

steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 5748fa196d117dee0f81c7e343a247706c05b8b1:

  • Root cause/owner: one-shot Gateway CLI consumers could still acquire writable shared-state ownership through startup, identity/token helpers, generic probes, and the required status RPC. The canonical fix carries sharedStateMode: "read-only" through the shared Gateway call/client/probe lifecycle, uses non-observing config/token access, and keeps the relevant CLI routes plugin-cold.
  • ClawSweeper P2 resolved: the gateway status --require-rpc status call now carries the same read-only lifecycle mode as the following probe. Real-process cases prove successful required status calls leave both absent and seeded SQLite artifacts byte-identical. This applies the sole actionable finding and Rank-up move from fix(cli): keep gateway calls and diagnostics read-only #125178 (comment); no Rank-up move remains.
  • Focused post-rebase proof: 489 tests passed across 13 files and five routed Vitest shards. Targeted formatting and git diff --check are clean. Fresh autoreview after the status-path repair reported no actionable findings. The final conflict refresh preserved main's gateway restart policy, and Git dropped the identical preaction expectation already upstream.
  • Environment gate: node --import tsx scripts/check-env-var-count.mts --base origin/main passed at 501/501. The ratchet repair is owned by merged PR fix(ci): restore environment variable count ratchet #125185; no budget, config, baseline, lockfile, or other fix(ci): restore environment variable count ratchet #125185-owned file is included in this PR. The unrelated Control UI build budget was repaired by merged PR fix(ui): refresh startup budget baseline #125200 and is likewise excluded.
  • Earlier full gates: node scripts/check-changed.mjs passed the selected core/coreTests typecheck, lint, dead-export, database-first, and cycle guards on the owner-boundary patch; pnpm build passed. Exact-head CI rebuilt and validated the final head: https://github.com/openclaw/openclaw/actions/runs/32022018786
  • Built-CLI behavior: explicit first-use calls succeed without state creation; invalid auth fails without state creation; absent-state diagnostics export contains successful status/health snapshots without creating state; export over existing unpaired state preserves SQLite bytes and reports pairing-required instead of hiding it.
  • LOC: production +38/-42 (net -4); tests +283/-36.
  • Proof gap: no suitable live noninteractive pairing path was available for stored-origin reachable success. The real process fixture covers the successful RPC execution order and verifies shared state remains unchanged; this is not claimed as live pairing proof.

@steipete
steipete force-pushed the steipete/gateway-readonly-auth-proof branch from f941c3d to a36a1d6 Compare August 17, 2026 09:35
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label 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
steipete force-pushed the steipete/gateway-readonly-auth-proof branch from a36a1d6 to 5748fa1 Compare August 17, 2026 10:49
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 17, 2026
@steipete
steipete merged commit bbe2208 into main Aug 17, 2026
220 checks passed
@steipete
steipete deleted the steipete/gateway-readonly-auth-proof branch August 17, 2026 10:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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