Suppress errors for requested session stops

This commit is contained in:
iris committed 2026-09-12 20:49:38 -04:00
1 parent 76895bc644
commit 559e6c9226
5 files changed
+101 -18

No files matched your search

+49
View File
@@ -1652,6 +1652,7 @@ impl SessionManager {
cwd.display(),
record.pid
);
process::mark_stopping(&dir)?;
process::stop(&record, process::STOP_GRACE);
}
Ok(())
@@ -1714,6 +1715,7 @@ impl SessionManager {
effort.unwrap_or("default"),
record.pid
);
process::mark_stopping(&dir)?;
process::stop(&record, process::STOP_GRACE);
}
Ok(())
@@ -1761,6 +1763,7 @@ impl SessionManager {
}
};
tracing::info!("stopping session {id} (pid {})", record.pid);
process::mark_stopping(&self.data_dir.join(id))?;
process::stop(&record, process::STOP_GRACE);
Ok(())
}
@@ -4329,6 +4332,52 @@ mod tests {
));
}
/// Stderr is a log of the process's whole lifetime, not necessarily why it
/// ended. A requested Stop used to paste its oldest surviving diagnostics
/// into the transcript as a fresh failure -- complete with terminal escape
/// codes -- even though the process ended only because the person asked.
#[tokio::test]
async fn stopping_a_session_does_not_report_old_stderr_as_a_failure() {
let dir = tempfile::tempdir().expect("tempdir");
let config_path = dir.path().join("config.ron");
let data_dir = dir.path().join("sessions");
let provider = seed_stand_in_cli(&config_path, dir.path());
let manager = SessionManager::new(config_path, data_dir.clone(), data_dir.join("models"))
.expect("manager");
let info = manager
.spawn_session(stand_in_spec(&provider))
.expect("spawn");
let mut rx = manager.session(&info.id).expect("live").subscribe();
let session_dir = data_dir.join(&info.id);
std::fs::write(
session_dir.join("stderr.log"),
"\u{1b}[31mERROR\u{1b}[0m an old tool diagnostic\n",
)
.expect("seed stderr");
manager.stop_session(&info.id).expect("stop");
let seen = collect_until(&mut rx, |event| {
matches!(
event,
Event::Status {
state: SessionStatus::Exited
}
)
})
.await;
assert!(
!seen
.iter()
.any(|entry| matches!(entry.event, Event::Error { .. })),
"a requested stop was presented as a failure: {seen:?}"
);
assert!(
!process::stopping(&session_dir),
"the completed stop left its marker behind"
);
}
/// A message and a command both mean "now", so neither answers that the
/// session's process has gone -- they start one and go to it.
///