Skip to content

fix: harden render concurrency, cache lifecycle, worker limits, and benchmark portability#64

Merged
yashmehrotra merged 2 commits into
mainfrom
speed-up-comments
Jul 17, 2026
Merged

fix: harden render concurrency, cache lifecycle, worker limits, and benchmark portability#64
yashmehrotra merged 2 commits into
mainfrom
speed-up-comments

Conversation

@yashmehrotra

@yashmehrotra yashmehrotra commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added validation for numeric server options, with clearer errors for invalid values.
    • Added automatic cleanup of older rendered fragments and improved Tailwind cache maintenance.
  • Bug Fixes
    • Improved server worker and SSR resource shutdown behavior.
    • Prevented temporary build files from remaining after failed builds.
    • Improved page readiness timeout handling.
  • Performance
    • Reduced repeated resource and file processing during builds and server monitoring.
    • Improved reuse of cached Tailwind and template build results.

@yashmehrotra
yashmehrotra requested a review from moshloop July 17, 2026 05:23
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 9 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5b210bda-cbdf-48c6-afd7-61bb967a2593

📥 Commits

Reviewing files that changed from the base of the PR and between 0a528fd and b6e1d0b.

📒 Files selected for processing (7)
  • cli/scripts/benchmark-server.mjs
  • cli/src/bundler/ssr-pool.ts
  • cli/src/loaders/ssr.ts
  • cli/src/server/config.test.ts
  • cli/src/server/config.ts
  • cli/src/server/worker-pool.ts
  • cli/src/utils/tailwind.ts

Walkthrough

Changes

The PR updates asynchronous local facet generation, persistent SSR loader ownership, worker resource accounting, build and fragment cache maintenance, page-readiness timing, and benchmark path/RSS handling.

Runtime reliability and performance

Layer / File(s) Summary
Asynchronous local facet generation
cli/src/builders/facet-directory.*, cli/src/bundler/vite-*.ts
Local facet package generation now awaits an asynchronous, non-blocking build lock; callers and tests await completion.
Persistent SSR loader ownership
cli/src/bundler/ssr-pool.ts, cli/src/server/preview.ts
SSR loaders track usage and async owners, enabling owner-scoped shutdown and LRU-style eviction.
Worker resource accounting and numeric configuration
cli/src/cli.ts, cli/src/server/config.ts, cli/src/server/worker-pool.*
Serve numeric options are validated, server limits accept numbers, and Chromium RSS sampling is cached with safer recycling bookkeeping.
Build and generated-artifact cache maintenance
cli/src/bundler/build-cache.ts, cli/src/loaders/ssr.ts, cli/src/server/routes.ts, cli/src/utils/tailwind.*
Template digests are cached, temporary SSR output is cleaned on build failure, and Tailwind and fragment caches are refreshed and pruned.
Readiness timing and benchmark portability
cli/src/utils/browser-readiness.ts, cli/scripts/*
Page readiness uses a shared deadline, while benchmark scripts use script-relative paths and a shared process-tree RSS helper.

Sequence Diagram(s)

sequenceDiagram
  participant PreviewServer
  participant OwnerContext
  participant SsrLoaderPool
  participant SsrLoaderProcess
  PreviewServer->>OwnerContext: Bind ssrLoaderOwner for request
  OwnerContext->>SsrLoaderPool: Run request in owner context
  SsrLoaderPool->>SsrLoaderProcess: Reuse or start loader
  SsrLoaderProcess-->>SsrLoaderPool: Return SSR response
  PreviewServer->>SsrLoaderPool: Shutdown owned loaders
Loading

Possibly related PRs

Suggested reviewers: moshloop, moshloop

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main themes of the changes: concurrency, cache handling, worker limits, and benchmark portability.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch speed-up-comments
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch speed-up-comments

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.

@yashmehrotra

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
cli/scripts/benchmark-server.mjs (1)

33-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider unref-ing the sampler interval.

If this script relies on a natural process exit rather than explicitly calling process.exit(), calling .unref() on the polling interval prevents it from keeping the Node.js event loop alive indefinitely after the server shuts down.

♻️ Proposed refactor
-const sampler = setInterval(() => {
+const sampler = setInterval(() => {
   const rss = processTreeRss(server.pid);
   peakRss = Math.max(peakRss, rss);
   requestPeakRss = Math.max(requestPeakRss, rss);
-}, 25);
+}, 25).unref();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/scripts/benchmark-server.mjs` around lines 33 - 37, Update the sampler
interval created in the benchmark script to call unref(), ensuring it cannot
keep the Node.js process alive after the server shuts down while preserving the
existing RSS sampling behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cli/src/bundler/ssr-pool.ts`:
- Around line 159-168: Update the loader eviction and cleanup logic around
SsrLoaderProcess creation to keep evicted loaders counted until close completes,
preventing live closing processes from exceeding FACET_MAX_SSR_LOADERS. Track or
await the eviction closure, and guard every exit cleanup—including loaderOwners
and unownedLoaders—with an identity check so an old loader cannot remove
metadata belonging to a replacement for the same facet root.

In `@cli/src/loaders/ssr.ts`:
- Around line 114-132: Update the cleanup in the build error handler around
Vite’s build call so rmSync(buildDir, { recursive: true, force: true }) cannot
replace the original build error. Wrap that cleanup operation in a nested
try/catch, ignore cleanup failures, and rethrow the original error from the
outer catch.

In `@cli/src/server/config.ts`:
- Around line 59-63: Validate the environment-derived worker limits before
constructing the pool, using the existing CLI safe-integer and minimum-value
validation behavior. Update the configuration handling for maxRendersPerWorker,
maxQueueDepth, maxWorkerAgeMs, maxWorkerRssMb, and workerAcquireTimeoutMs so
invalid or below-minimum values are rejected or replaced with their established
defaults, preventing NaN from reaching pool normalization.

In `@cli/src/server/worker-pool.ts`:
- Around line 161-171: In the worker replacement flow after await
launchBrowser() resolves, recheck this.shuttingDown before publishing the fresh
Worker to waiting or available. If shutdown has started, close the newly
launched browser and decrement the pool’s total count instead of adding or
resolving it; otherwise preserve the existing publication logic.

In `@cli/src/utils/tailwind.ts`:
- Around line 122-130: Wrap the best-effort utimes call in the cachedCss branch
with a try/catch so concurrent cache-file deletion cannot produce an unhandled
rejection. Preserve returning cachedCss regardless of timestamp refresh failure,
and leave the existing readFile cache-miss handling unchanged.

---

Nitpick comments:
In `@cli/scripts/benchmark-server.mjs`:
- Around line 33-37: Update the sampler interval created in the benchmark script
to call unref(), ensuring it cannot keep the Node.js process alive after the
server shuts down while preserving the existing RSS sampling behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb9211c2-a22e-4090-bf1e-b1a823b1b530

📥 Commits

Reviewing files that changed from the base of the PR and between b07e6f7 and 0a528fd.

📒 Files selected for processing (19)
  • cli/scripts/benchmark-render.mjs
  • cli/scripts/benchmark-server.mjs
  • cli/scripts/lib/proc-rss.mjs
  • cli/src/builders/facet-directory.test.ts
  • cli/src/builders/facet-directory.ts
  • cli/src/bundler/build-cache.ts
  • cli/src/bundler/ssr-pool.ts
  • cli/src/bundler/vite-builder.ts
  • cli/src/bundler/vite-server.ts
  • cli/src/cli.ts
  • cli/src/loaders/ssr.ts
  • cli/src/server/config.ts
  • cli/src/server/preview.ts
  • cli/src/server/routes.ts
  • cli/src/server/worker-pool.test.ts
  • cli/src/server/worker-pool.ts
  • cli/src/utils/browser-readiness.ts
  • cli/src/utils/tailwind.test.ts
  • cli/src/utils/tailwind.ts

Comment thread cli/src/bundler/ssr-pool.ts Outdated
Comment thread cli/src/loaders/ssr.ts
Comment thread cli/src/server/config.ts Outdated
Comment thread cli/src/server/worker-pool.ts
Comment thread cli/src/utils/tailwind.ts
@yashmehrotra
yashmehrotra merged commit 8639c96 into main Jul 17, 2026
15 checks passed
@yashmehrotra
yashmehrotra deleted the speed-up-comments branch July 17, 2026 10:17
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