Skip to content

feat(table): per-plan table dispatch concurrency with env overrides#5720

Merged
TheodoreSpeaks merged 4 commits into
stagingfrom
feat/increase-parallel-dispatch
Jul 17, 2026
Merged

feat(table): per-plan table dispatch concurrency with env overrides#5720
TheodoreSpeaks merged 4 commits into
stagingfrom
feat/increase-parallel-dispatch

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Table dispatch parallelism is now resolved from the invoking user's billing plan instead of a hardcoded 20: free 20, pro/team/enterprise 50 by default
  • Each tier is overridable via TABLE_DISPATCH_CONCURRENCY_{FREE,PAID}; billing-disabled deployments use the highest configured tier
  • Concurrency is resolved once in runWorkflowColumn (same billing attribution the cells are billed under) and threaded through the dispatcher invocation — the table-run-dispatcher task payload / in-process loop arg. No schema change; payloads without the field fall back to the legacy cap of 20
  • workflow-group-cell trigger.dev queue cap now derives from the highest configured tier (getMaxTableDispatchConcurrency()) instead of a second hardcoded 20, so the two can't drift
  • Database queue backend's batchEnqueueAndWait now enforces the shared concurrencyKey cap (same semaphore as runInline), so overlapping dispatches on one table share the per-table limit

Type of Change

  • New feature

Testing

Unit tests for the plan resolver (buckets, env overrides, billing-disabled) and the shared batch semaphore. Full lib/table + async-jobs suites, type-check, lint:check, and check:api-validation:strict all pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

🤖 Generated with Claude Code

https://claude.ai/code/session_016jTmy5BZiCzSrcBcY6Pf6N

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds billing-plan-aware concurrency for table dispatches. The main changes are:

  • Free and paid concurrency defaults with environment overrides.
  • Billing-based limit resolution for hosted and in-process dispatches.
  • A shared per-table semaphore for database-backed batches.
  • A Trigger.dev queue limit derived from the highest configured tier.
  • Tests for plan resolution and overlapping batch execution.

Confidence Score: 5/5

This looks safe to merge.

  • The database batch path now shares the same keyed semaphore as inline execution.
  • Slot release is protected by a finally block.
  • The resolved limit is forwarded through both hosted and in-process dispatch paths.
  • No blocking issue remains in the updated code.

Important Files Changed

Filename Overview
apps/sim/lib/core/async-jobs/backends/database.ts Applies the existing keyed semaphore to batch execution and releases each slot in a finally block.
apps/sim/lib/core/async-jobs/backends/database.test.ts Adds coverage for the shared limit across overlapping batches.
apps/sim/lib/table/dispatch-concurrency.ts Defines tier defaults, validates environment overrides, and resolves limits from billing attribution.
apps/sim/lib/table/dispatcher.ts Uses the resolved concurrency for both row windows and database queue options.
apps/sim/lib/table/workflow-columns.ts Resolves concurrency once per run and forwards it through both dispatcher paths.
apps/sim/background/workflow-column-execution.ts Derives the hosted cell-task queue limit from the configured table dispatch tiers.

Reviews (5): Last reviewed commit: "improvement(table): collapse dispatch co..." | Re-trigger Greptile

Comment thread apps/sim/lib/table/dispatcher.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 17, 2026 1:07am

Request Review

@TheodoreSpeaks
TheodoreSpeaks force-pushed the feat/increase-parallel-dispatch branch from 999c2be to e5d2bd5 Compare July 17, 2026 00:49
@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes table execution throughput and queue semantics (dispatcher windows, Trigger.dev limits, DB batch semaphore); mis-tuned env vars or stale Trigger deploy caps could throttle or overload cell execution, but behavior is backward-compatible for old dispatcher payloads.

Overview
Table runs now parallelize rows based on the invoker’s billing plan instead of a fixed 20 everywhere: free defaults to 20, paid tiers to 50, overridable via TABLE_DISPATCH_CONCURRENCY_FREE and TABLE_DISPATCH_CONCURRENCY_PAID (billing-disabled hosts use the paid value).

Concurrency is resolved once when a manual run starts (resolveTableDispatchConcurrency, same attribution as cell billing) and passed into the dispatcher loop and table-run-dispatcher task payload as concurrency; older payloads without it still fall back to 20. The dispatcher window size and per-cell concurrencyLimit in buildEnqueueItems follow that value so one window saturates the cell pool.

The workflow-group-cell Trigger.dev queue cap is set to getMaxTableDispatchConcurrency() so the per-table ceiling is never below any plan’s window (note: raising env above the current max may need a Trigger redeploy). The database job backend’s batchEnqueueAndWait now shares the same per-concurrencyKey semaphore as inline runs, so overlapping dispatches on one table respect the cap.

Reviewed by Cursor Bugbot for commit 57c9fe7. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e5d2bd5. Configure here.

Comment thread apps/sim/lib/table/dispatcher.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks
TheodoreSpeaks merged commit 9d5ed38 into staging Jul 17, 2026
21 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the feat/increase-parallel-dispatch branch July 17, 2026 01:16
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