Skip to content

fix(usage): refresh model prices after catalog writes - #146113

Merged
steipete merged 1 commit into
mainfrom
codex/usage-pricing-refresh-20260912
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/usage-pricing-refresh-20260912

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #130706, #142100.

What Problem This Solves

Fixes an issue where local usage estimates keep an agent's old model prices after OpenClaw successfully writes updated prices to its models.json. The file contains the new rate, but an already-warm process continues returning the old cached rate.

Why This Change Was Made

The existing models.json owner now holds the bounded price index and invalidates the written agent immediately after successful publication. Usage readers keep their synchronous, non-polling lookup. The same cut removes unused preparation result fields and one-caller wrappers, reducing production code by 33 lines.

User Impact

Subsequent local estimates use newly published agent prices without restarting the Gateway. Other agents retain their own cached prices, and recorded per-call costs retain their original amounts. The read-only planning path remains read-only.

Evidence

  • The regression failed on the base: after the real writer published rate 9, usage still returned rate 1; the second agent correctly remained at 5.
  • 109 focused writer, pricing, fingerprint, roster, and cache tests passed. The full pinned changed-file checks and independent P2 review passed.
  • A normal pnpm build passed. Four compiled scenarios exercised the real planner, catalog writer, and usage consumer: two-agent priming, publication and formatted cost, read-only planning, and warm reuse with caller-result isolation. No source imports or network requests occurred; all 12,092 build files and 2,130 observed module files remained unchanged.
  • This is compiled owner-boundary proof, not a Gateway RPC or hosted-provider run. It covers in-process catalog publication; it adds no external-file polling.

Storage compatibility: no migration is required. Existing data compatibility is preserved and verified: the models.json planner, catalog reader, SQLite catalog owner, configuration types, and private file writer are byte-identical to the base. models-config-state.ts contains process-local globalThis/Symbol.for coordination with Maps, promises, and an async queue; it is not serialized or persisted. The public writer result remains { agentDir, wrote }, the native state-schema guard passed unchanged at v17, and compiled read-only planning preserved exact file bytes.

Invalidate the written agent price index through the existing models.json owner. Remove unused preparation results and queue wrappers while preserving serialized writes and copied public results. Related: #130706.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 15:35
@clawsweeper

clawsweeper Bot commented Sep 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 12:21 PM ET / 16:21 UTC (Revision 2).

ClawSweeper review

What this changes

Refreshes cached local usage prices after an agent’s models.json is written, simplifies writer coordination, and adds regression coverage and documentation.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful fix with no blocking findings. The previous migration blocker is cleared: the changed state is process-local, and the persisted formats and storage operations are unchanged.

Priority: P2
Reviewed head: 7f21a8a4a43c1e39d1b957a715520e9b0686b9b0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no remaining correctness or migration blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor gate does not apply. The body reports compiled planner-to-writer-to-usage checks for refresh, agent isolation, and read-only planning; these were not independently rerun, and no authority-bearing behavior changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor gate does not apply. The body reports compiled planner-to-writer-to-usage checks for refresh, agent isolation, and read-only planning; these were not independently rerun, and no authority-bearing behavior changes.
Evidence reviewed 10 items Process-local state: The shared state consists of globalThis/Symbol.for coordination, Maps, WeakMaps, promises, and an async queue. No serialization or database schema is introduced.
Publication-owned invalidation: The writer deletes only the written agent’s price-cache entry after writeText succeeds. Per-path serialization, permission repair, copied public results, and the read-only planning path remain intact.
Persisted contracts unchanged: The pinned introduced comparison returns no changes to the catalog planner, SQLite catalog owner, model config types, or private file writer. The cache relocation does not require a migration.
Findings None None.
Security None None.

How this fits together

OpenClaw’s model catalog writer publishes agent-local model settings. Usage reporting reads those prices through a synchronous cache to estimate costs when recorded costs are unavailable.

flowchart TD
  A[Model configuration] --> B[Catalog planner]
  B --> C[Serialized catalog writer]
  C --> D[Agent models file]
  C --> E[Invalidate agent price cache]
  D --> F[Usage price lookup]
  E --> F
  F --> G[Local cost estimates]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -33, Tests +57, Docs +4. Total +28 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 28 61 -33
Tests 2 57 0 +57
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 89 61 +28

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/agents/models-config-state.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep price-cache invalidation with the successful catalog writer while preserving synchronous reads, agent isolation, and recorded billing totals.

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

Yes, from source: warm an agent’s price lookup, publish changed models.json prices through the writer, then read again; current main retains the old cached entry. No runtime execution was performed in this read-only review.

Is this the best way to solve the issue?

Yes. Invalidating the existing cache at successful publication directly repairs its lifecycle without polling, a second persistence owner, or a format migration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2a1bc8be3db5.

Labels

Label justifications:

  • P2: Stale local price estimates are a bounded reporting defect; recorded per-call billing totals remain preserved.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor gate does not apply. The body reports compiled planner-to-writer-to-usage checks for refresh, agent isolation, and read-only planning; these were not independently rerun, and no authority-bearing behavior changes.

Evidence

What I checked:

  • Process-local state: The shared state consists of globalThis/Symbol.for coordination, Maps, WeakMaps, promises, and an async queue. No serialization or database schema is introduced. (src/agents/models-config-state.ts:16, 7f21a8a4a43c)
  • Publication-owned invalidation: The writer deletes only the written agent’s price-cache entry after writeText succeeds. Per-path serialization, permission repair, copied public results, and the read-only planning path remain intact. (src/agents/models-config.ts:325, 7f21a8a4a43c)
  • Persisted contracts unchanged: The pinned introduced comparison returns no changes to the catalog planner, SQLite catalog owner, model config types, or private file writer. The cache relocation does not require a migration. (src/agents/models-config.plan.ts, 7f21a8a4a43c)
  • Current-main necessity: The writer, shared coordination state, and usage formatter on fetched main are unchanged from the PR merge base; main still has the private price cache without publication invalidation. (src/utils/usage-format.ts, 2a1bc8be3db5)
  • Released cache behavior: The latest supplied release, v2026.9.4, also retains modelsJsonCostCacheByAgentDir and reuses its parsed prices on warm reads. (src/utils/usage-format.ts:177, 3a9d69db306c)
  • Focused regression coverage: The new test primes two agents at rates 1 and 5, publishes rate 9 for the first, and checks both refreshed prices and agent-scoped fingerprint changes. Its planner is mocked while writes delegate to the real private file store; this is focused regression coverage, not independent live proof. (src/agents/models-config.write-serialization.test.ts:199, 7f21a8a4a43c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-12T16:06:40.855Z sha 7f21a8a :: blocked before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR body now records storage compatibility evidence for the before-merge item. models-config-state.ts is process-local coordination (globalThis/Symbol.for, Maps, promises and a queue), not persisted state. The serialized models.json planner/reader, SQLite catalog owner, config types, and private file writer are unchanged from the base; existing data compatibility is preserved and no migration is required. The compiled byte-preservation checks and unchanged v17 schema guard are also recorded. Please reassess the persistent-data-model classification against these owners.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer compatibility review: addressed. The latest technical review confirms that the changed state is process-local, persisted contracts are unchanged, and no migration is required. I independently verified the unchanged planner/reader, SQLite catalog owner, config types and private file writer, alongside the passing byte-preservation checks.

The remaining generated checklist contradicts that conclusion: its prose parser treats “without polling, a second persistence owner, or a format migration” as missing migration proof. This is a reporting false positive, not an outstanding data migration. No code, schema, baseline, or merge gate is being weakened; the normal native workflow will verify the completed review and required CI.

@steipete
steipete merged commit 7bb6926 into main Sep 12, 2026
263 checks passed
@steipete
steipete deleted the codex/usage-pricing-refresh-20260912 branch September 12, 2026 16:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
Invalidate the written agent price index through the existing models.json owner. Remove unused preparation results and queue wrappers while preserving serialized writes and copied public results. Related: openclaw#130706.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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