Repository navigation
fix(models): preserve replacement keys during removal - #145143
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: blocked before merge. Reviewed September 11, 2026, 3:23 PM ET / 19:23 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR preserves concurrently replaced model credentials during removal, reports unconfirmed Gateway application, and exercises rollback through registered CLI and Gateway handlers. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful repair: current main lacks the binding comparison that prevents removal from deleting a concurrently saved replacement. No blocking patch defect was found, and the supplied runtime evidence remains applicable. Priority: P2 Review scores
Verification
How this fits togetherThe Models page and CLI share OpenClaw’s credential-removal owner. It updates provider configuration and credential stores, then refreshes Gateway authentication state and returns success or recovery guidance. flowchart TD
A[Models page or CLI] --> B[Shared credential removal]
C[Concurrent key save] --> D[Locked configuration snapshot]
B --> D
D --> E{Selected binding unchanged?}
E -->|No| F[Preserve replacement and report conflict]
E -->|Yes| G[Remove selected credentials]
G --> H[Confirm application or return restart guidance]
Decision needed
Why: The available records do not establish listed-owner authorship, an explicit owner request, or active owner review. Before merge
Agent review detailsSecurityNone. PR surfaceSource +70, Tests +306. Total +376 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep credential removal within the shared config and store owners, preserving replacement bindings and reporting application outcomes through existing client warning fields. Do we have a high-confidence way to reproduce the issue? Yes: hold removal before config-lock acquisition, save a replacement through the registered CLI, then resume removal. Current-main source supports the failure, and the supplied body records before/after results; this review did not execute it. Is this the best way to solve the issue? Yes: comparing authored bindings inside the existing config writer is a focused repair, and reusing the application receipt avoids a competing reload mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f770fd99e0ce. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
landpr-approve-admin-merge |
|
landpr-approve-unrelated-red |
|
Merged after verified Gateway, CLI, and Models-page proof.
Validation: Real Gateway/CLI race on the pinned base and candidate; both Models-page messages captured in a real browser; five Gateway/CLI integration cases; 14 logout and 26 sibling cases; retained provenance/status suites; previous-release state; 16 direct config-corpus starts, plus a separate documented repair path for the base-matching legacy fixture. No schema or migration change. All structural and type checks passed. Two unrelated CI failures were reproduced on the exact CI base
Both reach the new published-commit author lookup added by #145128 in Landing uses the recorded owner-review exception and completed-run unrelated-red approval, with a fresh exact-head review and guarded merge. The owner-review exception resolves procedural involvement only; no code or security finding was waived. |
Related: openclaw#144420 ## What Problem This Solves Fixes an issue where removing an API key on Models could delete a replacement another client had just saved. The pending removal returned success even though it removed the newer key. The same Gateway method backs the web control. ## Why This Change Was Made The shared credential-removal owner now compares the admitted provider bindings with the source snapshot held by the config writer before any cleanup. It rejects changed literals, profile bindings, and secret references, including a new environment reference that resolves to identical bytes. Cleanup uses that same source snapshot and preserves externally managed keys. Unrelated provider edits and aliases without keys do not block removal. The same owner waits for the existing config-application receipt after store work. If application is not confirmed, Gateway and CLI return restart guidance; disabled reload remains disabled. This corrects the unguarded inline cleanup introduced in openclaw#144420 (`f6c20d2a5acf6b4859d387e5914107d146d78055`). Stored-profile generation checks remain in their existing store owner. No schema, migration, config option, or protocol field changes. ## User Impact A concurrent save wins. For a changed inline binding, removal reports: “The key changed while removing it. Nothing was removed. Reload Models and retry removal.” Ordinary removal still succeeds, and environment-backed keys remain managed by their source. With normal reload, status is current before acknowledgment. With reload disabled, users receive a restart warning. ## Evidence - Pinned main `fed8935cfa6e85f9361cd7005421058a9a749a69`: real Gateway `models.authLogout`, held at the config lock, then public CLI `config set` saved B in 1.696 seconds. Readback showed B before removal resumed. Removal then returned success and deleted B (probe exit 1). - The same real Gateway/CLI probe with the owner fix preserves B and returns the changed-key error. An additional external-process probe exposed and corrected same-value environment-reference replacement. - Five registered Gateway/CLI cases pass, 40 existing auth cases pass, 17 focused provenance cases pass, and 115 existing status-adapter cases pass. The original three regression cases fail on the original owner and pass on the candidate. Complete private transcripts retain commands, source identities, results, and scheduling controls. - Independent validation passes all eight runtime clauses (source blindness is self-attested) on `523fdbf7c33a0a3d080827eb7edd47fc33c9e740`: literal/reference races, status refresh/restart, observed reload acknowledgment, keyless alias, and real CLI stored-profile race. Config saves completed in 1.49–1.74 seconds. Subsequent revisions correct test typing and move rollback tests through registered dispatch; production files are identical to that validated head. - Sixteen sanitized config-corpus fixtures started a real Gateway with fake credentials and no inference. The legacy-roster fixture is rejected before startup on both the pinned base and candidate because its provider API value is the retired `openai` spelling (wrapper exit 1; inner CLI exit 78). On the candidate, the documented `doctor --fix --non-interactive` repair exits 0 and the repaired fixture starts successfully. Original and repaired inputs and full failures are retained. One successful fixture uses the supported Tailscale-off launch override because external publishing is outside the isolated test environment. - Real web Models page: clicking Remove key during a concurrent CLI save renders the changed-key error; persisted B remains. The browser race save completed in 2.695 seconds. A fresh click with reload disabled deletes the saved key and renders restart guidance. Both sanitized screenshots were visually inspected; fixture processes were stopped after capture. ## Consumers - `removeModelAuthCredentials` serves registered Gateway `models.authLogout` (`src/gateway/server-methods/models-auth-status.ts`) and CLI `models auth logout` (`src/cli/models-cli.ts`, `src/commands/models/auth-logout.ts`). Models API-key controls and saved-profile controls call that Gateway method (`ui/src/pages/model-providers/config-mutation.ts`, `profile-actions-controller.ts`). Native request types and logout result fields remain unchanged. - The inline value is `models.providers.*.apiKey`. Writers include registered CLI `config set`, Gateway config mutations, `models.authSetApiKey`, CLI manual-key login, and setup/config writers. All removal decisions run under the common config writer regardless of the replacement writer. - Stored generation targets remain private to `src/agents/auth-profiles/profiles.ts`; `createAuthProfileRemovalTarget`, `authProfileRemovalTargetMatches`, surviving-profile reads, OAuth locking, peer cleanup, and pre-delete comparison are unchanged. Doctor's `doctor-health-contribution-runners.config.ts` and login/setup callers of `removeProviderAuthProfilesWithLock` (model auth, LM Studio, llama.cpp, and provider-auth SDK adapters) retain their existing paths. - `resolveProviderConfigSecretInput` gains an optional authoritative source snapshot; omitted arguments retain current behavior. Direct readers: `src/cli/capability-cli/model.account-secrets.provenance.test.ts` (direct resolver test), `doctor-model-catalog-credentials.ts`, `commands/models/list.auth-overview.ts`, `commands/models/auth-api-key.ts`, `agents/runtime-plan/prepare-auth.ts`, `agents/model-auth-availability.ts`, `gateway/server-methods/models-auth-status-api-keys.ts`, and local `getCustomProviderApiKey`, `resolveUsableCustomProviderApiKey`, `resolveProviderEntryApiKeyProfileReference`, `isConfigBackedInlineProviderApiKey`, `hasSecretRefProviderApiKey`, and `resolveRuntimeProviderConfigApiKeyAuth` in `agents/model-auth-provider-config.ts`. - `resolveProviderEntryApiKeyProfileReference` carries that optional snapshot to the resolver. Existing readers remain unchanged: `commands/models/list.probe.ts`, `commands/models/auth-api-key.ts`, `agents/tools/model-config.helpers.ts`, `plugins/provider-auth-availability-core.ts`, `agents/runtime-plan/prepare-auth.ts`, `agents/model-auth-availability.ts`, `agents/model-auth-provider.ts`, `agents/model-auth-label.ts`, Gateway `models-auth-status-config.ts` and `models-auth-status-api-keys.ts`, its local binding reader, and the `agents/model-auth.ts` barrel. No direct calls in extensions, UI, native apps, or schemas require migration. - The remover now returns an optional warning; its Gateway and CLI callers consume it. Existing UI API-key and saved-profile controls already display the warning field. `startGatewayWithClient` forwards the existing optional server recovery callback so the integration test uses the full reload lifecycle; callers omitting it are unchanged. No public symbol or field is removed. The authored binding is checked at the final writer and asserted in persisted readback after the Gateway response. - Existing `startGatewayWithClient` callers (under `src/gateway/`) are `test-helpers.acquisition.test.ts`, `session-delivery-clock-jump.integration.test.ts`, `server.incognito-transcript-reconcile.test.ts`, `test-helpers.server-env.test.ts`, `server.chat-first-turn-binding.test.ts`, `gateway-allowlist-store-read-failure.e2e.test.ts`, `gateway.compaction-hot-reload.e2e.test.ts`, `link-understanding.product.test.ts`, `server.startup-recovery-webchat.test.ts`, `gateway.test.ts`, `server-rpc-restart-owner.test.ts`, `gateway-workshop-learning.e2e.test.ts`, `gateway-agent-skill-refresh.e2e.test.ts`, and `server-methods/{models-auth-refresh.integration,models-auth-refresh.catalog.integration,chat.abort-live-proof,chat.reset-visible-yield}.test.ts`. They omit the optional recovery callback and retain their current behavior. The new removal integration test supplies it. ## Contention The existing per-config-path queue and cross-process file lock (`src/config/write-lock.ts`) serialize config writers. The added comparison is synchronous and holds no new lock. Credential-store transactions and later OAuth locks remain unchanged; the inline-only case has no OAuth lock keys. Runtime preparation and awaiting the application receipt stay outside config/store locks. The originating Gateway request continuation lets the existing reload owner exclude that request from its own drain. The real external CLI save completes while removal is pending; final clean-commit timing is recorded with the proof. ## Invalidation The admitted binding map lasts for one request and creates no cache. A rejected removal performs no mutation. Successful replacement writers retain ownership of config reload and credential publication. Successful removal awaits observed config application, or reports unconfirmed application with restart guidance, then retains existing Gateway/CLI auth refresh, shared-store ownership reload, usage-cache clearing, credential snapshot invalidation, and prepared-runtime refresh. Config reload, explicit auth refresh, and restart remain the existing refresh paths; status is checked from settled state in runtime proof. Startup/refresh scope unification, Telegram, and new-account flows are outside this removal repair. Browser proof covers the existing Models error and restart-guidance consumers. ## Tests - New `models-auth-removal.integration.test.ts`: registered Gateway `models.authLogout` and registered CLI `config set`, with the real config lock, store, and remover. Covers changed literal, changed secret reference, equal-byte environment reference, unrelated-provider save, preservation of an existing environment-backed alias, and fresh status after hybrid reload. Disabled reload requires a warning. The real recovery callback is supplied and asserted unused. - `auth-logout.test.ts`: existing command-level cases retain their assertions and receive the config writer's `runtimeConfig` callback context. The incomplete/throw rollback rows now enter registered CLI `models auth logout` through Commander. Partial multi-store removal and API-key-only failure/retry enter the normal Gateway registry through `handleGatewayRequest` for `models.authLogout`. These tests inject store failures and use an in-memory config writer; the real selection, removal, and restoration owners execute. They are registered-dispatch tests, not live database/WebSocket proof. The separate real Gateway suite covers refresh/status. - `auth-api-key.test.ts`: existing key editing/removal sibling cases retained and run. - `model-auth.test.ts`: existing provider snapshot and custom-key provenance cases verify unchanged resolver defaults. - Previous-release state: published `[email protected]` saved the key through its CLI. The candidate Gateway started on that state, removed the key, and reported no key after restart. No state routing or schema changes. ## Deletion ledger No test or state assertion is deleted or weakened. The config double supplies the real callback context. The formerly helper-only “restores surviving config when store removal…” rows move to registered CLI dispatch; “restores only surviving references after partial multi-store removal” and “preserves an untargeted token binding through failed API-key removal and retry” move to registered Gateway dispatch in the same test file. Partial removal and retry now update the fake store to match the production boundary; Gateway selects the actual API-key profile instead of a hard-coded selection. The existing removal and restoration owners remain unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Removing a key from Models could delete a replacement saved by another client while removal was pending.
Why This Change Was Made
The shared removal owner compares current credential bindings under the config writer before cleanup and rejects changed bindings, including references resolving to the same value. It waits for config application and reports restart guidance when application is unconfirmed. This corrects the cleanup introduced in #144420.
User Impact
Concurrent replacements survive removal. Externally managed keys keep their source ownership. Normal removal reports current status; disabled reload produces a restart warning. No configuration or schema change is required.
Evidence
Real Gateway logout and CLI config-save races reproduced deletion before the fix and preserved the replacement afterward. Browser Remove key captures verify the error and restart guidance. Registered Gateway/CLI regressions, auth and provenance tests passed. Previous-release key removal and restart passed; the config startup corpus passed after documented repair of its legacy fixture.
Related: #144420.