Skip to content

feat: add automatic model query context - #6174

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

mday-io wants to merge 5 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

Style and fast tests were rerun after inheriting the test-only DuckLake cache fix.
Earlier checks remain applicable because the automatic-only patch is unchanged.

  • Local make style and all six make fast-test phases passed. 2,999 passed,
    13 skipped.
  • 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.
  • Windows CI
    passed with DuckDB 1.5.6 after the previous extension-install failure. The
    inherited worker-cache fix passed all four DuckLake adapter cases.
  • Remaining CI on the revised head.
  • 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 from 6889176 to b57bc31 Compare October 31, 2026 23:30
Signed-off-by: mday-io <mdaytn@gmail.com>
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 b57bc31 to a695f07 Compare November 1, 2026 21:50
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