{"record":{"id":"128a57908ddcd605","repo":"zed-industries/zed","slug":"failed-to-wait-for-agent-server-exit-err","errorCode":null,"errorMessage":"failed to wait for agent server exit: {err}","messagePattern":"failed to wait for agent server exit: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent_servers/src/acp.rs","lineNumber":963,"sourceCode":"            .spawn_dedicated(move |_executor| async move {\n                if let Err(err) = connection_future.await {\n                    log::error!(\"ACP connection error: {err}\");\n                }\n            });\n\n        let connection_rx = async move {\n            connection_rx\n                .await\n                .context(\"Failed to receive ACP connection handle\")\n        }\n        .boxed_local();\n        let status_fut = child\n            .status()\n            .map({\n                let debug_log = debug_log.clone();\n                move |status| match status {\n                    Ok(status) => Ok(exited_load_error_with_stderr(status, &debug_log)),\n                    Err(err) => Err(anyhow!(\"failed to wait for agent server exit: {err}\")),\n                }\n            })\n            .boxed_local();\n        let (connection, status_fut) = match futures::future::select(connection_rx, status_fut)\n            .await\n        {\n            futures::future::Either::Left((connection, status_fut)) => (connection?, status_fut),\n            futures::future::Either::Right((load_error, _connection_rx)) => {\n                return Err(load_error?.into());\n            }\n        };\n\n        // Set up the foreground dispatch loop to process work items from handlers.\n        let dispatch_context = ClientContext {\n            sessions: sessions.clone(),\n            session_list: client_session_list.clone(),\n            request_elicitations: request_elicitations.clone(),\n        };","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent_servers/src/acp.rs#L945-L981","documentation":"While spawning an ACP agent server, Zed races the stdio connection handshake against the child process's exit status. If waiting on the child (child.status()) itself returns an OS-level error — rather than a normal exit status, which is reported separately with captured stderr — the spawn fails with this message.","triggerScenarios":"The wait on the spawned agent process fails outright: the process handle was invalidated (e.g. a wrapper script that double-forks or detaches), the child was reaped elsewhere, or OS resource limits interfere with waiting.","commonSituations":"Agent server crashes at startup (missing binary, missing runtime) or is launched through a shell wrapper that detaches; sandboxed or containerized environments with unusual process semantics.","solutions":["Read the agent server stderr captured in the debug log that accompanies this error to find the underlying spawn failure","Run the configured agent command manually in a terminal to confirm it starts and speaks ACP over stdio","Update Zed and the agent package to pick up process-handling fixes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match connect_agent_server(config).await {\n    Err(err) if err.to_string().contains(\"failed to wait for agent server exit\") => {\n        // surface the captured stderr/debug log, then re-spawn once;\n        // a second failure indicates a broken command, not a transient OS issue\n    }\n    result => result,\n}","preventionTips":["Verify the agent command runs and stays alive in a terminal before configuring it","Avoid wrapper scripts that double-fork or detach — the parent must stay alive to be waited on","Always read the captured stderr debug log before debugging the connection code"],"tags":["acp","agent-server","process-spawn","io"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}