Skip to content

fix: refetch SQL query "All" options on every dashboard refresh - #3862

Open
karl-power wants to merge 3 commits into
claude/sql-filter-all-sql-queryfrom
claude/sql-filter-all-refresh-options
Open

karl-power wants to merge 3 commits into
claude/sql-filter-all-sql-queryfrom
claude/sql-filter-all-refresh-options

Conversation

@karl-power

@karl-power karl-power commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A SQL query filter set to "All" now refetches its options on every dashboard refresh, so new values reach tiles. Stacked on #3861, which added "All" for SQL query filters.

  • Before, an options query that doesn't use the time range kept its cache key across refreshes, and the five-minute staleTime never triggers a fetch on its own. "All" kept the options from the first load, so new services or regions stayed out of tiles until the page reloaded.
  • The refresh button, auto-refresh in live mode and time range changes all move the time range, so the page-level expansion now refetches the options of every SQL query filter with "All" selected when the range changes. This also covers kiosk mode.
  • useSqlQueryFilterValues takes a refreshKey: when it changes, every query refetches, and a request already in flight is reused. The dropdown and the page share one cache entry, so each refresh issues one options request per filter, not two, including for queries whose key changes with the range anyway.
  • Dropdowns of filters not set to "All" keep their cached options as before.

How to test

Use the test dashboard from #3861, and:

  1. Click "Edit filters", then "Add filter", and choose "SQL query values". Name it Minute, pick the connection, enter SELECT toString(toStartOfMinute(now())), set the variable name to minute, tick "Include "All" option" and save.
  2. Add a Markdown tile with the text Minute: $minute. Pick "All" in the Minute dropdown. The tile shows the current minute.
  3. Wait for the next minute and click the refresh button. The tile shows the new minute.

References


Note

Low Risk
Scoped to dashboard filter option fetching and caching; adds refetch work on time-range changes but no auth, security, or persistence changes.

Overview
SQL query filters set to "All" now reload their option lists whenever the dashboard time range changes (manual refresh, live auto-refresh, etc.), so tiles see newly appearing values even when the filter SQL does not reference the time range and would otherwise keep a stable React Query cache key.

useSqlQueryFilterValues accepts an optional refreshKey; when it changes, a useEffect refetches every filter-options query with cancelRefetch: false so an in-flight request is not duplicated. useExpandedSqlQueryVariables supplies the key from the range timestamps (by value, so identical ranges do not trigger extra fetches). Filter dropdown callers that omit refreshKey keep prior caching behavior but still benefit from the shared query cache when expansion refetches.

New integration tests cover time-range-agnostic vs time-aware SQL, no refetch on an equal range, and loading while dependent variables change.

Reviewed by Cursor Bugbot for commit b3b2426. Bugbot is set up for automated code reviews on this repo. Configure here.

@karl-power
karl-power requested a review from a team as a code owner November 30, 2026 10:33
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 30, 2026 10:56am UTC
hyperdx-storybook Ready Ready Preview Nov 30, 2026 10:56am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3b2426

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3

2 posted as inline comment(s) on the changed lines.


Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a focused, well-tested, and well-documented change. Correctness, performance, race-condition, and standards reviewers all came back clean: the refetch is linear in the number of "All" SQL filters, deduped across the dropdown and page via a shared react-query cache entry, and cancelRefetch: false prevents a double-fetch for time-aware queries (pinned by the "once per refresh" test). No P0/P1/P2 issues.

🔵 P3 nitpicks (1)
  • packages/app/src/hooks/useSqlQueryFilterValues.tsx:244 — the effect lists the identity-unstable results array (new each render from useQueries) as a dependency, so it runs every render and is suppressed only by the lastRefreshKeyRef guard; the ref is load-bearing but not explained, so a future "simplification" that trusts the dep array could reintroduce a refetch-per-render storm.
    • Fix: add a one-line comment noting the ref guard is what restricts the refetch to real refreshKey changes, since results changes identity every render.
    • maintainability, kieran-typescript

Reviewers (10): correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, kieran-typescript, julik-frontend-races, performance, previous-comments.

Testing gaps:

  • The refetch for-loop is only exercised with a single filter; multiple SQL filters refetching together on one refresh is uncovered.
  • Recovery of an errored/non-retryable options query on a subsequent refresh is not tested, though the loop calls refetch on errored results too.
  • The cancelRefetch: false in-flight-reuse path (a refreshKey change while a prior refetch is still pending) is only pinned indirectly via the "2 not 3" call-count assertion, not by holding a request open across overlapping refreshes.
  • Under rapid live auto-refresh with queries slower than the refresh cadence, intermediate refreshes for time-range-ignoring queries coalesce and "All" options can lag one cycle before self-correcting — an intended, code-documented tradeoff of cancelRefetch: false; worth product confirmation that one-cycle staleness is acceptable in live mode.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@karl-power
karl-power added this pull request to stack #3848 November 30, 2026 10:53
@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

1 new clone introduced by this PR.

  • packages/app/src/hooks/usePromqlLabelFilterValues.tsx:128-150 ↔ packages/app/src/hooks/useSqlQueryFilterValues.tsx:244-266 — 23 lines

If one of these duplicates a helper that already exists, import it instead
of redefining it. If the duplication is deliberate, ignore this comment —
the check is advisory and never fails the build.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.10%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

mockQuery.mockResolvedValue({
json: async () => ({ data: values.map(value => ({ value })) }),
});

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.

🟡 P2 — "doesn't refetch for an equal time range" checks the call count before any refetch could reach mockQuery

The queryFn first awaits renderValuesCall (useSqlQueryFilterValues.tsx:217) and only then calls getClickhouseClient().query. So a refetch fired by the effect on this rerender would not have called mockQuery yet when line 174 runs synchronously, and the test passes even if refreshKey were built from Date identity. Wait before asserting, for example with await waitFor(() => expect(result.current...isFetching).toBe(false)) or by flushing microtasks with await act(async () => {}), then check toHaveBeenCalledTimes(1).

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

useEffect(() => {
if (lastRefreshKeyRef.current === refreshKey) return;
lastRefreshKeyRef.current = refreshKey;
for (const result of results) {

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.

🟡 P2 — Refetched "All" options aren't treated as loading, so tiles run twice per refresh with stale options first

For a query that ignores the time range, refetch keeps the cached data and leaves isLoading false. useExpandedSqlQueryVariables (line 117) therefore expands "All" right away with the old options at the new range, so tiles run at once. When the new values arrive, the expanded variables change and the tiles run again. Queries that read the time range get a new key and wait instead, which is the behaviour the 'waits for new options' test pins. To fix this, surface a refreshKey-triggered fetch as loading, for example by tracking isFetching after a key change and mapping it to isLoading in the expansion. Then tiles wait once for the fresh options, as they do for time-aware queries.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 480 passed • 1 skipped • 1136s

Status Count
✅ Passed 480
❌ Failed 0
⚠️ Flaky 15
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — b3b24262 Deployed Nov 30, 2026 by vercel[bot]
Preview – hyperdx-oss — b3b24262 Deployed Nov 30, 2026 by vercel[bot]
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.

2 participants