Skip to content

fix(host-service): stop usage.history throwing on very large usage histories - #6912

Merged
saddlepaddle merged 1 commit into
mainfrom
sentry/usage-history-unbounded
Aug 27, 2026
Merged

saddlepaddle merged 1 commit into
mainfrom
sentry/usage-history-unbounded

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

usage.history (and anything else routed through collectUsageEntries) fails deterministically on machines with a very large Claude usage history: the usage worker throws RangeError: Maximum call stack size exceeded, so the Usage tab's history and leaderboard data never load — every time, for exactly the heaviest users. 3 events on release 1.25.0 (HOST-SERVICE-4V), all the same machines retrying.

User-visible harm: heavy Claude users open the Usage tab and its history/leaderboard never loads, on every attempt.

Reach: the defect shipped in the leaderboard work (#6875, release 1.25.0) and is unchanged on main. This fix rides the next host-service/desktop release and reaches affected users via the normal update path; the failure is deterministic per machine, so the fix verifiably removes it for them.

Why code: archiving does nothing — the feature is broken for those users, and the failure recurs on every query. A Sentry-side filter is forbidden by the classification contract (#6164) and wouldn't restore the feature. The one-line root-cause fix wins.

Root cause

packages/host-service/src/trpc/router/usage/history/entries.ts:83:

entries.push(...claudeEntriesByMessage.values());

Argument spread passes every deduped Claude entry as a distinct call argument. V8 bounds call arguments by stack size, so past roughly 100–125k entries the call itself throws RangeError: Maximum call stack size exceeded. A heavy user's 30-day window can exceed that (one entry per assistant API message). Reproduced under Node 22 (the worker's engine) with a 200k-entry map:

$ node spread-repro.mjs
spread: RangeError: Maximum call stack size exceeded
loop: ok, 200000 entries

(Bun/JSC tolerates 200k, which is why local bun test never caught it — production host-worker runs on V8.)

Fix

Append in a loop — stack usage no longer scales with entry count:

for (const entry of claudeEntriesByMessage.values()) {
	entries.push(entry);
}

Worker-boundary payload does NOT need bounding: I verified what actually crosses the MessagePort. computeUsageHistory returns UsageHistory, already a bounded aggregate — day buckets bounded by the days param, per-model rows bounded by distinct models, projectDetails capped at top 24 projects with top 20 sessions each (aggregate.ts). computeLeaderboardPayload returns day×provider×model buckets, likewise bounded. The unbounded entries array is internal to the worker and never serialized, so the spread is the whole defect and this is the minimal fix.

No typed cause added: this fix removes a throw rather than adding one — the query now succeeds. Nothing reads a cause.kind here, so no TRPCError machinery was introduced.

Adjacent, deliberately untouched: parseCodexLogFile pushes entries one at a time already (no spread); the array-literal spreads in aggregate.ts ([...map.values()]) iterate rather than pass call arguments and have no argument-count limit; the desktop minidump OOM issues (DESKTOP-12V et al.) are a separate memory-scaling face of this subsystem owned by the triage automation and are not addressed here.

Verification

$ bunx biome check packages/host-service/src/trpc/router/usage/history/entries.ts
Checked 1 file in 9ms. No fixes applied.

$ cd packages/host-service && bun run typecheck
$ tsc --noEmit --emitDeclarationOnly false
(exit 0)

$ bun run test src/trpc/router/usage/history/
 20 pass
 0 fail
 28 expect() calls
Ran 20 tests across 2 files. [31.00ms]

Refs HOST-SERVICE-4V

https://claude.ai/code/session_0133xN5zZ3goUNfKAy9cLfA9


Summary by cubic

Fixes usage.history failing with RangeError: Maximum call stack size exceeded for users with very large Claude usage histories, so the Usage tab history and leaderboard now load for heavy users. The deduped entries are appended one at a time instead of spread into push(), which passed every entry as a call argument and hit V8's argument limit. No payload changes are needed since the worker-boundary data is already bounded. Refs HOST-SERVICE-4V.

Written for commit b314cf1. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue that could prevent large usage histories from loading successfully.
    • Usage history entries are now processed reliably, avoiding failures when many Claude entries are present.

…stories

collectUsageEntries appended the deduped Claude entries with
entries.push(...map.values()), which passes every entry as a call
argument. Past V8's argument limit (~125k entries in the worker) that
throws RangeError: Maximum call stack size exceeded, so usage.history
failed deterministically for exactly the heaviest users. Append in a
loop instead — stack usage no longer scales with entry count.

Refs HOST-SERVICE-4V

Claude-Session: https://claude.ai/code/session_0133xN5zZ3goUNfKAy9cLfA9
@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 46b898a1-2b92-4bc3-b03e-6cc38535b39e

📥 Commits

Reviewing files that changed from the base of the PR and between dc5443b and b314cf1.

📒 Files selected for processing (1)
  • packages/host-service/src/trpc/router/usage/history/entries.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The usage history collector now appends deduplicated Claude entries individually. This avoids the V8 argument-count limit for large histories without changing other behavior.

Changes

Usage history

Layer / File(s) Summary
Safe Claude entry append
packages/host-service/src/trpc/router/usage/history/entries.ts
The collector replaces a spread-based push() call with a for...of loop that appends each deduplicated Claude entry individually.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to b314c

The change prevents very large usage histories from failing while preserving existing behavior and outputs. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: harshithmullapudi

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses conventional commit format and clearly identifies the fix for failures on very large usage histories.
Description check ✅ Passed The description explains the problem, root cause, fix, scope, and verification results. It provides the required testing information under “Verification,” but it does not include the template’s Checkl…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, root cause, fix, scope, and verification results. It provides the required testing information under “Verification,” but it does not include the template’s Checklist section.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentry/usage-history-unbounded

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@saddlepaddle
saddlepaddle merged commit 1629654 into main Aug 27, 2026
20 checks passed

This branch was previously deployed

1 inactive deployment
preview — b314cf16 Deployed Aug 27, 2026 by saddlepaddle via Deploy Web #8556
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.

1 participant