Repository navigation
fix(gateway): Models page never shows provider usage and re-probes providers on every load - #174741
Conversation
…ther's provider usage Both RPCs share one provider-usage entry per agent but request different provider sets (refreshable credentials vs every usage descriptor). On the Models page they run together, so each read missed, started a refresh, and superseded the other's in-flight refresh. Every page load re-resolved provider auth and plugin runtime for every usage provider and probed provider usage endpoints, and usage.status answered refreshing:true. Keep one entry and one in-flight refresh per provider set.
|
🦞👀 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 maintainer review before merge. What this changesThis PR caches provider usage and coalesces refreshes separately for each provider set within an agent. Example: Agent main requests OpenAI usage through models.authStatus and OpenAI plus Anthropic through usage.status.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current-main cache collision with a focused change, no introduced defects found, and passing exact-head CI. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway's shared provider-usage cache receives agent, configuration, credential, and provider-set identities from status RPCs and returns cached snapshots while coordinating provider HTTP refreshes. flowchart TD
A[Models page] --> B[models.authStatus]
A --> C[usage.status]
B --> D[Shared agent and provider set cache]
C --> D
D --> E[Provider usage loader]
E --> F[Provider endpoints]
E --> D
Technical reviewBest possible solution: Retain this focused repair in the shared cache owner while preserving credential invalidation, lifecycle ownership, and existing cold-read contracts. Do we have a high-confidence way to reproduce the issue? Current-main source shows differing provider sets competing for a single per-agent entry and refresh; the author additionally reports Gateway ABAB reproduction, which this read-only review did not execute. Is this the best way to solve the issue? Partitioning the existing owner's cache and refresh maps by the already-defined provider key fixes the collision without introducing another cache owner or changing RPC contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e45b2e78d9eb. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12, Tests +27. Total +39 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel 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 Reviewed October 16, 2026, 6:21 PM ET / 22:21 UTC. |
|
Runtime evidence from the ABAB Gateway run. Isolated Gateway on a copied state directory, outbound network denied, same restored state for each run. Provider names are the rig's two credentialed usage providers. Outbound usage probes (socket connects, main thread). Each probe is one
On base every call re-probes. With the fix, each provider set refreshes once inside the 60 s window: the warm-up refreshed one set, probe 2 refreshed the other, then nothing. Responses after identical warm-up (semantic diff, time fields ignored, base → fix): On base, usage never arrives on the page ( |
|
Landed in c3f0b6a.
|
) ## What Problem This Solves Fixes: agents keep shipping caches whose key leaves out an input that changes the answer. Callers then collide, serve another agent's or account's data, return stale results, or never hit the cache. No rule in `AGENTS.md` covers cache keys. ## User Impact No user-visible change. Agents get one rule that tells them what a cache key must contain and how to prove sharing is safe. ## Why This Change Was Made The rule adds one line under "Runtime and code safeguards": - key caches, memos, in-flight joins and shared snapshots by scope and request shape; - give callers asking different questions separate slots; - keep volatile values out of keys; - prove sharing with a work-count test where differing callers interleave. #174741 is the trigger. `usage.status` and `models.authStatus` shared one provider-usage slot per agent but asked for different provider sets. They evicted each other on every Models page load for 80 days, across 7 refactor passes, because no test interleaved the two callers. ## Evidence I reviewed main since 2026-04-01: every `fix` commit whose diff touched cache-key, cache get/set or in-flight lines (728 commits). Each one was judged by reading its message and diff. **95 fixed a cache identity bug.** That is about 3 per week, steady every month (Apr 14, May 13, Jun 8, Jul 15, Aug 18, Sep 16, Oct 1–16 11). | Kind | Count | Example | |---|---|---| | Key omits an input, so the answer is stale or wrong | 35 | 276ba10: markdown render cache ignored `codeBlockChrome` | | Data leaks across agent, account or credential scope | 23 | 6a12c6f: run→session lookup keyed by `runId` only; 1487b45: GitHub previews shared across credentials; 51042e8: cron deliveries routed to the wrong agent | | Different callers collide or evict each other | 14 | c3f0b6a (#174741); f8380a8: route keys with separators collided | | Key too volatile, so it never hits | 14 | 3f9d241: prompt-cache key was the per-run session id | | In-flight join dedups unrelated work | 9 | 2aabde7: deep health probe joined a passive refresh; 4ca63cb: dispatch joined a different `executionMode` | 23 of the 95 were data leaks across scopes, so this is a correctness and privacy issue, not only performance. Co-authored-by: Ayaan Zaidi <[email protected]>
…oviders on every load (openclaw#174741) ## What Problem This Solves Fixes: the Models page never shows provider usage, and every page load re-runs provider usage probes, when `models.authStatus` and `usage.status` are requested together (as the page does). ## User Impact User impact: provider usage appears on the Models page on load. Provider usage endpoints are polled once per 60 s cache window per provider set instead of on every page load. ## Why This Change Was Made Both RPCs share one provider-usage cache entry and one in-flight refresh per agent. They ask for different provider sets: `models.authStatus` asks for providers with refreshable credentials, and `usage.status` asks for every usage-capable provider. When they ran together, each read missed the other's entry and started a refresh that superseded the other's in-flight refresh, so the earlier result was discarded. The result: - `usage.status` answered `{ providers: [], refreshing: true }` on every load. - `models.authStatus` carried no `usage`. - Each load re-resolved auth and plugin runtime for every usage provider, and probed provider endpoints. The cache now keeps one entry and one in-flight refresh per provider set within each agent. Nothing else changes: TTL, credential-bound invalidation, cold-read markers and stale-while-revalidate stay as they were. `d24100c` (openclaw#115369) intended the two readers to share this cache. A later change gave them different provider sets. ## Evidence Isolated Gateway on a copy of a real state directory: outbound network denied, base and fix run ABAB on the same restored state. - **Work count** (alternating `usage.status` / `models.authStatus`, 8 calls): outbound usage probes on 7 of 8 calls (base) vs only on the first refresh of each provider set (fix). - **Responses after identical warm-up:** `agents.list`, `config.get`, `models.list` and `sessions.usage` are identical. `usage.status` now returns the provider snapshots instead of `refreshing: true`. `models.authStatus` providers now carry `usage`. - **Serial p50 over 20 calls, two rounds:** `usage.status` 4.9/4.3 ms → 0.8/1.0 ms. `models.list` 30.5/27.2 ms → 2.2/2.5 ms; the per-call refresh was also blocking it on the main thread. The host was heavily loaded, so treat wall times as indicative only. - **CPU profile:** the per-load `resolveProviderRuntimePlugin` → `applyPluginAutoEnable` frames (~100 ms main thread per page load) are gone from steady-state page loads. - **Tests:** new regression `refreshes each provider set once per TTL when page reads interleave` fails on base (4 refreshes in 3 loads) and passes with the fix (2). `usage.status-cache`, `usage-cache` and `models-auth-status` suites pass (66 tests). Co-authored-by: Ayaan Zaidi <[email protected]>
…claw#174837) ## What Problem This Solves Fixes: agents keep shipping caches whose key leaves out an input that changes the answer. Callers then collide, serve another agent's or account's data, return stale results, or never hit the cache. No rule in `AGENTS.md` covers cache keys. ## User Impact No user-visible change. Agents get one rule that tells them what a cache key must contain and how to prove sharing is safe. ## Why This Change Was Made The rule adds one line under "Runtime and code safeguards": - key caches, memos, in-flight joins and shared snapshots by scope and request shape; - give callers asking different questions separate slots; - keep volatile values out of keys; - prove sharing with a work-count test where differing callers interleave. openclaw#174741 is the trigger. `usage.status` and `models.authStatus` shared one provider-usage slot per agent but asked for different provider sets. They evicted each other on every Models page load for 80 days, across 7 refactor passes, because no test interleaved the two callers. ## Evidence I reviewed main since 2026-04-01: every `fix` commit whose diff touched cache-key, cache get/set or in-flight lines (728 commits). Each one was judged by reading its message and diff. **95 fixed a cache identity bug.** That is about 3 per week, steady every month (Apr 14, May 13, Jun 8, Jul 15, Aug 18, Sep 16, Oct 1–16 11). | Kind | Count | Example | |---|---|---| | Key omits an input, so the answer is stale or wrong | 35 | ec1fe7a: markdown render cache ignored `codeBlockChrome` | | Data leaks across agent, account or credential scope | 23 | 62706db: run→session lookup keyed by `runId` only; 61cfec6: GitHub previews shared across credentials; 07fdf40: cron deliveries routed to the wrong agent | | Different callers collide or evict each other | 14 | c373547 (openclaw#174741); 6a9b2cb: route keys with separators collided | | Key too volatile, so it never hits | 14 | 39dd2bb: prompt-cache key was the per-run session id | | In-flight join dedups unrelated work | 9 | 5db8377: deep health probe joined a passive refresh; 153d5a8: dispatch joined a different `executionMode` | 23 of the 95 were data leaks across scopes, so this is a correctness and privacy issue, not only performance. Co-authored-by: Ayaan Zaidi <[email protected]>
…ession tests (#176630) ## What Problem This Solves Performance work in OpenClaw keeps fixing the same waste twice: caches that stop hitting, batches that get reverted, and PRs that land with a regression their own numbers already show. Agents had no repository guide for this work, and three flows where the same waste keeps returning had no test that counts it. ## User Impact No user-visible change. Agents doing performance work now have one OpenClaw skill: measure the real flow with a committed workload, count operations first, delete waste before batching or caching, and land only when every user-facing metric holds or improves. Three work-count tests fail CI if known waste comes back. ## Why This Change Was Made A corpus of 103 performance cases from the last 90 days on `main` (70 randomly sampled, 33 seeded with every perf revert; each judged from its diff and PR text): - **Deleting waste lasts:** 3 of 31 random-sample deletes were later re-fixed, and those failed deletes broke a guard, not because the waste returned. - **Caches, batches and worker moves come back:** 4 of 5, 6 of 7 and 5 of 8 were later re-fixed (biased set, a signal not a rate). In 3 of the 4 cache re-fixes the cache silently stopped hitting, e.g. #115369 → #174741 and #149773 → #149879. - **Own regressions predict reverts:** 21 PRs landed while their own numbers showed a large regression; 11 of them were later reverted or re-fixed, against 25 of the other 82. Five of the six reverts had shown the regression in their own body. - **Same waste, again and again:** SQLite schema/admission re-checks (14 PRs, one revert), session list rows (two reverts in two days), model catalog rebuilds. Changes: - `.agents/skills/openclaw-performance/SKILL.md`: measure (committed bench per flow, counts first, acceptance rule before the first run, interleaved samples), find waste (10 recurring OpenClaw patterns with real cases), fix order (delete → once at the owner → carry the prepared fact → batch → cache with a written reason, cache-identity rules and an interleaved work-count test), land (no user-facing metric worse unless the owner accepts it). - Root `AGENTS.md`: the "Do less work" line keeps its core rule and points to the skill. - Work-count tests (counts, never wall time): - `src/state/openclaw-agent-execution.schema-admission.test.ts`: warm chat turns make only their own write requests; no re-open, schema prepare or integrity validation. - `src/gateway/session-row-projection.list-page.test.ts`: after an unrelated subagent renewal, repeating the same pages renders 0 rows, materializes 0 more and does 0 worker reads or SQL. - `src/gateway/server-methods/models-auth-status.work-count.test.ts` (own file, to keep the existing test under its line cap): interleaved `models.authStatus` and `usage.status` page loads add no provider probes, auth-health builds or catalog loads after warm-up. ## Evidence | Test | Back-test (parent of the historical fix) | |---|---| | Schema admission | fails at `8b7917c79b8^` (#166253): each warm turn adds `open` and `prepare` again | | Session list | fails at `1b896e6327f^` (#162280): 80 rows materialized instead of 10, plus 1 worker read | | Models page | fails at `c3f0b6abc01^` (#174741): 3 provider probes in 2 loads; the readers evict each other | - All three pass on head (each file about 0.3–1.7 s); `models-auth-status.test.ts` still passes 52/52. The Models page test still fails at `c3f0b6abc01^` with real-module mocks (one extra provider probe). - The pre-commit hook (line-cap ratchet, `AGENTS.md` size) passed; root `AGENTS.md` is 18,917 characters. - Every PR cited by the skill is merged; every named bench script exists on `main`. Blind replay of 8 held-out performance tasks (none cited by the skill; each from the parent of its known-good fix), Codex agent with and without the skill, 2 seeds; stopped early after 12 judged pairs to free the host: | | Without skill | With skill | |---|---|---| | Pair wins (blind Codex judge) | 3 | 8 (1 tie) | | Removed the same waste as the reference fix | 11/14 runs | 11/13 runs | | Proof includes a work-count test | 5/14 | 11/13 | | Added a cache | 1 | 1 | | Judge: proof / waste found / fix order (1-5) | 3.08 / 4.50 / 4.83 | 4.33 / 4.42 / 4.50 | The skill does not change whether agents find the waste; it changes how they prove it, which is what keeps the waste from returning. One judge and 12 pairs: the win split is not significant (p ≈ 0.23). **Merge danger:** two-way door; a revert removes the skill and the tests. No runtime change. Blast radius: agent instructions for performance work, and three test files. Co-authored-by: Ayaan Zaidi <[email protected]>
…ession tests (openclaw#176630) ## What Problem This Solves Performance work in OpenClaw keeps fixing the same waste twice: caches that stop hitting, batches that get reverted, and PRs that land with a regression their own numbers already show. Agents had no repository guide for this work, and three flows where the same waste keeps returning had no test that counts it. ## User Impact No user-visible change. Agents doing performance work now have one OpenClaw skill: measure the real flow with a committed workload, count operations first, delete waste before batching or caching, and land only when every user-facing metric holds or improves. Three work-count tests fail CI if known waste comes back. ## Why This Change Was Made A corpus of 103 performance cases from the last 90 days on `main` (70 randomly sampled, 33 seeded with every perf revert; each judged from its diff and PR text): - **Deleting waste lasts:** 3 of 31 random-sample deletes were later re-fixed, and those failed deletes broke a guard, not because the waste returned. - **Caches, batches and worker moves come back:** 4 of 5, 6 of 7 and 5 of 8 were later re-fixed (biased set, a signal not a rate). In 3 of the 4 cache re-fixes the cache silently stopped hitting, e.g. openclaw#115369 → openclaw#174741 and openclaw#149773 → openclaw#149879. - **Own regressions predict reverts:** 21 PRs landed while their own numbers showed a large regression; 11 of them were later reverted or re-fixed, against 25 of the other 82. Five of the six reverts had shown the regression in their own body. - **Same waste, again and again:** SQLite schema/admission re-checks (14 PRs, one revert), session list rows (two reverts in two days), model catalog rebuilds. Changes: - `.agents/skills/openclaw-performance/SKILL.md`: measure (committed bench per flow, counts first, acceptance rule before the first run, interleaved samples), find waste (10 recurring OpenClaw patterns with real cases), fix order (delete → once at the owner → carry the prepared fact → batch → cache with a written reason, cache-identity rules and an interleaved work-count test), land (no user-facing metric worse unless the owner accepts it). - Root `AGENTS.md`: the "Do less work" line keeps its core rule and points to the skill. - Work-count tests (counts, never wall time): - `src/state/openclaw-agent-execution.schema-admission.test.ts`: warm chat turns make only their own write requests; no re-open, schema prepare or integrity validation. - `src/gateway/session-row-projection.list-page.test.ts`: after an unrelated subagent renewal, repeating the same pages renders 0 rows, materializes 0 more and does 0 worker reads or SQL. - `src/gateway/server-methods/models-auth-status.work-count.test.ts` (own file, to keep the existing test under its line cap): interleaved `models.authStatus` and `usage.status` page loads add no provider probes, auth-health builds or catalog loads after warm-up. ## Evidence | Test | Back-test (parent of the historical fix) | |---|---| | Schema admission | fails at `04c36511d39^` (openclaw#166253): each warm turn adds `open` and `prepare` again | | Session list | fails at `d13db6a6cc8^` (openclaw#162280): 80 rows materialized instead of 10, plus 1 worker read | | Models page | fails at `c373547bbbd^` (openclaw#174741): 3 provider probes in 2 loads; the readers evict each other | - All three pass on head (each file about 0.3–1.7 s); `models-auth-status.test.ts` still passes 52/52. The Models page test still fails at `c373547bbbd^` with real-module mocks (one extra provider probe). - The pre-commit hook (line-cap ratchet, `AGENTS.md` size) passed; root `AGENTS.md` is 18,917 characters. - Every PR cited by the skill is merged; every named bench script exists on `main`. Blind replay of 8 held-out performance tasks (none cited by the skill; each from the parent of its known-good fix), Codex agent with and without the skill, 2 seeds; stopped early after 12 judged pairs to free the host: | | Without skill | With skill | |---|---|---| | Pair wins (blind Codex judge) | 3 | 8 (1 tie) | | Removed the same waste as the reference fix | 11/14 runs | 11/13 runs | | Proof includes a work-count test | 5/14 | 11/13 | | Added a cache | 1 | 1 | | Judge: proof / waste found / fix order (1-5) | 3.08 / 4.50 / 4.83 | 4.33 / 4.42 / 4.50 | The skill does not change whether agents find the waste; it changes how they prove it, which is what keeps the waste from returning. One judge and 12 pairs: the win split is not significant (p ≈ 0.23). **Merge danger:** two-way door; a revert removes the skill and the tests. No runtime change. Blast radius: agent instructions for performance work, and three test files. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: the Models page never shows provider usage, and every page load re-runs provider usage probes, when
models.authStatusandusage.statusare requested together (as the page does).User Impact
User impact: provider usage appears on the Models page on load. Provider usage endpoints are polled once per 60 s cache window per provider set instead of on every page load.
Why This Change Was Made
Both RPCs share one provider-usage cache entry and one in-flight refresh per agent. They ask for different provider sets:
models.authStatusasks for providers with refreshable credentials, andusage.statusasks for every usage-capable provider. When they ran together, each read missed the other's entry and started a refresh that superseded the other's in-flight refresh, so the earlier result was discarded. The result:usage.statusanswered{ providers: [], refreshing: true }on every load.models.authStatuscarried nousage.The cache now keeps one entry and one in-flight refresh per provider set within each agent. Nothing else changes: TTL, credential-bound invalidation, cold-read markers and stale-while-revalidate stay as they were.
a21f235(#115369) intended the two readers to share this cache. A later change gave them different provider sets.Evidence
Isolated Gateway on a copy of a real state directory: outbound network denied, base and fix run ABAB on the same restored state.
usage.status/models.authStatus, 8 calls): outbound usage probes on 7 of 8 calls (base) vs only on the first refresh of each provider set (fix).agents.list,config.get,models.listandsessions.usageare identical.usage.statusnow returns the provider snapshots instead ofrefreshing: true.models.authStatusproviders now carryusage.usage.status4.9/4.3 ms → 0.8/1.0 ms.models.list30.5/27.2 ms → 2.2/2.5 ms; the per-call refresh was also blocking it on the main thread. The host was heavily loaded, so treat wall times as indicative only.resolveProviderRuntimePlugin→applyPluginAutoEnableframes (~100 ms main thread per page load) are gone from steady-state page loads.refreshes each provider set once per TTL when page reads interleavefails on base (4 refreshes in 3 loads) and passes with the fix (2).usage.status-cache,usage-cacheandmodels-auth-statussuites pass (66 tests).