Skip to content

fix(semantic-cache): forced queries store their fresh result - #41826

Closed
mikebridge wants to merge 2 commits into
apache:sl-cachefrom
mikebridge:pr-40221-force-query-semantic-store
Closed

mikebridge wants to merge 2 commits into
apache:sl-cachefrom
mikebridge:pr-40221-force-query-semantic-store

Conversation

@mikebridge

Copy link
Copy Markdown
Member

SUMMARY

Third contribution into #40221's branch (sl-cache) — the remaining half of the force-refresh bug shape fixed in #41825:

_make_cached_dispatch returned the raw dispatcher when force_query was set, bypassing both the cache read and store_result. Consequence: a forced refresh executed fresh but never replaced the stale containment-cache entry — other requests whose queries were contained by that stale entry kept being served from it until TTL or a view-definition change. (#41825 fixed the same shape at the DATA-cache layer; this fixes it at the semantic layer.)

The fix: forced queries skip only the cache read and still store their fresh result; row-count queries continue to bypass entirely.

TESTING INSTRUCTIONS

The existing force test is rewritten to pin the full contract: the forced query re-executes, and a subsequent ordinary request is served from cache with the refreshed value rather than the stale one — validated to fail against the pre-fix mapper.

pytest tests/unit_tests/semantic_layers/cache_integration_test.py -q   # 15 passed

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

_make_cached_dispatch returned the raw dispatcher on force_query,
bypassing both the cache READ and store_result — so a forced refresh
never replaced the stale containment-cache entry, and other requests'
contained lookups kept serving it until TTL or invalidation. The
remaining half of the bug shape fixed for the DATA cache in the
force_query/cache_key PR.

Forced queries now skip only the read and store the fresh result;
row-count queries still bypass entirely. The existing force test is
rewritten to the full contract: forced execution happens, AND a
subsequent ordinary request is served from cache with the REFRESHED
value — validated to fail against the pre-fix mapper.
@dosubot dosubot Bot added the infra:caching Infra setup and configuration related to caching label Jul 6, 2026
@bito-code-review

bito-code-review Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at [email protected].

@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 2a4acad
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a4c279abf4fb30008fe2ea8
😎 Deploy Preview https://deploy-preview-41826--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 Jul 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.43%. Comparing base (5581315) to head (6675fe2).

Files with missing lines Patch % Lines
superset/semantic_layers/mapper.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           sl-cache   #41826    +/-   ##
==========================================
  Coverage     63.43%   63.43%            
==========================================
  Files          2592     2591     -1     
  Lines        138780   138647   -133     
  Branches      32235    32214    -21     
==========================================
- Hits          88038    87955    -83     
+ Misses        49212    49171    -41     
+ Partials       1530     1521     -9     
Flag Coverage Δ
hive 39.23% <0.00%> (-0.02%) ⬇️
mysql 58.78% <0.00%> (-0.01%) ⬇️
postgres 58.86% <0.00%> (-0.01%) ⬇️
presto 40.92% <0.00%> (-0.02%) ⬇️
python 59.10% <0.00%> (-0.01%) ⬇️
sqlite 58.50% <0.00%> (-0.01%) ⬇️

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.

mikebridge pushed a commit to mikebridge/superset that referenced this pull request Jul 6, 2026
Review-panel finding on the sibling force-store PR (apache#41826): candidates
were ranked by reuse mode only, and Python's stable sort preserves
insertion order within a rank — so an OLDER stale broader entry that
also satisfies the query (EXACT-with-leftovers) was served ahead of a
just-forced fresh entry for the identical query. The forced refresh
never stuck for readers.

Tie-break by entry timestamp, freshest first. Pinned by a test with a
deterministically older same-rank broader entry — fails under the
rank-only sort.
Review-panel finding (4/4 lenses): the docstring promised a forced
refresh 'replaces the stale entry that other requests' containment
lookups keep reading' — true only for the same canonical shape. Broader
stale entries are out of a narrower forced result's reach by design and
age out by TTL; the freshest-first ranking (added in the sibling index
PR) is what makes the refreshed entry win for the identical query.
Also clarified the test's mock-swap counter-reset subtlety.
@mikebridge

Copy link
Copy Markdown
Member Author

Round-2 review (four-lens panel via Claude, findings verified): 4/4 approve, 0 blockers. Resolutions pushed:

  • The shadowing gap is real and now fixed — in fix(semantic-cache): serialise index bucket writers under a cache-level lock #41824, which owns the cache.py changes: candidates were ranked by reuse mode only, and stable sort's insertion-order tie-breaking let an older stale broader entry be served ahead of a just-forced fresh entry for the identical query. e82bce3cd9 adds freshest-first tie-breaking with a deterministic regression test (fails under the rank-only sort). Placing it there preserves the verified property that all three sibling PRs merge cleanly in any order (git merge-tree checked).
  • Docstrings scoped honestly (6675fe294e here): a forced store replaces the entry for the same canonical shape; broader stale entries are out of a narrower result's reach by design and age out by TTL — with freshest-first ranking making the refreshed entry win for the identical query. Test's mock-swap counter-reset subtlety documented.

Panel also verified: forced stores are shape-safe (the stored entry is exactly what a cold miss would write), the payload overwrite survives #41824's lock-skip path (the set(vkey) precedes lock acquisition), and all four candidate mutants of the rewritten test are killed.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for chasing down the other half of this. The test proving it fails against the pre-fix mapper is a nice touch.

One thing I'm curious about, not blocking: could a slower concurrent ordinary query land after the forced write and clobber it with a stale result? Feels like a property of the general cache design rather than something new here.

@mikebridge

Copy link
Copy Markdown
Member Author

Supersession note to prevent accidental merge: #42760 is the consolidated replacement under review and explicitly carries forward the still-valid work and attribution from this PR stack. This does not mean #42760 has been accepted for adoption yet; that decision remains pending. Please do not merge this stacked PR while the consolidation decision is open; a maintainer or PR owner can close it and reopen later if the direction changes.

@rusackas

Copy link
Copy Markdown
Member

Same situation as #41825, still holding on the #42760 consolidation call, and unit-tests is red here too.

@mikebridge

Copy link
Copy Markdown
Member Author

Closing: this was a contribution into #40221's sl-cache branch, and #42760 has since replaced that branch as the semantic-layer containment cache. #42760 retains this fix — a successful forced refresh is stored after bypassing the read (repository.store(..., replace=force) in cache.py, driven from mapper.py) — see the "Superseded PR → contribution retained" table in its description. Nothing further is needed on this PR.

Closed by Claude (AI) on behalf of @mikebridge.

@mikebridge mikebridge closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra:caching Infra setup and configuration related to caching size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants