Skip to content

feat: open saved searches with a saved default time range - #3593

Open
Asheesh7298 wants to merge 7 commits into
ClickHouse:mainfrom
Asheesh7298:ai/saved-search-default-time-range
Open

Asheesh7298 wants to merge 7 commits into
ClickHouse:mainfrom
Asheesh7298:ai/saved-search-default-time-range

Conversation

@Asheesh7298

@Asheesh7298 Asheesh7298 commented Nov 7, 2026 •

Copy link
Copy Markdown

Summary

Closes #3567.

Saved searches can now store a default time range (for example "past 1 day") and open with it instead of always landing in Live Tail. This follows the approach agreed on the issue, which is the same one #3073 used for dashboards.

  • Storage. A new optional defaultTimeRange field on saved searches, shaped { type: 'relative', value: <seconds> } like the relative case of the dashboard savedDateRange. That relative variant is now a named RelativeDateRangeSchema, and both schemas use it. Saved searches accept only relative ranges: as agreed on the issue, fixed windows are out for now. Existing searches don't have the field and behave as before, so there's no migration.
  • Opening. When the URL carries no time (nav, list and Spotlight links are a bare /search/<id>), a stored range that live tail supports (1 minute to 6 hours) opens as live tail with that interval. Longer ranges open as [now − N, now] with live tail off, the same as dashboards. Links that already carry a time (isLive or liveInterval, e.g. alert links) keep winning. The URL writes use replace: a push would leave the bare URL in history, and Back would land on it and apply the range again.
  • Saving. Saving stores the selected time range when it reads as "the past N": a live tail interval (e.g. Last 1 hour with "Live tail ranges" on) or a window ending now (e.g. Last 1 days). The modal shows what the search will open with ("Opens with the past 1 day", "Opens in live tail for the past 1 hour", or "Opens in live tail") and a tooltip explains how to change it. Plain live tail stores nothing, and updating from it clears a stored range. A window in the past (e.g. brushed on the histogram) is never saved; updating from one keeps the stored range.
  • Clearing. The PATCH route used _.omitBy(…, _.isNil), which made it impossible to remove a stored range. It now drops only undefined. No other saved-search field accepts null, so validation still rejects null for those (there's a test for this).
  • Not in this PR. These are follow-ups mentioned on the issue:
    • keeping the range relative in the URL after opening, so copied links stay "past 1 day";
    • external API v2 and OpenAPI;
    • MCP and CLI.

Screenshots or video

Before After
before after

How to reproduce

Starting point: yarn app:dev:local, onboarding → Connect to Demo Server.

On main:

  1. Open Search and pick Demo Logs. In the time picker, choose Last 1 days.
  2. Click Save, name it, and save.
  3. Open the saved search from the saved searches list. It opens in Live Tail (last 15 minutes).

On this branch:

  1. Same as step 1 above.
  2. Click Save. The modal shows Opens with the past 1 day. Name it and save.
  3. Open the saved search from the saved searches list. It opens on the past day with live tail off. Press Back and you return to the list.
  4. Open it again, switch the time picker to Live Tail and click Update. The modal shows Opens in live tail. Opening the search from the list now gives Live Tail again.

How to test on Vercel preview

Preview routes: /search, /search/list

Steps:

  1. Open /search, select the Demo Logs source, open the time picker and click Last 1 days.
  2. Click Save, enter a name, confirm the modal shows Opens with the past 1 day, and click Save.
  3. Open /search/list and click the saved search you just created.
  4. Verify the URL contains isLive=false and the time picker shows a range of about one day ending now.

References


Note

Medium Risk
Touches core search URL/time state and saved-search PATCH semantics; behavior changes on every saved-search open, though existing searches without the field stay unchanged.

Overview
Saved searches gain an optional defaultTimeRange ({ type: 'relative', value: seconds }), shared via a new RelativeDateRangeSchema in common-utils (dashboard savedDateRange reuses the same shape). The API persists the field, validates relative-only ranges, and PATCH now omits only undefined so null can clear a stored range.

On the search page, opening a bare /search/:id applies the saved range (live tail for supported intervals, otherwise a window ending now) with history replace so Back does not re-apply it; URL time params still win. Saving/updating derives the range from the current live interval or a “past N” window, shows it in the save modal (SaveTimeRangeField), and skips custom historical brushes. parseRelativeTimeQuery accepts an anchor time; onTimeRangeSelect supports optional history mode.

Coverage adds unit, API integration, and e2e tests for save, open, and validation.

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

Saved searches can store a relative defaultTimeRange (e.g. past 1 day)
that is applied when the search is opened without a time in the URL,
instead of always landing in live tail. The save modal gets a "When
opened" choice. Same shape as the relative case of dashboard
savedDateRange; fixed windows are not accepted.

The saved-search PATCH route now drops only undefined, so sending null
clears the stored range.

Refs ClickHouse#3567
@Asheesh7298
Asheesh7298 requested a review from a team as a code owner November 7, 2026 10:14
@vercel

vercel Bot commented Nov 7, 2026

Copy link
Copy Markdown

@Asheesh7298 is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added external needs-vouch Author needs a maintainer to vouch for them labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Hi @Asheesh7298, thanks for the pull request!

Before we review code from a first-time contributor, a maintainer vouches for them, and you're not on our list yet. There's nothing else to file and this PR stays open — a maintainer will look at it, usually within a day or two, and vouch for you right here if it's a genuine attempt at the problem.

To make that quick, check the PR description has:

  • The issue it addresses (ideally one labelled Accepting PR) and why the change is needed
  • Steps to reproduce the problem and verify the fix, starting from https://play.hyperdx.io or yarn app:dev:local connected to the demo server
  • Before/after screenshots if anything in the UI changed

More detail in our contributing guide.

// Live updates pause while the save modal is open, so the window is stable.
const options = useMemo(() => {
const current: CurrentTimeRange =
isLive || openedAtMs == null

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.

🟠 major — A relative interval in live mode (Last 1–6 hours etc.) can't be saved as the default time range

In relative mode, onTimePickerRelativeSearch (DBSearchPage.tsx:2246) sets isLive=true and liveInterval=rangeMs for every option with relativeSupport (1 minute to 6 hours, TimePicker/utils.ts:185-193). This hook treats any isLive as { kind: 'live' }, so the modal only offers "Show live tail" and says "To save a time range, pick one first", even though the user just picked one. When the saved search reopens, it drops the chosen 1h interval and falls back to 15m live tail. Fix: pass interval into the hook. When isLive && interval !== LIVE_TAIL_DURATION_MS, offer current as { type: 'relative', value: interval / 1000 }.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 437ab94. A live tail interval (1 minute to 6 hours) can now be saved, and those ranges reopen as live tail with that interval. Longer ranges still open as a window ending now. Added unit and e2e coverage.

*/
export const RelativeDateRangeSchema = z.object({
type: z.literal('relative'),
value: z.number(),

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.

🔵 minor — RelativeDateRangeSchema accepts zero and negative durations, so the client has to guard against them

value: z.number() lets POST/PATCH store { type: 'relative', value: 0 } or -60. getSavedSearchLandingRange then silently ignores these values (savedSearchTimeRange.ts:29), and the unit tests pin that workaround. Make the schema z.number().positive() (this suits dashboards too) so invalid ranges are rejected with a 400. Then drop the <= 0 check on the client.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 437ab94. defaultTimeRange now requires a positive duration and returns 400 otherwise, and the client guard is removed. I left the shared RelativeDateRangeSchema as is so dashboard validation doesn't change in this PR.

if (!Number.isFinite(stored.value) || stored.value <= 0) return null;
// Whole seconds, like parseRelativeTimeQuery, so re-parsing the displayed
// text on the first submit lands on the same from/to.
const end = Math.floor(nowMs / 1000) * 1000;

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.

🔵 minor — New helpers duplicate existing time helpers in timeQuery.ts

getSavedSearchLandingRange rebuilds parseRelativeTimeQuery (packages/app/src/timeQuery.ts:46): the end is truncated to the second and the duration is subtracted. The comment even names it. formatRelativeDuration (line 67) also repeats the formatDuration(intervalToDuration(...)) logic of getRelativeInterval (timeQuery.ts:417). Fix: give parseRelativeTimeQuery an optional nowMs argument and call it. Export one duration formatter from timeQuery.ts and use it in both places, instead of keeping a second copy (this follows the REQUIRED DRY rule).

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Partly fixed in 437ab94: opening a search now calls parseRelativeTimeQuery, which takes an optional now. I kept formatRelativeDuration separate on purpose. It anchors at epoch 0, so a saved "1 day" never prints as "23 hours" across a DST change, which getRelativeInterval can do because it uses the real start and end dates.

@github-actions

github-actions Bot commented Nov 7, 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): 🔴 1 P0/P1 · 🟡 1 P2 · 🔵 0 P3

1 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🔴 P1 packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:748 — A preset like "Last 1 days" stops being saved once the window is more than 5 minutes old → isRangeEndingNow checks the window's end against openedAtMs with a fixed 5-minute tolerance, and the window only refreshes when a search runs. So if a user picks "Last 1 days" (or opens a saved search that landed on its stored day window), works for 6 minutes, then clicks Save or Update, the modal says "Custom time ranges aren't saved". Create saves nothing, and update quietly keeps the old value. Base the decision on how the range was chosen instead, i.e. whether the applied time input is a relative preset (appliedTimeInputValue in DBSearchPage, parsed with timeRangeInputToSeconds from components/TimePicker/utils.ts, as the dashboard save does). Keep the end-time check only for brushed or absolute ranges.

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 7, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Saved searches gain an optional relative defaultTimeRange and open with it when the URL carries no explicit time. Ten reviewers ran across correctness, testing, maintainability, standards, TypeScript, API contract, frontend races, adversarial input, prior comments, and security. The core design is sound: the mass-assignment surface is unchanged (the _.isNil → _.isUndefined switch only lets null through for the single .nullish() field, and SavedSearchSchema.partial() still rejects null everywhere else — proven by the orderBy: null → 400 test), the landing useEffect is guarded against re-entry, all URL writes use history: 'replace', and every prior review thread is resolved.

✅ No critical issues found.

🟡 P2 — recommended

  • packages/common-utils/src/types.ts:1416 — defaultTimeRange.value is validated only as z.number().positive() with no .finite() or upper bound, so a crafted API write of an absurd value (e.g. 1e308) persists and makes the search open broken on every visit: stored.value * 1000 overflows Date range, parseRelativeTimeQuery yields an Invalid Date, NaN reaches the from URL param and every chart query, and opening the update modal runs formatRelativeDuration over an infinite interval (risking a thrown render).
    • Fix: Add .finite() and a sane upper bound to the value schema, and guard the client parse so a non-finite stored duration never reaches Date math.
    • adversarial, security, kieran-typescript
  • packages/app/src/components/SavedSearches/SaveTimeRangeField.tsx:69 — the new customRangeIgnored modal copy and the clear-on-update path (defaultTimeRange: null sent when updating from default live tail) have no component or e2e coverage; both are exercised only by pure-function unit tests, leaving the user-visible wiring untested.
    • Fix: Add a component render asserting the customRangeIgnored copy and an e2e that updates a search from default live tail and confirms it reopens in live tail.
    • testing, correctness
🔵 P3 nitpicks (10)
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:63 — a sub-second window ending now rounds to value: 0, which the positive() schema rejects with a generic 400 and which renders as empty preview text.
    • Fix: Clamp the fallback with Math.max(1, Math.round(durationMs / 1000)).
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:110 — a live interval that is not a live-tail preset is stored as a relative range shown as "Opens with the past N" but lands as a fixed window, a mild intent mismatch.
    • Fix: Gate storage on isLiveTailDuration(current.intervalMs) or confirm the window landing is intended.
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:83 — CurrentTimeRange and SavedSearchLanding are byte-for-byte identical unions that can silently drift apart.
    • Fix: Alias one to the other (type CurrentTimeRange = SavedSearchLanding) with a comment on the two roles.
  • packages/app/src/DBSearchPage.tsx:1399 — performance.timeOrigin + performance.now() is duplicated as the nowMs source at two sites without an explanation of the non-Date.now() choice.
    • Fix: Extract a named wallClockNowMs() helper with a one-line rationale.
  • packages/app/src/components/SavedSearches/SaveTimeRangeField.tsx:49 — nowMs: openedAtMs ?? 0 silently yields customRangeIgnored for a closed modal; harmless today but a latent footgun.
    • Fix: Return an early sentinel outcome when openedAtMs is null, or document why the value is unused while closed.
  • packages/api/src/controllers/savedSearch.ts:67 — a cleared range persists as literal null via findOneAndUpdate, so GET returns null for cleared searches but omits the key for never-set ones — two representations of "no range".
    • Fix: $unset defaultTimeRange on clear if a single representation is wanted; otherwise acceptable since the field is .nullish().
  • packages/api/src/routers/api/savedSearch.ts:91 — the isUndefined safety relies on an undocumented invariant that no other SavedSearchSchema field becomes nullable; a future .nullish() field would silently let null clear it via PATCH.
    • Fix: Drop undefined everywhere but allow null only for defaultTimeRange explicitly.
  • packages/api/src/routers/external-api/v2/savedSearches.ts:602 — v2 PUT is documented as a full replace that resets omitted optional fields, but defaultTimeRange (absent from the v2 schema) is silently preserved.
    • Fix: Note in the PUT docs that UI-only fields are preserved, or clear it for strict replace semantics.
  • packages/app/src/DBSearchPage.tsx:483 — this file is ~3400 lines, far past the documented 300-line limit, and the PR adds modal wiring to it (pre-existing; new helpers were correctly extracted).
    • Fix: None required for this PR; consider extracting the save-modal component in a follow-up.
  • packages/app/src/timeQuery.ts:452 — pre-existing: live-tail refresh ticks call onTimeRangeSelect with no history option, so each 10s tick pushes a Back entry.
    • Fix: Pass { history: 'replace' } for live-tail refreshes (out of scope for this PR).

Reviewers (10): correctness, testing, maintainability, project-standards, kieran-typescript, api-contract, julik-frontend-races, adversarial, previous-comments, security.

Testing gaps:

  • The null-clear integration test asserts dbRecord?.defaultTimeRange ?? null toBeNull(), which passes for stored-null, undefined, or absent alike — it does not prove the field was actually cleared.
  • No boundary test for out-of-range defaultTimeRange.value (e.g. 1e15, 1e308) at the schema or landing level.
  • The landing useEffect is exercised only via e2e; no isolated assertion that it applies the range exactly once and that all writes use history: 'replace'.

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

Address review feedback:
- A live tail interval picked in the time picker (1 minute to 6 hours)
  can now be saved. Ranges live tail supports reopen as live tail with
  that interval; longer ones open as a window ending now.
- defaultTimeRange rejects zero and negative durations.
- Reuse parseRelativeTimeQuery (now takes an optional "now") instead of
  rebuilding it.

/** "1 day", "1 hour 30 minutes". Anchored at epoch 0 so DST never shifts it. */
export function formatRelativeDuration(seconds: number): string {
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));

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.

🔵 minor — formatRelativeDuration re-implements the duration formatting that getRelativeInterval in timeQuery.ts already does

getRelativeInterval (packages/app/src/timeQuery.ts:420) already does formatDuration(intervalToDuration(...)) to build the time picker's "Past …" label. This PR adds a second copy of that call in a new module, so the saved-search labels and the picker labels can drift apart. Extract one shared duration formatter in timeQuery.ts, use it from both getRelativeInterval and the save modal, and delete the copy, as the REQUIRED DRY convention asks.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same point as the earlier thread: I kept this separate on purpose. It anchors at epoch 0 so a saved duration like "1 day" never prints as "23 hours" across a DST change, which getRelativeInterval can do because it formats real start/end dates. Making both share it would change the picker's existing label, so I'd rather leave that for a separate change.


// A pick only counts for the opening it was made in. Until then the default
// applies, which can change once the stored saved search loads.
const [picked, setPicked] = useState<{

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.

🔵 minor — No test covers the hook's per-opening pick logic or the landing effect in DBSearchPage

Unit tests only cover the pure helpers. Nothing exercises the logic that drops a pick when openedAtMs changes, or that falls back to defaultChoice once stored loads. Nothing tests the DBSearchPage landing effect either, including whether it skips URLs that carry isLive/liveInterval. The e2e only covers the two create paths, so a regression where a reopened modal keeps the last pick (and Update overwrites the stored range) would still pass. Add a renderHook test for useSaveTimeRangeField (pick, close, reopen, expect default) and an update-flow case to DBSearchPage.saveSearch.test.tsx.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fair point. The choice logic and the update resolver are unit tested, and the landing path is checked by the two e2e tests (window and live interval). I'm stopping bot-driven changes after two review rounds per AGENTS.md. Happy to add a renderHook test for the pick/reopen behaviour if a maintainer would like it in this PR.

@Asheesh7298

Copy link
Copy Markdown
Author

@brandon-pereira this is ready for a look when you have time. It follows the plan from #3567 (defaultTimeRange, relative ranges only). Two automated review rounds are addressed: the live tail interval case is fixed, and the remaining minor notes are answered in their threads.

label={
isLiveTailDuration(currentRange.value * 1000)
? `Show live tail for the past ${formatRelativeDuration(currentRange.value)}`
: `Show the past ${formatRelativeDuration(currentRange.value)}`

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.

UX Feedback: would it not make sense to just say 'Saving Saved Search with the past {relativeTime} as default search' or something along those lines? I feel like we should not give an option for this, but add a tooltip to explain how to customize

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion,

Done in 3a4b8b1:

Removed the "When opened" choice. Saving now stores the selected range automatically.
The modal shows what the search will open with, e.g. "Opens with the past 1 day" or "Opens in live tail for the past 1 hour", with a tooltip explaining how to change it.
Ranges that end in the past aren't saved, and on Update they keep the stored range instead of clearing it.
Here's how it looks now. Happy to adjust the wording if you'd prefer something different.

Per review: drop the "When opened" choice from the save modal. Saving
stores the selected range when it reads as "the past N" (a live tail
interval or a window ending now). The modal shows what the search will
open with, and a tooltip explains how to change it.
[start, end]: [Date, Date],
nowMs: number,
): boolean {
const tolerance = Math.max(

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.

🔵 minor — Fixed windows that ended hours or days ago get saved as "the past N", which the tooltip says can't happen

Allowing 10% of the duration lets a 30-day absolute range that ended 2 days ago (tolerance is 3 days) be stored as {relative, 2592000}, and a 7-day range that ended 16h ago passes too. The tooltip in SaveTimeRangeField.tsx says "Ranges that end in the past are not saved". Cap the slack at a fixed small amount, or decide from what the picker shows rather than from timestamps (next finding).

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

const range = toDefaultTimeRange(current.intervalMs);
return { value: range, opensWith: range };
}
if (isRangeEndingNow(current.range, nowMs)) {

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.

🔵 minor — Dashboards and saved searches decide "is this relative" in two different ways

Dashboards get the relative range from the picker text with timeRangeInputToSeconds(displayedTimeInputValue, timeZone) (DBDashboardPage.tsx:2176, helper in components/TimePicker/utils.ts:166). This PR guesses from the window's end time with a tolerance instead. Reuse the existing picker-text approach, or move one shared rule into TimePicker/utils.ts, so the same picker choice saves the same way in both features.

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

Comment thread .changeset/saved-search-time-range.md Outdated
'@hyperdx/common-utils': minor
---

feat: saved searches can store a default time range (e.g. past 1 day) to open with instead of live tail, chosen in the save modal under "When opened"

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.

🔵 minor — Changeset mentions a "When opened" control that no longer exists

The last commit, "save the selected time range without asking", removed the chooser. The modal now only shows read-only "Opens with…" text. Reword the release note to say the selected range is saved automatically.

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

return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));
}

export type CurrentTimeRange =

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.

🔵 minor — CurrentTimeRange is the same union as SavedSearchLanding in the same file

Both are {kind:'live'; intervalMs} | {kind:'window'; range}. Keep one exported type, e.g. type CurrentTimeRange = SavedSearchLanding. Also have the live landing return its range too, so DBSearchPage.tsx:1336 doesn't need to call parseRelativeTimeQuery a second time.

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

}

/** "1 day", "1 hour 30 minutes". Anchored at epoch 0 so DST never shifts it. */
export function formatRelativeDuration(seconds: number): string {

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.

🔵 minor — formatRelativeDuration copies the existing getRelativeInterval formatting

timeQuery.ts:420 (getRelativeInterval) already formats a span with formatDuration(intervalToDuration(...)). Export one shared helper (anchored at epoch 0) and use it in both places.

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

savedSearch.id === savedSearchId && // Make sure we've loaded the correct saved search
isSearchConfigEmpty // Only populate if URL doesn't have explicit config
) {
const nowMs = performance.timeOrigin + performance.now();

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.

🔵 minor — performance.timeOrigin + performance.now() is used to get around the Date.now() lint rule

Here and in openSaveSearchModal, both inside an effect/callback, which the rule's message says is fine. Use Date.now() with // eslint-disable-next-line no-restricted-syntax, as parseRelativeTimeQuery in timeQuery.ts already does, so the intent stays obvious.

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

return (
<Group gap={6} data-testid="save-search-time-range">
<Text size="xs">{describeOpensWith(opensWith)}</Text>
<Tooltip label={TOOLTIP} multiline w={280} withArrow>

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.

🔵 minor — Keyboard users can't open the tooltip that explains how the range is saved

The Tooltip wraps a bare IconInfoCircle SVG, which can't take focus, so the explanation only shows on mouse hover. Wrap the icon in a focusable element such as <ActionIcon variant="subtle" aria-label=…>, or show the text inline under the label.

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

@vercel

vercel Bot commented Nov 23, 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 23, 2026 3:31pm UTC

Request Review

@brandon-pereira brandon-pereira 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.

Screenshot 2026-11-23 at 11 40 09 AM

if someone has a custom time range set, we show the live tail text which seems strange imo. thoughts?

@brandon-pereira

Copy link
Copy Markdown
Member

@Asheesh7298 one feedback above, mostly ready to go. Thanks for taking a look!

Per review: with a custom range that ends in the past, the save modal
said "Opens in live tail" with no reason. It now says "Custom time
ranges aren't saved." first. The "ends now" check uses a fixed
5-minute tolerance, so a long custom range that ended days ago is no
longer saved as "the past N". The changeset no longer mentions the
removed "When opened" choice.
@changeset-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80fb4ae

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

This PR includes changesets to release 4 packages
Name Type
@hyperdx/api Minor
@hyperdx/app Minor
@hyperdx/common-utils Minor
@hyperdx/otel-collector Minor

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

Comment thread packages/app/src/timeQuery.ts Outdated
const end = startOfSecond(nowMs != null ? new Date(nowMs) : new Date());
return [subMilliseconds(end, interval), end];
}
return [subMilliseconds(end, interval), end];

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.

🔴 P0 — Leftover lines after parseRelativeTimeQuery are a syntax error, so the app won't compile

Delete the orphaned return [subMilliseconds(end, interval), end]; and } at lines 53-54. They sit outside any function, after the new body that closes at line 52, so timeQuery.ts doesn't parse. Every importer then breaks, including DBSearchPage and the new savedSearchTimeRange.ts.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

setInterval(landing.intervalMs, { history: 'replace' });
onTimeRangeSelect(start, end, null, { history: 'replace' });
const label = getRelativeTimeOptionLabel(landing.intervalMs);
if (label) setDisplayedTimeInputValue(label);

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 — Live-tail landing sets the input label without updating the applied value

Call setAppliedTimeInput(label) here instead of setDisplayedTimeInputValue(label), the same way updateRelativeTimeInputValue (line 1944) does. As written, displayedTimeInputValue becomes 'Last 1 hour' while appliedTimeInputValue stays 'Live Tail', so isTimeInputEdited (line 1348) wrongly reports a user edit.

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


/** "1 day", "1 hour 30 minutes". Anchored at epoch 0 so DST never shifts it. */
export function formatRelativeDuration(seconds: number): string {
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));

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 — formatRelativeDuration shows long ranges in calendar months

Starting at epoch 0, intervalToDuration breaks long spans into calendar months: 60 days (5184000 s) shows as "2 months 1 day" and 45 days as "1 month 14 days", so the modal's "Opens with the past …" text doesn't match the range the user picked. Pass format: ['days','hours','minutes'] to formatDuration, or compute days, hours and minutes from the seconds directly.

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

@Asheesh7298

Asheesh7298 commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

@brandon-pereira , thanks! With a custom range, the modal now says "Custom time ranges aren't saved. Opens in live tail." instead of just "Opens in live tail". I also tightened the check, so a long custom range that ended days ago is no longer saved as "the past N".

I've also merged the latest main and resolved the conflict in timeQuery.ts.
after-custom-range

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 80fb4ae. Configure here.

nowMs: number,
): boolean {
return Math.abs(end.getTime() - nowMs) <= ENDS_NOW_TOLERANCE_MS;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Frozen range skipped after short delay

Medium Severity

isRangeEndingNow now treats a window as “the past N” only if its end is within 5 minutes of openedAtMs. Non-live picker presets such as Last 1 days freeze searchedTimeRange at selection, so waiting longer before Save makes that preset look custom: it is not stored and the search reopens in live tail.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 80fb4ae. Configure here.

);
// Replace, not push: a pushed entry would leave the bare URL behind,
// and Back would land on it and re-apply the range forever.
if (landing?.kind === 'live') {

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 — The live-tail landing branch re-implements onTimePickerRelativeSearch and updates only the displayed input

This branch copies the writes from onTimePickerRelativeSearch (DBSearchPage.tsx:2470), as its own comment says. It then sets the label with the raw setDisplayedTimeInputValue instead of updateRelativeTimeInputValue/setAppliedTimeInput. That leaves appliedTimeInputValue at 'Live Tail', so isTimeInputEdited is true until another effect overwrites it. Give onTimePickerRelativeSearch an optional { history } argument, move it above this effect, and call it here followed by updateRelativeTimeInputValue(landing.intervalMs). That leaves one code path for applying a live interval.

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

This branch was successfully deployed

1 active (outdated) deployment
Preview – hyperdx-oss — 3a4b8b1a Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external needs-vouch Author needs a maintainer to vouch for them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintain relative date selection for saved/linked searches

2 participants