fixing tests

This commit is contained in:
Ahmed Ibrahim
2025-07-15 16:14:43 -07:00
parent 9aa1331c92
commit 0bd53ac078
4 changed files with 46 additions and 11 deletions
+5 -1
View File
@@ -197,6 +197,10 @@ impl ModelClient {
}
}
}
pub fn streaming_enabled(&self) -> bool {
self.config.streaming_enabled
}
}
#[derive(Debug, Deserialize, Serialize)]
@@ -316,7 +320,7 @@ where
// duplicated `output` array embedded in the `response.completed`
// payload. That produced two concrete issues:
// 1. No real‑time streaming – the user only saw output after the
// entire turn had finished, which broke the “typing” UX and
// entire turn had finished, which broke the "typing" UX and
// made long‑running turns look stalled.
// 2. Duplicate `function_call_output` items – both the
// individual *and* the completed array were forwarded, which
+34 -8
View File
@@ -1122,12 +1122,14 @@ async fn try_run_turn(
let mut stream = sess.client.clone().stream(&prompt).await?;
let mut output = Vec::new();
// Patch: buffer for non-streaming mode
let mut assistant_message_buf = String::new();
let streaming_enabled = sess.client.streaming_enabled();
while let Some(event) = stream.next().await {
let event = event?;
match event {
ResponseEvent::Created => {
let mut state = sess.state.lock().unwrap();
// We successfully created a new response and ensured that all pending calls were included so we can clear the pending call ids.
state.pending_call_ids.clear();
}
ResponseEvent::OutputItemDone(item) => {
@@ -1140,23 +1142,37 @@ async fn try_run_turn(
_ => None,
};
if let Some(call_id) = call_id {
// We just got a new call id so we need to make sure to respond to it in the next turn.
let mut state = sess.state.lock().unwrap();
state.pending_call_ids.insert(call_id.clone());
}
// Patch: buffer assistant message text if streaming is disabled
if !streaming_enabled {
if let ResponseItem::Message { role, content } = &item {
if role == "assistant" {
for c in content {
if let ContentItem::OutputText { text } = c {
assistant_message_buf.push_str(text);
}
}
}
}
}
let response = match &item {
ResponseItem::Message { .. } | ResponseItem::Reasoning { .. } => None,
_ => handle_response_item(sess, sub_id, item.clone()).await?,
};
output.push(ProcessedResponseItem { item, response });
}
ResponseEvent::OutputTextDelta(text) => {
let event = Event {
id: sub_id.to_string(),
msg: EventMsg::AgentMessageDelta(AgentMessageEvent { message: text }),
};
sess.tx_event.send(event).await.ok();
if streaming_enabled {
let event = Event {
id: sub_id.to_string(),
msg: EventMsg::AgentMessageDelta(AgentMessageEvent { message: text }),
};
sess.tx_event.send(event).await.ok();
} else {
assistant_message_buf.push_str(&text);
}
}
ResponseEvent::ReasoningSummaryDelta(text) => {
let event = Event {
@@ -1169,6 +1185,16 @@ async fn try_run_turn(
response_id,
token_usage,
} => {
// Patch: emit full message if we buffered deltas
if !streaming_enabled && !assistant_message_buf.is_empty() {
let event = Event {
id: sub_id.to_string(),
msg: EventMsg::AgentMessage(AgentMessageEvent {
message: assistant_message_buf.clone(),
}),
};
sess.tx_event.send(event).await.ok();
}
if let Some(token_usage) = token_usage {
sess.tx_event
.send(Event {
+6 -2
View File
@@ -58,6 +58,8 @@ async fn chat_mode_stream_cli() {
.arg(&provider_override)
.arg("-c")
.arg("model_provider=\"mock\"")
.arg("-c")
.arg("streaming=false")
.arg("-C")
.arg(env!("CARGO_MANIFEST_DIR"))
.arg("hello?");
@@ -71,8 +73,8 @@ async fn chat_mode_stream_cli() {
println!("Stderr:\n{}", String::from_utf8_lossy(&output.stderr));
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(stdout.contains("hi"));
assert_eq!(stdout.matches("hi").count(), 1);
let hi_lines = stdout.lines().filter(|line| line.trim() == "hi").count();
assert_eq!(hi_lines, 1, "Expected exactly one line with 'hi'");
server.verify().await;
}
@@ -104,6 +106,8 @@ async fn responses_api_stream_cli() {
.arg("--")
.arg("exec")
.arg("--skip-git-repo-check")
.arg("-c")
.arg("streaming=false")
.arg("-C")
.arg(env!("CARGO_MANIFEST_DIR"))
.arg("hello?");
+1
View File
@@ -115,6 +115,7 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
};
let config = Config::load_with_cli_overrides(cli_kv_overrides, overrides)?;
println!("[DEBUG] streaming_enabled: {}", config.streaming_enabled);
let mut event_processor = EventProcessor::create_with_ansi(
stdout_with_ansi,
!config.hide_agent_reasoning,