Skip to content

Fix flaky OpenAiSttService SSE test (deterministic progress)#11963

Merged
niksedk merged 1 commit into
mainfrom
fix/flaky-openai-stt-sse-test
Jun 28, 2026
Merged

Fix flaky OpenAiSttService SSE test (deterministic progress)#11963
niksedk merged 1 commit into
mainfrom
fix/flaky-openai-stt-sse-test

Conversation

@niksedk

@niksedk niksedk commented Jun 28, 2026

Copy link
Copy Markdown
Member

TranscribeAsync_SseStream_AccumulatesDeltasAndReportsDoneSegments intermittently failed in the full (parallel) test run while always passing in isolation.

Root cause (test-only)

The service reports deltas/segments synchronously via IProgress<T>.Report while parsing the SSE stream (before TranscribeAsync returns). The test used the BCL Progress<T>, which doesn't run callbacks inline — it posts them to the captured SynchronizationContext, or to the thread pool if none. The test then polled WaitForAsync(..., 2000ms) and asserted on plain List<>s. Under full-suite xUnit parallelism this flaked two ways:

  • posted callbacks delayed past the 2 s deadline → incomplete list → ordered-equality assert fails;
  • with no sync context, callbacks ran on thread-pool threads, racing on the non-thread-safe List<>.

Production Progress<T> (marshaling to the UI thread) is correct — this was purely a test artifact, and only this one test used the pattern.

Fix

Use a tiny synchronous IProgress<T> stub so callbacks run inline on the parse thread; the lists are complete and ordered when TranscribeAsync returns, so assertions run directly and the polling WaitForAsync helper is removed.

Verification

Ran the full UI suite 3×: 481/481 each time (previously intermittently 480/481), and the class 5× in isolation.

🤖 Generated with Claude Code

TranscribeAsync_SseStream_AccumulatesDeltasAndReportsDoneSegments intermittently
failed in the full (parallel) test run while passing in isolation.

The service reports deltas/segments synchronously via IProgress<T>.Report while
parsing the stream, but the test used the BCL Progress<T>, which posts callbacks to
a SynchronizationContext / the thread pool instead of running them inline. Under
full-suite parallelism the posted callbacks either arrived after the 2s WaitForAsync
poll deadline or raced on the non-thread-safe List<T>s - both flaky.

Use a synchronous IProgress<T> stub so callbacks run inline on the parse thread; the
lists are then complete and ordered when TranscribeAsync returns, so the assertions
run directly and the polling WaitForAsync helper is removed. Test-only change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@niksedk niksedk merged commit 9ececef into main Jun 28, 2026
1 of 3 checks passed
@niksedk niksedk deleted the fix/flaky-openai-stt-sse-test branch June 28, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant