Repository navigation
fix: keep usage pricing from blocking the Gateway on filesystem lookups - #197599
Conversation
Publish the model catalog owner’s local source or absence into the existing pricing projection and retain prepared prices through each operation. Serialize async source reads with the existing writer queue, remove synchronous pricing reads and migrate callers without changing cost precedence. Regression tests cover repeated absent-file formatting, retained prices after eviction, read/write publication order and consumer readiness. Owner counters show 66 warm lstatSync calls reduced to zero. Preserve the cold async scheduling tradeoff separately from warm timing gains.
|
🦞👀 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 prepares usage prices asynchronously and carries captured pricing facts through accounting, status, and session rendering. Example: A running Gateway performs 66 pricing lookups for an agent without models.json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a synchronous pricing path still present on main, and I found no actionable code defect; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe model-catalog owner supplies agent-local prices and catalog policy to usage accounting, which produces numeric costs for persistence and synchronous presentation. flowchart LR
A[Agent models file] --> B[Catalog owner queue]
B --> C[Bounded source projection]
D[Catalog pricing policy] --> E[Captured operation prices]
C --> E
E --> F[Usage accounting]
F --> G[Status and session presentation]
Technical reviewBest possible solution: Retain asynchronous preparation at the existing catalog owner and pass captured prices or numeric costs through consumers. Do we have a high-confidence way to reproduce the issue? Current main demonstrably retries synchronous reads for absent models.json files; the body supplies owner-level before/after measurements, and no target code was executed during this review. Is this the best way to solve the issue? The change follows the existing ownership boundaries, removes the redundant Gateway price cache and synchronous context getter, and preserves lazy recorded-cost precedence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7910cd62c6ca. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfacePR surface statistics unavailable: the file list is incomplete. Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
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 HistoryReview history (9 earlier review cycles; latest 8 shown)
Reviewed November 12, 2026, 8:50 AM ET / 13:50 UTC (Revision 10). |
Preserve hosted-over-bundled and vendor-model pricing from main while retaining authored runtime prices before metadata preparation. Keep raw runtime tier shapes and identity through a narrow overload; ordinary cost lookups retain normalized return types. Validated 149 affected tests, four Chromium browser cases, seven UI E2E cases, affected typechecks, lint and exact-parent guards. Fresh isolated Codex review is clean; the authored-provider no-preparation regression fails on the intermediate eager capture and passes with the owner repair.
|
Addressed the latest review's numbered merge item on
The body now distinguishes historical owner measurements from the current main integration and records final controls. The source-owner counter proves 66 warm synchronous calls become zero; it is not represented as a new whole-Gateway trace. The UI E2E evidence exercises the changed session projection consumers with a fresh production UI build. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Await catalog publishing price assertions, supply projection owner facts in maintained benchmarks, and wait for actual observer publication. Keep fingerprint tests independent of utility discovery. Align internal and browser fixtures with the WebChat policy introduced by #197544 while preserving terminal and custody assertions.
|
Addressed the latest review's open item on
This commit also migrates the five maintained benchmark callers, repairs two Gateway fixture assumptions exposed by asynchronous preparation, and aligns three exact-parent failing fixtures with #197544's WebChat policy. No production runtime code changes. Focused tests, script and affected test types, lint, five benchmark smokes, formatting, and line budgets pass. Fresh independent Codex review is clean through P2. The body records the remaining research failure's exact-parent reproduction and the still-unqualified introducing commit without claiming a landing exception. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Final head:
The body contains the refreshed owner controls and scoped proof. Focused consumer/authority/SDK tests, affected types/lint, line budgets and isolated Codex review are green. Net test growth is 400 within the universal 400 allowance, with no allocation credit. The production growth is explained in the body. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Integrate pinned CI main and retain its canonical CLI provenance and research disposal fixture. Join the existing async work scope before asserting lease release, and leave post-await authority checks with completion callers. Allocate the exact two test lines above the shared 400-line allowance.
|
The latest ClawSweeper review covered
Core and affected test types, scoped lint, formatting, exact-parent line budgets and fresh isolated Codex review pass. The final test budget is 402 with exact 2-line credit above 400; production delta is +262 after main absorbed generated output. Prior Claw cold-load and lazy-cost findings remain resolved with unchanged pricing-owner bytes. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Preserve the exact #197736 prerequisite ancestry and its stable logging policy publication before catalog environment capture. Both remote catalog schema cases pass on the combined pricing tree. Pricing owner, benchmark, and dependency inputs remain unchanged; no default log-target changes are included.
|
The latest ClawSweeper review covered pricing head
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…plugin-reload-runtime-20261112 * commit '5d6a026e43757ea6302e4c1151d6ace28468ced0': fix(logging): avoid main-thread stalls when resolving default log files (#197742) fix(sessions): commit selected invitations with original messages (#184512) improve: make Telegram tool progress easier to scan (#197523) fix(test): keep queued Stop cleanup on real timers (#197734) fix: keep usage pricing from blocking the Gateway on filesystem lookups (#197599)
…ps (openclaw#197599) * fix: prepare usage pricing before synchronous consumers Publish the model catalog owner’s local source or absence into the existing pricing projection and retain prepared prices through each operation. Serialize async source reads with the existing writer queue, remove synchronous pricing reads and migrate callers without changing cost precedence. Regression tests cover repeated absent-file formatting, retained prices after eviction, read/write publication order and consumer readiness. Owner counters show 66 warm lstatSync calls reduced to zero. Preserve the cold async scheduling tradeoff separately from warm timing gains. * test: complete async pricing consumer migration Await catalog publishing price assertions, supply projection owner facts in maintained benchmarks, and wait for actual observer publication. Keep fingerprint tests independent of utility discovery. Align internal and browser fixtures with the WebChat policy introduced by openclaw#197544 while preserving terminal and custody assertions. * test: remove superseded usage pricing line allocation * test: stop provider services before research fixture retirement * fix(gateway): regenerate inherited config hint validator * fix(usage): preserve lazy pricing and share cold source reads * fix(logging): keep catalog refresh working after logging starts * test(usage): select the recreation fixture agent explicitly
…xtures doctor-schema-migrations.recipient-authority built "upstream 41" from the current schema minus authority, which now also carries upstream's 42 tool usage: a 41 no build wrote, so the bridge refused it before the backup. Strip tool usage for upstream's 41, add upstream's own 42, and expect 43. status.continuation's readiness case expected buildStatusMessage to price the turn from config. Upstream openclaw#197599 moved the estimate to the caller (estimatedCostUsd) and migrated its own status tests the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… status fixtures Carried to the pure candidate (stage 2) from the chain's a71cde4 and the status half of 2eb8f17, renumbered for 44. agent-create.retained-schema fabricates upstream's 41 from a current store by dropping 42's tool usage and 43's pending inputs, then expects 43. The pure candidate's current store also carries recipient authority (44), which upstream's 41 never had. Drop that table too, so Doctor's migration creates it, and expect 44. Red at f8ee3d2: 2 of 3 ("expected { user_version: 44 } to deeply equal { user_version: 43 }"). status.continuation's readiness case expected buildStatusMessage to price the turn from config. Upstream openclaw#197599 moved the estimate to the caller (estimatedCostUsd) and migrated its own status tests the same way. Red at f8ee3d2: 1 of 6 ("Cost: $0.0020" missing). The other half of 2eb8f17 (Doctor's recipient-authority shapes) and a71cde4's session-tombstone-recovery pin are not carried: 0ffb153 already takes Doctor to 44 over upstream's 37-43, and the tombstone suite does not exist on the pure tree. Refs openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Usage-pricing lookups repeatedly performed synchronous filesystem admission when an agent's
models.jsonwas absent. A slow lookup could block the Gateway main thread. Usage, status and session-list formatting now consume operation-prepared cost facts; recorded totals, including billed zero, skip optional pricing preparation entirely.User Impact
Recorded totals, authored positive prices, model selection, source precedence, unknown prices and tiered pricing preserve their existing behavior. Internal synchronous renderers receive numeric facts; the public terminal SDK helper remains synchronous. External manual edits to
models.jsonrequire a Gateway restart, matching the existing positive-entry behavior. No configuration option, dependency, schema or cache owner is added.Why This Change Was Made
The canonical catalog owner publishes its source or known absence into its existing bounded projection. Pricing-only cold reads recheck that projection inside the existing models-file writer queue, so concurrent readers share the result and delayed reads cannot overwrite newer committed prices. Fresh catalog captures retain their fresh-read contract. Each operation holds its exact agent/provider pricing context through presentation and persistence, so projection eviction cannot change its answer. The redundant Gateway per-model cache and obsolete synchronous pricing-context getter are removed.
Scope and tradeoffs
Against prerequisite
e22e72a4d281cf4795191c1797b9dacfb15b8985in #197736, pricing production grows by 262 lines: asynchronous fallback preparation and retained operation facts cross existing presentation, SDK and session-mutation boundaries. Tests grow by 405 lines, with an exact five-line allocation above the universal 400 allowance for cancellation cleanup and explicit E2E agent-scope setup. Previously repaired generated output and CLI/research fixtures are now in main and contribute no remaining PR delta.Cold capture now waits asynchronously. Five-sample candidate median/max were 2.056/10.300 ms, versus historical baseline medians 1.121/.570 ms. This scheduling cost is accepted to keep filesystem stalls off the main thread. All earlier samples, including a 57.117 ms cold maximum under heavier load, remain retained. These are owner measurements, not whole-Gateway latency claims.
Evidence
Current source:
6834f3959963e535b629c257396c36ec3abe33ac, building on the conflict-free merge of reviewed pricing heade3b6b18d073ec21b9f2f0caf31e3a901a05a2990with exact prerequisitee22e72a4d281cf4795191c1797b9dacfb15b8985. Prerequisite #197736 passed exact-head CI and merged as7910cd62c6ca2f8a5099298dd6de84be87d55739; its logging and bootstrap source inclusion in main was verified before this publication. The merge was conflict-free. Pricing owner, benchmark and dependency-manifest bytes remain unchanged; logging and Gateway bootstrap bytes match the reviewed prerequisite exactly. No default-log-target overlay is included.Prior pricing-head CI 43214846389 finished with 78 successful jobs, 25 skipped jobs and only the remote-catalog failure plus its aggregate gate. The producer regression was introduced by #197586: lazy logger initialization changed the process environment after the catalog pool captured it, causing admission rejection with live borrowers. The prerequisite establishes the existing logging policy during configuration before catalog capture, while preserving standalone logger initialization. It does not weaken the catalog environment check. On the combined source, both cases of the original failed remote-catalog file pass (32.203/10.179 seconds), with fresh runtime preparation recorded separately. Core and logging test types, scoped lint, formatting, exact-prerequisite line ratchet and pricing's final 405/400+5 test budget pass.
Earlier repairs are preserved: the abort assertion reproduced locally before repair; 61 cancellation/accounting/authority cases and the affected real CLI case pass. The complete retired/aborted table checks immediate rejection and no redispatch before draining tracked work, then checks lease release. Isolated Codex reviews of pricing and the prerequisite are clean through P2; the conflict-free composition retains those exact reviewed bytes. Prior full changed checks and subsequent focused repairs remain composed evidence, not a claim that the entire command was repeated at this head.
One local gap remains: the canonical research-fixture replay timed out during its five-second service-start phase before disposal; the following portable-documents case passed. The log does not distinguish jobs-module loading from wake-reference recovery. No timeout increase, error suppression or inherited-red waiver is used. New exact-head CI is required before landing.
Regression coverage includes 66 repeated missing-file lookups, captured prices surviving projection eviction, delayed read versus committed writer ordering, concurrent same-agent cold reads, interleaved agent scopes, billed zero, final unknown totals and cache-inclusive estimates. Retirement during the actual pricing await rejects with zero usage logs/diagnostics. Public SDK final-media cases retain their synchronous contract. Earlier qualified consumer, catalog, publisher, benchmark and presentation batches passed; the later BTW ownership/test relocation preserves all assertions. Both unused-file scans passed on their qualified earlier source snapshots.
Earlier local UI browser 4 cases and affected question-guest/post-deploy E2E 7 cases passed with a fresh production UI build; these remain prior-head evidence. The logging prerequisite is directly imported by the usage-sessions owner-attribution E2E file. The combined-source run used a fresh private-QA runtime and production UI build: both owner-attribution cases and the two-point recreation case passed, while the one-point case exposed missing fixture scope setup. Its screenshot showed the page scoped to main although the fixture creates an opus session. The fixture now selects opus through the public picker; both recreation cases pass with every existing assertion preserved. The unchanged owner-attribution pair retains its preceding green proof. UI-E2E types, scoped lint and fresh Codex review are green. This is composed 2+2 case evidence, not a claim of an all-four final-head rerun. Pricing head e3b has ClawSweeper zero findings/open items; the new integration requires final-head review and CI.
Matched owner measurements
Synthetic missing-file pricing, Node 26.12.1, five serial A1/B/A2 rounds of 10,000 warm lookups after 1,000 warmups. Count mode is separate from the counter-free timing mode, which also records exact V8 main-isolate allocation. Baseline owner modules are pinned to incident source
24819901d92ee379b5b36a957276d3b3657d7b79; this is a historical owner comparison, not attribution of unrelated current-main changes. All rows are retained; load1 ranged 33.70–38.38.Candidate allocation increased from the preceding candidate's 12.99 MB to 17.97 MB after cold-load sharing; this cost is retained. Main-CPU p95/max across five samples: 105.004/8.793/89.456 ms; wall 317.141/8.800/98.479 ms includes a retained A1 scheduling outlier. Counts: 66 warm lstatSync calls → 0 synchronous and 0 asynchronous file calls. Cold: one lstatSync→one async readFile, zero synchronous calls. API counts are not one-to-one kernel syscall counts.