File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -804,12 +804,22 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
804804 if ( buffer . length > 0 ) {
805805 if ( ( yield * handleDataLine ( buffer ) ) === "terminate" ) return ;
806806 }
807+ const hadPendingToolCallsAtEof = pendingToolCalls . length > 0 ;
807808 yield * flushToolCalls ( ) ;
808809 // Reader EOF. A graceful close shows at least one terminal signal: `[DONE]` (returns above),
809810 // a non-null finish_reason (sawFinish), or a trailing usage chunk (providers emit usage only
810811 // at end-of-generation). If NONE of those were seen, the stream was cut mid-flight — fail
811812 // closed so the bridge emits a classified response.failed rather than a silent truncation.
812813 const sawFinish = finishReason !== undefined ;
814+ if ( ! sawFinish && pendingUsage === undefined && hadPendingToolCallsAtEof ) {
815+ debugProviderDiagnostic ( "openai-chat" , "stream-truncated" , {
816+ finishReason : finishReason ?? null ,
817+ hadUsage : false ,
818+ pendingToolCalls : true ,
819+ } ) ;
820+ yield { type : "error" , message : "upstream stream ended without a terminal signal ([DONE] or finish_reason) - possible truncation" } ;
821+ return ;
822+ }
813823 if ( ! sawFinish && pendingUsage === undefined && ! sawOutput ) {
814824 debugProviderDiagnostic ( "openai-chat" , "stream-truncated" , {
815825 finishReason : finishReason ?? null ,
You can’t perform that action at this time.
0 commit comments