Skip to content

fix(cli): keep concurrent Gateway calls authenticated - #166523

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-concurrent-cli-device-identity-20260919
Oct 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-concurrent-cli-device-identity-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent openclaw gateway call processes stalled while loading credentials and could silently connect without device identity when that loading failed. Idempotent sessions.create then lost the identity required to bind its request.

User Impact

Existing identity and token reads no longer copy the shared database. An identity-load failure stops before connecting and gives recovery guidance. Native read-only SQLite may create empty WAL/SHM coordination files; credential rows, schema, permissions, and update behavior are unchanged.

Why This Change Was Made

Authentication performed two whole-database snapshots, then loaded the broad shared-state runtime just to prepare a token command. Both readers now use the existing native read-only owner. All eight device-auth commands move together into the existing early worker registry and a narrow adapter; the old dispatch is deleted. The same actor, FIFO, transaction, and commit-authority checks remain.

CI also exposed an inherited HTTP tool-invocation defect: the adapter omitted its Gateway-owned plugin registry from request scope, causing provider discovery to register the same workspace plugin again. HTTP now carries the existing instance-owned registry, as RPC already does. The concrete factory preserves its known plugin type; generic metadata and authorization readers retain their prior view contract. Partial-registry and undeclared-provider discovery behavior is unchanged.

Production LOC delta: +17. The typed worker boundary and explicit HTTP ownership handoff preserve existing asynchronous and lifecycle contracts while removing broad runtime dispatch. No cache, configuration option, dependency, schema change, or migration is added.

Evidence

A real dist Gateway and 20 concurrent CLI processes shared one identity and 512 MiB of synthetic state. Each call used a distinct idempotency key.

Measurement Original Complete CLI fix
8-core Linux rig, solo 6.64 s 4.19 s
20-call median 26.41 s 14.40 s
20-call maximum 29.97 s 14.78 s
Successful identity-bearing calls 20/20 20/20

A separate 16-vCPU Blacksmith Testbox run completed 20/20 calls with identity: solo 2.46 s, concurrent median 8.39 s, maximum 8.61 s. The overall five-second burst target remains unmet. The synthetic rig reproduced stalls/transport timeouts, but not spontaneous identity loss; baseline-failing load-error regressions independently prove the swallowed-error defect.

The HTTP repair has separate real dist-Gateway proof on Node 26.8.1: both requests returned HTTP 200, while registration count changed 1 → 2 before and stayed 1 → 1 after. All five candidate source files were restored byte-for-byte after the comparison.

Proof

  • Blacksmith Testbox tbx_01m4adhez7w8zt60rf8fxy0kn0: original snapshot reader fails the 20-process regression when snapshot subprocess capacity is unavailable; the native reader passes (1.79 s test time). Original broad worker preparation fails the cold-auth import regression; the narrow dispatcher passes. Gateway, storage/admission, and worker-import suites passed 179 tests.
  • Blacksmith Testbox tbx_01m4akpmh9m0cf84h2n4vbq1fw: CLI suites passed 49 tests in 70.13 s with exact stored-byte assertions. The capsule receiver verified source tree 70714aa030d5655c1a42ca3fe21678c390cfe4e9. The cliStartup runtime build passed in 44.5 s, followed by the real 20-process benchmark.
  • Blacksmith Testbox tbx_01m4artqr2rs5yzmbb1388qdv9: remote-onboarding 21 tests passed in 23.67 s; the credential-rotation E2E passed in 36.47 s. Both changed-file gates passed. These correct the obsolete silent-fallback expectation and the inherited error-message expectation from fix: stop recommending onboarding for OpenClaw runtime failures #166234. A full runtime build passed in 353.8 s.
  • The HTTP registration test reproduced with 12 passed / 1 failed both on the former PR head and exact pre-lane parent 526ed332c00f243d52691c79ca5a58aa8f1cbecc. Its assertion was preserved. The owner handoff is proven by the before/after dist-Gateway comparison above.
  • Authorized Linux-rig fallback after prolonged Testbox admission: node scripts/check-changed.mjs --staged passed for the original 19-file candidate and the final five-file HTTP repair. The latter finished with exit 0 at 11:22Z, including core/test types, lint, storage guards, and zero runtime import cycles. Both HTTP-comparison cliStartup builds passed. The supplemental Testbox replay did not run: one lease finished before accepting a command, and its replacement stayed queued; the authorized rig supplied the real-flow proof and gate.
  • Independent reviews of the CLI change, test corrections, and final HTTP repair found no actionable P0–P2 issues. All test leases were stopped. No merge command was submitted.

Individual test costs on Blacksmith Testbox tbx_01m4ap2t31r0e4ymby3kr50kcd, using node scripts/run-vitest.mjs <file> --maxWorkers=1 (the pnpm test wrapper):

Test file Wall seconds
src/gateway/call.test.ts 21.01
src/infra/device-auth-store.test.ts 32.56
src/infra/device-auth-store.worker.test.ts 26.90
src/infra/device-identity-async.test.ts 2.28
src/infra/device-identity-worker.test.ts 37.56
src/infra/device-identity.test.ts 29.90
src/state/openclaw-state.worker.imports.test.ts 33.06
src/cli/gateway-backed-exit.process.test.ts 56.56
src/cli/gateway-backed-exit-health.process.test.ts 31.06

All nine runs passed. Cold compiled-worker preparation dominates the longer wall times. The process/worker tests protect SQLite concurrency, authority, clean exit, and unchanged stored bytes.

Prior CI runs 37594337983 and 37601573757 consumed 13,839 and 14,046 job-seconds, including 8,574 and 9,090 Node-test job-seconds. They are failure evidence, not passing proof: the former found the two stale expectations and inherited HTTP defect; the latter failed only on that HTTP defect. The next run, 37616530633, passed every Node test job and failed only on an inherited terminal-font fixture type error; its cost was 17,218 job-seconds, including 9,187 Node-test job-seconds. Main fixed that unused argument in 1d10375ee563; rebase incorporated the fix and dropped the identical local correction. The exact ui-components type group passed in 93.0 s in the scoped rig gate, and review found no actionable issues. Current-head CI run 37620590123, attempt 2, completed successfully on 1ed5997ed826; all 97 jobs in the latest result set passed or were intentionally skipped. That set accounts for 18,741 job-seconds, including 10,361 Node-test job-seconds. The first attempt failed one Android Play case, ChatComposerLayoutTest.reviewMenuLoadsCurrentConversationSnapshotAndRetiresOnSessionSwitch, on its one-second Compose wait (3,567 tests, one failure). Android sources were unchanged from the preceding passing run. One exact-job replay passed on the unchanged head; no test, timeout, or production code was changed for it, and its root cause remains unresolved. The separate aggregate CI/security status is also green on this head.

Final rebase retained all reviewed HTTP and device-auth changes. It incorporated an upstream plugin-state-only transaction admission optimization; the shared worker's default admission path used by device auth remains unchanged. The generated mock baseline also incorporates upstream shrink-only removals. Only this lane's three commits remain above main.

Published head: 1ed5997ed826fae38de607f8abbbc6c629ccd91f. The latest rebase preserved all reviewed/tested file contents byte-for-byte.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: M labels Oct 7, 2026
@steipete
steipete marked this pull request as ready for review October 7, 2026 08:31
@steipete
steipete enabled auto-merge (squash) October 7, 2026 08:32
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1ed5997ed826fae38de607f8abbbc6c629ccd91f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/call-device-auth.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/methods/registry.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/method-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/request-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-auth-store.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 8:31 AM ET / 12:31 UTC (Revision 5).

ClawSweeper review

What this changes

The PR reduces Gateway credential-loading overhead, stops calls when selected device identity loading fails, and reuses the Gateway’s plugin registry for HTTP tool requests.

Merge readiness

✅ Ready for maintainer review

The repair remains necessary: current main retains the snapshot reads and swallowed identity-load errors. No blocking correctness finding emerged, and the supplied real-runtime evidence supports the changed behavior.

Priority: P2
Reviewed head: 1ed5997ed826fae38de607f8abbbc6c629ccd91f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-preserving repair with strong runtime evidence and no actionable blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Reported real dist-Gateway concurrent CLI runs exercise the changed credential readers, and the HTTP before/after run exercises registry reuse with observed registration counts. Current source preserves those tested blobs; load-error regressions supplement the runtime evidence. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Reported real dist-Gateway concurrent CLI runs exercise the changed credential readers, and the HTTP before/after run exercises registry reuse with observed registration counts. Current source preserves those tested blobs; load-error regressions supplement the runtime evidence. No stored-data contract changes.
Evidence reviewed 10 items Pinned introduced change: Reviewed the merge-base-to-head delta, independently of endpoint drift. The checkout is the original PR head; final git status remained clean.
Still necessary on current main: Fetched main still catches identity-loading failures and returns null. Its identity reader still uses the artifact-preserving snapshot owner, and HTTP tool scope still omits the instance-owned plugin registry.
Complete worker cutover: All eight device-auth operations use the narrow registry adapter; their previous runtime dispatch is removed. Mutations retain synchronous transaction and commit admission, unchanged token kernels, and the existing actor lifecycle.
Findings None None.
Security None None.

How this fits together

Gateway CLI calls load credentials before opening an authenticated WebSocket connection. The shared-state worker owns token operations, while HTTP tool requests consume the Gateway’s existing plugin registry before dispatch.

flowchart TD
  A[Gateway CLI calls] --> B[Identity and token loading]
  C[Shared SQLite state] --> B
  B --> D{Identity loading succeeds}
  D -->|Yes| E[Authenticated Gateway connection]
  D -->|No| F[Recovery guidance]
  G[HTTP tool requests] --> H[Gateway plugin registry and authorized dispatch]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +17, Tests +83, Docs +8, Other -1. Total +107 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 11 76 59 +17
Tests 13 178 95 +83
Docs 1 9 1 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 26 263 156 +107

Review metrics

Metric Value Why it matters
Production versus test growth production +17; tests and test support +83 The body justifies production growth through the narrow worker adapter and explicit HTTP registry handoff.

Technical review

Best possible solution:

Keep credential reads and mutations under their existing SQLite owners, preserve selected identity through connection setup, and share the Gateway-owned plugin registry across transports.

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

Yes, source establishes the swallowed-error path on current main, and the supplied baseline-failing regressions isolate it. This read-only review did not execute the reproduction.

Is this the best way to solve the issue?

Yes, the patch reuses existing read and worker owners, removes superseded dispatch, and preserves authorization rather than adding competing mechanisms.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f2c5ed82c5f1.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway authentication and concurrent CLI reliability repair.
  • merge-risk: 🚨 compatibility: Selected identity-load failures now stop previously device-less calls; the maintainer-authored PR explicitly accepts and documents this behavior.
  • 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. Sufficient (terminal): Reported real dist-Gateway concurrent CLI runs exercise the changed credential readers, and the HTTP before/after run exercises registry reuse with observed registration counts. Current source preserves those tested blobs; load-error regressions supplement the runtime evidence. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported real dist-Gateway concurrent CLI runs exercise the changed credential readers, and the HTTP before/after run exercises registry reuse with observed registration counts. Current source preserves those tested blobs; load-error regressions supplement the runtime evidence. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta, independently of endpoint drift. The checkout is the original PR head; final git status remained clean. (1ed5997ed826)
  • Still necessary on current main: Fetched main still catches identity-loading failures and returns null. Its identity reader still uses the artifact-preserving snapshot owner, and HTTP tool scope still omits the instance-owned plugin registry. (src/gateway/call-device-auth.ts:106, f2c5ed82c5f1)
  • Complete worker cutover: All eight device-auth operations use the narrow registry adapter; their previous runtime dispatch is removed. Mutations retain synchronous transaction and commit admission, unchanged token kernels, and the existing actor lifecycle. (src/infra/device-auth-store.worker.ts:24, 1ed5997ed826)
  • HTTP ownership and authorization: HTTP now carries the concrete Gateway-owned registry, matching the existing RPC pattern. Request revalidation, cancellation, session authorization, and the final pre-tool authority check remain intact; authorization consumers retain the existing registry-view contract. (src/gateway/tools-invoke-http.ts:115, 1ed5997ed826)
  • Accepted compatibility behavior: The maintainer-authored body explicitly chooses failure before connection when selected identity loading fails and accepts empty SQLite WAL/SHM coordination artifacts. Documentation explains recovery; ordinary local shared-secret identity bypass remains unchanged. The supplied security-guard comment verifies the author’s repository admin role. Public docs: docs/cli/gateway/query.md. (docs/cli/gateway/query.md:21, 1ed5997ed826)
  • Real production-path proof: The captured body reports real dist-Gateway runs with 20 concurrent CLI processes and 512 MiB of synthetic state: 20/20 identity-bearing calls, Linux median 26.41→14.40 seconds, and separate Testbox median 8.39 seconds. HTTP before/after requests returned 200 while registration changed from 1→2 to 1→1. The five-second target remains unmet; spontaneous identity loss was not reproduced, and baseline-failing load-error regressions separately establish that defect. (1ed5997ed826)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-10-07T08:37:03.005Z sha 27c0e79697c9771489aa59038af1983c9166e64c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T09:40:45.085Z sha 5db4a40 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T10:05:38.413Z sha 5db4a40 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T11:56:34.043Z sha fc71f5d6d47c30980ac13039a14e7765ac877e59 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/perf-micro-concurrent-cli-device-identity-20260919 branch from 27c0e79 to 5db4a40 Compare October 7, 2026 09:34
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Oct 7, 2026
@steipete
steipete force-pushed the steipete/perf-micro-concurrent-cli-device-identity-20260919 branch from 5db4a40 to fc71f5d Compare October 7, 2026 11:47
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

I’m investigating one-shot gateway call cold-start overhead in a separate performance change. The intended scope is CLI startup/config ownership and unnecessary eager imports; device identity storage, locking, token reads, and worker admission remain owned by this PR. I’ll preserve its fail-closed authentication behavior and avoid copying its changes. Please flag any overlap with CLI registration or reduced dispatch-config loading.

Read existing device identities and tokens without full database snapshots,
and fail before connecting when identity storage is unavailable. Prepare
all device-auth commands through the narrow worker adapter while retaining
the existing actor and transaction/commit admission checks.
@steipete
steipete force-pushed the steipete/perf-micro-concurrent-cli-device-identity-20260919 branch from fc71f5d to 1ed5997 Compare October 7, 2026 12:22
@steipete
steipete merged commit 7a75498 into main Oct 7, 2026
251 of 253 checks passed
@steipete
steipete deleted the steipete/perf-micro-concurrent-cli-device-identity-20260919 branch October 7, 2026 13:07
steipete added a commit that referenced this pull request Oct 7, 2026
Restores artifact-preserving reads for Doctor's device-identity detector during migration planning (regressed in #166523). Proven with a published-driver (2026.9.8) x candidate cell.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
* fix(cli): keep concurrent Gateway calls authenticated

Read existing device identities and tokens without full database snapshots,
and fail before connecting when identity storage is unavailable. Prepare
all device-auth commands through the narrow worker adapter while retaining
the existing actor and transaction/commit admission checks.

* test(gateway): align authentication failure expectations

* fix(gateway): preserve plugin registry in HTTP tool requests
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…w#166671)

Restores artifact-preserving reads for Doctor's device-identity detector during migration planning (regressed in openclaw#166523). Proven with a published-driver (2026.9.8) x candidate cell.
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 docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed 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