Skip to content

fix(models): unblock requests after saving a replacement API key - #169528

Merged
obviyus merged 1 commit into
mainfrom
fix/models-api-key-cooldown-current
Oct 12, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/models-api-key-cooldown-current

Conversation

@obviyus

@obviyus obviyus commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #151354. Carries forward the saved-profile repair from #160452, which conflicts with current main.

What Problem This Solves

Fixes: after a provider key hits a rate limit, saving a replacement in Settings → Models reports success but the next request is still blocked by the old key's cooldown.

User Impact

User impact: operators can use a replacement API key immediately without restarting the Gateway or waiting for the old key's cooldown. Other accounts, profile order, and usage history stay unchanged.

Why This Change Was Made

Clear only the replaced profile's failure state in the same locked credential write. Models and models auth paste-api-key already share this writer; generic writes remain health-preserving unless explicitly asked to reset.

Why it was this way: #124014 deliberately restricted failure-state resets to successful credential replacement rather than clearing every account before login; #144420 later shared manual key editing through the generic writer without opting into that reset. This applies the existing scoped-reset contract to manual keys while keeping its sibling-account and usage-history protections.

Evidence

Built isolated Gateways with a loopback OpenAI-compatible stub and dummy keys. Both runs use the actual Models page's Set API key action, then the already-connected Gateway transport for the next agent request:

Step Current main (cbba7e2e2ef4) This change (6dfd10508f8a)
Save key A; request returns HTTP 429 Rate-limit failure and persisted cooldown Same
Save key B in Models “Secret saved.” “Secret saved.”
Immediately request again Auth profile "rotation:manual" is temporarily unavailable; zero provider calls Stub receives key B and replies “Key B works immediately after rotation.”

The screenshots show the saved-key state. The request results above come from Gateway responses and the stub's recorded requests, not from an inferred screenshot result.

Before After
Before: replacement saved but model remains unavailable After: replacement saved and model is available
  • Extended the existing configured/explicit/ordered key-replacement regression: all three cases fail on main because the old cooldown and failure count survive; all pass with the fix. It also preserves a sibling's failure state and the replaced profile's lastUsed.
  • Focused command, locked SQLite writer, and Gateway auth suites: 152 tests passed across four files. Formatting and git diff --check passed.
  • Final bounded Codex review found no actionable defects.

Scope: saved API-key replacement only. The second issue report about stale stored credentials taking precedence over a directly edited config key remains separate; this does not change credential precedence, doctor migration, or logging.

Merge danger: two-way door for future saves; reverting restores the old save behavior, but cannot reconstruct cooldown counters already cleared. Blast radius is the one saved API-key profile explicitly replaced through Models or the shared CLI writer. No schema, permission, storage-location, or credential-disclosure changes.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 commands Command implementations labels Oct 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 12, 2026
@github-actions

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: 6dfd10508f8a1d1e5ae7373cc60c2861629082b5
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/upsert-with-lock.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Saving a replacement API key clears that profile’s old failure state so requests can try the new key immediately.

Example: The rotation:manual profile receives HTTP 429 with key A, then an operator saves key B in Models.

  • Before: The save succeeds, but the next request is rejected locally by key A’s retained cooldown.
  • After: The next request reaches the provider with key B and receives a reply.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong production-path proof and a focused repair; the overall rating reflects intentionally partial coverage of the broader linked issue.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied evidence exercises the actual Models Set API key action and an already-connected built Gateway against an isolated HTTP 429 stub, then records key B reaching the provider and receiving a reply; inspected screenshots corroborate restored availability.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Saving a working replacement key reports success while the old key’s cooldown still prevents the next request.
Reason: Maintainer direction and observed recovery failure justify this narrow repair; it covers saved-profile replacement while deliberately leaving the linked issue’s separate config-key precedence concern open.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a current credential-replacement bug at the existing writer, with convincing production-path evidence and no actionable findings.

Priority: P0
Reviewed head: 6dfd10508f8a1d1e5ae7373cc60c2861629082b5

Before merge

None.

Findings

None.

Agent review details

How this fits together

Models and CLI API-key saves share a credential writer that persists credentials and profile health through the existing SQLite owner and publishes updated runtime state.

flowchart TD
  A[Models settings] --> C[Shared API key saver]
  B[Models auth CLI] --> C
  C --> D[Locked profile updater]
  D --> E[SQLite credentials and health]
  E --> F[Runtime auth selection]
  F --> G[Provider request]
Loading

Technical review

Best possible solution:

Make Models’ existing Set API key action restore requests immediately by clearing only the replaced profile’s obsolete failure state in the credential transaction.

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

Yes: current-main source retains cooldown state during manual key replacement, and the supplied before/after Gateway scenario demonstrates the resulting local rejection; this review executed no target code.

Is this the best way to solve the issue?

The repair belongs in the shared credential writer and correctly reuses the existing scoped-reset contract without adding another refresh mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared manual API-key persistence keeps the original intent (09e2b15: Unify Models and CLI editing while preserving credential metadata, selected models, references, and account ownership.)
  • Failure-state reset after successful replacement keeps the original intent (fix(auth): reset only the profile replaced by a successful login #124014: Clear failure state only after successful replacement of the exact profile, preserving unrelated accounts and history.)
  • Gateway-owned credential writes keeps the original intent (408a1f3: Allow API-key setup through the live local Gateway while retaining owner-bound dispatch and write-time authority checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 09e2b15 adds src/commands/models/auth-api-key.ts:143 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 09e2b15466e1; files: src/commands/models/auth-api-key.ts)
  • Vincent Koc: Raw commit b824b72 adds src/agents/auth-profiles/upsert-with-lock.ts:224 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b824b72ce284; files: src/agents/auth-profiles/upsert-with-lock.ts)

PR surface

Source +6, Tests +19, Docs +4. Total +29 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 6 0 +6
Tests 2 19 0 +19
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 29 0 +29

Root-cause cluster

Relationship: partial_overlap
Canonical: #151354
Summary: This PR repairs the saved-profile cooldown portion of the broader key-rotation report and carries forward the earlier contributor patch.

Members:

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

Labels

Label changes:

  • add P0: Models can report a successful replacement while useful requests remain blocked, leaving community users without effective in-product recovery until cooldown expiry or a technical restart.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P0: Models can report a successful replacement while useful requests remain blocked, leaving community users without effective in-product recovery until cooldown expiry or a technical restart.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 11, 2026, 10:11 PM ET / October 12, 2026, 02:11 UTC.

@obviyus

obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override

The only failing CI job is checks-node-compact-small-1 in run https://github.com/openclaw/openclaw/actions/runs/38194372331 (attempt 2), with the derived openclaw/ci-gate failure. Its test/scripts/eager-import-closure.test.ts:173 duplicate wrapper-inventory assertion reports src/chat/sender-identity.ts, src/sessions/input-provenance.ts, and src/sessions/user-turn-transcript.metadata.ts.

The identical failure is proven on clean main 44f538c1855de6924851f56d23018852a7e3e86c: #169511 (comment). Current origin/main 1b77dd5c6557 still lists each of those paths twice. This PR changes only the saved API-key writer, its regression tests, and model-auth documentation; it does not change the wrapper inventory or those files.

After the initial fail-fast cancellation, the failed/cancelled jobs were rerun once. All applicable jobs have now completed; only this known main failure and its aggregate remain red. The exact head 6dfd10508f8a1d1e5ae7373cc60c2861629082b5 has a ClawSweeper ready review with no findings: #169528 (comment). Ayaan approved this bounded unrelated-main-failure exception.

@obviyus
obviyus merged commit 2b9aa2e into main Oct 12, 2026
166 of 198 checks passed
@obviyus
obviyus deleted the fix/models-api-key-cooldown-current branch October 12, 2026 02:20
@obviyus

obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merged as 2b9aa2e. Models and the shared CLI API-key save now clear only the replaced profile’s stale failure state. The real Models → Set API key flow reproduced zero provider calls after rotation on main and a successful key-B request with this fix; all 152 focused tests passed. Exact-head ClawSweeper was ready. Required jobs completed on CI attempt 2; the sole unrelated wrapper-inventory failure used the documented maintainer override. Thank you @masatohoshino for the original fix and @blance2599 for the report. The separate stored-versus-config credential-precedence report remains open.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…nclaw#169528)

Related: openclaw#151354. Carries forward the saved-profile repair from openclaw#160452, which conflicts with current main.

## What Problem This Solves

Fixes: after a provider key hits a rate limit, saving a replacement in Settings → Models reports success but the next request is still blocked by the old key's cooldown.

## User Impact

User impact: operators can use a replacement API key immediately without restarting the Gateway or waiting for the old key's cooldown. Other accounts, profile order, and usage history stay unchanged.

## Why This Change Was Made

Clear only the replaced profile's failure state in the same locked credential write. Models and `models auth paste-api-key` already share this writer; generic writes remain health-preserving unless explicitly asked to reset.

Why it was this way: openclaw#124014 deliberately restricted failure-state resets to successful credential replacement rather than clearing every account before login; openclaw#144420 later shared manual key editing through the generic writer without opting into that reset. This applies the existing scoped-reset contract to manual keys while keeping its sibling-account and usage-history protections.

No overlap with Pash/Sarah changes.

## Evidence

Built isolated Gateways with a loopback OpenAI-compatible stub and dummy keys. Both runs use the actual Models page's **Set API key** action, then the already-connected Gateway transport for the next agent request:

| Step | Current main (`b372edb6424e`) | This change (`6dfd10508f8a`) |
| --- | --- | --- |
| Save key A; request returns HTTP 429 | Rate-limit failure and persisted cooldown | Same |
| Save key B in Models | “Secret saved.” | “Secret saved.” |
| Immediately request again | `Auth profile "rotation:manual" is temporarily unavailable`; zero provider calls | Stub receives key B and replies “Key B works immediately after rotation.” |

The screenshots show the saved-key state. The request results above come from Gateway responses and the stub's recorded requests, not from an inferred screenshot result.

| Before | After |
| --- | --- |
| ![Before: replacement saved but model remains unavailable](https://github.com/user-attachments/assets/59947379-f7ee-497c-9d5f-8b7e11212895) | ![After: replacement saved and model is available](https://github.com/user-attachments/assets/e4ec28d3-222e-4881-8fe2-27e99ccf617e) |

- Extended the existing configured/explicit/ordered key-replacement regression: all three cases fail on main because the old cooldown and failure count survive; all pass with the fix. It also preserves a sibling's failure state and the replaced profile's `lastUsed`.
- Focused command, locked SQLite writer, and Gateway auth suites: **152 tests passed across four files**. Formatting and `git diff --check` passed.
- Final bounded Codex review found no actionable defects.

Scope: saved API-key replacement only. The second issue report about stale stored credentials taking precedence over a directly edited config key remains separate; this does not change credential precedence, doctor migration, or logging.

Merge danger: two-way door for future saves; reverting restores the old save behavior, but cannot reconstruct cooldown counters already cleared. Blast radius is the one saved API-key profile explicitly replaced through Models or the shared CLI writer. No schema, permission, storage-location, or credential-disclosure changes.

Co-authored-by: Masato Hoshino <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation security-sensitive-changed size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant