Skip to content

Commit 36e0307

Browse files
factorydroidechobt
authored andcommitted
fix(cli): only save history on successful run completion
Fixes bounty issue #1531 Previously, cortex run would create a rollout file immediately upon starting a session. If the session failed (e.g. due to an API error), this file would persist, polluting the history with failed attempts. This change ensures that if an error occurs during a new session, the rollout file is cleaned up before exiting.
1 parent b4fd139 commit 36e0307

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

cortex-cli/src/run_cmd.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,21 @@ impl RunCli {
745745
let _ = session_task.await;
746746

747747
if error_occurred {
748+
// If it was a new session and an error occurred, we should probably clean up
749+
// the history entry so it doesn't pollute the logs with failed runs.
750+
if let SessionMode::New { .. } = session_mode {
751+
let rollout_path =
752+
cortex_engine::rollout::get_rollout_path(&config.cortex_home, &session_id);
753+
if rollout_path.exists() {
754+
if let Err(e) = std::fs::remove_file(&rollout_path) {
755+
if self.verbose {
756+
eprintln!("Failed to remove failed session history: {}", e);
757+
}
758+
} else if self.verbose {
759+
eprintln!("Removed failed session history: {}", session_id);
760+
}
761+
}
762+
}
748763
std::process::exit(1);
749764
}
750765

0 commit comments

Comments
 (0)