Skip to content

fix(default-reporter): render install stats once - #13103

Merged
zkochan merged 3 commits into
mainfrom
fix-output
Jul 17, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-output

Conversation

@zkochan

@zkochan zkochan commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Fix duplicate Packages: +N statistics output from Rust pnpm installs in
append-only and non-interactive terminals.

The installer emits separate added and removed statistics events. The
TypeScript reporter combines this pair, while the Rust reporter rendered after
each event and therefore printed the same block twice when the removed count
was zero. The Rust reporter now buffers the pair and renders the combined
statistics once. If the run ends with only one event, it flushes the partial
statistics at summary time, matching the TypeScript stream-completion fallback.
The TypeScript implementation already has the intended behavior, so it does not
need a matching code change.

Reproduction: https://github.com/pnpm/pnpm/actions/runs/29564581286/job/87834282836

Squash Commit Body

The installer emits separate added and removed statistics events. The Rust
append-only reporter rendered both immediately, which printed the same package
statistics block twice when the removed count was zero.

Buffer both statistics events and render their combined result once, matching
the TypeScript reporter. Flush partial statistics when the run summary arrives
so a missing event cannot suppress the output. Add append-only regression tests
for both the normal pair and incomplete-pair fallback.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Codex, GPT-5).


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed duplicate package statistics output during installs in non-interactive terminals.
    • Improved package statistics rendering so “added” and “removed” counts are displayed together, with correct timing, even when messages arrive separately.
    • Prevented premature or incorrect stats summaries from being shown for the wrong working directory.
  • Tests

    • Expanded and renamed stats rendering tests to verify append-only behavior and summary flushing.
  • Release

    • Included as a patch-level update for pacquet.

Buffer the paired stats events before rendering.

This prevents append-only output from printing an intermediate stats block.
Copilot AI review requested due to automatic review settings July 17, 2026 12:35

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix Rust default reporter printing install stats twice

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Buffer added/removed stats events and render a single combined package block.
• Prevent duplicate "Packages: +N" output in append-only/non-interactive terminals.
• Add regression test coverage and a patch changeset release note.
Diagram

graph TD
  P{{"Pacquet installer"}} --> E["Stats events (Added/Removed)"] --> R["ReporterState.on_stats"] --> O["Output (Frame/Lines)"] --> T["Append-only terminal"]
  R --> S["Stats cache (added/removed)"] --> R
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Render only on Removed event (assume ordering)
  • ➕ Minimal state management (only keep Added until Removed arrives)
  • ➕ Simpler control flow
  • ➖ Relies on event ordering guarantee that may not hold (or could change)
  • ➖ Still needs fallback behavior if Removed never arrives
2. Change upstream protocol to emit a single combined stats event
  • ➕ Eliminates buffering complexity in all reporters
  • ➕ Clearer contract: one event equals one render
  • ➖ Requires coordinated change across pacquet and all consumers
  • ➖ Higher rollout risk and potentially larger scope
3. Time-based debounce before rendering stats
  • ➕ Handles missing/late counterpart events without hard dependency on ordering
  • ➕ Can reduce flicker if events burst
  • ➖ Introduces latency and timing flakiness
  • ➖ Harder to test deterministically; adds complexity

Recommendation: The PR’s approach (buffer both Added and Removed and render once when complete) is the best trade-off: it matches the existing TypeScript reporter behavior, avoids assuming event order, and fixes the duplicate output without changing upstream event semantics. Upstream protocol changes are cleaner long-term but are higher-scope and coordination-heavy for a patch fix.

Files changed (4) +51 / -13

Bug fix (1) +12 / -8
state.rsBuffer stats events and render combined output once +12/-8

Buffer stats events and render combined output once

• Updates stats handling to track Added and Removed counts separately and return early until both have been observed for the current cwd. Uses 'take()' to consume buffered values and ensures a single stats render per pair, preventing duplicate blocks when removed is zero.

pnpm/crates/default-reporter/src/state.rs

Tests (2) +34 / -5
tests.rsRename stats coalescing test for clarity +1/-1

Rename stats coalescing test for clarity

• Renames the stats test to reflect that stats events should not be throttled/coalesced, without changing behavior.

pnpm/crates/default-reporter/src/tests.rs

render.rsAdd regression test for append-only stats rendering once +33/-4

Add regression test for append-only stats rendering once

• Updates existing stats rendering tests to provide both Added and Removed events and adds a new append-only regression test that asserts no output after the first event and a single combined output after the second. Adjusts the full install frame test to include the Removed stats event for correct ordering/output.

pnpm/crates/default-reporter/tests/render.rs

Documentation (1) +5 / -0
pacquet-render-stats-once.mdAdd patch changeset for duplicate stats output fix +5/-0

Add patch changeset for duplicate stats output fix

• Adds a patch changeset noting that installs no longer print duplicate package statistics in non-interactive terminals.

.changeset/pacquet-render-stats-once.md

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 692fc171-94b7-48d9-810c-f9e414c7d275

📥 Commits

Reviewing files that changed from the base of the PR and between b29593e and 748be4d.

📒 Files selected for processing (2)
  • pnpm/crates/default-reporter/src/state.rs
  • pnpm/crates/default-reporter/tests/render.rs
📝 Walkthrough

Walkthrough

The default reporter now collects added and removed package statistics before rendering, flushes incomplete statistics at summary time, and includes tests and a pacquet patch changeset documenting the fix.

Changes

Pacquet statistics rendering

Layer / File(s) Summary
Collect complete statistics before rendering
pnpm/crates/default-reporter/src/state.rs
ReporterState::on_stats filters by cwd, stores added and removed values, renders complete pairs, and flushes pending values during summary processing.
Update statistics coverage and release metadata
pnpm/crates/default-reporter/tests/render.rs, pnpm/crates/default-reporter/src/tests.rs, .changeset/pacquet-render-stats-once.md
Render tests cover deferred and summary-flushed output, the unit test name is updated, and the pacquet patch changeset records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StatsMessage
  participant ReporterState
  participant ReporterRenderer
  StatsMessage->>ReporterState: provide added or removed statistics
  ReporterState->>ReporterState: collect both matching values
  ReporterState->>ReporterRenderer: render complete or summary-flushed statistics
Loading

Suggested labels: product: pacquet

Suggested reviewers: copilot, ychampion

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-output

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.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The change is safe to merge: focused, well-tested fix to buffering logic in the append-only reporter with no effect on the interactive TTY path.

The fix correctly defers rendering until both stats events arrive, clears state with .take() to avoid double-renders, and guards the summary-flush with a prefix match to avoid premature output. New tests directly exercise both the complete-pair and incomplete-pair paths.

No files require special attention.

Reviews (3): Last reviewed commit: "fix(default-reporter): scope stats summa..." | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Summary flush wrong prefix ✓ Resolved 🐞 Bug ☼ Reliability
Description
ReporterState::on_summary() now flushes buffered stats whenever either half is present, but it
cannot verify that the triggering SummaryLog belongs to the same prefix as the buffered stats. In
multi-prefix/concurrent installs, an unrelated summary can flush and clear an incomplete stats pair,
causing the later half to be emitted separately (or not at all if no later flush occurs), breaking
the intended “render combined stats once” behavior.
Code

pnpm/crates/default-reporter/src/state.rs[R619-621]

+        if self.stats_added.is_some() || self.stats_removed.is_some() {
+            self.render_stats();
+        }
Evidence
The new on-summary flush will call render_stats() whenever any buffered stat exists. render_stats()
now clears the buffers with take(), so flushing at the wrong time can split or omit the second
event. Summary events carry a prefix identifying the importer, but ReporterState currently ignores
it, so on_summary cannot filter to the matching prefix.

pnpm/crates/default-reporter/src/state.rs[618-624]
pnpm/crates/default-reporter/src/state.rs[509-511]
pnpm/crates/default-reporter/src/state.rs[311-327]
pnpm/crates/reporter/src/lib.rs[237-247]
pnpm/crates/package-manager/src/create_virtual_store.rs[508-518]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`on_summary()` flushes pending stats without knowing which `SummaryLog.prefix` triggered the summary. Because `render_stats()` consumes the buffered values (`take()`), an out-of-prefix summary can prematurely flush an incomplete pair, splitting the added/removed output or dropping the later half if nothing triggers another flush.

### Issue Context
- `SummaryLog` explicitly carries `prefix` to identify the importer.
- `ReporterState::handle` currently discards that prefix for `LogEvent::Summary`, so `on_summary()` cannot filter.
- `render_stats()` now clears buffered values via `take()`, making premature flushes lossy.

### Fix Focus Areas
- pnpm/crates/default-reporter/src/state.rs[618-624]
- pnpm/crates/default-reporter/src/state.rs[311-327]

### Suggested fix
1. Change `on_summary(&mut self)` to `on_summary(&mut self, prefix: &str)`.
2. In `handle`, pass the prefix: `LogEvent::Summary(log) => self.on_summary(&log.prefix)`.
3. Gate the stats flush on the summary being relevant to the buffered stats, e.g.:
  - if stats are only tracked for `self.cwd`, require `prefix == self.cwd` (or `self.is_current_prefix(prefix)` if that matches your intended semantics).

This preserves the “flush incomplete stats at end” behavior while avoiding unrelated summaries flushing and consuming another importer’s pending stats.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.12     13.5±1.41ms    27.7 MB/sec    1.00     12.0±0.78ms    31.2 MB/sec
packument/parse                1.06     42.3±0.81µs  1569.7 MB/sec    1.00     40.0±1.03µs  1657.1 MB/sec
tarball/download_dependency    1.05      3.3±0.56ms  1321.1 KB/sec    1.00      3.1±0.53ms  1383.9 KB/sec

@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent repeated statistics rendering

Add a stats_rendered boolean flag to ReporterState to prevent rendering
statistics more than once. Guard on_stats and render_stats with this flag to
ignore subsequent stats events.

pnpm/crates/default-reporter/src/state.rs [504-511]

+    if self.stats_rendered {
+        return;
+    }
     if self.stats_added.is_some() && self.stats_removed.is_some() {
         self.render_stats();
     }
 }
 
 fn render_stats(&mut self) {
+    if self.stats_rendered {
+        return;
+    }
+    self.stats_rendered = true;
     let added = self.stats_added.take().unwrap_or(0);
     let removed = self.stats_removed.take().unwrap_or(0);
  • Apply / Chat
Suggestion importance[1-10]: 1

__

Why: The PR already fixes the duplication issue by waiting for both events to be received before rendering; adding a stats_rendered flag is unnecessary as the backend only emits one pair of stats events per install.

Low
  • More

Render a partial stats pair when the run summary arrives.
@codecov-commenter

codecov-commenter commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (e7138af) to head (748be4d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13103   +/-   ##
=======================================
  Coverage   85.45%   85.45%           
=======================================
  Files         501      501           
  Lines       80654    80664   +10     
=======================================
+ Hits        68924    68934   +10     
  Misses      11730    11730           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 17, 2026 12:49

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit b29593e

@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent repeated statistics rendering

Add a stats_rendered boolean flag to ReporterState to prevent rendering
statistics more than once. Guard on_stats and render_stats with this flag to
ignore subsequent stats events.

pnpm/crates/default-reporter/src/state.rs [504-511]

+    if self.stats_rendered {
+        return;
+    }
     if self.stats_added.is_some() && self.stats_removed.is_some() {
         self.render_stats();
     }
 }
 
 fn render_stats(&mut self) {
+    if self.stats_rendered {
+        return;
+    }
+    self.stats_rendered = true;
     let added = self.stats_added.take().unwrap_or(0);
     let removed = self.stats_removed.take().unwrap_or(0);
  • Apply / Chat
Suggestion importance[1-10]: 1

__

Why: The PR already fixes the duplication issue by waiting for both events to be received before rendering; adding a stats_rendered flag is unnecessary as the backend only emits one pair of stats events per install.

Low
  • More

Keep unrelated importer summaries from consuming buffered stats.
Copilot AI review requested due to automatic review settings July 17, 2026 13:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Addressed Qodo's "Summary flush wrong prefix" finding in 748be4d. The summary prefix is now forwarded to the reporter state, and only the matching current-project summary can flush incomplete stats. The regression test sends a foreign summary first and verifies that the buffered stats are preserved until the matching summary arrives.


Written by an agent (Codex, GPT-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 748be4d

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent repeated statistics rendering

Add a stats_rendered boolean flag to ReporterState to prevent rendering
statistics more than once. Guard on_stats and render_stats with this flag to
ignore subsequent stats events.

pnpm/crates/default-reporter/src/state.rs [504-511]

+    if self.stats_rendered {
+        return;
+    }
     if self.stats_added.is_some() && self.stats_removed.is_some() {
         self.render_stats();
     }
 }
 
 fn render_stats(&mut self) {
+    if self.stats_rendered {
+        return;
+    }
+    self.stats_rendered = true;
     let added = self.stats_added.take().unwrap_or(0);
     let removed = self.stats_removed.take().unwrap_or(0);
  • Apply / Chat
Suggestion importance[1-10]: 1

__

Why: The PR already fixes the duplication issue by waiting for both events to be received before rendering; adding a stats_rendered flag is unnecessary as the backend only emits one pair of stats events per install.

Low
  • More

@zkochan
zkochan merged commit 61ed26e into main Jul 17, 2026
32 checks passed
@zkochan
zkochan deleted the fix-output branch July 17, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants