Skip to content

feat: add automatic model query context - #6174

Draft
mday-io wants to merge 4 commits into
SQLMesh:mainfrom
mday-io:feat/automatic-query-execution-context
Draft

mday-io wants to merge 4 commits into
SQLMesh:mainfrom
mday-io:feat/automatic-query-execution-context

Conversation

@mday-io

@mday-io mday-io commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

With query_execution_context: true, SQLMesh now supplies model-batch context
without an application-defined provider. Warehouse SQL and observer callbacks
can use the same operation ID during Context.apply() and built-in scheduler runs.

This PR depends on #6173 and includes
that provider until the parent lands.
The automatic-only comparison
shows the additional changes.

Native observation events create an immutable context with model, snapshot,
operation ID, and available interval and batch index. Nested audits reuse the
batch ID. Callbacks read it through get_query_execution_context().

  • Isolate worker context and restore it after completion or cancellation.
  • Forward console-observer events once. Automatic context works without a console
    observer; observer_scope(None) disables it explicitly.
  • Exclude observer-callback SQL from automatic model context. Custom providers
    remain authoritative, including when they return None.

A supported, enabled warehouse adapter without a custom provider activates the
observer. State-only opt-in does not. Coverage is model batches and nested audits,
with broad phases. Standalone operations and detailed per-statement roles are
outside this scope.

Test Plan

The DuckLake extension-cache repair moved to #6193 and is excluded from this PR.

Local style and fast tests passed on the revised head. Earlier feature
checks remain applicable because all other file contents are unchanged.

  • Local make style and all six make fast-test phases passed. 2,998 passed,
    13 skipped, with automatic workers limited to two.
  • The restored DuckDB adapter module passed all 15 tests serially.
  • Earlier 71 observer, transport, and integration checks passed, including
    audit-only batches, malformed facts, restoration, disablement, and custom providers.
  • Earlier CLI init/DLT tests, doctests, and runnable example passed. Native
    plan/apply/run checks matched batch and audit IDs across provider, automatic,
    and default-console modes. Rows, hashes, snapshots, and intervals matched;
    default state SQL had no context.
  • GitHub CI on the revised head. The DuckLake repair in fix(tests): isolate DuckLake extension caches per worker #6193 may
    need to land before Windows CI passes.
  • Strict local MkDocs build and remote warehouse qualification. MkDocs is
    unavailable locally; remote warehouses were not exercised locally.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: mday-io <mdaytn@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@mday-io
mday-io force-pushed the feat/automatic-query-execution-context branch 2 times, most recently from b57bc31 to a695f07 Compare November 1, 2026 21:50
Signed-off-by: mday-io <mdaytn@gmail.com>
Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io
mday-io force-pushed the feat/automatic-query-execution-context branch from a695f07 to df12e07 Compare November 4, 2026 02:55
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