Skip to content

feat: add query execution context provider transport - #6173

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

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

Conversation

@mday-io

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

Copy link
Copy Markdown
Collaborator

Description

This PR adds the query execution context provider and SQL comment transport.
PR #6174 adds automatic model context.

Why

Warehouse query history records SQLMesh's plan or run marker, but it cannot
connect each statement to the model evaluation reported by an execution
observer. Applications need to use one evaluation ID in both records.

How

Add an opt-in provider to engine adapters. It returns an immutable
QueryExecutionContext, which SQLMesh serializes as bounded, escaped version-one
JSON in a SQL comment. Keep the legacy marker first. Omit optional metadata on
ordinary provider or serialization failures and continue the query. Preserve
provider settings when adapters are cloned. Prevent provider settings from
leaking into cached DuckDB adapters or the default state adapter. Add a runnable
example that builds context from observer events.

Roll back adapter-owned transactions when a provider or driver raises a
BaseException, then propagate the original cancellation. This prevents a later
statement from reusing an abandoned transaction.

The connection flag enables context comments. It does not infer model context.
An application provider must supply that context.

Test Plan

  • 61 serializer, transport, configuration, and Jupyter output tests passed.
  • Cancellation tests cover adapter-owned and nested transactions, adapters
    without transactions, and driver cancellation with query context disabled.
    All 130 adjacent adapter and connection-pool tests passed.
  • All 15 CLI init and DLT tests passed, including the two updated config
    expectations. These slow tests are outside make fast-test.
  • make style passed.
  • make fast-test passed all six phases. 2,983 passed and 13 skipped.
  • make doc-test passed. 29 passed.
  • A native DuckDB check compared Context.plan(), Context.apply(), and
    Context.run(). Observer, materialization, and audit IDs matched for six
    batches. Hashes and rows were unchanged. Default state SQL had no rich context.
  • The runnable example and isolated enable-condition mutation check passed.
  • Documentation links and navigation passed. The strict MkDocs build was
    unavailable because MkDocs is not installed 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 is paused · Paused

The task's access, billing or publication was refused. Check the Coding task for the specific failure before resuming.

@mday-io mday-io mentioned this pull request Oct 31, 2026
4 tasks done
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Autofix was enabled. Check current status in the Coding task.

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