story-kit: merge 159_bug_server_restart_leaves_orphaned_claude_code_pty_processes_running

This commit is contained in:
Dave
2026-02-24 17:56:40 +00:00
parent 876f944acd
commit e6662c8f8e
2 changed files with 203 additions and 3 deletions

View File

@@ -110,6 +110,8 @@ async fn main() -> Result<(), std::io::Error> {
let startup_root: Option<PathBuf> = app_state.project_root.lock().unwrap().clone();
let startup_agents = Arc::clone(&agents);
let startup_reconciliation_tx = reconciliation_tx.clone();
// Clone for shutdown cleanup — kill orphaned PTY children before exiting.
let agents_for_shutdown = Arc::clone(&agents);
let ctx = AppContext {
state: app_state,
@@ -170,6 +172,10 @@ async fn main() -> Result<(), std::io::Error> {
let result = Server::new(TcpListener::bind(&addr)).run(app).await;
// Kill all active PTY child processes before exiting to prevent orphaned
// Claude Code processes from running after the server restarts.
agents_for_shutdown.kill_all_children();
if let Some(ref path) = port_file {
remove_port_file(path);
}