Skip to content

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

Merged
kodiakhq[bot] merged 9 commits into
ClickHouse:mainfrom
Asheesh7298:ai/saved-search-default-time-range
Dec 1, 2026
Merged

kodiakhq[bot] merged 9 commits into
ClickHouse:mainfrom
Asheesh7298:ai/saved-search-default-time-range

Conversation

@Asheesh7298

@Asheesh7298 Asheesh7298 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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 load path, URL/time state, and saved-search PATCH semantics; behavior is well tested but wrong landing logic could surprise users or clash with alert links that carry explicit time params.

Overview
Saved searches can now store an optional defaultTimeRange ({ type: 'relative', value: seconds }) so opening a bare /search/:id uses the range chosen at save time instead of always defaulting to live tail.

Backend adds the Mongo field and validates it via shared RelativeDateRangeSchema on SavedSearchSchema (relative only; fixed historical windows rejected). PATCH omits only undefined keys so null can clear a stored range without affecting other fields.

Search UI derives what to save from the current live interval, preset pick, or window ending “now,” shows that in the save/update modal (SaveTimeRangeField), and on load calls getSavedSearchLanding to set live tail or a [now−N, now] window when the URL has no explicit isLive / liveInterval, using history: 'replace' so Back does not re-apply the range. Custom ranges that end in the past are not persisted.

timeQuery gains an optional nowMs for parseRelativeTimeQuery and onTimeRangeSelect supports history: 'replace'. Dashboard savedDateRange reuses the same relative schema shape.

Reviewed by Cursor Bugbot for commit 87b6ad8. 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.

*/
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
Contributor 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
Contributor 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.

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

None could be anchored to changed lines; they are listed below. 2 unchanged from an earlier push (already inline above).

Findings outside the changed lines

  • 🟡 P2 packages/app/src/DBSearchPage.tsx:1530 — A re-submitted preset window no longer matches windowPreset, so "Last 1 days" stops being saveable after 5 minutes → windowPreset is only set in onTimePickerSearch. The normal search submit (onSubmit, line ~1530) calls onSearch(displayedTimeInputValue), which re-parses "Last 1 days" into a new window ending at submit time, but it leaves windowPreset.endMs at the time of the original pick. Example: pick Last 1 days at T0, edit WHERE and press Enter at T0+10m, then click Save at T0+20m. fromPreset is false because the end is 10 minutes past preset.endMs, and isRangeEndingNow is false because the end is 10 minutes old. The modal then says "Custom time ranges aren't saved", and an Update keeps the old stored range. Fix: refresh the preset wherever onSearch(text) runs, e.g. setWindowPreset(getPresetWindow(displayedTimeInputValue, now)) in onSubmit, or record the preset inside useNewTimeQuery.onSearch. Add a unit/E2E case for picking a preset, re-submitting later, then saving.

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

✅ No critical issues found. No P0/P1 ship-blockers. The feature is well-factored (logic extracted into pure, unit-tested helpers), the PATCH null-clear semantics are correctly scoped, and the shared RelativeDateRangeSchema extraction leaves the dashboard savedDateRange contract unchanged. The items below are robustness and coverage recommendations.

🟡 P2 -- recommended

  • packages/common-utils/src/types.ts:1455 -- defaultTimeRange.value has no upper bound, and a crafted large value produces an Invalid Date in getSavedSearchLanding → parseRelativeTimeQuery that throws in dateRangeToString on landing, breaking the saved-search page for everyone the search is shared with.
    • Fix: Add a sane maximum to the schema (e.g. .int().max(...)) and have getSavedSearchLanding return null when the computed range contains an invalid Date.
    • adversarial, api-contract, previous-comments
  • packages/app/src/DBSearchPage.tsx:1428 -- the landing effect detects "URL already chose a time" by reading window.location.search, which lags nuqs' synchronous React state; a user who picks a time before the async savedSearch resolves can have their selection silently overwritten by the stored range via a non-undoable replace.
    • Fix: Derive the explicit-time check from the nuqs time state (isLive/liveInterval/from/to) the component already holds rather than from the DOM URL string.
    • julik-frontend-races, correctness
  • packages/app/src/components/SavedSearches/SaveTimeRangeField.tsx:16 -- the new save-modal copy is unasserted: neither the customRangeIgnored prefix ("Custom time ranges aren't saved. …") nor the null-range "Opens in live tail" wording has any test, while e2e only checks the two "Opens with…"/"Opens in live tail for…" strings.
    • Fix: Add unit coverage for describeOpensWith across its three branches and render SaveTimeRangeField with customRangeIgnored=true to assert the custom-ignored copy.
    • testing
🔵 P3 nitpicks (7)
  • packages/app/src/DBSearchPage.tsx:1419 -- the landing effect re-applies the stored range on any later searchedConfig wipe (re-clicking the same saved search, or the setSearchedConfig({}) clear path), so a user who adjusted only the time loses that adjustment.
    • Fix: Track a per-savedSearchId "landing applied" ref and skip the time-range block (but keep config repopulation) on subsequent empties, if a re-click should not reset the time.
  • packages/app/src/components/SavedSearches/SaveTimeRangeField.tsx:53 -- nowMs: openedAtMs ?? 0 is correct only because the outcome is unread while the modal is closed; a future consumer reading it with openedAtMs == null gets a wrong customRangeIgnored result against epoch 0.
    • Fix: Return a neutral outcome early when openedAtMs == null, or document the "unused while closed" invariant at the fallback.
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:67 -- a sub-second window ending ~now makes toDefaultTimeRange round to value: 0, which the server's positive() schema rejects, failing the entire save (name, config, tags) with a generic error.
    • Fix: Clamp the fallback with Math.max(1, Math.round(durationMs / 1000)), or treat a sub-1s window as customRangeIgnored.
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:79 -- formatRelativeDuration anchors intervalToDuration at epoch 0, so a stored duration ≥31 days renders as "1 month N days" and disagrees with the exact window actually opened (reachable only via a crafted value above the 30-day UI cap).
    • Fix: Format from fixed units (days/hours/minutes) computed from the second count instead of a calendar-anchored interval.
  • packages/app/src/components/SavedSearches/savedSearchTimeRange.ts:63 -- RELATIVE_TIME_OPTIONS entries are read by raw index (option[1], option[2] === true) in several spots, obscuring the [label, duration, relativeSupport?] shape.
    • Fix: Destructure with names after the !== 'divider' guard, or add small optionDuration/optionSupportsLive helpers.
  • packages/app/src/DBSearchPage.tsx:1420 -- the explicit-URL-wins landing branch is exercised only at the pure-function layer; the effect wiring that leaves an already-timed URL untouched has no end-to-end coverage.
    • Fix: Add an e2e step that opens a stored-range search via a URL already carrying isLive/liveInterval and assert the URL time params are preserved.
  • packages/api/src/models/savedSearch.ts:90 -- agent-native parity gap: defaultTimeRange is absent from the MCP tools, external API v2 schema/OpenAPI, and toExternalJSON, so agents can neither set, clear, nor read the new default (explicitly acknowledged as out-of-scope follow-up work).
    • Fix: In the follow-ups, add defaultTimeRange to mcpSaveSavedSearchSchema, savedSearchRequestSchema, and toExternalJSON.

Reviewers (11): correctness, testing, maintainability, project-standards, api-contract, kieran-typescript, julik-frontend-races, adversarial, previous-comments, agent-native, learnings-researcher.

Testing gaps:

  • No test drives an out-of-range stored value (or a malformed GET payload, since the client fetch path does not re-validate) through landing to prove a safe fallback rather than a thrown Invalid Date.
  • No test covers interacting with the time picker while savedSearch is still loading (the window.location.search staleness race).
  • useSaveTimeRangeField and the (isUpdate=true, stored=null) / (isUpdate=false, stored!=null) outcome cells are not asserted in isolation.

Verified addressed from prior review: the Bugbot "frozen preset after 5 minutes" case (now handled via WindowPreset/getPresetWindow), the timeQuery.ts merge-conflict syntax error, the live-tail landing applied-input fix, and the custom-range modal copy.

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
Contributor 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
Contributor 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
Contributor 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
Contributor 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 Dec 1, 2026 8:13pm UTC
hyperdx-storybook Ready Ready Preview Dec 1, 2026 8:13pm 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: 263ca92

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

Comment thread packages/app/src/DBSearchPage.tsx Outdated
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
Contributor 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.

);
// 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

@brandon-pereira

Copy link
Copy Markdown
Member

@Asheesh7298 can you please check the latest AI findings and review if they are realtistic? Primarily the P0's and cursor bugbot findings

Per review (Cursor Bugbot, P1): a picked "Last 1 days" stays frozen until
the next search, so after 5 minutes the save modal treated it as a custom
range and didn't save it. The page now remembers which preset (or stored
range) produced the window on screen, and saves it while that window is
unchanged. A moved window (1h back, brushing) still isn't saved.

Also set the applied time input when landing in live tail, so the picker
doesn't report the input as edited.
@Asheesh7298

Copy link
Copy Markdown
Contributor Author

@brandon-pereira Thanks for flagging these. Went through them:

  • P0 (syntax error in timeQuery.ts): real, left over from my conflict resolution. Already fixed in 80fb4ae, which the bot reviewed after.
  • P1 / Cursor Bugbot (preset not saved after 5 minutes): real, and the same bug. Since picked presets now stay frozen until the next search, my 5-minute "ends now" check treated an aged "Last 1 days" as custom. Fixed in 263ca92: the page remembers which preset (or stored range) produced the window on screen and saves it while that window is unchanged. Moving the window (1h back, brushing) still counts as custom. Verified in the app 6 minutes after picking, and added unit tests.
  • P2 (live tail landing didn't set the applied input): fixed in the same commit.
  • The other P2s (duplicated landing logic, month formatting past ~31 days, no upper bound on the stored value) are small or only reachable through crafted API input, so I left them to keep the PR focused. Happy to address any you want.

filters: z.array(FilterSchema).optional(),
alerts: z.array(AlertSchema).optional(),
defaultTimeRange: RelativeDateRangeSchema.extend({
value: z.number().positive(),

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 — defaultTimeRange.value has no upper bound or integer check, so an API-written value breaks the search page

Change it to z.number().int().positive().max(<a sane cap, e.g. 365 days in seconds>). As written, a PATCH with {type:'relative', value: 1e13} passes validation. On open, getSavedSearchLanding runs parseRelativeTimeQuery(value*1000), which returns an Invalid Date, so onTimeRangeSelect writes from=NaN to the URL. Fractional values such as 0.001 are also accepted.

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

@brandon-pereira brandon-pereira added automerge and removed needs-vouch Author needs a maintainer to vouch for them labels Dec 1, 2026

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

LGTM

@kodiakhq
kodiakhq Bot merged commit 2c0e20f into ClickHouse:main Dec 1, 2026
27 of 30 checks passed
@Asheesh7298

Copy link
Copy Markdown
Contributor Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintain relative date selection for saved/linked searches

2 participants