Hmbown/CodeWhale · error

Agent not found

Error message

Agent not found

What it means

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.

Solutions

  1. Verify the agent id against the registry's current roster (list agents) before continuing it.
  2. Re-resolve the agent ref with `resolve_agent_ref` and confirm it maps to a live record.
  3. If the agent came from a prior session, treat it as gone and spawn a new child with the desired continuation context.
  4. Check that the registry was not recreated (session switch/reset) between acquiring the id and using it.

Example fix

// before
let target = registry.continuation_target(&stale_id)?;
// after
if !registry.contains_agent(&stale_id) {
    let agent_ref = spawn_new_agent_with_context(&original_task)?;
    return registry.continue_agent(&agent_ref, text);
}
let target = registry.continuation_target(&stale_id)?;
Defensive patterns

Strategy: validation

Validate before calling

if !registry.contains_agent(agent_id) {
    anyhow::bail!("agent {agent_id} is not registered; list agents and pick a live id");
}
let target = registry.continuation_target(agent_id)?;

Try / catch

let target = registry.continuation_target(agent_id)
    .with_context(|| format!("agent {agent_id} missing from registry; was it reaped or from another session?"))?;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/1d81dadf9d106cae. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/subagent/mod.rs:5991

    pub(crate) fn followup_child_for_session(
        &mut self,
        active_session_id: &str,
        agent_ref: &str,
        text: String,
    ) -> Result<ParentMailReceipt> {
        let agent_id = self.resolve_agent_ref_for_session(active_session_id, agent_ref)?;
        self.followup_child(&agent_id, text)
    }

    /// Follow the persisted continuation chain without treating deliberate
    /// `start + resume_from` forks as continuation targets. Every hop retains
    /// the original root conversation; malformed or cyclic state fails closed.
    fn continuation_target(&self, agent_id: &str) -> Result<String> {
        let source = self
            .agents
            .get(agent_id)
            .ok_or_else(|| anyhow!("Agent not found"))?;
        let owner = &source.owner_session_id;
        let mut target = agent_id.to_string();
        let mut seen = HashSet::new();
        while let Some(next) = self.resume_targets.get(&target) {
            if !seen.insert(target.clone()) {
                return Err(anyhow!("Invalid agent continuation lineage: cycle"));
            }
            let successor = self
                .agents
                .get(next)
                .ok_or_else(|| anyhow!("Agent continuation target is no longer retained"))?;
            if owner.is_empty() || successor.owner_session_id != *owner {
                return Err(anyhow!(
                    "Agent continuation target is outside the active session"
                ));
            }
            target.clone_from(next);
        }

View on GitHub (pinned to 73e0f67d83)