发布

  • [OPIK-5733] Fix Online Scoring for traces completed via PATCH (#6141)

    frostbyte_neo 发布于 2026-04-09 14:29:48 +00:00

    • [OPIK-5733] [BE] fix: score traces completed via PATCH (TracesUpdated)

    The original OPIK-5605 fix filters out partial traces (endTime == null)
    in OnlineScoringSampler.onTracesCreated(). This works when the SDK sends
    two POSTs (via @track decorator), but breaks when using the manual
    trace.end() API which sends POST then PATCH. In the PATCH path, the
    completion arrives as a TracesUpdated event, which the sampler did not
    listen to — so the trace was never scored.

    Fix: enrich TracesUpdated with a hasEndTimeUpdate flag set when the PATCH
    includes endTime, and add a @Subscribe handler in OnlineScoringSampler
    that fetches the completed traces and delegates to scoring. Tag updates,
    metadata edits, etc. (no endTime in the PATCH) are ignored.

    • [OPIK-5733] fix: add missing startTime in test, fix import ordering
    • Add startTime to trace in testTracesUpdatedWithEndTimeTriggersScoring
      (required by @NotNull validation, was causing 422)
    • Fix Spotless import ordering for CollectionUtils
    • [OPIK-5733] fix: provide reactive context for getByIds, rename tests
    • Add contextWrite with WORKSPACE_ID and USER_NAME when calling
      traceService.getByIds() from onTracesUpdated — the DAO uses
      Mono.deferContextual which requires RequestContext in the reactive
      context (was causing NoSuchElementException: Context is empty)
    • Rename test methods to scenario-based naming convention
    • [OPIK-5733] address PR review: decouple event from business logic
    • Replace boolean hasEndTimeUpdate with TraceUpdate in TracesUpdated
      event — keeps the event neutral, consumers decide what to check
    • Remove overloaded constructor, force all callers to provide TraceUpdate
    • Move isEmpty guard into sampleAndScore for self-defensive method
    • Fix log format: move printed values to end of sentences for grep
    • Tests: use podam for trace generation, extract MOCK_AI_RESPONSE
      constant, assert expected score values, use TestUtils#waitForMillis
    • Update ExperimentAggregateEventListenerTest for new constructor
    • [OPIK-5733] add comment about potential ClickHouse replication race condition

    • [OPIK-5733] fix: use workspaceId/userName params instead of stale tracesBatch ref from merge

    下载附件