{"record":{"id":"21948821c2cec21c","repo":"Hmbown/CodeWhale","slug":"agent-not-found-in-the-active-session","errorCode":null,"errorMessage":"Agent not found in the active session","messagePattern":"Agent not found in the active session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":6718,"sourceCode":"                    .worker_records\n                    .get(&agent.id)\n                    .is_none_or(|record| record.spec.parent_run_id.is_none())\n                && !delivered_ids.contains(&agent.id)\n        })\n    }\n\n    /// Resolve either a durable agent id or a model-facing session name.\n    fn resolve_agent_ref(&self, agent_ref: &str) -> Result<String> {\n        self.resolve_agent_ref_inner(agent_ref, None)\n    }\n\n    fn resolve_agent_ref_for_session(\n        &self,\n        active_session_id: &str,\n        agent_ref: &str,\n    ) -> Result<String> {\n        self.resolve_agent_ref_inner(agent_ref, Some(active_session_id))\n            .map_err(|_| anyhow!(\"Agent not found in the active session\"))\n    }\n\n    fn resolve_agent_ref_inner(\n        &self,\n        agent_ref: &str,\n        active_session_id: Option<&str>,\n    ) -> Result<String> {\n        let agent_ref = agent_ref.trim();\n        if let Some(agent) = self.agents.get(agent_ref)\n            && active_session_id\n                .is_none_or(|session_id| self.agent_is_owned_by_session(agent, session_id))\n        {\n            return Ok(agent.id.clone());\n        }\n\n        let matches = self\n            .agents\n            .values()","sourceCodeStart":6700,"sourceCodeEnd":6736,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/subagent/mod.rs#L6700-L6736","documentation":"Session-scoped reference resolution (resolve_agent_ref_for_session) maps every failure — unknown id, unknown name, ambiguous name, or an id owned by a different session — to this single deliberately vague message. The manager intentionally does not distinguish 'foreign agent' from 'missing agent' so user- and model-facing callers cannot probe which agents exist in other sessions (an existence-oracle hardening measure documented at the get_result_for_session seam).","triggerScenarios":"Calling a *_for_session API with an agent_id whose owner_session_id differs from the active session; passing a name that resolves in another session only; refs left over after switching the active root session; ids from restored state belonging to the old boot.","commonSituations":"Multi-session TUI usage where the model reuses an agent_id learned in a previous conversation; session switching mid-orchestration; copied prompts carrying agent ids between chats.","solutions":["List the active session's agents (manager.list() filtered to the session) and use one of those ids","Only pass refs that came from spawn receipts issued in the same active session","If the agent truly belongs to another session, switch the active session or re-spawn the work there instead of cross-referencing"],"exampleFix":"// before\nlet id = manager.resolve_for_session(&active_session, &agent_ref)?; // opaque miss\n\n// after\nlet owned: Vec<String> = manager.list().into_iter()\n    .filter(|s| s.owner_session_id == active_session)\n    .map(|s| s.agent_id)\n    .collect();\nensure!(owned.contains(&agent_ref), \"ref not owned by this session; pick from list()\");","handlingStrategy":"validation","validationCode":"// Restrict refs to those the active session actually owns.\nlet owned: Vec<String> = manager.list().into_iter()\n    .filter(|s| s.owner_session_id == active_session_id)\n    .map(|s| s.agent_id)\n    .collect();\nanyhow::ensure!(owned.contains(&agent_ref.trim()),\n    \"ref not owned by the active session; valid ids: {owned:?}\");","typeGuard":null,"tryCatchPattern":"Handle 'Agent not found in the active session' as a hard stop for that ref: do not probe variants or other sessions (the vague message is intentional anti-probing); re-derive the ref from the session's own roster or respawn.","preventionTips":["Pass only refs returned by spawn receipts of the current session","When the user switches sessions, clear cached agent refs from UI/model context","Store owner_session_id alongside every cached agent id and validate before use"],"tags":["subagent","rust","session-isolation","agent-not-found","security","information-hiding"],"backgroundTag":"resource-not-found","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}