Skip to content

fix(agent-usage): preserve mixed price versions in usage bills - #168

Merged
239573049 merged 1 commit into
AIDotNet:mainfrom
Timskt:fix/usage-mixed-price-provenance
Dec 1, 2026
Merged

239573049 merged 1 commit into
AIDotNet:mainfrom
Timskt:fix/usage-mixed-price-provenance

Conversation

@Timskt

@Timskt Timskt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #165.

Two 100,000-input-token requests priced at $10/M and $30/M should still total $4, but a new bill must not attribute all $4 to the first catalog. This fixes the price label; it does not reprice history on refresh.

  • history.js now compares the incoming estimate's source and sync time at the point where it is recorded. A row that spans versions stays mixed after serialization and after per-directory rows are merged for billing.
  • bill.js uses the selected rows' versions when available. A mixed CSV row has price_source=mixed and an empty price_synced_at; the HTML receipt labels it a multi-version snapshot. Single-version rows retain their timestamps. Older rows without their own version still use unambiguous snapshot metadata.

Verification

On unmodified main@3742ff6, the two new Jaunt regression cases both failed: with the second request in the same directory the snapshot returned mixed=false; in a different directory the snapshot was mixed but the merged CSV row was not. The plugin and test sources did not change between that baseline and 39a8b4f.

Operation Fixed result
First request at A; refresh to B without new usage $1, still A; CSV unchanged
Append at B in the same or a different directory; reload the plugin 2 requests, 200,000 input tokens, $4, mixed in both CSV and HTML
Explicitly re-estimate at B $6, single version B

On main@39a8b4f plus this patch, macOS 27.2.1 arm64, .NET SDK 10.0.403: dotnet test tests/Octopus.Plugins.Jaunt.Tests/Octopus.Plugins.Jaunt.Tests.csproj -c Release passed 56/56 (0 skipped). The tests use the real plugin modules, file access, Jaunt engine and a local synthetic price catalog. Also checked filtered bills and older metadata-only rows against the bill renderer. No desktop UI or full-solution run. The existing SQLite restore warning is tracked in #129.

Impact and compatibility

This affects users of the built-in Agent Usage history and bill exporter on any desktop platform. No schema migration or rewrite of saved bills. An old snapshot that already lost its second price version cannot reconstruct it retrospectively; explicit re-estimation remains available.

@239573049 239573049 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified locally alongside #171 (AgentUsagePluginTests 24/24 passed, 0 conflicts).

@239573049
239573049 merged commit e39ac48 into AIDotNet:main Dec 1, 2026
1 of 4 checks passed
239573049 added a commit that referenced this pull request Dec 1, 2026
The per-day store (one segment file per day plus a manifest) replaced the single usage-snapshot.json, so the two
upstream fixes are re-applied on top of it:

- #168: a row priced from the table keeps one price version; tokens recorded at another version mark it "mixed" (no
  single snapshot price), the snapshot meta turns mixed as rows are recorded, and bill rows merge versions the same way.
  Segments store a mixed row's missing price apart from a model without a price.
- #171: rows inside a day are indexed by the encoded [cwd, agent, model] tuple, so directories and model names with
  '|' never merge two rows; a version 1-2 snapshot's pipe-joined keys are split the same way #171 does.

Migrating a version 1-2 snapshot now keeps every row as it was (no recount, no reprice), Claude rows included, and
leaves the old file untouched so a rollback to a version that only reads it resumes from a consistent state. Claude
replies are counted once per message id from the upgrade on.

The #171 tests read the per-day store instead of the old file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

用量账单:同一模型换价后追加用量,混合金额仍标为旧价格版本

2 participants