{"record":{"id":"d888b82c47d39ab9","repo":"aaif-goose/goose","slug":"acp-agent-rejected-session-set-mode-err","errorCode":null,"errorMessage":"ACP agent rejected session/set_mode: {err}","messagePattern":"ACP agent rejected session/set_mode: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/goose/src/acp/provider.rs","lineNumber":1478,"sourceCode":"                    .iter()\n                    .map(|mode| mode.id.0.to_string())\n                    .collect();\n                return Err(anyhow::anyhow!(\n                    \"Requested mode(s) [{}] not offered by agent. Available modes: {}\",\n                    candidates.join(\", \"),\n                    available.join(\", \")\n                ));\n            };\n            if modes.current_mode_id.0.as_ref() != mode_id.as_str() {\n                let _: SetSessionModeResponse = cx\n                    .send_request(SetSessionModeRequest::new(\n                        session.session_id.clone(),\n                        mode_id,\n                    ))\n                    .block_task()\n                    .await\n                    .map_err(|err| {\n                        anyhow::anyhow!(\n                            \"ACP agent rejected {}: {err}\",\n                            AGENT_METHOD_NAMES.session_set_mode\n                        )\n                    })?;\n            }\n        }\n    }\n\n    Ok(session)\n}\n\nfn initial_mode_candidates(\n    config: &AcpProviderConfig,\n    current_mode: Option<GooseMode>,\n) -> Vec<String> {\n    current_mode\n        .and_then(|mode| config.mode_mapping.get(&mode).cloned())\n        .or_else(|| config.session_mode_id.clone().map(|id| vec![id]))","sourceCodeStart":1460,"sourceCodeEnd":1496,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose/src/acp/provider.rs#L1460-L1496","documentation":"The intersection succeeded (a concrete mode_id was selected and differs from the session's current_mode_id), but the subsequent session/set_mode RPC was answered with an error by the agent. So the agent advertised the mode yet refused to activate it — a runtime rejection rather than a capability mismatch.","triggerScenarios":"The mode id matches an advertised mode but the agent's internal state rejects the transition (session already closed, license/feature gate, or an agent-side validation bug); a race where the session ends between session/new and session/set_mode.","commonSituations":"Agent version bugs in mode handling, concurrent session/close racing the set_mode call, or an agent that lists modes it cannot actually switch to under the current configuration.","solutions":["Retry creating the session — if it was a race with session teardown it will succeed","Update the agent to a version where set_mode works for the advertised modes","As a workaround, drop the mode override so no set_mode call is made, and select the mode inside the agent if it supports it"],"exampleFix":"# before: mode requested that agent advertises but rejects\nmode: edit\n\n# after: let the agent start in its default mode\n# (remove the override; file an issue against the agent's set_mode handler)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let mut attempts = 0;\nloop {\n    match apply_session_mode(config, &mode, cx, session.clone()).await {\n        Ok(s) => break Ok(s),\n        Err(e) if e.to_string().contains(\"set_mode\") && attempts < 2 => {\n            attempts += 1;\n            session = new_session(cx).await?; // rebuild then retry\n        }\n        Err(e) => break Err(e),\n    }\n}","preventionTips":["Create the session and set the mode in one quick sequence to avoid races with session close","Report repeated set_mode rejections upstream to the agent maintainer"],"tags":["acp","session","mode","race"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}