Hmbown/CodeWhale · error · anyhow::Error

Agent not found in the active session

Error message

Agent not found in the active session

What it means

`resolve_agent_ref_for_session` resolves an agent id or session name but only accepts agents owned by the currently active session. Any resolution failure — unknown ref, or a valid ref belonging to a different session — is collapsed into this single message, so the caller cannot distinguish "no such agent" from "agent exists elsewhere".

Solutions

  1. Re-list the sub-agents within the current session and use one of those ids/names.
  2. If the source agent is from a prior session, re-derive the continuation source from the current session's records, or start a fresh agent instead of continuing.
  3. Verify the ref string (trim whitespace, full id or exact session name) before retrying.

Example fix

// before
resume_from_agent_id: Some("agent_a1b2c3d4".into()) // from a prior session
// after
let live = manager.list_in_session(&session_id)?;
resume_from_agent_id: Some(live[0].id.clone())
Defensive patterns

Strategy: validation

Validate before calling

const sessionAgentIds = new Set(listAgentsInSession(currentSessionId).map(a => a.id));
if (!sessionAgentIds.has(ref)) throw new Error(`${ref} is not an agent of the active session`);

Try / catch

match resolve_err {
    e if e.message == "Agent not found in the active session" => re_list_and_pick_ref(),
    other => propagate(other),
}

Prevention

When it happens

Trigger: Calling an API that resolves refs against the active session (e.g. checkpoint continuation's resume_from_agent_id) with a ref that does not match any agent owned by the active session namespace.

Common situations: Passing an agent id from a previous session's ledger (workers hydrated from old ledgers are invisible to session-scoped status/peek/followup); using an id captured in a different TUI session or workspace; typos in the ref.

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/21948821c2cec21c. Report an issue: GitHub.

Appendix: source

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

                    .worker_records
                    .get(&agent.id)
                    .is_none_or(|record| record.spec.parent_run_id.is_none())
                && !delivered_ids.contains(&agent.id)
        })
    }

    /// Resolve either a durable agent id or a model-facing session name.
    fn resolve_agent_ref(&self, agent_ref: &str) -> Result<String> {
        self.resolve_agent_ref_inner(agent_ref, None)
    }

    fn resolve_agent_ref_for_session(
        &self,
        active_session_id: &str,
        agent_ref: &str,
    ) -> Result<String> {
        self.resolve_agent_ref_inner(agent_ref, Some(active_session_id))
            .map_err(|_| anyhow!("Agent not found in the active session"))
    }

    fn resolve_agent_ref_inner(
        &self,
        agent_ref: &str,
        active_session_id: Option<&str>,
    ) -> Result<String> {
        let agent_ref = agent_ref.trim();
        if let Some(agent) = self.agents.get(agent_ref)
            && active_session_id
                .is_none_or(|session_id| self.agent_is_owned_by_session(agent, session_id))
        {
            return Ok(agent.id.clone());
        }

        let mut matches = self
            .agents
            .values()

View on GitHub (pinned to 73e0f67d83)