Skip to content

Feature: Run audits concurrently using concurrent_tasks setting#5718

Draft
airhorns wants to merge 3 commits intoTobikoData:mainfrom
airhorns:feat/concurrent-audits-clean
Draft

Feature: Run audits concurrently using concurrent_tasks setting#5718
airhorns wants to merge 3 commits intoTobikoData:mainfrom
airhorns:feat/concurrent-audits-clean

Conversation

@airhorns
Copy link

@airhorns airhorns commented Mar 4, 2026

I'm porting a really test-heavy dbt project over to sqlmesh and noticing overall runtimes are WAY slower, and its because sqlmesh runs the audits in serial for each model, and that serial audit run blocks donwstream models from getting started. This PR adjusts the concurrenct tasks approach to apply to both models and audits run during an apply, or just all the audits when running an audit_only run.

WIP

Summary

  • Adds per-model audit concurrency in SnapshotEvaluator.audit() using concurrent_apply_to_values, controlled by the existing concurrent_tasks connection setting
  • Adds cross-model audit concurrency in Scheduler for audit_only=True runs — all audit tasks are flattened into a single thread pool since audits are read-only SELECT queries and don't need DAG ordering
  • Renames ddl_concurrent_tasks to concurrent_tasks on SnapshotEvaluator to reflect its broader scope

Closes #5468

🤖 Generated with Claude Code

Adds two levels of audit concurrency:

1. Per-model (SnapshotEvaluator): audits within a single snapshot now run
   concurrently via concurrent_apply_to_values, controlled by concurrent_tasks.
   This benefits both plan/apply and audit-only runs.

2. Cross-model (Scheduler): when audit_only=True, all audit tasks across all
   snapshots are flattened into a single thread pool instead of following DAG
   ordering. Since audits are read-only SELECT queries with no side effects,
   DAG dependencies are irrelevant and all concurrent_tasks slots stay filled.

The SnapshotEvaluator parameter ddl_concurrent_tasks is renamed to
concurrent_tasks to reflect its broader scope.

Closes TobikoData#5468

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

airhorns and others added 2 commits March 3, 2026 21:05
- Circuit breaker: Use a shared threading.Event to cancel remaining
  audit tasks when the circuit breaker fires. Previously, CircuitBreakerError
  was collected like any other error and all tasks ran to completion.

- Nested concurrency: Pass audit_concurrent_tasks=1 from the scheduler's
  flat pool to the evaluator, preventing max_workers * concurrent_tasks
  threads from hitting the DB simultaneously. Add audit_concurrent_tasks
  parameter to SnapshotEvaluator.audit() for this override.

- Add tests for circuit breaker short-circuiting, blocking audit error
  collection (NodeAuditsErrors), and nested concurrency prevention.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Apply ruff formatting to new/modified lines
- Fix mypy error in test_audit_only_no_nested_concurrency: use
  fully mocked evaluator instead of real evaluator with replaced
  method, avoiding type mismatch on call_count/call_args_list

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Concurrency in tests and audits

2 participants