Repository navigation
fix(agents): keep cumulative token totals consistent - #117930
Conversation
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 7:49 AM ET / 11:49 UTC. ClawSweeper reviewWhat this changesThe PR removes Merge readinessKeep this PR open for normal maintainer review. The branch is a focused, coherent repair for a source-proven mixed-basis usage object, but it changes the observable meaning of an existing metadata field and this read-only environment could not complete the repository-required direct sibling Codex source inspection because Priority: P2 Review scores
Verification
How this fits togetherEmbedded agent runs combine token usage from each model call into agent metadata. That metadata feeds session-context accounting, cron telemetry, OpenAI-compatible gateway responses, and gateway worker payloads, which need aggregate billing data and latest-call context to remain distinct. flowchart LR
A[Model calls] --> B[Usage accumulator]
B --> C[Agent metadata builder]
C --> D[Latest-call context]
C --> E[Cumulative usage metadata]
D --> F[Session context]
E --> G[Cron telemetry]
E --> H[Gateway responses and workers]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -40, Tests +45. Total +5 across 11 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt one canonical cumulative Do we have a high-confidence way to reproduce the issue? Yes: current main has a deterministic source path where cumulative accumulator fields are returned with only Is this the best way to solve the issue? Yes in code shape: deleting the mixed-basis override is the narrowest owner-boundary repair because latest-call context already has separate fields. The merge decision remains conditional on direct Codex-contract verification and compatibility acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 096cd231ea74. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Owner decision: accept and land the cumulative metadata contract after normal maintainer review. ClawSweeper rank-up moves are complete:
The reported storage-schema flag is a path heuristic false positive: |
|
@clawsweeper re-review |
|
Follow-up proof at |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head rank-up closeout for |
|
Merged via squash.
|
* fix(agents): keep aggregate usage totals cumulative * test(agents): cover cumulative usage reporting paths
Closes #117586
What Problem This Solves
Fixes an issue where multi-call agent runs exposed token metadata whose input/output/cache buckets were cumulative but whose
totalwas replaced with the latest provider-call total. Consumers of agent-exec JSON, diagnostics, cron telemetry, and billing metadata could therefore receive an internally inconsistent aggregate.Why This Change Was Made
usagenow remains the canonical cumulative run aggregate. Latest-call context stays in the existinglastCallUsageandpromptTokensfields. The obsoletelastTurnTotaloverride and its cross-loop plumbing were removed instead of adding another reconciliation rule.Architectural owner: embedded agent usage normalization/reporting. No config, protocol, SDK, provider, or persistence contract changes.
User Impact
Multi-call runs now report internally consistent cumulative token totals. Current-context behavior is unchanged because it already reads
lastCallUsage/promptTokens.Evidence
350, but metadata returned the latest-call total200.usage-reporting.test.tspassed 10/10;pnpm check:changedpassed. Run: https://github.com/openclaw/openclaw/actions/runs/30739656157git diff --check, and the 41-test focused suite passed on currentorigin/main.Codex dependency contract checked directly at
openai/codex@2b5bdcf67547860f2e5c5a605009a70026796b2b:TokenUsageInfoseparates cumulativetotal_token_usagefromlast_token_usage, and appends the latter into the former.Regression provenance: the mixed-basis reporting policy originated in
a62ff19a6638(2026-02-16, @artale; committed by @steipete), and PR #34275 propagated it into error metadata (authored by @RealKai42, merged by @jalehman on 2026-03-04).AI assistance: Codex assisted with investigation, implementation, tests, and structured review. The maintainer directly verified the source contracts, diff, and proof above.