Skip to content

fix(fe): pass time range to trace list query in ThreadDetailsPanel#6541

Open
zhoufengen wants to merge 1 commit intocomet-ml:mainfrom
zhoufengen:fix/thread-details-panel-time-range
Open

fix(fe): pass time range to trace list query in ThreadDetailsPanel#6541
zhoufengen wants to merge 1 commit intocomet-ml:mainfrom
zhoufengen:fix/thread-details-panel-time-range

Conversation

@zhoufengen
Copy link
Copy Markdown

Summary

Fixes #6148

ThreadDetailsPanel queries traces by thread_id without passing fromTime/toTime parameters, preventing ClickHouse from using index pruning on the time-based UUID id column. On large datasets (~4.7M traces), this causes query timeouts (HTTP 500).

Changes

  • Pass thread.start_time and thread.end_time as fromTime/toTime to the useTracesList hook call in ThreadDetailsPanel
  • Defer the traces query until thread data is loaded (enabled: Boolean(threadId) && !isThreadPending) to ensure time range is available

Testing

  • Verified that useTracesList hook already supports fromTime and toTime parameters
  • The Thread type includes start_time and end_time fields from the API
  • The change is minimal and scoped to the query parameters only

Related Issues

Fixes #6148 — ThreadDetailsPanel does not pass time range to trace list query, causing slow loading


This PR was authored with AI assistance. All changes have been reviewed for correctness.

Fixes comet-ml#6148

ThreadDetailsPanel queried traces by thread_id without passing
fromTime/toTime parameters, preventing ClickHouse from using index
pruning on the time-based UUID id column. On large datasets this caused
query timeouts (HTTP 500).

Use the thread start_time and end_time (already available from
useThreadById) as time bounds for the useTracesList call. Also defer
the traces query until the thread data is loaded to ensure the time
range is available.
@zhoufengen zhoufengen requested a review from a team as a code owner April 29, 2026 10:29
Comment on lines 197 to 199
{
enabled: Boolean(threadId),
enabled: Boolean(threadId) && !isThreadPending,
},
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.

enabled only checks !isThreadPending, so when useThreadById errors thread is still undefined and useTracesList runs with just thread_id; should we gate on a successful thread load (e.g. enabled: Boolean(thread) / isSuccess)?

Finding type: Logical Bugs | Severity: 🟠 Medium


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

Before applying, verify this suggestion against the current code. In
apps/opik-frontend/src/v2/pages-shared/traces/ThreadDetailsPanel/ThreadDetailsPanel.tsx
around lines 197-199, the `useTracesList` query `enabled` flag only checks
`Boolean(threadId)` and `!isThreadPending`. Refactor this to gate on a successful thread
load instead (e.g., use the `useThreadById` status/isSuccess, or require
`Boolean(thread)`), so that on error (when `thread` is undefined) the traces query does
not run without the intended `fromTime`/`toTime` time-range constraints. Ensure the
`enabled` condition and any dependent `fromTime`/`toTime` props are only applied when
the thread data is actually present.

@aadereiko
Copy link
Copy Markdown
Collaborator

@zhoufengen to review this PR, I would like to ask for a video showing you changes and also for checkint the comments from Baz

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ThreadDetailsPanel does not pass time range to trace list query, causing slow loading

2 participants