Skip to content

[OPIK-5619] [BE] fix: add workspace-wide fallback header for dataset item streaming#6060

Merged
thiagohora merged 6 commits intomainfrom
thiaghora/OPIK-5619-be-workspace-fallback-dataset-item-streaming
Apr 2, 2026
Merged

[OPIK-5619] [BE] fix: add workspace-wide fallback header for dataset item streaming#6060
thiagohora merged 6 commits intomainfrom
thiaghora/OPIK-5619-be-workspace-fallback-dataset-item-streaming

Conversation

@thiagohora
Copy link
Copy Markdown
Contributor

Details

When old SDK versions send a wrong project_name (e.g. "Default Project") to the streamDatasetItems endpoint, the backend should still find the dataset via workspace-wide fallback and emit the X-Opik-Deprecation header — the same deprecation signal already emitted on non-streaming endpoints.

Changes:

  • Added blocking resolveDatasetByName(DatasetIdentifier) to DatasetService (safe to call on the HTTP thread) that sets the workspace fallback message on the request context when the project name was given but couldn't be resolved.
  • Renamed the existing reactive version to resolveDatasetByNameAsync and cleaned it up to read workspaceId/visibility from reactor context via Mono.deferContextual (avoids Guice OutOfScopeException on boundedElastic threads).
  • streamDatasetItems in DatasetsResource now (1) eagerly captures RequestContext before any lambdas, (2) calls the blocking resolveDatasetByName to trigger the fallback check, (3) injects HttpServletResponse to set the X-Opik-Deprecation header synchronously before returning the ChunkedOutput.
  • Added AsyncUtils.setRequestContext(Context, RequestContext) overload that accepts an already-resolved RequestContext object, so contextWrite can safely use values captured on the HTTP thread without calling the Guice-scoped Provider inside a reactive lambda.
  • Updated DatasetItemService.getItems signature (removed the redundant Visibility parameter — now read from reactor context inside the service).
  • Added integration test regression covering the new X-Opik-Deprecation header on streaming when a non-existing project_name is provided.

Change checklist

  • User facing
  • Documentation update

Issues

  • Resolves OPIK-5619

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): claude-sonnet-4-6
  • Scope: full implementation
  • Human verification: code review + manual testing

Testing

cd apps/opik-backend
mvn test -Dtest="DatasetsResourceTest#StreamDatasetItems"
mvn test -Dtest="DatasetsResourceIntegrationTest"

Scenarios validated:

  • Streaming with valid project_name works as before (15 existing StreamDatasetItems tests pass)
  • Streaming with non-existing project_name returns items (workspace-wide fallback) + emits X-Opik-Deprecation header (new test)
  • Streaming error handling (timeout) works correctly (integration test)

Documentation

N/A — internal fallback behavior, no user-facing API surface changes.

…reaming

When an old SDK sends a wrong project_name (e.g. "Default Project") to
the stream-items endpoint, the backend now finds the dataset via workspace-wide
search and returns the correct items. The X-Opik-Deprecation header is also
emitted on streaming responses (ChunkedOutput) when the fallback is triggered.

Key changes:
- DatasetService: add blocking resolveDatasetByName that sets the fallback
  header on the HTTP request thread; rename reactive variant to
  resolveDatasetByNameAsync and remove the invalid requestContext.get() call
  inside Mono.fromCallable
- DatasetItemService: updated streaming getItems to use resolveDatasetByNameAsync;
  interface no longer carries Visibility (read from reactor context instead)
- DatasetsResource.streamDatasetItems: call blocking resolveDatasetByName first
  (sets fallback message), then inject HttpServletResponse to emit
  X-Opik-Deprecation header before ChunkedOutput is committed; capture
  RequestContext eagerly to avoid Guice OutOfScopeException inside contextWrite
- AsyncUtils: add setRequestContext(Context, RequestContext) overload that
  accepts an already-resolved RequestContext object
- Tests: add streamDataItems__whenNonExistingProjectName__thenReturnDeprecationHeader
  to verify the header is sent on streaming responses
@github-actions github-actions bot added java Pull requests that update Java code Backend tests Including test files, or tests related like configuration. labels Apr 2, 2026
@thiagohora thiagohora marked this pull request as ready for review April 2, 2026 12:23
@thiagohora thiagohora requested a review from a team as a code owner April 2, 2026 12:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Backend Tests - Integration Group 15

 25 files  ±0   25 suites  ±0   4m 44s ⏱️ -6s
243 tests +1  242 ✅ ±0  0 💤 ±0  0 ❌ ±0  1 🔥 +1 
242 runs  ±0  242 ✅ ±0  0 💤 ±0  0 ❌ ±0 

For more details on these errors, see this check.

Results for commit e9fec2f. ± Comparison against base commit 7511a9a.

Copy link
Copy Markdown
Contributor

@ldaugusto ldaugusto left a comment

Choose a reason for hiding this comment

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

Minor things to tackle

@thiagohora thiagohora requested a review from ldaugusto April 2, 2026 12:44
Copy link
Copy Markdown
Contributor

@ldaugusto ldaugusto left a comment

Choose a reason for hiding this comment

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

LGTM

@thiagohora thiagohora merged commit 183e30e into main Apr 2, 2026
21 of 64 checks passed
@thiagohora thiagohora deleted the thiaghora/OPIK-5619-be-workspace-fallback-dataset-item-streaming branch April 2, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend java Pull requests that update Java code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants