Skip to content

fix(stats): bound retained events during stalled writes - #20941

Merged
OrcaWin merged 3 commits into
mainfrom
np-oom-scan-stats-retention
Sep 18, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
np-oom-scan-stats-retention

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

Stats events were capped only when a snapshot was serialized. A stalled asynchronous profile write could delay serialization indefinitely while new events kept accumulating in Electron main.

Apply the existing 10,000-event limit when each event is recorded. Keep the newest events and preserve lifetime aggregate totals.

Validation: 24 stats tests passed, including a regression that blocks a write, records more than 20,000 events, checks the in-memory bound before serialization, and verifies the saved order and lifetime totals after unblocking. Targeted oxlint and oxfmt passed.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a5cdd1d3-04fd-41e9-b3d7-9881ca5a91be

📥 Commits

Reviewing files that changed from the base of the PR and between d06c78f and b34a5d9.

📒 Files selected for processing (1)
  • src/main/stats/collector-async-save.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/stats/collector-async-save.test.ts

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


📝 Walkthrough

Walkthrough

StatsCollector.record() now trims the in-memory events array to 10,000 entries after each event. A new test records 20,000 events while an asynchronous write is stalled. It verifies the retained in-memory slice, persisted events, and aggregate values after the write completes.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b34a5

No merge-blocking issue was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, and validation, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof with an N/A explanation, Testing checkboxes, Re… Complete the required template sections. Add an ELI5 summary, a linked issue after “Fixes #”, Visual Proof with “N/A” and a reason because this is not a UI change, testing details and checkbox status, review information, the agent skill ups…
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: bounding retained stats events during stalled asynchronous writes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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, solution, and validation, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof with an N/A explanation, Testing checkboxes, Review, boundary confirmation, Notes, and Checklist items.

Resolution

Complete the required template sections. Add an ELI5 summary, a linked issue after “Fixes #”, Visual Proof with “N/A” and a reason because this is not a UI change, testing details and checkbox status, review information, the agent skill upstream boundary checkbox, notes on compatibility and performance, and the applicable checklist confirmations.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • In-memory retention during stalled writes — record() in src/main/stats/collector.ts now trims this.events to MAX_EVENTS immediately after each push, closing the window where a write parked on writeFile deferred the cap until serialize() ran.
  • Regression test — bounds retained events while a stalled write prevents serialization holds the async write open, records a seed plus 20,000 events, asserts the in-memory bound mid-stall, and then asserts the persisted newest-10k order plus lifetime aggregates.

The new cap is redundant with the serialize() trim only for the normal path; keeping both is correct since serialize() still guards events loaded from an oversized on-disk file. updateAggregates is called on the incoming event after trimming, so lifetime totals are preserved. I confirmed the regression test is real by reverting just the record() cap: it fails with expected 10001 to be less than or equal to 10000, and pnpm test src/main/stats passes 24/24 with the fix.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit 28c32f3 into main Sep 18, 2026
52 of 54 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
* fix(stats): cap retained events before asynchronous persistence

* test: use typed access in memory retention regressions

---------

Co-authored-by: m4air <[email protected]>
Co-authored-by: m4air <[email protected]>
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