Opus finding
types.ts comment claims 'thinking chunks MUST arrive before text chunks' but Anthropic provider does not enforce this invariant
- src/providers/types.ts:15-21
- src/providers/anthropic.ts:99-113
The invariant comment in types.ts is asserted as MUST, but the Anthropic implementation forwards deltas in whatever order they arrive from the SDK with no buffering or ordering enforcement. The OpenAI implementation likewise just forwards reasoning_content and content as they appear. If a downstream consumer relies on the stated invariant (UI rendering, for example), interleaved deltas will violate it silently. Either the invariant needs to be enforced (buffer text until thinking ends) or the comment is deceptive and should be softened.
Recommendation
Either buffer text deltas until first text_delta marks transition, or rewrite comment to 'Thinking and text deltas may interleave; consumers should accumulate.'