Skip to content

refactor: separate usage pricing preparation from formatting - #203043

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/usage-pricing-owner
Nov 21, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/usage-pricing-owner

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #202999

What Problem This Solves

Developers changing usage formatting currently share a module with model-catalog preparation and pricing caches. Token-only callers also reach that stateful module through a redundant forwarding export.

User Impact

No user-visible change. Pricing precedence, cache identity, zero/partial/tier pricing, and the existing public cost-config type remain unchanged.

Why This Change Was Made

Move pricing preparation into the model-catalog owner, keep formatting and cost arithmetic separate, and migrate every pricing consumer. Route seven token-only callers directly to the existing formatter and remove the superseded exports. Move pricing tests with their filesystem setup while retaining pure formatting tests. The context-estimate formatter also moves unchanged to its existing status-formatting owner.

Evidence

The 17-suite run passed 252 tests with one existing Windows-only skip. Core and seven test type graphs and the assertion check passed. Initial typed lint found one residual runtime import for a type-only dependency; the correction passed all 13 affected usage-line tests and that file’s typed lint. Other source and dependency inputs were verified unchanged before reusing the prior-head checks.

Normal hooks and formatting passed. A fresh review of the complete corrected 40-file range found no actionable defects. Current-head CI and its required gate passed, including build:ci-artifacts and the mandatory sealed-worker file/import checks.

@vincentkoc vincentkoc self-assigned this Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes scripts Repository scripts agents Agent runtime and tooling size: XL labels Nov 21, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 21, 2026
@clawsweeper

clawsweeper Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves pricing preparation into the model-catalog owner, migrates consumers and tests, and keeps formatting and arithmetic separate.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Source comparisons support a useful, correct refactor, but application tests, typechecks, targeted lint, assertion-ratchet validation, and build evidence remain pending.
Proof confidence 🦪 silver shellfish (2/6) This behavior-preserving refactor requires no shipped-entry-point demonstration; no executable validation was performed in this read-only review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Developers maintaining formatting encounter pricing preparation and filesystem-heavy test setup in the same module boundary.
Reason: The maintainer-authored issue and PR establish direction, and the focused move improves ownership without introducing settings, public APIs, or additional state.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR implements the linked ownership plan, and source review found no actionable correctness or security defect.

Priority: P3
Reviewed head: ccb973ee69845d564a7f2842cff78cc39c49bd7d

Before merge

None.

Findings

None.

Agent review details

How this fits together

Usage accounting prepares rates from agent-local, configured, and catalog sources, then passes numeric cost facts to session accounting and status or CLI formatting.

flowchart LR
 A[Config and catalog sources] --> B[Model catalog pricing preparation]
 B --> C[Usage accounting]
 C --> D[Cost formatting]
 F[Token formatter] --> D
 D --> E[Status and CLI output]
Loading

Technical review

Best possible solution:

Complete the existing ownership split with unchanged pricing contracts and successful focused validation.

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

This PR addresses an internal module boundary rather than a runtime failure; source inspection confirms that current main still combines the responsibilities.

Is this the best way to solve the issue?

The move uses existing model-catalog, token-formatting, and status-formatting owners, removes superseded exports, and preserves the implementations without parallel machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0ac0df3 adds src/utils/usage-format.ts:413 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0ac0df32c165; files: src/utils/usage-format.ts)
  • Ayaan Zaidi: Raw commit 723cc5d adds src/utils/usage-format.ts:455 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 723cc5d527ab; files: src/utils/usage-format.ts)
  • Vincent Koc: Raw commit 625945b adds src/agents/embedded-agent-runner/model.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 625945b7ae01; files: src/agents/embedded-agent-runner/model.ts)

PR surface

Source -13, Tests +11, Other -1. Total -3 across 40 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 26 413 426 -13
Tests 12 286 275 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 2 3 -1
Total 40 701 704 -3

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: same_root_cause
Canonical: #202999
Summary: This PR directly implements the linked issue's specified ownership split.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P3: This is behavior-preserving ownership and test-isolation cleanup without a demonstrated runtime defect or claimed performance improvement.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is behavior-preserving ownership and test-isolation cleanup without a demonstrated runtime defect or claimed performance improvement.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Validate the moved pricing and retained formatting suites, affected consumers, types, lint, assertion ratchet without pruning, and build at the reviewed head.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 21, 2026, 5:25 AM ET / 10:25 UTC.

@vincentkoc
vincentkoc marked this pull request as ready for review November 21, 2026 11:06
@vincentkoc
vincentkoc merged commit 8ae5dd4 into main Nov 21, 2026
239 checks passed
@vincentkoc
vincentkoc deleted the refactor/usage-pricing-owner branch November 21, 2026 11:31
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Nov 21, 2026
…3044

* origin/main:
  refactor(test): remove duplicate token startup wait case (#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (#203074)
  fix(test): exercise the sign-in callback path guard (#203075)
  refactor(tts): separate caption eligibility from text helpers (#203068)
  test: reuse worker preload options (#203058)
  refactor(test): share Bun native-policy test launcher (#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (#203056)
  refactor(test): remove duplicate claw origin rejection case (#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (#203047)
  refactor: separate skill queries from workspace discovery (#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (#203043)
  fix: avoid repeated filesystem probes before agent turns (#203057)
  perf(agents): preserve sealed history during endpoint compaction (#203037)
  fix(test): give deferred identity fixtures read scope (#203053)
  refactor(test): remove redundant channel catalog facade (#203052)
  refactor(cli): isolate daemon port presentation (#203020)
  refactor(cron): isolate CLI input parsing (#203031)
vincentkoc added a commit that referenced this pull request Nov 21, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (#203026)
  fix(ci): shard capable compatibility UI targets (#203042)
  perf(agents): restore selected subagent payloads once (#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (#203040)
  refactor(hooks): separate event predicates from hook registry (#203017)
  fix(ci): align update export audits with their consumers (#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (#203074)
  fix(test): exercise the sign-in callback path guard (#203075)
  refactor(tts): separate caption eligibility from text helpers (#203068)
  test: reuse worker preload options (#203058)
  refactor(test): share Bun native-policy test launcher (#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (#203056)
  refactor(test): remove duplicate claw origin rejection case (#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (#203047)
  refactor: separate skill queries from workspace discovery (#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (#203043)
  fix: avoid repeated filesystem probes before agent turns (#203057)
  perf(agents): preserve sealed history during endpoint compaction (#203037)
  fix(test): give deferred identity fixtures read scope (#203053)
  refactor(test): remove redundant channel catalog facade (#203052)
  refactor(cli): isolate daemon port presentation (#203020)
  refactor(cron): isolate CLI input parsing (#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 22, 2026
- status-message: the fork moved formatVoiceModeLine out (line cap) and
  upstream openclaw#203043 moved formatEstimatedContextBudgetTokens out; together
  they took the last reader of the SessionEntry type import (TS6133).
- followup-runner.test: upstream openclaw#202997/openclaw#203029 replaced the
  createSettledExecution fixture with createExecution("settled" default);
  the fork's suppressed-delivery ordering case follows (TS2552).

No behavior change.

Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…w#203043)

* refactor(usage): move pricing resolution to model catalog

* fix(usage): erase the pricing snapshot type import
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
* feat: open shared sessions in their source Control UI

* feat: open shared sessions in their source Control UI

OpenClaw-Publication: a3826b6b-5899-8ff2-a1b5-84961c64219f

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  fix(ci): decouple boundary fixture from timing inventory (openclaw#203026)
  fix(ci): shard capable compatibility UI targets (openclaw#203042)
  perf(agents): restore selected subagent payloads once (openclaw#203039)
  fix: keep standalone context from completing QA tool steps
  perf(sessions): reuse sealed ownership for context projections (openclaw#203040)
  refactor(hooks): separate event predicates from hook registry (openclaw#203017)
  fix(ci): align update export audits with their consumers (openclaw#203030)
  fix: keep cold baseline checks within the existing heap limit

* fix(session-share): accept the runtime config snapshot in the source link resolver

The stored-session link resolver took a mutable config, so the plugin's readonly
runtime snapshot failed production and test typechecks. Accept the snapshot type.

Document the real Open original setup: allow the link command on the receiver
Gateway, set the source Control UI origin, reinstall the source node with all
three commands, then approve the widened surface. Move the section ahead of
Security boundary and add a troubleshooting entry.

Assert through the Gateway catalog list that a provider-supplied link survives
streamed and final rows, and drop the menu unit test the browser fixture covers.

* Merge remote-tracking branch 'origin/main' into land/open-original-203044

* origin/main:
  refactor(test): remove duplicate token startup wait case (openclaw#203087)
  fix: keep Plugin SDK declarations within the build limit
  fix(ci): remove unused hook type exports (openclaw#203074)
  fix(test): exercise the sign-in callback path guard (openclaw#203075)
  refactor(tts): separate caption eligibility from text helpers (openclaw#203068)
  test: reuse worker preload options (openclaw#203058)
  refactor(test): share Bun native-policy test launcher (openclaw#203064)
  fix(cron): a chat-created automation's failure notice reaches that chat (openclaw#203056)
  refactor(test): remove duplicate claw origin rejection case (openclaw#203067)
  refactor(channels): move chunk-mode lookup to streaming readers (openclaw#203047)
  refactor: separate skill queries from workspace discovery (openclaw#203045)
  fix: resume new chat turns in retained tasks after a restart
  refactor: separate usage pricing preparation from formatting (openclaw#203043)
  fix: avoid repeated filesystem probes before agent turns (openclaw#203057)
  perf(agents): preserve sealed history during endpoint compaction (openclaw#203037)
  fix(test): give deferred identity fixtures read scope (openclaw#203053)
  refactor(test): remove redundant channel catalog facade (openclaw#203052)
  refactor(cli): isolate daemon port presentation (openclaw#203020)
  refactor(cron): isolate CLI input parsing (openclaw#203031)

* chore(plugin-sdk): record the approved session-discussion surface growth

Open original adds two exports to openclaw/plugin-sdk/session-discussion: the
stored-session Control UI path resolver and the session path parser. Raise the
public export and callable budgets by two for them.

Use neutral fixtures for the rejected-origin and rejected-query URL tests so the
fixtures do not resemble credentials; the same rejections are covered.

Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL 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.

refactor(usage): separate pricing preparation from formatting

1 participant