Repository navigation
fix(auth): cooldown inline api key billing failures - #88709
Patrick-Erichsen merged 23 commits into
Conversation
|
Codex review: found issues before merge. Reviewed August 3, 2026, 10:18 AM ET / 14:18 UTC. ClawSweeper reviewWhat this changesThe PR records billing and auth failures for inline Merge readinessKeep this PR open: it fixes the reported retry spiral, but its provider-scoped fail-closed cooldown has no supported recovery when an inline key is restored or replaced. The prior P1 remains on the identical head and needs an auth-policy decision before merge. Priority: P1 Review scores
Verification
How this fits togetherEmbedded agent failures update provider authentication state; model resolution, browsing, and tool-auth checks consume that state before offering an inline provider key. Stored auth profiles already have a deliberate re-authentication recovery flow, while this PR introduces a provider-scoped state row for inline keys. flowchart LR
A[Provider billing or auth failure] --> B[Embedded agent failover]
B --> C[Provider-scoped cooldown state]
C --> D[Model credential resolver]
C --> E[Browse and tool availability]
D --> F[Stored profile fallback]
D --> G[Inline key blocked]
H[Explicit re-authentication] --> F
Decision needed
Why: The branch correctly prevents repeated billing retries, but choosing whether deliberate key replacement, an explicit clear action, or expiry-only behavior is the durable operator contract cannot be resolved mechanically. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +347, Tests +719. Total +1066 across 25 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve the provider-level backoff, but add one supported, documented recovery contract for intentional inline-key remediation—preferably a generic explicit clear/reconfigure action that does not require editing state files—and cover both rotated-key and restored-credit flows. Do we have a high-confidence way to reproduce the issue? Yes, by source: an inline billing failure writes Is this the best way to solve the issue? No. Provider-level cooldown enforcement is a sound repair for repeated failures, but expiry-only recovery is not the best complete solution because the established re-authentication path clears only stored profiles and cannot clear the new inline state. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ffcca757eb3a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
2c33109 to
160ac62
Compare
|
Follow-up after CI guard failure on the replacement PR. Fix:
Additional validation:
|
160ac62 to
6db1364
Compare
|
Updated the Real behavior proof section with the local terminal probe output for the exact current head Latest proof status:
|
|
@clawsweeper re-review Addressed the remaining P1 prompt-stage no-profile marker gap. Change:
Current head: d1c43c4 Validation after this patch:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
The runner failure-marker now gates on isConfigBackedInlineProviderApiKey, so isInlineProviderApiKeyAuth has no remaining callers. Removing the dead export also trims one public callable export back under the plugin-SDK surface budget. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The inline-api-key cooldown was recorded for managed (file/exec) SecretRef provider keys but never enforced: these keys resolve through the synthetic runtime path (resolveSyntheticLocalProviderAuth) and the explicit api-key override path, neither of which consulted the inline-key cooldown gate. So an exhausted file/exec SecretRef provider kept resolving and reporting available during an active inline-api-key:<provider> cooldown. Gate both resolution exits (and the provider-availability check) on isConfigBackedInlineProviderApiKey + assertInlineProviderApiKeyUsable, matching the literal/env paths. Local no-auth markers are not config-backed inline keys, so they stay untouched. Adds regression coverage for both resolution paths. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Rebased this PR onto current Changes made:
Local verification:
Note: local @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Direct hasRuntimeAvailableProviderAuth callers omitted the auth store, so inline provider keys in billing cooldown were still advertised as available in model browsing (models.list) and model-backed tool auth checks. Pass the scoped auth store at each call site and cover the cooled-key paths with regression tests, including profile fallback and cooldown expiry. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Closed the remaining P1: direct @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Resolve conflicts and re-port the inline-api-key billing cooldown onto main's refactored auth/runner/browse modules (~5570 commits of drift). - model-auth.ts: interleave inline-key cooldown enforcement with main's new resolveDirectProviderCredentialMode / isAuthModeAllowedForModel mode gating. - Write side (run.ts was gutted into run/* modules): port the inline-key failure marker into failover-retry-controller.maybeMarkAuthProfileFailure (thread getApiKeyInfo) and relax the two prompt-failure.ts profile-id gates so inline keys record cooldowns on prompt failover. - Browse side (models-list-result.ts availability moved to model-auth-availability.ts): hide config-backed inline keys from browse availability while their inline cooldown is active. - tool auth (model-config.helpers.ts): keep store threading through the runtime availability checks. - usage.ts: align markInlineProviderApiKeyFailure with main's no-arg resolveAuthCooldownConfig (main dropped configurable per-provider cooldowns); drop the now-obsolete per-provider-override regression test. - plugin-sdk surface budgets: keep main's values (our exports are not SDK surface; report confirms 4721/2879). Validated: 618 targeted tests pass, tsgo core typecheck clean, plugin-sdk surface check passes. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Merged current
The branch is now current with @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…ndependence) - failover-retry-controller.ts: apply oxfmt formatting missed after the port. - model-auth-availability.ts: the browse-side inline cooldown check imported resolveInlineProviderApiKeyUnusableUntil from the auth-profiles usage module, which several command/directive tests partially mock — the new export was absent from those mocks, so every mocking test threw at the browse path. Read the inline cooldown via usage-state primitives (resolveProfileUnusableUntil + isAuthCooldownBypassedForProvider) and build the usage id with the same normalizeProviderId the write side uses, so the hot browse path no longer depends on the mocked usage module while keeping key resolution identical. Co-Authored-By: Claude Fable 5 <[email protected]>
resolveApiKeyForProvider/assertInlineProviderApiKeyUsable read the inline provider API-key cooldown, which this PR routes through the auth-profiles usage module. Many existing suites partially mock that barrel (e.g. run.overflow-compaction.test.ts) without the new export, so those tests threw once merged code reached the inline path. Read the cooldown via usage-state primitives (resolveProfileUnusableUntil + isAuthCooldownBypassedForProvider) and build the `inline-api-key:<provider>` usage id with the same normalizeProviderId the write side uses, so model-auth no longer depends on the mocked usage module while key resolution stays identical. Verified across all 30 suites that mock the auth-profiles module. Co-Authored-By: Claude Fable 5 <[email protected]>
|
CI is now fully green on the merged branch ( Since the last re-review I merged current
Verified locally: the full set of suites that mock the auth-profiles module (1557 tests) pass, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
The previous re-review looks like it stalled: ClawSweeper posted "review started" ~20h ago (2026-07-22 12:26 UTC) but never followed up with a verdict, and the PR has had no activity since — so that run didn't complete and the Nothing has changed on the branch in the meantime: it's still merged with current @clawsweeper re-review |
Main split the model-auth monolith into a facade plus responsibility-focused modules, so the inline-api-key cooldown had to be re-ported onto that layout rather than merged mechanically. - model-auth.ts: take main's facade; re-export isConfigBackedInlineProviderApiKey so the runner's failure marker keeps its import path. - model-auth-provider-config.ts: home for the shared inline-key helpers (isConfigBackedInlineProviderApiKey, resolveInlineProviderApiKeyCooldownUntil, assertInlineProviderApiKeyUsable). Both the provider and runtime modules already import this module, and the cooldown read still goes through usage-state primitives so partially-mocked suites keep working. - model-auth-provider.ts: fail closed on a cooling inline key at each site that returns one (env-first and profile-first env paths, managed SecretRef runtime auth, and both custom-key returns), reusing the module's getScopedStore(). - model-auth-runtime.ts: restore the optional auth store on hasRuntimeAvailableProviderAuth and gate the env/custom/managed branches on the inline cooldown, so browse and tool selection hide a cooled key. - model-auth-model.ts: resolve the store before the env/custom/synthetic checks in hasAvailableAuthForProvider and apply the same gate. Validated: 844 targeted tests pass across the auth, browse, tool, command and failover suites; tsgo core typecheck clean for these modules; oxfmt clean. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Merged current Main split the model-auth monolith into a facade plus responsibility-focused modules since the last merge, so the cooldown was re-ported onto that layout rather than merged mechanically:
Verified locally: 844 targeted tests pass across the auth, browse, tool, command and failover suites; On the open question about recovery after credit restoration — that concern is real, and I'd rather flag it precisely than paper over it. There is an asymmetry in the current design:
Net effect: a user who tops up credit immediately after a 402 still waits out the window (5h default, escalating toward the 24h cap on repeat failures), and That is a product/policy decision rather than a mechanical fix, which is why I have not changed it unilaterally. The options I see, smallest first:
Happy to implement whichever direction maintainers prefer — or to reduce the PR to the detection/marking half and leave enforcement policy for a follow-up, if that lands more easily. |
…ng case
Main reworked EmbeddedRunAttemptResult so attempt failures are reported via
`terminal: { kind: "failed", source, error }` instead of the old
`promptError`/`promptErrorSource` fields. The inline-key billing regression
test still used the removed fields, which merged cleanly but broke
check-test-types.
Switch it to the same shape the sibling helper in this file already uses.
Verified with `pnpm check:test-types` (exit 0).
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Refreshed the Real behavior proof section in the PR body at the current head ( It now shows a live run against the real production modules (no vitest, no mocks, isolated home/agent dir) covering each requested item: failure marking ( The body also now states the recovery scope explicitly: it is expiry-only today. Stored profiles clear their cooldown on success ( Also fixed the @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Offer: split this into a small mechanical PR + a separate policy PRThis PR is PR A — record only (no behavior change). Adds the provider-scoped failure marker so an inline PR B — enforcement policy. Everything that acts on that state: failing closed during the window in Being explicit about the tradeoff: PR A on its own does not fix the reported symptom — the retry spiral in #39807 stops only once enforcement lands in B. A is the narrow, reviewable foundation; B is where the policy call belongs. Happy to do this split, keep it as one PR, or reshape it some other way — whichever is easiest to review. Just say which and I'll turn it around. For reference, current state of this PR: merged with current |
Single conflict in model-config.helpers.ts: main added `runtimeLookup` to the `hasRuntimeAvailableProviderAuth` call in hasProviderAuthForTool while this branch added the scoped auth `store` to the same call. Both are needed, so keep them together rather than picking a side. Validated: 746 targeted tests pass across the auth, browse, tool, command and directive suites; `pnpm check:test-types` is clean; oxfmt is clean. Co-Authored-By: Claude Fable 5 <[email protected]>
Three conflicts, all where this branch's inline-key cooldown meets main's ongoing auth refactor: - model-auth-availability.ts: keep both sides of the import block — main's new listProviderEnvAuthLookupKeys and this branch's usage-state primitives. - model-auth-provider-config.ts: adopt main's restructured imports (order.js / types.js, resolveApiKeyForProfile now imported dynamically) and its un-exported isCustomLocalProviderConfig, keeping the inline-key helpers. - auth-profile-rotation.e2e.test.ts: keep this branch's inline-key billing regression test and honor main's removal of its deferred-mark test, whose authProfileUsageTesting hook no longer exists. Validated: 563 targeted tests pass; `pnpm check:test-types` clean; oxfmt clean. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Maintainer decision: we accept the provider-scoped, expiry-only recovery policy for inline API-key auth/billing cooldowns in this PR. The intended scope is to stop the retry spiral while preserving the existing inline-key path; we are not requiring credential migration, synthetic auth profiles, or an early clear after key replacement/credit restoration in this change. Healthy stored profiles remain available independently during the window. One wording correction for the record: current Proceeding through the guarded landing workflow on head |
|
Merged via squash.
|
Summary
models.providers.<id>.apiKeycredentialsCloses #39807.
Real behavior proof
inline-api-key:<provider>), fail closed while that cooldown is active, stay hidden from model browsing and model-backed tool auth during it, keep healthy stored profiles usable as fallback, and become usable again once the window expires.upstream/main, branch head80595c9ae7a.HOME=$(mktemp -d) OPENCLAW_HOME=$HOME/.openclaw node --import tsx proof.ts— the driver builds a throwaway agent dir plus a config carrying an inlinemodels.providers.proofprov.apiKey, then callsresolveApiKeyForProvider,markInlineProviderApiKeyFailure,hasRuntimeAvailableProviderAuthandhasAvailableAuthForProviderdirectly.node node_modules/.bin/vitest runover the auth, browse, tool, command and failover suites (844 tests).pnpm check:test-typesnode scripts/run-tsgo.mjs -p tsconfig.core.json./node_modules/.bin/oxfmt --checkon the touched files.80595c9ae7a(keys are placeholders by construction):inline-api-key:proofprovwithdisabledReason=billingand a 5h window; model auth then failed closed on reuse with the temporary-disabled message, and both browse (hasRuntimeAvailableProviderAuth) and model auth (hasAvailableAuthForProvider) reported the provider unavailable. Adding a healthy stored profile restored resolution throughprofile:proofprov:backupwhile the inline key stayed cooled and stayed hidden from browse. After the window lapsed, the inline key resolved again and availability returned.markAuthProfileSuccess→resetSuccessfulUsageStatsresetsdisabledUntil/errorCount), but inline keys have no success counterpart, and because they fail closed while cooling no request is attempted, so nothing clears the state early — a user who restores credit still waits out the window, anderrorCountnever resets so repeat failures escalate toward the 24h cap. This is left as a maintainer policy call; candidate directions are success-clear parity, a half-open probe after expiry, an explicit clear command, or a shorter initial billing backoff for inline keys.*.e2e.test.tsregression file is excluded from the local vitest projects, so its behavioral run is covered by CI rather than locally.Background
This replaces the closed polluted PR #80482 with the same intended auth-runtime fix rebuilt as a clean branch from current upstream/main.