Sitelet https://github.com/comet-ml/opik/pull/7960
Skip to content

[NA] [SDK] fix: respect search wait timeouts - #7960

Draft
jstar0 wants to merge 1 commit into
comet-ml:mainfrom
jstar0:jstar0/NA-search-wait-timeout
Draft

[NA] [SDK] fix: respect search wait timeouts#7960
jstar0 wants to merge 1 commit into
comet-ml:mainfrom
jstar0:jstar0/NA-search-wait-timeout

Conversation

@jstar0

@jstar0 jstar0 commented Aug 21, 2026

Copy link
Copy Markdown

Details

searchAndWaitForDone currently sleeps for the full polling interval even when less time remains in the caller-provided timeout. This can make a short timeout wait for several seconds longer than requested. The polling sleep is now capped to the remaining timeout budget, with a fake-timer regression covering a poll interval longer than the timeout.

Change checklist

  • User facing
  • Documentation update

Issues

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: AI coding assistant
  • Model(s): not disclosed
  • Scope: implementation and regression-test drafting
  • Human verification: contributor reviewed the final diff and ran the repository's TypeScript unit, lint, formatting, and diff checks.

Testing

  • ./node_modules/.bin/vitest run tests/unit/utils/searchHelpers.test.ts — 28 passed
  • ./node_modules/.bin/eslint src/opik/utils/searchHelpers.ts tests/unit/utils/searchHelpers.test.ts — passed
  • ./node_modules/.bin/prettier --check src/opik/utils/searchHelpers.ts tests/unit/utils/searchHelpers.test.ts — passed
  • git diff --check origin/main...HEAD — passed
  • The full TypeScript SDK test suite was not run; this PR is limited to the polling helper and its focused unit coverage.

Documentation

No documentation changes are needed for this internal timeout-boundary fix.

@github-actions github-actions Bot added tests Including test files, or tests related like configuration. typescript *.ts *.tsx TypeScript SDK labels Aug 21, 2026
Comment on lines 26 to 30
const traces = await parseNdjsonStreamToArray<OpikApi.TracePublic>(
streamResponse,
serialization.TracePublic,
maxResults
maxResults,
);

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.

Truncation and stream resource leak

parseNdjsonStreamToArray stops after maxResults, so client.searchTraces() truncates backend-overdelivered batches allowed by the integration contract — should we parse the complete response instead? When stopping early, it only calls reader.releaseLock() rather than cancelling the ReadableStream, so remaining trace/thread/span bodies can continue consuming connection resources — should we call await reader.cancel() with lock release in a finally block?

Severity web_search

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
`sdks/typescript/src/opik/utils/searchHelpers.ts` around lines 26-30, update
`searchTracesWithFilters` and the analogous thread/span search helpers so they do not
pass `maxResults` as a client-side cap to `parseNdjsonStreamToArray`; the backend may
legitimately return more results than requested. If an intentional parser limit must
remain, modify the early-return path to `await reader.cancel()` and release the lock in
a `finally` block so remaining HTTP stream resources are not consumed.

Comment on lines +102 to 103
oqlFactory: (filterString: string) => OpikQueryLanguage,
): TFilter[] | 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.

Misleading parser documentation omits spans

The generic parser comment still says it supports “both traces and threads,” even though oqlFactory is used by forTraces, forThreads, and forSpans to select the resource-specific OQL schema, so it can mislead contributors — should we update it to mention traces, threads, spans, and oqlFactory’s role?

Severity

Want Baz to fix this for you? Activate Fixer You can also update your AI coding guidelines based on this comment by apply pr to [branch name]

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
`sdks/typescript/src/opik/utils/searchHelpers.ts` around lines 102-103, update the
`parseFilterStringGeneric` documentation to state that it supports traces, threads, and
spans. Document that `oqlFactory` selects the resource-specific OQL schema/parser used
to interpret the filter string, so contributors understand how to extend or reuse this
helper.

maxResults: number,
truncate: boolean,
exclude?: OpikApi.SpanSearchStreamRequestPublicExcludeItem[]
exclude?: OpikApi.SpanSearchStreamRequestPublicExcludeItem[],

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.

Generated enum blocks forward compatibility

The public searchSpansWithFilters helper types exclude as OpikApi.SpanSearchStreamRequestPublicExcludeItem[], so callers cannot pass forward-compatible backend values — should we use exclude?: string[] for both searchSpansWithFilters and searchTracesWithFilters?

Severity

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
sdks/typescript/src/opik/utils/searchHelpers.ts around lines 176 and 16, update the
`exclude` parameters of `searchSpansWithFilters` and `searchTracesWithFilters` from the
generated exclusion-item array types to `string[]`. Preserve forwarding these values to
the API request while decoupling the public helpers from the current generated enum so
future backend exclusion values are accepted.

@jstar0

jstar0 commented Aug 21, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I checked each Baz finding against the diff and am keeping this PR scoped to the reported timeout-boundary bug:

  • The parseNdjsonStreamToArray result cap/stream cancellation behavior predates this PR and is shared by the trace, thread, and span helpers; changing it would alter existing search semantics and resource-lifecycle behavior beyond the timeout fix.
  • The generic parser documentation wording is also pre-existing and can be corrected independently without affecting this regression.
  • Widening generated exclusion-item types to string[] is a public API/forward-compatibility decision unrelated to polling timeouts.

I am leaving these as separate follow-up work rather than bundling unrelated behavior changes into this focused PR.

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

Labels

baz: pending 🟢 size/S tests Including test files, or tests related like configuration. TypeScript SDK typescript *.ts *.tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TypeScript SDK] search polling can exceed the requested timeout

1 participant