Repository navigation
fix: keep secret and catalog CLI writes with the Gateway owner - #168108
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs real behavior proof before merge. What this changesThis PR routes secret CLI mutations through the local Gateway owner and requires exclusive offline ownership for CLI catalog refreshes. Example: Run openclaw secrets store set SERVICE_MODE --value production while the local Gateway owns the state directory.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 5 items remain Keep this PR open: the ownership repair is useful and remains absent from current main, but the previously reported validation exit-code regression is unresolved. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherAdministrative CLI commands select the physical state owner, which authorizes mutations, persists them through the shared-state worker, and publishes affected runtime state. flowchart TD
A[Administrative CLI] --> B[Local state owner selection]
B --> C[Authenticated Gateway RPC]
B --> D[Exclusive offline custody]
C --> E[Shared state worker]
D --> E
E --> F[SQLite state]
C --> G[Secrets runtime refresh]
Technical reviewBest possible solution: Retain the existing owner routing while preserving structured validation refusals and completing authority and existing-state compatibility verification. Do we have a high-confidence way to reproduce the issue? Source establishes the direct CLI write path and traces the introduced remote-validation failure to exit 1; no target code was executed during this review. Is this the best way to solve the issue? Reusing local-state-owner admission and the shared worker fits the existing architecture, but routed refusals must preserve the established CLI error contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dfdda05fe3c5. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: Source composes live authority guards, but the supplied evidence does not establish rejection at the new final-persistence boundary. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +193, Tests +210, Docs +3, Other -14. Total +392 across 27 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
Reviewed October 10, 2026, 12:26 AM ET / 04:26 UTC (Revision 3). |
The local-state owner requires the Gateway to be stopped for models refresh, and #168108 removed the running-Gateway notice. Assert the exact saved-download summary instead, retaining migration diagnostics, JSON payload, and persisted-row coverage.
…law#168108) * fix(secrets): route CLI mutations through the local state owner * test(secrets): prove CLI writes stay with the Gateway owner * fix(secrets): preserve legacy mutation response and host validation * docs: explain secret and catalog command ownership * style(secrets): normalize mutation and fixture completion * fix(protocol): isolate secret owner schema metadata
The local-state owner requires the Gateway to be stopped for models refresh, and openclaw#168108 removed the running-Gateway notice. Assert the exact saved-download summary instead, retaining migration diagnostics, JSON payload, and persisted-row coverage.
Related: #168135, #168108, #168471 ## What Problem This Solves Fixes API-key setup from the CLI when a running Gateway owns local state. ## User Impact Users can run `openclaw models auth paste-api-key --provider <id>` without stopping the Gateway. The Gateway saves the key and refreshes its model catalog. Offline behavior is unchanged. An explicit, non-empty `--profile-id` still requires offline use. ## Why This Change Was Made #168135 correctly stopped CLI processes from writing credentials around a live Gateway. It also kept CLI flows offline where the existing Gateway APIs could not preserve their behavior. Manual API-key setup already uses the same credential writer as `models.authSetApiKey`, so that subset can use the owner instead of refusing. This change uses the canonical `local-state-owner.ts` route, as in #168108 and #168471. It binds the request to the discovered local owner and port, sends `expectedOwnerId`, requires `operator.admin`, rechecks ownership before dispatch, and never retries a possibly accepted write locally. API-key input is collected only after owner selection. The RPC checks the expected owner at credential and config writes; calls without that field retain their existing behavior. Owner-bound requests preserve the CLI's agent-selection rules. Update behavior: an older Gateway that lacks `models-auth-set-api-key-owner-v1` is refused before the API-key request; update and restart it, or stop it and retry offline. No request/response schema, new RPC method, config option, database schema, or paired-device fallback is added. ### Command-to-RPC mapping | CLI command or option | Existing RPC | Result in this change | | --- | --- | --- | | `paste-api-key --provider <id> [--agent <id>]` | `models.authSetApiKey` | Delegate provider, key, and agent; print saved profile and any application warning. | | `paste-api-key --profile-id <id>` | No profile-id field in `models.authSetApiKey` | Refuse this option with offline guidance. | | `paste-token [--expires-in <duration>]` | No equivalent API-key write | Stay offline: token type and expiry must not become an API key. | | `login`, including API-key plugin methods | `models.authLogin` and `wizard.*` | Stay offline: CLI method/profile/default/force semantics are not an exact manual-key mapping. | | `login-github-copilot` | `models.authLogin` and `wizard.*` | Stay offline; device flow is outside this change. | | `add` / `setup-token` | No exact generic mapping | Stay offline; these can run local provider CLI or import flows. | | `list` | `models.authStatus` | Stay offline: the status projection lacks the CLI list's state-path, cooldown, disabled-state, and recovery fields. | | `logout <profileId> [--yes]` | `models.authLogout` | Deferred; retain current offline behavior. | | `order get` | `models.authStatus` | Deferred; retain the existing owner-aware read. | | `order set <profileIds...>` | `models.authOrderSet` | Stay offline: the RPC requires the full profile order; the CLI allows partial lists. | | `order clear` | `models.authOrderSet` | Deferred; retain offline reset behavior. | | `activate <profileId>` | No exact test-and-activate mapping | Stay offline. | ## Evidence ACP CI comparison: `src/gateway/server.chat.acp-completion.test.ts` passed all 12 cases when run directly on PR head `4f32198a3a8f5446e1c24b783d624884415553e6` and on clean main at its exact merge parent `4f3eb4f254664cd0ed1a4b31678e9e4957348d20`. The CI failure in `completes persistence failure after explicit abort once` expected `[start, end]` but received `[end]`; that case passed on both local runs. This does not establish an inherited failure or a PR-caused failure—it records that neither isolated run reproduced it. No code or test assertion was changed. Latest review repair: removed only the stale `prepareDispatchCurrent` test expectation after #168882 retired that callback. Owner binding, capabilities, authentication, `assertDispatchCurrent`, and no-local-write assertions remain. The requested direct command `node scripts/run-vitest.mjs run src/cli/models-cli.state-owner.test.ts` passed all 16 tests (24.22 seconds total). No retired production callback was restored. - The new CLI regression fails with the original main-branch auth router: 12 existing refusal cases pass, and API-key delegation fails with `OWNER_UNAVAILABLE`. - The initial candidate passed 153 targeted tests across CLI ownership, the real API-key writer, Gateway transport, and the real API-key RPC. - Tests cover cancelled input, no local fallback, old-Gateway capability refusal before request dispatch, and rejected owner changes without credential/config writes. - Existing unbound API-key RPC requests still pass the real credential-writer test. - `pnpm build` passed. - Isolated live profile: piped a real OpenAI key into `pnpm openclaw --profile <profile> models auth paste-api-key --provider openai`. The Gateway picker changed from zero available OpenAI models to one. A real `openclaw agent` turn returned `AUTH_OWNER_OK`, using the saved auth profile. The listener PID stayed the same; no restart was needed. - The Gateway token was supplied only at runtime and was not in config. The same CLI path worked when it received that token. Without the token, it refused without a local write and named `OPENCLAW_GATEWAY_TOKEN` / `OPENCLAW_GATEWAY_PASSWORD` as the next step. - An earlier `node scripts/check-changed.mjs --staged` run passed the format, ownership, dependency, and other early guards, then stopped at main's UI-e2e test-root budget (722 versus 720). That result predates the empty-input regression below; no UI files are changed here. ### Review repair: authority at the final write - The captured requester guard now reaches the auth store's existing SQLite worker admission, not only the updater callback. It also reaches config `beforeCommit` and the config writer's effect-time authority check. - Credential observation: revoke after the real updater returns, before commit; the operation rejects, the original stored key remains, and config bytes do not change. The permitted control stores the replacement key. - Config observation: revoke after the transform returns; the operation rejects and the source config remains byte-for-byte unchanged. The already saved, unchanged credential remains intact. The permitted control publishes the auth-profile config. - The four allowed/revoked controls and 17 auth-store update tests pass. These tests use real credential/config persistence; only the revocation instant is controlled. - Fixed the two `curly` lint errors in the CLI input adapter. Targeted production lint passes for the adapter, API-key writer, and auth-profile upsert owner. - After merging main, the changed-file gate passed core typechecking and all 28 core test graphs. It stopped at unrelated unused exports in `extensions/codex/src/app-server/managed-binary.ts`, `tools/solid-lint/index.mjs`, and `ui/src/test-helpers/solid-application-context.tsx`; those files are unchanged by this PR. ### Review repair: configured loopback auth-none - Owner-bound shared-auth requests now enable the transport's existing bounded auth-none path. A Gateway explicitly configured with `gateway.auth.mode: "none"` uses the backend client identity without creating or reading device credentials. Remote targets and URL overrides retain the existing refusal rules. - A registered `paste-api-key` regression invokes the real `resolveGatewayCallDeviceAuth` with the owner route's options. It failed before the fix with `GatewayLocalBackendSharedAuthUnavailableError` and passes after the fix. All 105 transport tests and 16 CLI ownership tests pass. - The latest main was merged after these focused checks. Clean-main export-name collision checking passed at `76a282c7a1c6ca958517ce15f13e17371c14be11`; the channel collision was fixed upstream by `13296b17cd0`. The same clean main reproduced the three lint errors in the untouched plugin-state observation cache and SQLite comparison test. Remaining baseline runs were stopped at maintainer request while upstream CI repairs were being merged. ### Review repair: empty API-key input - Empty or whitespace-only stdin now reports: `No API key was supplied. Rerun this command and paste a non-empty API key, or pipe one to stdin.` - Two short tests read real streams and cover both inputs. Both failed with the old `Required` message and pass after this change. - The changed-file gate passed formatting, core typechecking, and all six selected test graphs. It stopped at the unrelated `GatewayApprovalEventPublisherV2` unused export in `src/gateway/server-instance-runtime.types.ts`, which this repair does not modify. ### Existing CI failures checked on main - On clean main `aec6e7a56eb03eaba1a648310876d2d6d4811745`, the UI cloud-startup toast-recovery case fails with the same `Control UI readiness hook is unavailable` error as this branch (two cases pass, one fails). - The same clean main also reproduces the FIFO assertions missing `QUEUED_STEER_A` and `ORDINARY_MESSAGE_B`. Neither test nor its steer behavior is changed by this PR. - The document-steer case also fails on clean main, but earlier: the initial turn does not reach the mock provider (zero requests). On this branch it reaches the later missing-document assertion. The baseline failure prevents an exact comparison of that later assertion; it is not claimed as an identical local reproduction. - On the repaired head, [the Node shard](https://github.com/openclaw/openclaw/actions/runs/38082252267/job/114301617040) reports the same FIFO failures. A [separate cron shard](https://github.com/openclaw/openclaw/actions/runs/38082252267/job/114301616913) reports `hydrates runtime metadata for a reasoning-capable fallback candidate` (expected two calls, received four); its main-branch investigation is separate and no auth change is claimed to fix it. - `src/cli/plugin-local-state-owner.test.ts` has the same result on this branch (`5033eb75ade`) and clean main (`9a165c492058ddf6fc3468cde27b201514c954f1`): 33 pass, one fails. The failed case is `routes memory search limits and JSON output through the discovered owner`; both report `The memory runtime does not support CLI search` inside `OUTCOME_UNKNOWN`. The fixture supplies a manager but not the `searchForCli` callback now required by the Memory Core handler. This is a main-branch fixture mismatch, not an auth routing regression; no test or routing behavior was changed to hide it. ### CI 38113017692: pinned per-file comparison Compared PR head `f062e5069509128680db873fa6643d262b034b0b` with its exact main parent `9e444e1078169a5bd1117eaf8b5c50cdca2fde15`. Each file ran through the repository test runner under pueue. | File | PR result | Main result | Verdict | | --- | --- | --- | --- | | `src/gateway/server-methods/models-auth-api-key.integration.test.ts` | 1 failed: corrupt config revision key during startup | Same | Inherited; failure occurs before the auth RPC or acknowledgment | | `src/gateway/gateway-cli-plugin-routing.test.ts` | 1 failed: corrupt config revision key | Same | Inherited | | `src/gateway/server-methods/sessions-mutations.sticky-model.test.ts` | 3 failed, 66 passed: two undefined-error assertions and an invalid transcript frame | Same | Inherited | | `src/gateway/server.sessions.create-worktree-spawn.test.ts` | 1 failed, 18 passed: invalid transcript frame | Same | Inherited | | `src/gateway/server/ws-connection/connect-device-pairing.test.ts` | 12 failed: corrupt config revision key | Same | Inherited | | `src/gateway/session-message-events.test.ts` | Setup failed: corrupt config revision key; 30 skipped | Same | Inherited | | `src/gateway/session-message-events.exec-completion.test.ts` | Setup failed: corrupt config revision key; 2 skipped | Same | Inherited | | `src/gateway/session-message-events.history-worker.test.ts` | Setup failed: corrupt config revision key; 2 skipped | Same | Inherited | | `src/gateway/sessions-history-http.physical-source.test.ts` | 4 failed: corrupt config revision key | Same | Inherited | | `ui/src/pages/workboard/workboard-native-bundle.e2e.test.ts` | 2 passed (Chromium and WebKit) | Same | CI failure not reproduced on either revision | The config-revision owner unit file also passes both tests on both revisions. The Gateway integration failures therefore do not establish an auth-specific `configRevisionHash`/`appliedConfigHash` regression: they stop while loading the installation revision key. No corruption check was weakened and no test was changed to bypass startup. Workboard's initial missing dependencies/browser artifact were repaired before the successful comparison runs. No overlap with protected maintainer changes. Two-way code change: a revert restores offline-only CLI setup. Keys saved through the Gateway remain saved. The affected paths are local CLI API-key setup and the existing Gateway API-key save handler. Co-authored-by: Ayaan Zaidi <[email protected]>
) Related: openclaw#168135, openclaw#168108, openclaw#168471 ## What Problem This Solves Fixes API-key setup from the CLI when a running Gateway owns local state. ## User Impact Users can run `openclaw models auth paste-api-key --provider <id>` without stopping the Gateway. The Gateway saves the key and refreshes its model catalog. Offline behavior is unchanged. An explicit, non-empty `--profile-id` still requires offline use. ## Why This Change Was Made openclaw#168135 correctly stopped CLI processes from writing credentials around a live Gateway. It also kept CLI flows offline where the existing Gateway APIs could not preserve their behavior. Manual API-key setup already uses the same credential writer as `models.authSetApiKey`, so that subset can use the owner instead of refusing. This change uses the canonical `local-state-owner.ts` route, as in openclaw#168108 and openclaw#168471. It binds the request to the discovered local owner and port, sends `expectedOwnerId`, requires `operator.admin`, rechecks ownership before dispatch, and never retries a possibly accepted write locally. API-key input is collected only after owner selection. The RPC checks the expected owner at credential and config writes; calls without that field retain their existing behavior. Owner-bound requests preserve the CLI's agent-selection rules. Update behavior: an older Gateway that lacks `models-auth-set-api-key-owner-v1` is refused before the API-key request; update and restart it, or stop it and retry offline. No request/response schema, new RPC method, config option, database schema, or paired-device fallback is added. ### Command-to-RPC mapping | CLI command or option | Existing RPC | Result in this change | | --- | --- | --- | | `paste-api-key --provider <id> [--agent <id>]` | `models.authSetApiKey` | Delegate provider, key, and agent; print saved profile and any application warning. | | `paste-api-key --profile-id <id>` | No profile-id field in `models.authSetApiKey` | Refuse this option with offline guidance. | | `paste-token [--expires-in <duration>]` | No equivalent API-key write | Stay offline: token type and expiry must not become an API key. | | `login`, including API-key plugin methods | `models.authLogin` and `wizard.*` | Stay offline: CLI method/profile/default/force semantics are not an exact manual-key mapping. | | `login-github-copilot` | `models.authLogin` and `wizard.*` | Stay offline; device flow is outside this change. | | `add` / `setup-token` | No exact generic mapping | Stay offline; these can run local provider CLI or import flows. | | `list` | `models.authStatus` | Stay offline: the status projection lacks the CLI list's state-path, cooldown, disabled-state, and recovery fields. | | `logout <profileId> [--yes]` | `models.authLogout` | Deferred; retain current offline behavior. | | `order get` | `models.authStatus` | Deferred; retain the existing owner-aware read. | | `order set <profileIds...>` | `models.authOrderSet` | Stay offline: the RPC requires the full profile order; the CLI allows partial lists. | | `order clear` | `models.authOrderSet` | Deferred; retain offline reset behavior. | | `activate <profileId>` | No exact test-and-activate mapping | Stay offline. | ## Evidence ACP CI comparison: `src/gateway/server.chat.acp-completion.test.ts` passed all 12 cases when run directly on PR head `4f32198a3a8f5446e1c24b783d624884415553e6` and on clean main at its exact merge parent `e1b944d4a80ef3b4e0df75f1e324cb4a5ffc08dd`. The CI failure in `completes persistence failure after explicit abort once` expected `[start, end]` but received `[end]`; that case passed on both local runs. This does not establish an inherited failure or a PR-caused failure—it records that neither isolated run reproduced it. No code or test assertion was changed. Latest review repair: removed only the stale `prepareDispatchCurrent` test expectation after openclaw#168882 retired that callback. Owner binding, capabilities, authentication, `assertDispatchCurrent`, and no-local-write assertions remain. The requested direct command `node scripts/run-vitest.mjs run src/cli/models-cli.state-owner.test.ts` passed all 16 tests (24.22 seconds total). No retired production callback was restored. - The new CLI regression fails with the original main-branch auth router: 12 existing refusal cases pass, and API-key delegation fails with `OWNER_UNAVAILABLE`. - The initial candidate passed 153 targeted tests across CLI ownership, the real API-key writer, Gateway transport, and the real API-key RPC. - Tests cover cancelled input, no local fallback, old-Gateway capability refusal before request dispatch, and rejected owner changes without credential/config writes. - Existing unbound API-key RPC requests still pass the real credential-writer test. - `pnpm build` passed. - Isolated live profile: piped a real OpenAI key into `pnpm openclaw --profile <profile> models auth paste-api-key --provider openai`. The Gateway picker changed from zero available OpenAI models to one. A real `openclaw agent` turn returned `AUTH_OWNER_OK`, using the saved auth profile. The listener PID stayed the same; no restart was needed. - The Gateway token was supplied only at runtime and was not in config. The same CLI path worked when it received that token. Without the token, it refused without a local write and named `OPENCLAW_GATEWAY_TOKEN` / `OPENCLAW_GATEWAY_PASSWORD` as the next step. - An earlier `node scripts/check-changed.mjs --staged` run passed the format, ownership, dependency, and other early guards, then stopped at main's UI-e2e test-root budget (722 versus 720). That result predates the empty-input regression below; no UI files are changed here. ### Review repair: authority at the final write - The captured requester guard now reaches the auth store's existing SQLite worker admission, not only the updater callback. It also reaches config `beforeCommit` and the config writer's effect-time authority check. - Credential observation: revoke after the real updater returns, before commit; the operation rejects, the original stored key remains, and config bytes do not change. The permitted control stores the replacement key. - Config observation: revoke after the transform returns; the operation rejects and the source config remains byte-for-byte unchanged. The already saved, unchanged credential remains intact. The permitted control publishes the auth-profile config. - The four allowed/revoked controls and 17 auth-store update tests pass. These tests use real credential/config persistence; only the revocation instant is controlled. - Fixed the two `curly` lint errors in the CLI input adapter. Targeted production lint passes for the adapter, API-key writer, and auth-profile upsert owner. - After merging main, the changed-file gate passed core typechecking and all 28 core test graphs. It stopped at unrelated unused exports in `extensions/codex/src/app-server/managed-binary.ts`, `tools/solid-lint/index.mjs`, and `ui/src/test-helpers/solid-application-context.tsx`; those files are unchanged by this PR. ### Review repair: configured loopback auth-none - Owner-bound shared-auth requests now enable the transport's existing bounded auth-none path. A Gateway explicitly configured with `gateway.auth.mode: "none"` uses the backend client identity without creating or reading device credentials. Remote targets and URL overrides retain the existing refusal rules. - A registered `paste-api-key` regression invokes the real `resolveGatewayCallDeviceAuth` with the owner route's options. It failed before the fix with `GatewayLocalBackendSharedAuthUnavailableError` and passes after the fix. All 105 transport tests and 16 CLI ownership tests pass. - The latest main was merged after these focused checks. Clean-main export-name collision checking passed at `25b2400af13218f379b306a2e4cc504288f320eb`; the channel collision was fixed upstream by `2f395451b88`. The same clean main reproduced the three lint errors in the untouched plugin-state observation cache and SQLite comparison test. Remaining baseline runs were stopped at maintainer request while upstream CI repairs were being merged. ### Review repair: empty API-key input - Empty or whitespace-only stdin now reports: `No API key was supplied. Rerun this command and paste a non-empty API key, or pipe one to stdin.` - Two short tests read real streams and cover both inputs. Both failed with the old `Required` message and pass after this change. - The changed-file gate passed formatting, core typechecking, and all six selected test graphs. It stopped at the unrelated `GatewayApprovalEventPublisherV2` unused export in `src/gateway/server-instance-runtime.types.ts`, which this repair does not modify. ### Existing CI failures checked on main - On clean main `e99d1a8c933639bea9961f7731624eb1ef3f3615`, the UI cloud-startup toast-recovery case fails with the same `Control UI readiness hook is unavailable` error as this branch (two cases pass, one fails). - The same clean main also reproduces the FIFO assertions missing `QUEUED_STEER_A` and `ORDINARY_MESSAGE_B`. Neither test nor its steer behavior is changed by this PR. - The document-steer case also fails on clean main, but earlier: the initial turn does not reach the mock provider (zero requests). On this branch it reaches the later missing-document assertion. The baseline failure prevents an exact comparison of that later assertion; it is not claimed as an identical local reproduction. - On the repaired head, [the Node shard](https://github.com/openclaw/openclaw/actions/runs/38082252267/job/114301617040) reports the same FIFO failures. A [separate cron shard](https://github.com/openclaw/openclaw/actions/runs/38082252267/job/114301616913) reports `hydrates runtime metadata for a reasoning-capable fallback candidate` (expected two calls, received four); its main-branch investigation is separate and no auth change is claimed to fix it. - `src/cli/plugin-local-state-owner.test.ts` has the same result on this branch (`5033eb75ade`) and clean main (`45943833ee81802976d1e7ef0650d668b13b6f5a`): 33 pass, one fails. The failed case is `routes memory search limits and JSON output through the discovered owner`; both report `The memory runtime does not support CLI search` inside `OUTCOME_UNKNOWN`. The fixture supplies a manager but not the `searchForCli` callback now required by the Memory Core handler. This is a main-branch fixture mismatch, not an auth routing regression; no test or routing behavior was changed to hide it. ### CI 38113017692: pinned per-file comparison Compared PR head `f062e5069509128680db873fa6643d262b034b0b` with its exact main parent `fece4b1cfc8b5778c0e8f69a8c9899f548038819`. Each file ran through the repository test runner under pueue. | File | PR result | Main result | Verdict | | --- | --- | --- | --- | | `src/gateway/server-methods/models-auth-api-key.integration.test.ts` | 1 failed: corrupt config revision key during startup | Same | Inherited; failure occurs before the auth RPC or acknowledgment | | `src/gateway/gateway-cli-plugin-routing.test.ts` | 1 failed: corrupt config revision key | Same | Inherited | | `src/gateway/server-methods/sessions-mutations.sticky-model.test.ts` | 3 failed, 66 passed: two undefined-error assertions and an invalid transcript frame | Same | Inherited | | `src/gateway/server.sessions.create-worktree-spawn.test.ts` | 1 failed, 18 passed: invalid transcript frame | Same | Inherited | | `src/gateway/server/ws-connection/connect-device-pairing.test.ts` | 12 failed: corrupt config revision key | Same | Inherited | | `src/gateway/session-message-events.test.ts` | Setup failed: corrupt config revision key; 30 skipped | Same | Inherited | | `src/gateway/session-message-events.exec-completion.test.ts` | Setup failed: corrupt config revision key; 2 skipped | Same | Inherited | | `src/gateway/session-message-events.history-worker.test.ts` | Setup failed: corrupt config revision key; 2 skipped | Same | Inherited | | `src/gateway/sessions-history-http.physical-source.test.ts` | 4 failed: corrupt config revision key | Same | Inherited | | `ui/src/pages/workboard/workboard-native-bundle.e2e.test.ts` | 2 passed (Chromium and WebKit) | Same | CI failure not reproduced on either revision | The config-revision owner unit file also passes both tests on both revisions. The Gateway integration failures therefore do not establish an auth-specific `configRevisionHash`/`appliedConfigHash` regression: they stop while loading the installation revision key. No corruption check was weakened and no test was changed to bypass startup. Workboard's initial missing dependencies/browser artifact were repaired before the successful comparison runs. No overlap with protected maintainer changes. Two-way code change: a revert restores offline-only CLI setup. Keys saved through the Gateway remain saved. The affected paths are local CLI API-key setup and the existing Gateway API-key save handler. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #167965
What Problem This Solves
Secret-store commands and
models refreshcan write SQLite from a second process while a Gateway owns the state directory, leaving its in-process state stale once foreign-commit probes are removed.User Impact
Team secret
set,rm, dotenv import, and allowed-host changes are applied by the running local Gateway. If no Gateway owns the state, the commands take exclusive offline ownership through write settlement and cleanup. An unreachable, replaced, or older owner produces an actionable refusal without replaying a possibly accepted write locally.models refreshnow requires the local Gateway to be stopped. Stop it through its service owner, run the refresh, then start it again. The Gateway's scheduled catalog refresh continues normally while running.Why This Change Was Made
The commands reuse
runWithLocalStateOwner. Existingsecrets.store.setandsecrets.store.deletemethods accept the expected owner identity; narrow import and allowed-host methods use the same mutation authority and runtime refresh owner. Import remains an atomic batch, inherited kind and argv protections are checked against authoritative rows, and allowed-host changes preserve the stored credential. The formerly native allowed-host write now uses the existing state worker and checks authority at transaction entry and commit.Catalog refresh retains its existing conditional 304/newer-result behavior and accepted-write settlement inside exclusive offline custody. The schema, stored representation, retention policy, durability, and operator scopes are unchanged; no migration or version bump is needed. Older clients retain the existing secret RPC contract. Older Gateways that cannot accept the owner-bound CLI mutation refuse it instead of receiving an unguarded write.
Evidence
A real Gateway-owner lock, authenticated WebSocket fixture, and separate CLI process prove live/offline secret writes, owner refusal, and lost-reply settlement without local replay. Live secret commands perform zero secret mutations in the CLI process; the owner's next reads observe set/import/host-policy/delete changes. The same fixture proves
models refreshrefuses while the owner is live and downloads/persists a synthetic HTTP catalog offline.The published-driver × candidate update cell passed on final head
c28b327e625a15907d5831a457bbb31816bca07a: published 2026.9.8 → candidate 2026.9.9, phasefinished,readyz=200, running version verified, durable and incognito state checks passed. Testbox run 38024777178, leasetbx_01m4j1p26z5qt74cedqsfeg8tn; package integrity passed and embedded commit matched. Update took 188.8 s; combined package/cell command took 10m13s. No schema migration is involved.Landing correction and exact-head CI
Commit
c28b327e625a15907d5831a457bbb31816bca07afixes a PR-caused prompt-schema regression:withSincemutates its schema argument, and the two newexpectedOwnerIdfields annotated the sharedNonEmptyStringobject. Fresh nonempty-string schemas keep version metadata local to those fields. No prompt snapshots or validation constraints were changed. Independent P0/P1 review of this two-line fix was clean.CI run 38023678177 passed on that exact head, including
check-prompt-snapshots, the Node test shards,security-fast, andopenclaw/ci-gate. The prior head's nine memory-recovery failures independently reproduced on maina285e8ba5841732229a931b3ed230b45574e09ccin Testbox run 38022094582; that code is unchanged by this PR. The passing final CI run does not claim those intermittent failures are repaired. No CI bypass is needed for this head.Final-head whole-workload pair (maintainer accepted)
Testbox run 38020389690 compared baseline
427f926e7c2d763e362f59678c6486b6f2f4aec4with reviewed head46b0945c9e8d811402f9e39605f8c7703ccbcee8in one baseline/candidate pair. Both workload executions passed. Total statements were 21,666 → 21,804 (+138, +0.6%); warmed statements/turn were 1,026.3 → 1,039.4. MAIN totals were unchanged at 2,506; worker-thread totals were 18,708 → 18,843 and helper-process totals 452 → 455. Workload durations were 43.7 s / 44.1 s.The maintainer coordinator explicitly accepted this pair as noise: harness pair-to-pair variance is at least ±3%; the increase is in unchanged worker-side schema/admission paths, and no changed-file SQL site executes during turns. This is an accepted variance exception, not a claim of reduced SQL or a passing strict non-increase gate.
This workload evidence is reused after the two-line schema-metadata correction above; it changes neither SQL nor the measured runtime paths.
Statements and worker requests
This is an outside-writer correctness change, with zero removed chat statements and zero removed chat worker requests attributed to this PR. Three strict alternating pairs compare base
427f926e7c2dwith the built runtime ata53b45d1df3e, on the same host and Node 24.21.0. All phase duration ratios are ≤1.154.Observed warmed-turn increase: +23.9 all-thread statements (+2.13%), from 1122 to 1145.9; requests 205.8 → 205.9. This does not pass the campaign's generic strict warmed-statement rule, and no such pass is claimed. The lane-specific instruction is to report turn-SQL changes for outside-writer routing; this PR claims correctness of the single-owner boundary, not a workload saving. Touched administrative command/RPC paths are absent from the harness workload; observed variation is in unchanged admission/background owners.
Values are per-phase medians [min–max] across three strict alternating pairs. Warmed counts/requests are per turn; warmed duration is the ten-turn window. All threads and helper processes are included; MAIN is Gateway thread 0.
Statement totals follow the harness's successful-statement accounting. Failed native admission attempts were base
[0, 2, 0]and candidate[1, 3, 0], confined to connect/first-turn windows; there were no warmed failures. These failed attempts are excluded from the successful-statement totals above. Every workload receipt succeeded.No cross-thread move is counted as a saving. The host-policy operation itself now has an off-thread worker request and no per-call schema ensure; it is outside this chat workload. The worker inventory confirms no T1 growth (707 → 707).
The final runtime differs from the measured artifact only in preserving the original allowed-host name validator, keeping the legacy set response unchanged for clients without
expectedOwnerId, and consistently returning settled refusal completion. Those changes emit identical SQL and do not run in measured chat paths. Test/tooling/docs changes likewise do not change the measured runtime. The measurement owner verified SHA-256 for 28,956 runtime artifact files before the final run; proof reuse is explicit rather than representing the measured artifact as a later source build.Exact selected-median-run statement attribution
Additive decomposition compares the actual run supplying each side’s total median (it is not the median of each class). Classes conserve every successful statement. No reduction is claimed as caused by this lane.
02.first-turn: base run 3, candidate run 3.
03.warmed: base run 2, candidate run 1.
The unchanged admission stacks include
refreshOpenClawAgentDatabaseSchema → openClaimedWriter/openWriter,getAdmittedSqliteSchemaFacts/readSqliteCacheDataVersion, andhasSqliteSessionOwnerColumns → prepareExactSessionEntryRowReads. First-turn reductions also include unchangedexecutePluginStateCommandand memorycreatePublicationBackendwork. The changed generic worker dispatch module appears for existing operations, andserver-aux-handlersappears only for its unchanged bootcloseOrphanedOperatorApprovalswork (12 statements per run). No secret mutation, CLI, or catalog-admin operation appears in these traces.Validation and costs
admin-state-owner.process.test.ts --maxWorkers=1 -t 'secret|catalog'secrets-store-cli.test.tssecrets-store-cli.kind-inheritance.test.ts --maxWorkers=1server-methods/secrets.test.ts --maxWorkers=1provider-auth-persistence.test.ts --maxWorkers=1models/refresh.test.ts --maxWorkers=136be39fb)The process cases take 1.7–8.0 s each and reuse one suite-level owner/socket fixture. A separate process is needed to prove lock discovery, authenticated routing, caller SQL placement, and no replay after transport loss. Most other measured time is import/compiler setup on the shared proof host. CI seconds are pending the first PR run.
check:changedpassed through both typecheck lanes, then stopped on the untouched base's direct config writer insrc/gateway/server-methods/agents.ts; main fixed that in959197ba0923. The separately completed dead-export scan found onlyisTelegramReadOnlyControlLaneTextandresolveContextTokensin untouched files; main removed those exports inafb4f0ff366b. Sparse type-aware lint passed after local fixture/return-consistency corrections, and the remaining planned guards passed. No unrelated source fix or main integration is included.Known P2 follow-up under the three-round review convergence rule: if a concurrent protection change causes validation to fail only in the Gateway after CLI preflight, the write still rolls back and no local replay occurs, but the CLI currently reports generic exit
1with conservative outcome guidance instead of the offline validation exit2. Ordinary input validation remains local with exit2. This is error classification only; the authoritative kind/argv/batch protections remain enforced.Original-path negative controls both failed for the intended reason: the old secret command produced four native secret-write observations in the CLI process instead of zero, and old catalog refresh succeeded with a live owner instead of refusing. Candidate command sources were restored exactly after the control run. All six candidate process cases passed; the negative-control file ran two selected failures and 29 skips.
All remaining planned guards passed. The only unresolved check results are the three untouched base findings already fixed on main, described above. The final sparse lint rerun passed in 77.13 s.
Production growth supplies the owner-bound RPC adapters and off-thread host-policy operation; shared mutation/reload logic stays with the existing secret owner. The previous native host-policy body and obsolete CLI reload hint are removed.