Skip to content

[OPIK-5206] [BE] feat: consume EM opikVersion for workspace version determination#5964

Merged
andrescrz merged 2 commits intomainfrom
andrescrz/OPIK-5206-em-workspace-version
Mar 30, 2026
Merged

[OPIK-5206] [BE] feat: consume EM opikVersion for workspace version determination#5964
andrescrz merged 2 commits intomainfrom
andrescrz/OPIK-5206-em-workspace-version

Conversation

@andrescrz
Copy link
Copy Markdown
Member

@andrescrz andrescrz commented Mar 30, 2026

Details

Consume the opikVersion field from the EM auth response and propagate it through the auth cache and RequestContext to the workspace version service. This implements the auth one-way V2 gate: when EM indicates version_2, always return V2 regardless of entity state (prevents V2→V1 demotion). Defensive design — gracefully degrades when EM doesn't provide the field (null falls through to entity check).

  • Auth pipeline: added opikVersion to AuthResponse, ValidatedAuthCredentials, AuthCredentials, Redis cache, and RequestContext
  • Workspace version: getWorkspaceVersion receives authSuggestedVersion as parameter; computeVersion checks for one-way V2 gate; auth-aware fallback on DB failure
  • Refactored CacheService.cache() to accept AuthCredentials record instead of individual args
  • RemoteAuthService: factory methods for clean mapping, setCredentialIntoContext encapsulates all context writes
  • OpikVersion.findByValue now case-insensitive (defensive hardening)

Change checklist

  • User facing
  • Documentation update

Issues

  • OPIK-5206

AI-WATERMARK

AI-WATERMARK: yes

  • If yes:
    • Tools: Claude Code
    • Model(s): Claude Opus 4.6
    • Scope: Implementation, test coverage, PR description
    • Human verification: Yes — iterative code review, manual test runs, design decisions

Testing

Commands run:

  • mvn test -pl . -Dtest="RemoteAuthServiceTest" — 17 tests, all pass
  • mvn test -pl . -Dtest="AuthCredentialsCacheServiceTest" — 12 tests, all pass
  • mvn test -pl . -Dtest="RemoteAuthServiceTest,AuthCredentialsCacheServiceTest,AuthServiceImplTest" — 32 tests, all pass

Scenarios validated:

  • Cache round-trip: opikVersion null/V1/V2 stored and retrieved from Redis with full equality assertion
  • API key auth: opikVersion propagation from EM response to RequestContext (null, V1, V2 × header/query param workspace)
  • Session token auth: same propagation + default workspace rejection + missing workspace + error responses (401, 403, 500)
  • Cache miss/hit integration: toAuthCredentials()from(AuthCredentials) preserves all fields via mock CacheService with ArgumentCaptor
  • E2E workspace version: auth one-way V2 gate (auth=V2 + V1 entities → V2), auth=V1 not a gate, auth=null defensive
  • Regression: existing feature flag, entity check, cache TTL, and unauth tests unchanged and passing

Documentation

No documentation updates required — internal API change, no user-facing API changes.

@andrescrz andrescrz requested a review from a team as a code owner March 30, 2026 14:12
@github-actions github-actions bot added java Pull requests that update Java code Backend tests Including test files, or tests related like configuration. labels Mar 30, 2026
@andrescrz andrescrz force-pushed the andrescrz/OPIK-5206-em-workspace-version branch from bd67c06 to d307bbc Compare March 30, 2026 14:13
@comet-ml comet-ml deleted a comment from github-actions bot Mar 30, 2026
@comet-ml comet-ml deleted a comment from github-actions bot Mar 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

TS SDK E2E Tests - Node 22

275 tests  ±0   273 ✅ ±0   16m 0s ⏱️ - 1m 35s
 32 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 50adc38. ± Comparison against base commit acc2fb4.

♻️ This comment has been updated with latest results.

…etermination

Implement the auth one-way V2 gate and fallback using the opikVersion
field from the EM auth response (OPIK-5170).
Change @JsonCreator fromValue to return null instead of throwing
IllegalArgumentException for unknown values. This prevents auth
failures when EM is deployed with a newer version value before the
backend is updated.

The system already handles null opikVersion defensively: auth gate is
skipped, entity check runs, fallback returns VERSION_1.
@andrescrz andrescrz force-pushed the andrescrz/OPIK-5206-em-workspace-version branch from d307bbc to 50adc38 Compare March 30, 2026 14:52
Copy link
Copy Markdown
Contributor

@thiagohora thiagohora left a comment

Choose a reason for hiding this comment

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

Well done. Left two low-severity comments, but they are not blockers.

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.

[Low] No test covers a cache hit where the Redis map is missing the opikVersion key entirely (i.e. entries written before this PR). m.get(OPIK_VERSION_KEY) returns null in that case, which findByValue handles correctly — but a regression test would lock this behavior in and prevent silent breakage if the read path changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Already covered — testCacheAndRetrieveOpikVersion(null) tests the opikVersion=null round-trip, which exercises the same findByValue → Optional.empty() → null code path. The only difference with a pre-PR entry is the input to findByValue (null vs ""), but both are non-matching values that produce the same result. Testing the missing-key case specifically would require direct Redis writes (not black box).

🤖 Reply posted via /address-github-pr-comments

@andrescrz andrescrz merged commit 74de3ac into main Mar 30, 2026
76 checks passed
@andrescrz andrescrz deleted the andrescrz/OPIK-5206-em-workspace-version branch March 30, 2026 15:35
andrescrz added a commit that referenced this pull request Mar 30, 2026
- Add comments explaining the serialize→Map→override→re-serialize
  pattern in testAuthSuccessful/testSessionAuthSuccessful (bypasses
  @jsonvalue to inject raw strings like "VERSION_1", "version_unknown")
andrescrz added a commit that referenced this pull request Mar 31, 2026
…rsion (#5975)

* [OPIK-5206] [BE] feat: add V1 entity check for alerts in workspace version

Add alerts to the workspace version V1 entity check. Alerts without
project_id (workspace-level) now signal VERSION_1. Project-scoped
alerts do not trigger V1.

* test(auth): address PR #5964 review feedback from thiagohora

- Add comments explaining the serialize→Map→override→re-serialize
  pattern in testAuthSuccessful/testSessionAuthSuccessful (bypasses
  @jsonvalue to inject raw strings like "VERSION_1", "version_unknown")
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