Skip to content

Commit fc2ff62

Browse files
authored
fix: don't store early exit sessions (#7263)
1 parent b897880 commit fc2ff62

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

codex-rs/core/src/unified_exec/session_manager.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,18 @@ impl UnifiedExecSessionManager {
101101

102102
let text = String::from_utf8_lossy(&collected).to_string();
103103
let output = formatted_truncate_text(&text, TruncationPolicy::Tokens(max_tokens));
104-
let chunk_id = generate_chunk_id();
105104
let has_exited = session.has_exited();
106-
let stored_id = self
107-
.store_session(session, context, &request.command, cwd.clone(), start)
108-
.await;
109-
let exit_code = self
110-
.sessions
111-
.lock()
112-
.await
113-
.get(&stored_id)
114-
.map(|entry| entry.session.exit_code());
115-
// Only include a session_id in the response if the process is still alive.
116-
let session_id = if has_exited { None } else { Some(stored_id) };
117-
105+
let exit_code = session.exit_code();
106+
let chunk_id = generate_chunk_id();
107+
let session_id = if has_exited {
108+
None
109+
} else {
110+
// Only store session if not exited.
111+
let stored_id = self
112+
.store_session(session, context, &request.command, cwd.clone(), start)
113+
.await;
114+
Some(stored_id)
115+
};
118116
let original_token_count = approx_token_count(&text);
119117

120118
let response = UnifiedExecResponse {
@@ -123,7 +121,7 @@ impl UnifiedExecSessionManager {
123121
wall_time,
124122
output,
125123
session_id,
126-
exit_code: exit_code.flatten(),
124+
exit_code,
127125
original_token_count: Some(original_token_count),
128126
session_command: Some(request.command.clone()),
129127
};

codex-rs/core/tests/suite/unified_exec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ async fn unified_exec_emits_begin_for_write_stdin() -> Result<()> {
585585

586586
let open_call_id = "uexec-open-for-begin";
587587
let open_args = json!({
588-
"cmd": "/bin/sh -c echo ready".to_string(),
588+
"cmd": "bash -i".to_string(),
589589
"yield_time_ms": 200,
590590
});
591591

@@ -651,7 +651,7 @@ async fn unified_exec_emits_begin_for_write_stdin() -> Result<()> {
651651
vec![
652652
"/bin/bash".to_string(),
653653
"-lc".to_string(),
654-
"/bin/sh -c echo ready".to_string()
654+
"bash -i".to_string()
655655
]
656656
);
657657
assert_eq!(
@@ -687,7 +687,7 @@ async fn unified_exec_emits_begin_event_for_write_stdin_requests() -> Result<()>
687687

688688
let open_call_id = "uexec-open-session";
689689
let open_args = json!({
690-
"cmd": "/bin/sh -c echo ready".to_string(),
690+
"cmd": "bash -i".to_string(),
691691
"yield_time_ms": 250,
692692
});
693693

@@ -767,7 +767,7 @@ async fn unified_exec_emits_begin_event_for_write_stdin_requests() -> Result<()>
767767
vec![
768768
"/bin/bash".to_string(),
769769
"-lc".to_string(),
770-
"/bin/sh -c echo ready".to_string()
770+
"bash -i".to_string()
771771
]
772772
);
773773
assert!(
@@ -785,7 +785,7 @@ async fn unified_exec_emits_begin_event_for_write_stdin_requests() -> Result<()>
785785
vec![
786786
"/bin/bash".to_string(),
787787
"-lc".to_string(),
788-
"/bin/sh -c echo ready".to_string()
788+
"bash -i".to_string()
789789
]
790790
);
791791
assert!(

0 commit comments

Comments
 (0)