Avoid duplicate provider startup probes#2777
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new startup benchmarking script and adjusts managed provider startup behavior so that only the ProviderRegistry triggers the initial refresh, with updated tests to match.
Changes:
- Introduces
scripts/bench-startup.jsto seed a large dataset, start the server, optionally measure initial web sync, and emit a JSON result payload. - Adds
bench:startup/bench:pending-actionsscripts topackage.json. - Removes managed provider “probe on construction” behavior and updates/extends tests to ensure ProviderRegistry is the single startup refresh owner.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/bench-startup.js | New CLI benchmark that seeds data, starts server, measures readiness/web sync, and reports metrics. |
| package.json | Adds npm scripts to run the new benchmark (and pending-actions bench). |
| apps/server/src/provider/makeManagedServerProvider.ts | Stops triggering an initial forced refresh during provider construction. |
| apps/server/src/provider/makeManagedServerProvider.test.ts | Updates tests to reflect no probe on construction; adds coverage for explicit refresh and periodic refresh. |
| apps/server/src/provider/Layers/ProviderRegistry.test.ts | Adds test ensuring ProviderRegistry performs exactly one startup refresh for managed instances. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ApprovabilityVerdict: Needs human review This PR modifies server startup behavior by deferring provider probes until after server readiness, changing initialization timing and when provider state becomes available. Changes to startup/initialization lifecycle ordering warrant human review to validate the intended behavior across different scenarios. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9246bde9ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
realized I should make the script a separate commit so I'm gonna do that too. |
9246bde to
f48b553
Compare
f48b553 to
d85ef38
Compare
Move provider CLI status checks out of provider layer construction and start them from ServerRuntimeStartup only after the server has printed ready access information. ProviderRegistry now exposes an explicit startBackgroundRefreshes hook; manual refresh paths still work before startup readiness, and rebuilt instances refresh immediately once background refreshes are enabled. Benchmarks (100 projects x 100 threads, projected seed, server-ready-only): | ref | seed ms | serverReady ms | top ready-path evidence | | --- | ---: | ---: | --- | | server-ready-delete-boot-refresh-10k | n/a | 4357.344 | OpenCode provider check still dominated startup | | server-ready-provider-refresh-async-10k | 2962.655 | 4609.096 | provider refresh was forked but still contended before ready output | | server-ready-provider-refresh-after-output-10k | 3004.054 | 2725.643 | provider spans only show in post-ready stop trace; ready output is no longer behind CLI probes | Verification: nix develop "git+file:///Users/mjc/projects/t3code?ref=daily-use" -c bun fmt; bun lint; bun typecheck; bun run test.
|
I noticed #2728 is addressing the same startup bottleneck: provider probing is on the server readiness path. I tried a slightly different version of that idea in Measured with the same server-ready-only startup benchmark: Fixture: synthetic home with 100 projects x 100 threads, 10,000 threads total, 0 activities/thread, projected seed. 5 measured runs.
So #2728 is a real improvement, but this approach is another I’m going to add this commit to this PR as the follow-up version of the same fix. |
Dismissing prior approval to re-evaluate 1b6bbc1
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1b6bbc1. Configure here.

Summary
Provider startup checks were being kicked off from two places:
makeManagedServerProviderstarted its own background boot probe when constructedProviderRegistryLivealso subscribes to new provider instances and force-refreshes them during startupThat meant startup could run duplicate provider status checks for the same instance. This removes the older self-starting boot probe from managed providers and makes
ProviderRegistryLivethe single owner of startup refresh work.Managed providers still refresh on explicit
refresh, meaningful settings changes, and the periodic refresh interval.Performance
Measured with:
Against
origin/mainatd1e85c4e:Initial web sync itself stayed roughly flat, which is expected; the improvement is in server readiness.
Update
Added
1b6bbc1cas a follow-up to move provider refreshes off the startup readiness path. Context and benchmark comparison against #2728 are in this comment: #2777 (comment)Tests
Added coverage that:
getSnapshotreads do not proberefreshstill probes and streams updatesProviderRegistryLiveperforms exactly one startup refresh for a managed providerVerification
bun run --cwd apps/server test src/provider/makeManagedServerProvider.test.ts src/provider/Layers/ProviderRegistry.test.ts bun fmt bun lint bun typecheckAlso launched the dev GUI in Chrome and verified it paired successfully and rendered the app shell on this branch.
Note
Low Risk
Test-only change that adjusts expectations around when the startup provider refresh runs; low risk aside from potentially masking a regression if the new timing assumptions are wrong.
Overview
Updates the
ProviderRegistryLivestartup-refresh test to assert that no provider probe happens during layer construction and that the initial snapshot remains visible untilregistry.startBackgroundRefreshesis invoked.The test now waits for the background refresh to complete and verifies exactly one startup refresh call and that
getProviderseventually reflects the refreshed snapshot.Reviewed by Cursor Bugbot for commit 587d983. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Avoid duplicate provider startup probes by deferring background refreshes until server is ready
refresh(), settings change, or periodic timer fires.ProviderRegistryLiveno longer awaits provider checks during layer build or instance sync; it subscribes to change streams immediately and only starts refreshes whenstartBackgroundRefreshesis called.providerRegistry.startBackgroundRefreshesafter the ready lifecycle event, forked in scope, so it does not block startup.bench:startupscript in scripts/bench-startup.js to measure server boot time under configurable database load.Macroscope summarized 587d983.