Skip to content

fix: avoid array spread when merging messages - #10

Merged
evanlong-me merged 1 commit into
evanlong-me:mainfrom
stephanschuler:fix/spread-rangeerror
Sep 16, 2026
Merged

evanlong-me merged 1 commit into
evanlong-me:mainfrom
stephanschuler:fix/spread-rangeerror

Conversation

@stephanschuler

Copy link
Copy Markdown
Contributor

What & why

mu aborts with ❌ Error fetching usage data: Maximum call stack size exceeded and prints
nothing once a source returns more than roughly 100k messages. My ~/.claude/projects/ holds
120,654 assistant messages, which is enough to hit it on every run — with and without -s,
and -t / -p are no workaround because filtering happens after the merge.

The three merge sites append with a spread, so every message becomes its own argument to
Array.prototype.push and V8 throws past its argument limit:

  • src/usage.ts:76 — merges all sources, the one that actually fails today
  • src/sources/claude.ts:64 and src/sources/pi.ts:64 — still below the threshold because
    they accumulate per directory, but the same failure waits there

Closes #9

How

Each site pushes in a loop instead. One comment per site names the trap, so the spread does
not come back as a "simplification" later:

// no spread: RangeError past ~100k args
for (const m of messages) allMessages.push(m);

No behaviour change beyond not crashing: same messages, same order, same totals. Fixing only
usage.ts would have left two loaded guns in the adapters, which is why all three are in
here — it is the same one-line change three times, not three concerns.

Verification

  • npm run build passes
  • Verified the change by running node dist/cli.js with the affected flags
  • Docs updated if behavior changed (README.md, AGENTS.md, and the help text in
    src/cli.ts stay in sync)

Details:

$ npm run build          # tsc, clean

$ node dist/cli.js -s claude
  Results: 3 entries (149 msgs from 120675 total)   # was: RangeError

$ node dist/cli.js       # all sources, no filter
  Results: 3 entries (150 msgs from 120676 total)   # was: RangeError

Docs need no change — the observable behaviour is unchanged, the command simply stops
crashing. No new flags, no new output, so README.md, AGENTS.md and the help text in
src/cli.ts stay as they are.

No tests: the repo has no test setup, and a regression test for this would have to build
100k+ objects to trip the limit. Happy to add one if you want the infrastructure.

Array.prototype.push with a spread passes every element as its own
argument; V8 throws RangeError: Maximum call stack size exceeded past
roughly 100k arguments. With 120k messages in ~/.claude/projects the
merge in autoDetect crashed the whole run.

All three merge sites now push in a loop.
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.

bug: RangeError "Maximum call stack size exceeded" when a source returns >100k messages

2 participants