fix: change log_sse_event() so it no longer takes a closure (#4953)
Unlikely fix for https://github.com/openai/codex/issues/4381, but worth a shot given that https://github.com/openai/codex/pull/2103 changed around the same time.
This commit is contained in:
@@ -389,10 +389,12 @@ async fn process_chat_sse<S>(
|
||||
let mut reasoning_text = String::new();
|
||||
|
||||
loop {
|
||||
let sse = match otel_event_manager
|
||||
.log_sse_event(|| timeout(idle_timeout, stream.next()))
|
||||
.await
|
||||
{
|
||||
let start = std::time::Instant::now();
|
||||
let response = timeout(idle_timeout, stream.next()).await;
|
||||
let duration = start.elapsed();
|
||||
otel_event_manager.log_sse_event(&response, duration);
|
||||
|
||||
let sse = match response {
|
||||
Ok(Some(Ok(ev))) => ev,
|
||||
Ok(Some(Err(e))) => {
|
||||
let _ = tx_event
|
||||
|
||||
@@ -649,10 +649,12 @@ async fn process_sse<S>(
|
||||
let mut response_error: Option<CodexErr> = None;
|
||||
|
||||
loop {
|
||||
let sse = match otel_event_manager
|
||||
.log_sse_event(|| timeout(idle_timeout, stream.next()))
|
||||
.await
|
||||
{
|
||||
let start = std::time::Instant::now();
|
||||
let response = timeout(idle_timeout, stream.next()).await;
|
||||
let duration = start.elapsed();
|
||||
otel_event_manager.log_sse_event(&response, duration);
|
||||
|
||||
let sse = match response {
|
||||
Ok(Some(Ok(sse))) => sse,
|
||||
Ok(Some(Err(e))) => {
|
||||
debug!("SSE Error: {e:#}");
|
||||
|
||||
@@ -148,21 +148,15 @@ impl OtelEventManager {
|
||||
response
|
||||
}
|
||||
|
||||
pub async fn log_sse_event<Next, Fut, E>(
|
||||
pub fn log_sse_event<E>(
|
||||
&self,
|
||||
next: Next,
|
||||
) -> Result<Option<Result<StreamEvent, StreamError<E>>>, Elapsed>
|
||||
where
|
||||
Next: FnOnce() -> Fut,
|
||||
Fut: Future<Output = Result<Option<Result<StreamEvent, StreamError<E>>>, Elapsed>>,
|
||||
response: &Result<Option<Result<StreamEvent, StreamError<E>>>, Elapsed>,
|
||||
duration: Duration,
|
||||
) where
|
||||
E: Display,
|
||||
{
|
||||
let start = std::time::Instant::now();
|
||||
let response = next().await;
|
||||
let duration = start.elapsed();
|
||||
|
||||
match response {
|
||||
Ok(Some(Ok(ref sse))) => {
|
||||
Ok(Some(Ok(sse))) => {
|
||||
if sse.data.trim() == "[DONE]" {
|
||||
self.sse_event(&sse.event, duration);
|
||||
} else {
|
||||
@@ -191,7 +185,7 @@ impl OtelEventManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Some(Err(ref error))) => {
|
||||
Ok(Some(Err(error))) => {
|
||||
self.sse_event_failed(None, duration, error);
|
||||
}
|
||||
Ok(None) => {}
|
||||
@@ -199,8 +193,6 @@ impl OtelEventManager {
|
||||
self.sse_event_failed(None, duration, &"idle timeout waiting for SSE");
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
fn sse_event(&self, kind: &str, duration: Duration) {
|
||||
|
||||
Reference in New Issue
Block a user