fix(agents): keep a Codex command that moved to the background from showing as failed (#7724)

A command Codex leaves running when its turn completes was still open at the turn's end, so the conversation settled its card as failed while it kept running. When a turn completes, the adapter now reports its still-open commands as done; the command's own completion reports how it ended. Interrupted and failed turns are unchanged.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-03 15:18:12 +08:00
1 джерело f09d51bd49
коміт 9d8fdab75e
2 files changed
+41

No files matched your search

+13
Переглянути файл
@@ -1415,6 +1415,19 @@ impl CodexShim {
t.turn = None;
}
t.completed = Some(id.to_owned());
// A command still open when its turn completed goes on in the background (a
// background terminal): its call returned, so it didn't fail with the turn. Its
// own completion reports how it ended. Sent before the prompt's answer settles the
// turn.
if completed {
let commands = t.items.values().filter(|i| i["type"] == "commandExecution");
for id in commands.filter_map(|i| i["id"].as_str()) {
self.emit(
thread,
json!({ "sessionUpdate": "tool_call_update", "toolCallId": id, "status": "completed" }),
);
}
}
t.items.clear();
t.last_chunk = None;
let error = t.error.take();
+28
Переглянути файл
@@ -2369,3 +2369,31 @@ async fn a_codex_without_background_terminals_reports_none() {
acp.kill();
native.kill();
}
#[tokio::test(flavor = "multi_thread")]
async fn a_command_left_running_by_a_completed_turn_is_not_a_failure() {
for (status, settled) in [("completed", true), ("interrupted", false)] {
let server = TerminalServer::new(Vec::new(), true);
let client = Arc::new(Client::default());
let (native, acp) = terminal_session(server, client.clone()).await;
let item = json!({"type": "commandExecution", "id": "call_1", "command": "/bin/zsh -lc 'sleep 240'",
"cwd": "/w", "status": "inProgress", "commandActions": []});
native.notify("item/started", json!({"threadId": "s", "turnId": "t1", "item": item})).unwrap();
native.notify("turn/completed", json!({"threadId": "s", "turn": {"id": "t1", "status": status}})).unwrap();
until("the command card", || client.of("s").iter().any(|u| u["sessionUpdate"] == "tool_call")).await;
tokio::time::sleep(Duration::from_millis(50)).await;
let updates: Vec<Value> = client
.of("s")
.into_iter()
.filter(|u| u["sessionUpdate"] == "tool_call_update" && u["toolCallId"] == "call_1")
.collect();
let expected = if settled {
vec![json!({"sessionUpdate": "tool_call_update", "toolCallId": "call_1", "status": "completed"})]
} else {
Vec::new()
};
assert_eq!(updates, expected, "turn {status}");
acp.kill();
native.kill();
}
}