Skip to content

fix(mcp): expose resolved query time boundaries - #44105

Merged
aminghadersohi merged 4 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/mcp-report-resolved-time-range
Sep 10, 2026
Merged

aminghadersohi merged 4 commits into
apache:masterfrom
aminghadersohi:aminghadersohi/mcp-report-resolved-time-range

Conversation

@aminghadersohi

@aminghadersohi aminghadersohi commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

The query engine resolves a relative time range to concrete bounds, but MCP discarded them. Callers could not tell which range produced the numbers: a model can narrate one range while the query used another.

Verified on master: from_dttm/to_dttm appear nowhere in superset/mcp_service/, while superset/common/query_context_processor.py computes the result payload containing those resolved bounds.

Both query_dataset and get_table return from_dttm (inclusive) and to_dttm (exclusive), including on cached and empty results. The response schemas and tool documentation explain how to report these ISO 8601 values. Missing primary bounds remain null.

What this does not do: no parser change; no year-offset bug was found. Callers can identify the engine's primary logical range, not every additional SQL filter or timezone-adjusted boundary. These fields are not observed row minima/maxima, and naive timestamps are not asserted to be UTC. Additional column filters, virtual dataset SQL, and semantic-view one-sided ranges rewritten as comparison filters can still constrain results.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable (MCP response metadata only).

Before: the request's relative expression was available, but the resolved primary bounds were omitted.

After: for example, previous calendar month evaluated on July 17, 2026 returns from_dttm: "2026-06-01T00:00:00" and to_dttm: "2026-07-01T00:00:00" (exclusive).

TESTING INSTRUCTIONS

  • Run pytest -q tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py.
  • With MCP configured, query a temporal dataset using query_dataset and a relative time_range; compare the returned bounds with the engine result and generated primary time predicate.
  • Repeat using get_table for a built-in dataset and an external semantic view.
  • Repeat with a cache hit and with a query returning zero rows. Both fields should remain present and reflect the engine payload.
  • Check an unbounded query: missing primary bounds should serialize as null. Verify that descriptions distinguish an inclusive start from an exclusive end.

Validation: all changed-file uvx pre-commit run --files ... hooks passed, including mypy and pylint. Targeted unit tests: 128 passed (PYTHONPATH=.:superset-core/src /tmp/ssvenv/bin/pytest -q with the two files above). A live-server check was unavailable because no service was listening on localhost:8088.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Additive response fields only; no database migration or date-parser changes.

Deferred follow-ups (outside this PR)

  • Cached execution provenance: The engine excludes concrete from_dttm/to_dttm values from its cache key and assembles these response fields from the requesting query object. A cache hit spanning a relative-range rollover can therefore report the requesting range rather than the original cached execution's bounds. This PR forwards the engine's metadata unchanged; it does not establish historical execution provenance. Investigating cache identity/provenance belongs in a separate change.
  • Optional test coverage: Real cache storage/retrieval across a rollover, direct get_table null assertions, and timezone-aware serialization cases could strengthen coverage separately. The added cached-result cases use mocked execution payloads.

Review: one adversarial review round found no substantive in-scope defects in cached/empty forwarding, boundary semantics, or serialization. That round required no changes. The subsequent maintainer review requested a model-facing cache caveat: both to_dttm field descriptions and the query-date documentation explain that cache-hit bounds reflect the requesting range, not necessarily the original cached execution, and point to cache_status.cache_hit. No query or parser behavior changed. Changed-file pre-commit and all 128 targeted unit tests passed again after this update.

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Sep 9, 2026
@netlify

netlify Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit d4b228a
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aa22bceca3a4600081c9c4d
😎 Deploy Preview https://deploy-preview-44105--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.09%. Comparing base (70346a5) to head (d4b228a).
⚠️ Report is 34 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #44105    +/-   ##
========================================
  Coverage   80.09%   80.09%            
========================================
  Files        2922     2922            
  Lines      171996   172204   +208     
  Branches    39911    39960    +49     
========================================
+ Hits       137765   137935   +170     
- Misses      31653    31684    +31     
- Partials     2578     2585     +7     
Flag Coverage Δ
hive 37.35% <100.00%> (-0.05%) ⬇️
mysql 56.90% <100.00%> (-0.08%) ⬇️
postgres 56.92% <100.00%> (-0.08%) ⬇️
presto 39.24% <100.00%> (-0.05%) ⬇️
python 84.50% <100.00%> (-0.01%) ⬇️
sqlite 56.62% <100.00%> (-0.08%) ⬇️
unit 75.84% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gabotorresruiz gabotorresruiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The engine has carried from_dttm/to_dttm in the result payload since 2021 and MCP was just dropping them, so forwarding them is the right fix.

I verified the resolution independently under a frozen clock: Last month (rolling), previous calendar month, Last year, Current year, an explicit range, and the no-range case all resolve to exactly the bounds the new tests assert, and the schema serializes datetime to ISO 8601 and null to null. Both execute_tabular_query callers (query_dataset, get_table) are covered, and the values leak nothing beyond the caller's own input, so no boundary concern.

One non-blocking note. The cache-hit caveat is documented in the PR body and the .mdx, but the model reads the field description, and to_dttm's says "Report these bounds when describing results" with no mention of the cache case. I verified QueryObject.cache_key deletes from_dttm/to_dttm and keys on the relative time_range string, so a query_dataset call with time_range="Last month" served from cache across a day rollover returns the earlier cached rows while from_dttm/to_dttm report the new day's resolved range. Since performance.cache_status already surfaces the hit, one sentence in the description would close it, e.g. "On a cache hit these bounds reflect the current request; cross-check performance.cache_status." Purely the description, no behavior change. Approving regardless.

@aminghadersohi
aminghadersohi marked this pull request as ready for review September 10, 2026 03:41
@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Thanks @gabotorresruiz — addressed in d2f02a5. Both response schemas now include the cache-hit caveat in the model-facing to_dttm description, and the query-date documentation carries the same warning. I used cache_status.cache_hit rather than performance.cache_status because the latter is no_data on empty-result responses, including cached empty results. No behavior or parser changes. Verified the generated JSON schemas, all changed-file pre-commit hooks passed (including mypy and pylint), and the two targeted tool test files passed all 128 tests.

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct: the test case for cached results only verifies the is_cached flag and does not validate that the from_dttm and to_dttm fields are correctly reconstructed or serialized from the cache. To resolve this, the test should be updated to mock a cache entry containing specific time bounds and assert that these values are correctly returned in the QueryDatasetResponse when is_cached is true. I have not implemented the fix as the test file is not present in the provided PR context. Please provide the test file content if you would like me to implement the fix.

@aminghadersohi

Copy link
Copy Markdown
Contributor Author

@gabotorresruiz Thanks for the careful verification. Updated both from_dttm and to_dttm descriptions in QueryDatasetResponse and GetTableResponse in 16ecbfc with: "On cache hits, these are current-request bounds; cached rows can reflect an earlier relative range. Check performance.cache_status."

This explicitly covers the rollover case you verified: QueryObject.cache_key retains the relative time_range and removes from_dttm/to_dttm, so the resolved bounds do not establish the range of the cached rows. Description-only change; no behavior changes.

Validation: uvx pre-commit run --files <all branch-changed files> passed, including mypy and pylint. Targeted unit tests were blocked during collection by local test-environment initialization. Before this push, CI had no failed checks, with 15 still pending/running. Left the PR ready for review (not draft).

@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Addressed the review comments in d4b228a. The cache-serialization suggestion is covered by a real cache write/read regression test across a frozen-clock rollover, for both populated and empty results; details are in the review-thread reply. The external one-sided-range report does not reproduce through MCP validation, so I added entry-point regression tests and clarified the documentation rather than changing query behavior.

@gabotorresruiz Both bound descriptions retain the explicit rollover caveat. They point to cache_status.cache_hit: the new empty-result cache test confirms that performance.cache_status is no_data even on a cache hit.

Validation: 134 targeted tool tests passed with the local superset-core/src source path configured. uvx pre-commit run --files <all branch-changed files> passed, including mypy and pylint. CI had no failed checks before this push; remaining jobs were running. The PR remains ready for review, not draft.

@bito-code-review

bito-code-review Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #92bfa8

Actionable Suggestions - 0
Additional Suggestions - 1
  • docs/admin_docs/configuration/mcp-server.mdx - 1
    • Doc inaccuracy: open-ended ranges · Line 1034-1036
      This claim is inaccurate. `validate_time_range` (time_range_validation.py:177-178) returns any separator-containing string unchanged, and `get_since_until` (date_parser.py:634-640) resolves the empty side to `None` — a null primary bound, not a rejection. Suggest rewording to say open-ended ranges resolve to a null bound rather than being rejected.
Review Details
  • Files reviewed - 7 · Commit Range: 63b266a..d4b228a
    • docs/admin_docs/configuration/mcp-server.mdx
    • superset/mcp_service/dataset/schemas.py
    • superset/mcp_service/dataset/tool/query_dataset.py
    • superset/mcp_service/semantic_layer/schemas.py
    • superset/mcp_service/semantic_layer/tool/get_table.py
    • tests/unit_tests/mcp_service/dataset/tool/test_query_dataset.py
    • tests/unit_tests/mcp_service/semantic_layer/tool/test_get_table.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi
aminghadersohi merged commit 46d40e1 into apache:master Sep 10, 2026
75 checks passed
shivamgoel added a commit to shivamgoel/superset that referenced this pull request Sep 10, 2026
… its cache

With the bounds in the cache key, "Last month" spanning midnight is a distinct
query rather than a cache hit, so the from_dttm/to_dttm a response reports are
the ones its rows were queried for. This is the cached-execution provenance
follow-up deferred by apache#44105.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants