fix: harden render concurrency, cache lifecycle, worker limits, and benchmark portability#64
Conversation
…enchmark portability
38e4b03 to
0a528fd
Compare
|
Warning Review limit reached
Next review available in: 9 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughChangesThe 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
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
cli/scripts/benchmark-server.mjs (1)
33-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider 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
📒 Files selected for processing (19)
cli/scripts/benchmark-render.mjscli/scripts/benchmark-server.mjscli/scripts/lib/proc-rss.mjscli/src/builders/facet-directory.test.tscli/src/builders/facet-directory.tscli/src/bundler/build-cache.tscli/src/bundler/ssr-pool.tscli/src/bundler/vite-builder.tscli/src/bundler/vite-server.tscli/src/cli.tscli/src/loaders/ssr.tscli/src/server/config.tscli/src/server/preview.tscli/src/server/routes.tscli/src/server/worker-pool.test.tscli/src/server/worker-pool.tscli/src/utils/browser-readiness.tscli/src/utils/tailwind.test.tscli/src/utils/tailwind.ts
Summary by CodeRabbit