mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Print TUI session info on fatal exits (#27417)
## Summary TUI exits printed the resume/session summary only after checking the exit reason. On fatal exits, both CLI wrappers wrote the error and called `process::exit(1)` immediately, so an active session that ended on a fatal error could skip the session information entirely. This change prints the normal exit summary before returning the fatal nonzero exit code. If a fatal exit has a known thread id but no resumable rollout hint, it prints `Session ID: <id>` instead of staying silent. It also flushes stdout before `process::exit(1)` so the summary line is not lost during process teardown. ## Implementation - Apply the fatal-exit ordering fix in both `codex` and standalone `codex-tui`. - Keep normal user-requested exit behavior unchanged. - Preserve the existing resume hint when a rollout is resumable, and use the raw thread id only as a fatal-exit fallback.
This commit is contained in:
1 parent
df9dd22248
commit
9d88e299a7
5 files changed
+92
-36
No files matched your search
+17
-10
@@ -397,7 +397,7 @@ const COMMIT_ANIMATION_TICK: Duration = tui::TARGET_FRAME_INTERVAL;
|
||||
pub struct AppExitInfo {
|
||||
pub token_usage: TokenUsage,
|
||||
pub thread_id: Option<ThreadId>,
|
||||
pub thread_name: Option<String>,
|
||||
pub resume_hint: Option<String>,
|
||||
pub update_action: Option<UpdateAction>,
|
||||
pub exit_reason: ExitReason,
|
||||
}
|
||||
@@ -407,7 +407,7 @@ impl AppExitInfo {
|
||||
Self {
|
||||
token_usage: TokenUsage::default(),
|
||||
thread_id: None,
|
||||
thread_name: None,
|
||||
resume_hint: None,
|
||||
update_action: None,
|
||||
exit_reason: ExitReason::Fatal(message.into()),
|
||||
}
|
||||
@@ -433,10 +433,7 @@ fn session_summary(
|
||||
rollout_path: Option<&Path>,
|
||||
) -> Option<SessionSummary> {
|
||||
let usage_line = (!token_usage.is_zero()).then(|| token_usage.to_string());
|
||||
let resumable_thread = resumable_thread(thread_id, thread_name, rollout_path);
|
||||
let resume_hint = resumable_thread.as_ref().and_then(|thread| {
|
||||
codex_utils_cli::resume_hint(thread.thread_name.as_deref(), Some(thread.thread_id))
|
||||
});
|
||||
let resume_hint = resume_hint_for_resumable_thread(thread_id, thread_name, rollout_path);
|
||||
|
||||
if usage_line.is_none() && resume_hint.is_none() {
|
||||
return None;
|
||||
@@ -467,6 +464,15 @@ fn resumable_thread(
|
||||
})
|
||||
}
|
||||
|
||||
fn resume_hint_for_resumable_thread(
|
||||
thread_id: Option<ThreadId>,
|
||||
thread_name: Option<String>,
|
||||
rollout_path: Option<&Path>,
|
||||
) -> Option<String> {
|
||||
let thread = resumable_thread(thread_id, thread_name, rollout_path)?;
|
||||
codex_utils_cli::resume_hint(thread.thread_name.as_deref(), Some(thread.thread_id))
|
||||
}
|
||||
|
||||
fn rollout_path_is_resumable(rollout_path: &Path) -> bool {
|
||||
std::fs::metadata(rollout_path).is_ok_and(|metadata| metadata.is_file() && metadata.len() > 0)
|
||||
}
|
||||
@@ -1216,15 +1222,16 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
let resumable_thread = resumable_thread(
|
||||
app.chat_widget.thread_id(),
|
||||
let thread_id = app.chat_widget.thread_id().or(app.primary_thread_id);
|
||||
let resume_hint = resume_hint_for_resumable_thread(
|
||||
thread_id,
|
||||
app.chat_widget.thread_name(),
|
||||
app.chat_widget.rollout_path().as_deref(),
|
||||
);
|
||||
Ok(AppExitInfo {
|
||||
token_usage: app.token_usage(),
|
||||
thread_id: resumable_thread.as_ref().map(|thread| thread.thread_id),
|
||||
thread_name: resumable_thread.and_then(|thread| thread.thread_name),
|
||||
thread_id,
|
||||
resume_hint,
|
||||
update_action: app.pending_update_action,
|
||||
exit_reason,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user