{"record":{"id":"0f94a7af6e372b4d","repo":"block/buzz","slug":"pool-initialization-cancelled-by-shutdown","errorCode":null,"errorMessage":"pool initialization cancelled by shutdown","messagePattern":"pool initialization cancelled by shutdown","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"info","filePath":"crates/buzz-acp/src/lib.rs","lineNumber":5485,"sourceCode":"    for i in 0..startup.agents as usize {\n        let spawn_result = AcpClient::spawn(\n            &startup.command,\n            &startup.args,\n            &startup.extra_env,\n            startup.has_generated_codex_config,\n        )\n        .await;\n        match spawn_result {\n            Ok(mut acp) => {\n                acp.set_observer(startup.observer.clone(), i);\n                let initialize = tokio::time::timeout(Duration::from_secs(60), acp.initialize());\n                let initialize_result = match shutdown.as_mut() {\n                    Some(shutdown) => tokio::select! {\n                        biased;\n                        _ = shutdown.changed() => {\n                            acp.shutdown().await;\n                            shutdown_agent_slots(&mut agent_slots).await;\n                            return Err(anyhow::anyhow!(\"pool initialization cancelled by shutdown\"));\n                        }\n                        result = initialize => result,\n                    },\n                    None => initialize.await,\n                };\n                match initialize_result {\n                    Ok(Ok(init_result)) => {\n                        tracing::info!(agent = i, \"agent initialized: {init_result}\");\n                        let protocol_version =\n                            init_result[\"protocolVersion\"].as_u64().unwrap_or(1) as u32;\n                        tracing::info!(\n                            agent = i,\n                            name = init_result\n                                .get(\"agentInfo\")\n                                .or_else(|| init_result.get(\"serverInfo\"))\n                                .and_then(|info| info.get(\"name\"))\n                                .and_then(|v| v.as_str())\n                                .unwrap_or(\"unknown\"),","sourceCodeStart":5467,"sourceCodeEnd":5503,"githubUrl":"https://github.com/block/buzz/blob/6c35e82bd50f4ad6587554eeb429e7378d474ba7/crates/buzz-acp/src/lib.rs#L5467-L5503","documentation":"During agent-pool startup each agent gets a 60-second initialize window, raced via a biased tokio::select! against the shutdown signal. If shutdown fires first, the harness cleanly shuts that agent down, releases the pool slots, and returns this error instead of an initialize timeout. It is the designed cancellation path for SIGTERM during startup, not a defect.","triggerScenarios":"ctrl-C, SIGTERM, SIGQUIT, or a supervisor stop signal arrives while agents are still inside their 60s initialize() window; the biased select favors shutdown.changed() and aborts pool init.","commonSituations":"Kubernetes/container runtime killing the pod during a slow agent startup (aggressive liveness probe or short grace period); systemd restart loops; the operator interrupting a stuck startup manually.","solutions":["If the shutdown was intentional, no fix is needed — this is a clean cancellation","If the signal is spurious: find the sender (container probe timeouts, supervisor policy) and lengthen the grace period past agent init time","If agents initialize slowly, investigate why they approach the 60s window (binary cold start, model downloads)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Distinguish intentional shutdown from a crashed supervisor when wrapping the harness\nlet result = run_harness(cfg).await;\nif let Err(e) = &result {\n    if e.to_string().contains(\"cancelled by shutdown\") && !shutdown_was_requested() {\n        tracing::error!(\"shutdown signal arrived unexpectedly — investigate supervisor/probes\");\n    }\n}","preventionTips":["Size container termination grace periods larger than worst-case agent init time (the 60s window)","Don't set liveness probes so tight that they kill pods mid-initialization","Log the shutdown source alongside this error so operators can tell SIGTERM from a probe kill"],"tags":["buzz-acp","shutdown","cancellation","agent-pool","tokio"],"backgroundTag":"graceful-shutdown-abort","analyzedSha":"6c35e82bd50f4ad6587554eeb429e7378d474ba7","analyzedAt":"2026-08-20T04:38:24.874Z","contentChangedAt":"2026-08-20T04:38:24.874Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}