Skip to content

use Batch Worker - #211

Merged
ianmacartney merged 4 commits into
mainfrom
ian/batch-worker
Jul 15, 2026
Merged

ianmacartney merged 4 commits into
mainfrom
ian/batch-worker

Conversation

@ianmacartney

@ianmacartney ianmacartney commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

use Batch Worker

ianmacartney commented Jun 19, 2026 •

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@pkg-pr-new

pkg-pr-new Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/workpool/@convex-dev/workpool@211

commit: def56cc

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 34 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: Repository: get-convex/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2656d39b-e8eb-42ea-99c9-6f14b92c87ec

📥 Commits

Reviewing files that changed from the base of the PR and between 82a0d4f and def56cc.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • src/component/_generated/api.ts is excluded by !**/_generated/**
📒 Files selected for processing (23)
  • example/convex/schema.ts
  • example/convex/setup.test.ts
  • example/convex/test/scenarios/burstyBatches.ts
  • package.json
  • src/component/README.md
  • src/component/complete.test.ts
  • src/component/complete.ts
  • src/component/config.ts
  • src/component/convex.config.ts
  • src/component/crons.ts
  • src/component/kick.test.ts
  • src/component/kick.ts
  • src/component/lib.test.ts
  • src/component/lib.ts
  • src/component/loop.test.ts
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/schema.ts
  • src/component/setup.test.ts
  • src/component/shared.ts
  • src/component/stateMachine.test.ts
  • src/component/stats.ts
  • src/test.ts
📝 Walkthrough

Walkthrough

This change migrates workpool loop scheduling to @convex-dev/batch-worker. The loop now exposes getBatch and run, while kickMainLoop delegates to worker pings and forceKick uses stop/start operations. The schema removes runStatus and makes generation optional. Callers, diagnostics, component configuration, test registration, loop tests, state-machine tests, and saturation coverage are updated for the new worker-driven lifecycle.

Sequence Diagram(s)

sequenceDiagram
  participant Producer
  participant Workpool
  participant BatchWorker
  participant WorkpoolDB
  Producer->>Workpool: enqueue, complete, cancel, or retry
  Workpool->>BatchWorker: ping main worker
  BatchWorker->>Workpool: call getBatch
  Workpool->>WorkpoolDB: read pending queues and state
  Workpool-->>BatchWorker: return work or idle batch
  BatchWorker->>Workpool: call run for work batch
  Workpool->>WorkpoolDB: process items and persist state
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and doesn’t clearly describe the batch-worker refactor or related schema/test changes. Rename it to summarize the main change, such as "Adopt Batch Worker for loop scheduling".
Description check ❓ Inconclusive The description is equally vague and provides no meaningful summary of the changeset. Replace it with a short description of the main change, such as migrating the loop to Batch Worker and updating tests/schema.
✅ Passed checks (2 passed)
Check name Status Explanation
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 ian/batch-worker

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.

Comment thread src/component/loop.ts Outdated
completed.map(async (c) => {
// Guard: getBatch and main run in separate transactions, so defend
// against a doc that was already processed/removed.
if (!(await ctx.db.get("pendingCompletion", c._id))) {

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.

I think the guard here is good, but I'm curious if this scenario is ever possible in theory (besides cases where users directly modify the data)? run is the only function that modifies pendingCompletion and it does not run concurrently

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah this is overly cautious

});

it("transitions to scheduled (saturated=false) when only future-scheduled work remains", async () => {
it("idles with a timeoutMs when only future-scheduled work remains", async () => {

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.

should we also test that timeoutMs is the difference until the next recovery segment if that is closer than future work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added a test

});
// A pre-migration scheduled call lands here after deploy. It just pings
// batch-worker (no-op in tests) and must not throw.
await t.mutation(internal.loop.main, { generation: 1n, segment: 123n });

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.

hmm i think this just tests that main does not throw and not necessarily that it resumes the loop

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

@ianmacartney
ianmacartney merged commit e1dccc8 into main Jul 15, 2026
4 checks passed
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.

2 participants