Skip to content

Commit b576bb4

Browse files
authored
fix(usage): retain reset history and unify accounting (#131667)
* fix(usage): retain reset history and unify accounting Keep family selection within the recorded agent and assign each instance once. Carry discovered SQLite or JSONL sources into batched loading, including empty current sessions and history encountered before a current artifact. Share Gateway and Control UI aggregation and total arithmetic, use canonical pricing for detail logs, and invalidate both result caches on config changes. Split calendar, cache, selection, and loading owners out of the usage handler. Add failing-before regressions for reset history, overlapping families, mixed sources, config replacement, missing-price exports, and log pricing. * refactor(usage): keep accounting type imports acyclic Make batched loading own its minimal input contract and import shared accounting types from the leaf definition instead of the runtime barrel. Remove obsolete current-JSONL fixture setup to keep the existing usage test within its line cap. Verified both CI failures locally: zero Madge cycles and passing core lint with the CI tsconfig. No runtime behavior or public protocol changes. * refactor(usage): remove unused accounting type re-exports The shared usage contracts now import their canonical leaf definitions. Remove the six obsolete internal-barrel type re-exports left by that ownership repair.
1 parent b18d444 commit b576bb4

25 files changed

Lines changed: 2288 additions & 1985 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,6 @@ src/gateway/server-methods/terminal.ts 7
29882988
src/gateway/server-methods/tools-catalog.ts 2
29892989
src/gateway/server-methods/ui-command.ts 1
29902990
src/gateway/server-methods/update.ts 2
2991-
src/gateway/server-methods/usage.ts 3
29922991
src/gateway/server-methods/web.ts 3
29932992
src/gateway/server-methods/wizard.ts 1
29942993
src/gateway/server-methods/workspace-fs.ts 2
@@ -3237,7 +3236,7 @@ src/infra/session-cost-usage-cache-runtime.ts 1
32373236
src/infra/session-cost-usage-cache.sqlite.ts 1
32383237
src/infra/session-cost-usage-collection.ts 4
32393238
src/infra/session-cost-usage-pricing.ts 6
3240-
src/infra/session-cost-usage-reporting.ts 9
3239+
src/infra/session-cost-usage-reporting.ts 8
32413240
src/infra/session-delivery-queue-runtime.ts 1
32423241
src/infra/session-delivery-queue-storage.ts 6
32433242
src/infra/shell-env.ts 1

‎config/max-lines-baseline.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ src/gateway/server-methods/sessions-files.ts
653653
src/gateway/server-methods/skills.ts
654654
src/gateway/server-methods/talk.test.ts
655655
src/gateway/server-methods/talk.ts
656-
src/gateway/server-methods/usage.ts
657656
src/gateway/server-node-events.test.ts
658657
src/gateway/server-node-events.ts
659658
src/gateway/server-plugins.test.ts
@@ -884,7 +883,6 @@ ui/src/pages/sessions/view.test.ts
884883
ui/src/pages/sessions/view.ts
885884
ui/src/pages/skill-workshop/view.ts
886885
ui/src/pages/skills/view.ts
887-
ui/src/pages/usage/metrics.ts
888886
ui/src/pages/usage/view-details.ts
889887
ui/src/pages/usage/view-overview.ts
890888
ui/src/pages/usage/view.ts

‎docs/reference/api-usage-costs.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Map of OpenClaw features that can call paid provider APIs, where each reads its
2828

2929
- Shows transcript-derived token and estimated-cost totals for the selected date range, with breakdowns by provider, model, agent, channel, and token type.
3030
- Named sessions use their stored agent owner. Identical session IDs under different agents remain separate, including when historical lineage is grouped.
31+
- Grouped history remains visible after a session reset, even before the new session has its first message. Filtering and JSON exports retain the breakdown of entries with missing model prices.
3132
- Compares shorter calendar windows ending on the selected range end date. Missing dates count as zero-usage calendar days; they are not skipped to create a denser window.
3233
- Labels the daily chart scale directly. A `√` badge means square-root compression is keeping low-usage days visible.
3334
- These totals describe the available local session history, not a provider invoice or lifetime billing ledger. The UI warns when pricing is missing for some entries.

‎scripts/check-session-accessor-boundary.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export const readOnlyGatewaySessionAccessorFiles = new Set([
268268
"src/gateway/server-methods/sessions-subscriptions.ts",
269269
"src/gateway/server-methods/task-suggestions.ts",
270270
"src/gateway/server-methods/tools-effective.ts",
271-
"src/gateway/server-methods/usage.ts",
271+
"src/gateway/server-methods/usage-session-selection.ts",
272272
"src/gateway/server-session-events.ts",
273273
]);
274274

0 commit comments

Comments
 (0)