Skip to content

fix(gateway): provider usage follows reloaded account config - #124131

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-refill-usage-status-outcomes-v2
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-refill-usage-status-outcomes-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #121799

What Problem This Solves

Fixes an issue where provider usage could show no provider or the wrong account after runtime configuration changed, because the cache refresh could fetch through an ambient configuration different from the configuration that keyed the cache.

Why This Change Was Made

The provider-usage cache now carries its exact OpenClawConfig into the provider loader. The configuration that determines cache ownership is therefore also the configuration used for provider discovery, account selection, and usage fetches.

This is complementary to #121799: that PR changes cold-read behavior and cache identity, but its current head still does not pass the exact runtime config into loadProviderUsageSummary. This PR does not change provider auth, routing, defaults, billing semantics, public protocol/SDK, configuration shape, persistence, or schema.

Production growth is one line (+5/-4): the single added capability is the missing owner-boundary handoff from cache refresh to provider loading. The other production edits tighten the existing cache config types.

User Impact

Provider plan, quota, balance, and account data now follows the active runtime configuration after account or provider changes. Identical configuration reuses the correct cached value; a different account/configuration receives an isolated value; one provider error or timeout does not hide successful providers.

No CHANGELOG.md edit is included. Release generation owns changelog updates for normal fixes.

Evidence

Exact candidate:

  • Head: fbc479feec2303aeba3f3b3770e978969114238f
  • Tree: ecd20f392c9d4e8c9da7006048fec960c3408067
  • Base: 447393dc3221e14f63dc9b3818ddd04051553936
  • Production: +5/-4 (net +1)
  • Tests: +27/-0

Source-blind built-Gateway proof on Blacksmith Testbox tbx_01m02aygy1hdqmja1jkqyca8a5 (run 31876290317) used an isolated state directory, free loopback ports, and a controlled local provider with no external credentials:

  • Ambient config/account B returned proof-b / [email protected].
  • Hot-applied runtime config A fetched proof-a / A; no B request occurred, and usage.status returned [email protected] instead of an empty healthy payload.
  • The second A request was byte-identical and generated zero provider requests.
  • Config/account C generated a new proof-c / C request and response rather than reusing A.
  • Controlled success + HTTP 503 + timeout completed in 6.832s: successful A remained visible alongside controlled provider error and Timeout snapshots.
  • A forced config revision contacted good/error/timeout providers again and completed in 6.892s with the successful provider preserved.
  • Cleanup verified the Gateway exited, both owned ports closed, isolated state was removed, and the Testbox had zero fixture directories or Gateway processes.

Verification on the exact tree:

  • Focused cache regression: 3/3 passed.
  • models.authStatus sibling: 85/85 passed.
  • Provider usage auth/load siblings: 18/18 passed.
  • Full pnpm build: passed.
  • Changed gate completed successfully through format, oxlint, core and test typechecks, import cycles, native schema, database-first, dependency, plugin-boundary, dead-export, sidecar, webhook, and pairing guards.
  • Exact-tree finalizer: git diff --check passed and reported only the three intended files.
  • Fresh Codex autoreview: clean, no accepted/actionable findings (overall: patch is correct (0.99)).
  • Claude land decision: approved.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Aug 15, 2026
@steipete
steipete marked this pull request as ready for review August 15, 2026 09:28
@steipete
steipete requested a review from a team as a code owner August 15, 2026 09:28
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 5:39 AM ET / 09:39 UTC.

ClawSweeper review

What this changes

The PR passes the runtime configuration captured by the provider-usage cache into provider discovery and usage loading so reloaded accounts return their own usage data.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer merge review: current main still refreshes usage without the captured runtime configuration, while this branch repairs that owner-boundary handoff. The maintainer attribution and protected label rule out automated cleanup.

Priority: P2
Reviewed head: fbc479feec2303aeba3f3b3770e978969114238f

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with credible exact-head Gateway evidence and no blocking code findings.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This member-authored PR is not subject to the external contributor proof gate; its body nevertheless documents an exact-head built-Gateway account-reload trace.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is not subject to the external contributor proof gate; its body nevertheless documents an exact-head built-Gateway account-reload trace.
Evidence reviewed 6 items Current-main defect: The refresh scheduler retains configRef for cache matching but calls the loader without it, allowing the loader to choose ambient runtime configuration instead.
Loader contract: When config is absent, the loader falls back to getRuntimeConfig(), then uses that config for provider descriptors, auth resolution, and plugin usage snapshots.
Proposed owner-boundary repair: The branch passes params.configRef at the sole refresh-to-loader boundary, covering both cold and stale refresh paths through the shared scheduler.
Findings None None.
Security None None.

How this fits together

Gateway status methods cache provider account usage and refresh it in the background. The provider loader resolves configured providers and credentials, then returns account, plan, and quota data to usage-status and model-auth clients.

flowchart LR
  A[Runtime configuration] --> B[Gateway status request]
  B --> C[Provider usage cache]
  C --> D[Background refresh]
  D --> E[Provider usage loader]
  E --> F[Account usage snapshot]
  F --> G[Gateway clients]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; refresh the exact merge result and required checks before landing, even though current-main changes do not touch this patch surface.
  • Complete next step (P2) - This protected, maintainer-authored PR has no mechanical repair to dispatch; a maintainer should refresh the exact merge/check state and decide whether to land it.
Agent review details

Security

None.

PR surface

Source +1, Tests +27. Total +28 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 4 +1
Tests 2 27 0 +27
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 32 4 +28

Review metrics

Metric Value Why it matters
Production vs test delta production +5/-4 (net +1); tests +27/-0 The one-line production growth carries the already-captured configuration across the refresh owner boundary; the remaining production edits narrow its existing types.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the single cache-to-loader configuration handoff after exact-head/base validation, preserving one canonical provider-loading path for both usage-status and model-auth reads.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the single cache-to-loader configuration handoff after exact-head/base validation, preserving one canonical provider-loading path for both usage-status and model-auth reads.

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

Yes—source-reproducible: current main invokes the provider loader without the cache's reloaded configuration, and the loader demonstrably falls back to ambient runtime configuration.

Is this the best way to solve the issue?

Yes. Passing the captured configuration at the shared refresh-to-loader boundary controls provider discovery, auth resolution, and plugin usage loading without adding a parallel path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 03c1d7727cfd.

Labels

Label changes:

  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.

Label justifications:

  • P2: The PR repairs wrong or missing provider account usage after a runtime configuration reload.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; 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. Not applicable: This member-authored PR is not subject to the external contributor proof gate; its body nevertheless documents an exact-head built-Gateway account-reload trace.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the cache refresh call to this contributor’s recent gateway work, and they authored the focused follow-up fix. (role: recent area contributor; confidence: high; commits: 056184bccc38, fbc479feec23; files: src/gateway/server-methods/models-auth-status-usage-cache.ts, src/gateway/server-methods/usage.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-15T09:34:22.212Z sha fbc479f :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Landing proof for exact head fbc479feec2303aeba3f3b3770e978969114238f:

ClawSweeper rank-up / merge-risk dispositions:

  1. Production net +1: accepted. The sole added line is the exact cache-owner configuration handoff into loadProviderUsageSummary; both ClawSweeper and autoreview found no net-neutral alternative, and the maintainer explicitly approved +5/-4 production.
  2. Behind current main: no rebase solely for advisory drift. GitHub reports MERGEABLE, the native three-way review is conflict-free, and required exact-head CI is green. Repository policy does not chase moving main absent conflict or material risk.
  3. Protected maintainer PR: satisfied through the native scripts/pr review/artifact/prepare/merge path.

No linked issue exists to close. Related PR #121799 remains open because it addresses a distinct cold-cache/client-convergence contract.

@steipete
steipete merged commit 9fabdb4 into main Aug 15, 2026
256 checks passed
@steipete
steipete deleted the fix/autoqa-refill-usage-status-outcomes-v2 branch August 15, 2026 09:40
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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