fix(openaimodel): preserve refusals and completed stream content #1467
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.55) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 571 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.380
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1467"
general
weight: 0.35
ktsoator
Link to Issue or Description of Change
Closes #1466. Closes #1476.
The OpenAI stream translator ignores
response.refusal.delta. A refusal-onlyresponse loses incremental delivery, and a refusal following reasoning can be
omitted entirely because the non-empty aggregator suppresses terminal-response
fallback. The resulting thought-only turn may cause up to 10 model calls without
surfacing an answer.
Translate non-empty refusal deltas into ordinary, non-thought text, matching the
blocking representation. Explicitly classify
response.refusal.doneas aninformational event; this documents its existing behavior and avoids emitting
the complete refusal again after its deltas.
When
response.completedcontains non-thought text or a function call, useits content for the final response only if it retains the visible text and
function calls already collected from the stream. Otherwise, keep the aggregate.
When replacement is allowed, final reasoning follows the completed response;
thoughts already delivered as partials are not added back.
This does not merge content from both sources. For example, if visible text
streams first and the completed response contains only a tool call, the text
is retained and the call is not recovered. Calls whose streamed ID fell back
to
item_idcan also prevent recovery when the completed response uses adifferent
call_id. Both remain limitations of the current approach.Preserve aggregated content when the completed payload is empty or cannot be
converted, and when the stream ends without a terminal event or its first
terminal event is
response.incomplete. With no aggregated response, theexisting terminal fallback and conversion errors are unchanged. Final metadata
continues through the existing finalization path.
The partial-delta case was reproduced with synthetic SSE events. This validates
the adapter's behavior for that input; it does not establish how often a live
provider emits such a stream.
Testing Plan
argument and ID differences, and one-to-one call matching. Each of the five
mutations identified in the review makes a test fail.
thoughts omitted by the completed response, and recovery of completed text
after a function call with
nullor{}arguments. Thenullcase failedbefore argument normalization and passes afterward.
including partial deltas with and without
refusal.done, and partial refusalafter reasoning. They also verify that incremental text contains only the
deltas actually received.
unsupported terminal content, incomplete responses, and first-terminal-event
precedence.
TestModel_GenerateStream_TerminalOnlyMessageContentpreserves the original#1476 reproduction: reasoning is streamed, while the visible answer appears
only in
response.completed. It fails against the pre-fix implementation andpasses with the completed-content fix, comparing final content with blocking.
responses that omit a streamed function call, and function calls that appear
only in
response.completed.response.output_item.addedpreviously omitted its
type, andresponse.completedcontained a messageinstead of the function call from the stream. Both events now describe the
same call.
Before the terminal-content fix, all three new partial-refusal cases failed:
They pass after the fix. Local validation on Go 1.26.6:
Tests use a local HTTP server and synthetic SSE; no live model calls are made.
Checklist