{"record":{"id":"d272fbfc9e391cc0","repo":"aaif-goose/goose","slug":"acp-initialize-failed-err","errorCode":null,"errorMessage":"ACP initialize failed: {err}","messagePattern":"ACP initialize failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/goose/src/acp/provider.rs","lineNumber":1254,"sourceCode":"    cx: ConnectionTo<Agent>,\n    rx: &mut mpsc::Receiver<ClientRequest>,\n    prompt_response_tx: Arc<Mutex<Option<mpsc::Sender<AcpUpdate>>>>,\n    init_tx: oneshot::Sender<Result<InitializeResponse>>,\n) -> Result<(), agent_client_protocol::Error> {\n    let mut init_tx = Some(init_tx);\n\n    let client_capabilities = ClientCapabilities::new();\n    let init_response: InitializeResponse = cx\n        .send_request(\n            InitializeRequest::new(ProtocolVersion::LATEST)\n                .client_capabilities(client_capabilities),\n        )\n        .block_task()\n        .await\n        .map_err(|err| {\n            let message = format!(\"ACP {} failed: {err}\", AGENT_METHOD_NAMES.initialize);\n            if let Some(tx) = init_tx.take() {\n                let _ = tx.send(Err(anyhow::anyhow!(message.clone())));\n            }\n            agent_client_protocol::Error::internal_error().data(message)\n        })?;\n\n    let supports_close = init_response\n        .agent_capabilities\n        .session_capabilities\n        .close\n        .is_some();\n    let supports_load = init_response.agent_capabilities.load_session;\n    let mcp_capabilities = init_response.agent_capabilities.mcp_capabilities.clone();\n    if let Some(tx) = init_tx.take() {\n        log_undelivered(tx.send(Ok(init_response)), AGENT_METHOD_NAMES.initialize);\n    }\n\n    let mut session_ids: Vec<SessionId> = Vec::new();\n\n    while let Some(request) = rx.recv().await {","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose/src/acp/provider.rs#L1236-L1272","documentation":"The JSON-RPC 'initialize' request to the ACP agent failed at the protocol layer. The request is sent with ProtocolVersion::LATEST and the client capabilities right after the child spawns; failure means the agent process answered with an error, closed the connection, or the transport broke before/while responding. The message is both returned as the init error and surfaced to the caller as an internal_error.","triggerScenarios":"The agent process prints non-protocol text to stdout (banners, logs, compile output) corrupting the JSON-RPC stream; the agent exits or crashes immediately after spawn (bad args, missing runtime like an unavailable node version); a protocol version or schema mismatch between goose and the agent.","commonSituations":"Wrapping a CLI that logs to stdout instead of stderr, npx downloading/caching output polluting stdout on first run, agent built against an older agent_client_protocol version, or the agent exiting due to a missing env var needed at startup.","solutions":["Run the agent command manually with the same args/env and watch stderr; ensure nothing but JSON-RPC goes to stdout (route logs to stderr)","For npx-based agents, pre-install the package (npm i -g) so first-run download output cannot corrupt the stream","Align versions: update goose and the agent so both use a compatible agent-client-protocol crate","Set any env vars the agent requires at startup via the provider's env map"],"exampleFix":"# before (agent code pollutes stdout)\nconsole.log('agent starting');\n\n# after\nconsole.error('agent starting');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match provider.initialize().await {\n    Ok(resp) => resp,\n    Err(e) if e.to_string().contains(\"initialize\") => {\n        tracing::error!(%e, \"ACP agent failed to initialize; check agent stderr and stdout hygiene\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep agent logging strictly on stderr; stdout must carry only ACP JSON-RPC","Pin compatible versions of goose and the agent's agent-client-protocol","Pre-install npx-based agents to keep first-run output off stdout"],"tags":["acp","protocol","initialization","stdio","version-mismatch"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}