fix(openai): improve Responses API streaming reliability and diagnostics
Some checks failed
CI / Check (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Formatting (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Release Build (push) Has been cancelled

This commit is contained in:
2026-03-17 18:45:09 +00:00
parent c3d81c1733
commit b131094dfd

View File

@@ -26,7 +26,7 @@ impl OpenAIProvider {
.timeout(std::time::Duration::from_secs(300))
.pool_idle_timeout(std::time::Duration::from_secs(90))
.pool_max_idle_per_host(4)
.tcp_keepalive(std::time::Duration::from_secs(30))
.tcp_keepalive(std::time::Duration::from_secs(15))
.build()?;
Ok(Self {
@@ -441,6 +441,7 @@ impl super::Provider for OpenAIProvider {
self.client
.post(&url)
.header("Authorization", format!("Bearer {}", api_key))
.header("Accept", "text/event-stream")
.json(&body),
)
.map_err(|e| AppError::ProviderError(format!("Failed to create EventSource for Responses API: {}", e)))?;
@@ -527,8 +528,8 @@ impl super::Provider for OpenAIProvider {
}
Ok(_) => {
// If the probe returned 200, but the stream ended, it might be a silent failure or timeout.
tracing::warn!("Responses stream ended prematurely (probe returned 200)");
Err(AppError::ProviderError(format!("Responses stream error (probe returned 200): {}", e)))?;
tracing::warn!("Responses stream ended prematurely (probe returned 200). Error: {}", e);
Err(AppError::ProviderError(format!("Responses stream error (connection closed by server after 200 OK): {}", e)))?;
}
Err(probe_err) => {
tracing::error!("OpenAI Responses Stream Error Probe failed: {}", probe_err);