{"record":{"id":"1d81dadf9d106cae","repo":"Hmbown/CodeWhale","slug":"agent-not-found","errorCode":null,"errorMessage":"Agent not found","messagePattern":"Agent not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":5991,"sourceCode":"\n    pub(crate) fn followup_child_for_session(\n        &mut self,\n        active_session_id: &str,\n        agent_ref: &str,\n        text: String,\n    ) -> Result<ParentMailReceipt> {\n        let agent_id = self.resolve_agent_ref_for_session(active_session_id, agent_ref)?;\n        self.followup_child(&agent_id, text)\n    }\n\n    /// Follow the persisted continuation chain without treating deliberate\n    /// `start + resume_from` forks as continuation targets. Every hop retains\n    /// the original root conversation; malformed or cyclic state fails closed.\n    fn continuation_target(&self, agent_id: &str) -> Result<String> {\n        let source = self\n            .agents\n            .get(agent_id)\n            .ok_or_else(|| anyhow!(\"Agent not found\"))?;\n        let owner = &source.owner_session_id;\n        let mut target = agent_id.to_string();\n        let mut seen = HashSet::new();\n        while let Some(next) = self.resume_targets.get(&target) {\n            if !seen.insert(target.clone()) {\n                return Err(anyhow!(\"Invalid agent continuation lineage: cycle\"));\n            }\n            let successor = self\n                .agents\n                .get(next)\n                .ok_or_else(|| anyhow!(\"Agent continuation target is no longer retained\"))?;\n            if owner.is_empty() || successor.owner_session_id != *owner {\n                return Err(anyhow!(\n                    \"Agent continuation target is outside the active session\"\n                ));\n            }\n            target.clone_from(next);\n        }","sourceCodeStart":5973,"sourceCodeEnd":6009,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L5973-L6009","documentation":"Thrown by `continuation_target` when the supplied agent id (or resolved agent ref) is not present in the registry's `agents` map. The registry only holds live/retained agent records, so a reference to an agent that was dropped, never started in this registry, or already reaped cannot be resolved to a continuation lineage.","triggerScenarios":"Calling `continuation_target(agent_id)` (reached via continue/follow-up flows) with an id that `self.agents.get()` cannot find — e.g. a stale id from a previous session, a typo, or an agent that was reaped after completion.","commonSituations":"Reusing an agent id persisted from an earlier run; referencing a child after the registry was rebuilt on session switch; passing a display name instead of the resolved id when resolve_agent_ref already returned it; a race where the record was removed between calls.","solutions":["Verify the agent id against the registry's current roster (list agents) before continuing it.","Re-resolve the agent ref with `resolve_agent_ref` and confirm it maps to a live record.","If the agent came from a prior session, treat it as gone and spawn a new child with the desired continuation context.","Check that the registry was not recreated (session switch/reset) between acquiring the id and using it."],"exampleFix":"// before\nlet target = registry.continuation_target(&stale_id)?;\n// after\nif !registry.contains_agent(&stale_id) {\n    let agent_ref = spawn_new_agent_with_context(&original_task)?;\n    return registry.continue_agent(&agent_ref, text);\n}\nlet target = registry.continuation_target(&stale_id)?;","handlingStrategy":"validation","validationCode":"if !registry.contains_agent(agent_id) {\n    anyhow::bail!(\"agent {agent_id} is not registered; list agents and pick a live id\");\n}\nlet target = registry.continuation_target(agent_id)?;","typeGuard":null,"tryCatchPattern":"let target = registry.continuation_target(agent_id)\n    .with_context(|| format!(\"agent {agent_id} missing from registry; was it reaped or from another session?\"))?;","preventionTips":["Keep agent ids in session-scoped state, never persisted across registry rebuilds.","Refresh the roster after any session switch or registry reset.","Use resolve_agent_ref output immediately; do not cache ids across operations.","Log reaping events so stale-id errors are traceable."],"tags":["subagent","resource-not-found","stale-reference","rust"],"backgroundTag":"entity-not-found","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}