fix(stats): stop reporting oversized session files to Sentry (MAESTRO-M9)#1114
fix(stats): stop reporting oversized session files to Sentry (MAESTRO-M9)#1114pedramamini wants to merge 1 commit into
Conversation
The global-stats incremental parse loops in agentSessions.ts called captureException() on every parse failure, including the expected RangeError: Invalid string length thrown when fs.readFile(..., 'utf-8') hits a session file too large for V8 to read into a single string. This produced Sentry noise (MAESTRO-M9) for an expected, recoverable condition: the oversized file is simply skipped and global stats continue for every other session. Mirror the pattern already used in claude-session-storage.ts and codex-session-storage.ts - treat RangeError as 'file too large to parse' (log a warning, skip) and keep reporting genuinely unexpected errors to Sentry.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesRangeError handling for oversized session file parsing
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Addresses four stable-channel (main) Sentry issues seen on the current
0.17.x release, all where the bug and path to resolution are clear:
- MAESTRO-RR: the Codex usage sampler reported network "request: fetch
failed" errors to Sentry (the dominant cause, ~375 events). Offline /
DNS / TLS / abort-timeout failures are expected for a best-effort
background sampler, so skip them - the UI still surfaces the error
state. The existing 401/403 carve-out (un-logged-in CODEX_HOME) stays.
- MAESTRO-M9: the global-stats refresh reported the RangeError ("Invalid
string length") that V8 throws when a session log is too large to read
into a single string. Treat it as an expected, recoverable data
condition (skip the file, log a warning) instead of a Sentry crash -
mirrors the storage-layer pattern and the rc fix in #1114 so the two
converge cleanly on the next rc -> main merge.
- MAESTRO-SP: stats:record-shortcut-usage threw "Database not
initialized" when a shortcut fired before the stats DB finished
initializing. Skip the fire-and-forget analytics write when the DB
isn't ready yet (new StatsDB.isReady()).
- MAESTRO-QF: the debounced session-persistence flush reported the main
process's deliberate "recoverable disk error" (a false return thrown
only to preserve isPending for retry) to Sentry. Keep that expected
user-environment condition out of Sentry; genuine flush failures still
report.
Adds regression tests for RR, SP, and QF.
Summary
Resolves Sentry issue MAESTRO-M9 -
RangeError: Invalid string lengthin theagentSessionsglobal-stats handler (events on bothchannel:rcandchannel:stable).The two incremental parse loops in
getGlobalStats(agentSessions.ts) calledcaptureException(error)on every parse failure. That includes the expectedRangeError: Invalid string length, which V8 throws whenfs.readFile(file, 'utf-8')hits a session file too large to read into a single string (> ~512 MB). The result was Sentry noise for a condition we already recover from gracefully: the oversized file is skipped and global stats continue for every other session.Fix
Treat
RangeErroras the expected "file too large to parse" condition - log a warning and skip - while still reporting genuinely unexpected errors to Sentry. This mirrors the exact pattern already used in the per-agent storage layer:src/main/storage/claude-session-storage.ts(parseSessionFile)src/main/storage/codex-session-storage.ts(readSessionFile)Both global-stats loops (Claude + Codex) now follow the same convention. No behavior change for any readable file; this only silences telemetry on an expected, recoverable data condition (consistent with the project's error-handling guidance in
CLAUDE.mdand the earlier rc telemetry-noise cleanup in #1094).Validation
tsc -p tsconfig.main.json --noEmit- 0 errorseslint+prettier --checkon the changed file - cleanvitest run src/__tests__/main/ipc/handlers/agentSessions.test.ts- 20/20 passNotes
rc(the affected code lives on bothrcandmain; this PR fixes the branch of focus).partition_alloc::OnNoMemoryInternalOOM crashes (MAESTRO-9J/4T/5W),Window unresponsive(MAESTRO-62), the Linux glibc 2.38 packaging error forbetter-sqlite3(MAESTRO-RS), a different project's cron (CAM-WORKERS-9), andmaestro-p --status(MAESTRO-Q2, previously deliberately deferred).Summary by CodeRabbit