Repository navigation
Yield to the event loop during provider lifecycle sweeps - #4651
Conversation
The periodic provider lifecycle sweep started every environment's sweep in one synchronous pass, which showed up as the longest server stall on installs with many provider environments. Yield after every 25 scheduled sweeps and between providers, and skip rows already marked as blocked on a provider-owner mismatch, since sweeping them again is a no-op until the owning plugin provides them again. Co-authored-by: hemaaanth <[email protected]> Co-Authored-By: Claude Code <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7591ad1700
ℹ️ 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".
| deps.db, | ||
| record.provider.id, | ||
| )) { | ||
| if (isBlockedOnProviderOwnerMismatch(row, record)) continue; |
There was a problem hiding this comment.
Filter blocked lifecycle rows in SQL
When one provider has a large backlog of owner-mismatch rows, listProviderLifecycleEnvironments(...).all() still synchronously materializes every row, and this continue filters them in JavaScript before the interval-yield check, so an all-blocked backlog performs no intermediate yield and can still monopolize the event loop—the exact workload this change targets. Pass the current plugin owner into the query and exclude these permanently blocked rows with a targeted predicate, while allowing them to reappear when the matching plugin returns.
AGENTS.md reference: AGENTS.md:L31-L35
Useful? React with 👍 / 👎.
Filter rows blocked on a provider-owner mismatch in the query instead of after loading them, so a backlog of blocked rows is never materialized and the yield interval counts only rows that are swept. Co-Authored-By: Claude Code <[email protected]>
Human comments
What was wrong
The periodic provider lifecycle sweep started a sweep for every provider environment in one synchronous pass, including rows that are permanently parked on a provider-owner mismatch. On installs with many provider environments that pass held the event loop.
What changed
Split out of #4532 (the
environment-engine.tspart of commit 9537a77, re-applied on current main). Part 2 of 6.apps/server/src/services/environments/environment-engine.ts:sweepProviderLifecyclesyields to the event loop after every 25 scheduled sweeps and between providers.packages/db/src/data/environments.ts:listProviderLifecycleEnvironmentsexcludes rows already marked failed with the owner-mismatch message, with no owner thread and still owned by a different plugin. Sweeping them was a no-op that wrote nothing. They come back as soon as the owning plugin provides them again. (Speed up thread switching, resume, realtime, and composer #4532 filtered these after loading; moved into the query after review.)Not included from #4532: the event-loop stall log threshold change (500 ms → 250 ms). No wire change.
How you verified
pnpm exec turbo run typecheck lint --filter=@bb/server --filter=@bb/db: pass.vitest run test/query-plans.test.tsinpackages/db: 37/37 pass.vitest run test/services/environments/provider-orchestration.test.ts: 64/64 pass, including the new test that blocked rows are left untouched, a retryable row is still removed, and a blocked row is picked up again once its plugin provides it.🤖 Generated with Claude Code