Skip to content

fix(agent-usage): preserve project and model names in usage history - #171

Merged
239573049 merged 1 commit into
AIDotNet:mainfrom
Timskt:fix/usage-history-path-keys
Dec 1, 2026
Merged

239573049 merged 1 commit into
AIDotNet:mainfrom
Timskt:fix/usage-history-path-keys

Conversation

@Timskt

@Timskt Timskt commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #166.

A Claude request recorded under /projects/core|mobile exported as mobile,claude instead of claude,fixture-model. Changing just the pipe to a hyphen made the CSV correct. The bug is in the history index, before CSV escaping: it joined the day, directory, agent and model with | and later split on the same character.

History now indexes the tuple without delimiter ambiguity and keeps its four fields on each row. Bills, budgets, history charts and model lookup read those fields directly. Models containing | and two different tuples that previously produced the same key remain distinct.

Snapshot compatibility

  • Existing v1 objects and v2 entry arrays are read without repricing old amounts or resetting file cursors. The writer retains the v2 [key, row] layout and gives colliding tuples distinct storage keys, so the previous reader doesn't drop their costs.
  • An ambiguous legacy key has no complete record of where its fields ended. The reader uses the rightmost known agent; if two records were already combined, their total is preserved, but their individual shares cannot be reconstructed. Downgrading restores the old labeling behavior, not the fix. Saved bill exports are untouched.

Verification

On main@5b3efc9, all three new Jaunt cases failed before the fix. With this patch, dotnet test tests/Octopus.Plugins.Jaunt.Tests/Octopus.Plugins.Jaunt.Tests.csproj -c Release passed 57/57 (0 skipped), on macOS 27.2.1 arm64 with .NET SDK 10.0.403.

  • With one $1 request in core-mobile and one in core|mobile, the CSV now reports claude,fixture-model,2,200000,0,0,200000,2.000000. Removing the synthetic transcripts and reloading the plugin reproduces the same CSV and all four project totals in the collision fixture.
  • Both v1 and v2 keep a historical $7 estimate, ignore a duplicate request at the saved cursor, and add only the new $0.50. A separate round-trip through the actual previous plugin read $8, appended $0.50 to a plain-path project, and returned $8.50 after re-upgrade.

I also applied this commit and #168 together to main@1304ffa: no merge conflicts, and the combined Jaunt suite passed 59/59 (0 skipped).

Impact

This affects the built-in Agent Usage history, project budgets and new bill exports on desktop. The tests use local synthetic transcripts and an offline price catalog. No desktop UI or full-solution run.

@239573049
239573049 merged commit 4a9b276 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.

用量导出:项目目录名含竖线时,CSV 的智能体和模型列错位

2 participants