Skip to content

refactor(runtime): defer unused model pricing lookup - #189893

Merged
vincentkoc merged 1 commit into
mainfrom
refactor/inference-x42-usage-price-fallback
Nov 1, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
refactor/inference-x42-usage-price-fallback

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Related: #188252

What Problem This Solves

Plugin completion accounting resolves configured and catalog prices even when an explicit billed cost already takes precedence.

User Impact

No intended result or billing-policy change. Recorded costs, including billed zero, retain precedence; missing costs keep direct or aggregate estimation, and unavailable costs stay unavailable.

Why This Change Was Made

Resolve prices only inside the existing estimation fallback. Keep the shared accounting owner, price arguments, usage callbacks and sparse diagnostic semantics unchanged. No cache, API, SDK or configuration change is introduced.

Production decreases by one line. The existing host-dispatch case also protects billed zero through returned usage and logging; two owning cases independently assert direct and aggregate configured-price fallback. Tests grow 40 lines with an exact separate allocation.

Evidence

  • Qualified execution passed 88 tests across four accounting, host-dispatch, pricing and usage suites in 87.915s wrapper time. Core types, owning plugin test types and targeted typed production/test lint passed.
  • Native author formatting, syntax, whitespace, signed hooks and the source test-line ratchet passed. Fresh independent full-range review of 03f2b2d44c04ee6aa805fb998c458a97628e0c9e..3599e3e5c632487e6f9ce1bc41a2cad658ee4478 found no actionable findings (confidence 0.95).
  • Current-owner intake confirmed the eager lookup remains present. Source, reviewed head, qualified dependency inputs and native binding were independently verified before and after measurement. Only the production file varied during comparison; final committed test inputs were identical.
  • Native preparation passed at the unchanged reviewed head. The ordinary squash route merged it as 72943b04f5aba1337efd4e59a13e68103c9e72b4; the observed final PR rollup had 60 successes, 153 skips and one neutral result, with no failures. Native completion is recorded. No production latency, CPU, RSS or physical-allocation gain is claimed.

Matched work and cost

The acceptance rule was published before measurement: five serial interleaved baseline/candidate pairs, retain the first baseline and every point, unchanged outputs, fewer billed-path lookups, unchanged necessary fallback lookups. Any 20% adverse measured cell stops the sequence. No additional or replacement samples were run; the largest adverse paired cell was 15.812%.

Committed workload:

node scripts/run-vitest.mjs src/plugins/runtime/runtime-llm.runtime.test.ts src/plugins/runtime/runtime-model-usage.test.ts --maxWorkers=1 -t "preserves billed cost|estimates (direct|aggregate) cost when no billed total is recorded"

Use Node 26.13.0, Vitest 5.0.5, Darwin arm64, the frozen qualified install, one worker, fresh processes and distinct fresh filesystem-module caches, with native V8 coverage. Normal native compiler-output reuse is unchanged. The production file is restored after every command. Observed one-minute host load ranged from 8.030 to 14.248.

All ten runs passed the same four literal-output cases. Actual worker profiles contained both the pricing resolver and its lower implementation even at zero: billed host lookups fell 2→0, while direct/aggregate configured fallback stayed 2→2. Every run retained four accounting completions and two host dispatches. This exercises the real runtime accounting consumer with provider I/O isolated; it is not live-provider latency evidence.

All durations below are seconds. A is baseline, B is candidate; unit-fast owns the two configured-fallback rows and plugins owns the two billed host-dispatch rows.

Pair A wrapper B wrapper A unit-fast B unit-fast A plugins B plugins
1 79.722 82.038 44.17 47.87 27.27 26.52
2 79.311 68.398 44.47 40.84 27.38 20.44
3 77.148 79.310 42.51 42.26 27.43 27.40
4 77.923 72.449 47.20 40.40 23.69 24.93
5 75.011 82.336 44.28 46.80 23.59 27.32
Metric Baseline median / p95 Candidate median / p95
Wrapper 77.923 / 79.722 79.310 / 82.336
Unit-fast group 44.280 / 47.200 42.260 / 47.870
Plugins group 27.270 / 27.430 26.520 / 27.400

P95 uses nearest rank over all five samples. Wrapper ranges were 75.011–79.722s and 68.398–82.336s.

Maintainer cost decision: accept the observed instrumented-wrapper median increase of 1.780%, p95 increase of 3.279%, and unit-fast p95 increase of 1.419% for the verified removal of unused pricing work with unchanged outputs. The cause of these timing movements remains unresolved; rounded transform shares and cache state do not establish causation. This accepts the measured diagnostic-test cost, makes no production/provider speed claim and waives no native or CI gate.

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

clawsweeper Bot commented Nov 1, 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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR resolves model prices only when plugin completion accounting needs an estimated cost.

Example: A plugin completion reports a provider-billed total of $0.

  • Before: Accounting resolves model prices and returns costUsd: 0.
  • After: Accounting skips price resolution and still returns costUsd: 0.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source change is focused and appears correct, but runtime validation remains pending and successful checks do not establish accounting behavior.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor is outside the ordinary contributor proof gate; its body candidly supplies source reasoning rather than an exercised completion or measured lookup reduction.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Completion accounting performs unnecessary pricing work even when provider billing already supplies the final cost.
Reason: The maintainer-authored direction is established, and the change removes a concrete unnecessary operation while preserving the existing accounting contract; the broader campaign is correctly referenced as related.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored draft open: it removes unused pricing work through the existing accounting owner, with no introduced correctness or security defect found.

Priority: P3
Reviewed head: 3599e3e5c632487e6f9ce1bc41a2cad658ee4478

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No after-fix shipped plugin-completion trace or matched baseline/head lookup counts are supplied, and the changed tests have not been reported as executed.
Agent review details

How this fits together

The shared plugin accounting owner receives completion usage, model identity, and configuration, then returns normalized counters and cost while notifying logging and diagnostic consumers.

flowchart TD
  A[Plugin completion] --> C[Shared usage accounting]
  B[Accepted decision result] --> C
  C --> D[Explicit billed cost]
  C --> E[Fallback price resolution]
  D --> F[Normalized usage]
  E --> F
  F --> G[Caller and diagnostics]
Loading

Technical review

Best possible solution:

Retain the lazy lookup in the shared accounting owner while preserving billed-cost precedence and both estimation modes.

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

Current-main source unconditionally resolves prices for direct and aggregate accounting before checking explicit billed cost; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Moving the existing resolver into the estimation fallback is the smallest complete change: it removes unnecessary work without introducing another owner, cache, API, or billing policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • RoboClaw: Raw commit cff3c30 adds src/plugins/runtime/runtime-model-usage.ts:54 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cff3c307ba6d; files: src/plugins/runtime/runtime-model-usage.ts)
  • Peter Steinberger: Raw commit 496f32b adds src/plugins/runtime/runtime-llm.runtime.test.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 496f32bef297; files: src/plugins/runtime/runtime-llm.runtime.test.ts)

PR surface

Source -1, Tests +40, Other +2. Total +41 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 9 -1
Tests 2 115 75 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 125 84 +41

Review metrics

Metric Value Why it matters
Production versus test LOC Production +8/-9; tests +115/-75. Production shrinks by one line; net test growth protects billed-zero logging and direct/aggregate configured-price fallback without adding production machinery.

Labels

Label changes:

  • add P3: This is a narrow behavior-preserving cleanup with no established user-facing failure or measured performance regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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 a narrow behavior-preserving cleanup with no established user-facing failure or measured performance regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

  • Run the focused accounting and runtime completion suites plus targeted type and lint checks.
  • Record baseline/head pricing lookup counts through a shipped plugin completion, including billed zero and an unbilled estimation fallback.

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 October 31, 2026, 8:38 PM ET / November 1, 2026, 00:38 UTC.

@vincentkoc
vincentkoc marked this pull request as ready for review November 1, 2026 01:46
@vincentkoc
vincentkoc enabled auto-merge (squash) November 1, 2026 01:47
@vincentkoc
vincentkoc merged commit 72943b0 into main Nov 1, 2026
211 checks passed
@vincentkoc
vincentkoc deleted the refactor/inference-x42-usage-price-fallback branch November 1, 2026 01:54
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

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

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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