fix(gateway): compute sessions.usage aggregate totals from all sessions, not just the limited page (fixes #76496)#93612
Conversation
|
ClawSweeper review: did not complete due to Codex infrastructure failure. Reviewed June 16, 2026, 8:04 AM ET / 12:04 UTC. Summary PR surface: Source +3, Tests +53. Total +56 across 2 files. Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Merge readiness This is a ClawSweeper/Codex infrastructure failure, not a PR readiness or patch-quality verdict. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 65805e519df2. Evidence reviewedPR surface: Source +3, Tests +53. Total +56 across 2 files. View PR surface stats
What I checked:
Likely related people:
How this review workflow works
|
85b2297 to
fe4949d
Compare
|
Maintainer repair applied and pushed. Verification:
The final patch aggregates beyond the visible session page with bounded filesystem concurrency and keeps capped-page UI insights internally consistent. |
…ns, not just the limited page The limit parameter was applied before the aggregation loop, causing totalCost, totalTokens, and all other aggregate fields to reflect only the top N sessions by mtime. With >50 active sessions and the default limit=50, daily usage reports under-counted by 15-60%. Now all discovered sessions contribute to aggregates; only the per-session detail array (sessions) is capped by the limit. Fixes openclaw#76496
fe4949d to
349b8cd
Compare
|
Merged via squash.
Thanks @liuhao1024! |
…ns, not just the limited page (fixes openclaw#76496) (openclaw#93612) Merged via squash. Prepared head SHA: 349b8cd Co-authored-by: liuhao1024 <[email protected]> Co-authored-by: vincentkoc <[email protected]> Reviewed-by: @vincentkoc
…ns, not just the limited page (fixes openclaw#76496) (openclaw#93612) Merged via squash. Prepared head SHA: 349b8cd Co-authored-by: liuhao1024 <[email protected]> Co-authored-by: vincentkoc <[email protected]> Reviewed-by: @vincentkoc
What does this PR do?
Fixes the
sessions.usagegateway endpoint so that aggregate totals (totalCost, totalTokens, etc.) are computed across all sessions, not just the paginated subset. Previously, thelimitparameter silently capped both the per-session detail rows and the aggregate computation, making totals inaccurate when more sessions existed than the page size.Related Issue
Fixes #76496
Type of Change
Changes Made
src/gateway/server-methods/usage.ts: ReplacelimitedEntriesiteration with fullmergedEntriesiteration for usage loading and aggregation. Use alimitedKeysSet to filter which sessions appear in the response detail rows while still computing totals from all entries.src/gateway/server-methods/usage.sessions-usage.test.ts: Add test that verifies aggregate totals reflect all sessions even whenlimittruncates the detail list.How to Test
sessions.usagewith a smalllimit(e.g.,limit: 5)totalCostand token aggregates reflect ALL sessions, not just the 5 shownReal behavior proof
Behavior or issue addressed: The
sessions.usagegateway endpoint computed aggregate totals only from the limited page of sessions. When a user had more sessions than thelimitparameter, the totals were silently capped, showing incorrect cost/token sums.Real environment tested: macOS, Node.js, OpenClaw local build from
upstream/main+ patchExact steps or command run after the patch:
Observed result after fix: All four verification checks pass. The source now iterates all
mergedEntriesfor usage loading/aggregation, gates detail-row emission onlimitedKeys, and contains zero references to the oldlimitedEntriespattern. The test file confirms aggregate totals include sessions outside the page window.What was not tested: Live gateway session with >limit sessions (requires multi-session runtime setup). The logic correctness is verified via source inspection and the dedicated test file.