Hmbown/CodeWhale · error
Sub-agent session name
Error message
Sub-agent session name '{name}' is already in use by agent_id '{}' (status: {}, started {since}). Wait for its completion event, or open a new agent with a different name. What it means
Sub-agent session names must be unique among live (non-settled, current-session) agents. When spawning with an explicit `name`, the manager checks existing agents and rejects a name held by a live worker, reporting the conflicting agent_id, its status, and how long ago it started so the parent can decide whether to wait or rename. Settled workers and workers from prior sessions release their names and do not collide (#6313, #3020).
Solutions
- Wait for the conflicting worker's completion event, then retry with the same name.
- Spawn with a different name (the error names the holder's agent_id so you can verify it is not the worker you meant).
- If the holder is a stale/failed spawn, cancel or reap it first so its status becomes settled and the name is released, then retry.
Example fix
// before
spawn(AgentSpawnOptions { name: Some("worker-a".into()), ..Default::default() })?;
// after (holder still live)
spawn(AgentSpawnOptions { name: Some("worker-a-2".into()), ..Default::default() })?; Defensive patterns
Strategy: try-catch
Validate before calling
const liveNames = new Set(currentAgents.filter(a => !a.settled && a.session === currentSession).map(a => a.sessionName)); if (liveNames.has(requestedName)) requestedName = uniqueName(requestedName);
Try / catch
if (err.message.includes("already in use")) {
// parse holder agent_id from the message, decide wait vs rename
await waitForCompletion(holderId) /* or */ spawn({ ...opts, name: altName });
} Prevention
- Generate unique names (suffix with agent id or a counter) instead of reusing remembered names.
- After a spawn failure, cancel/reap the stale worker before retrying with the same name.
- Parse the holder agent_id and elapsed time from the error to decide wait-vs-rename.
When it happens
Trigger: Spawning a sub-agent with options.name = "worker-a" while another agent in the same session has session_name "worker-a" and a non-settled status (running, cancelled-but-live, failed-but-unreaped).
Common situations: A retry after a failed/stale spawn still holds the name; the model reuses a remembered name from a previous turn while the original worker is still running; two parallel spawns in the same turn pick the same name.
Related errors
- agent action=claim widens an enforced write scope, and the…
- Agent has no continuable checkpoint to resume from…
- Agent not found
- Agent continuation target is no longer retained
- Agent continuation target is outside the active session
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/6894147c4477ae9c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/subagent/mod.rs:7024
// `status`/`peek`/`followup`, so it must not reserve the name
// either (cloud-agent e2e, 2026-08-30: a fresh `exec` in the same
// workspace could not spawn `worker-a` again). Settled workers
// release their names the same way: a retry after cancel must
// not fail "already in use" (#6313). Name lookup prefers the
// live holder, so a reused name never resolves ambiguously.
if let Some(existing) = self.agents.values().find(|existing| {
existing.session_name == name
&& !self.is_from_prior_session(existing)
&& !subagent_status_is_settled(&existing.status)
}) {
// #3020: Include elapsed time so the parent can distinguish a
// live worker from a stale/failed earlier spawn (#2656).
let elapsed = existing.started_at.elapsed();
let since = format!(
"{} ago",
crate::elapsed::format_elapsed_secs(elapsed.as_secs())
);
return Err(anyhow!(
"Sub-agent session name '{name}' is already in use by agent_id '{}' \
(status: {}, started {since}). \
Wait for its completion event, or open a new agent with a different name.",
existing.id,
subagent_status_name(&existing.status)
));
}
agent.session_name = name.to_string();
}
agent.fork_context = options.fork_context;
let agent_id = agent.id.clone();
let started_at = agent.started_at;
let tool_profile = match tools.clone() {
Some(tools) => AgentWorkerToolProfile::Explicit(tools),
None => AgentWorkerToolProfile::Inherited,
};
let mut runtime_profile = match options.preserve_runtime_profile.clone() {
Some(preserved) => {View on GitHub (pinned to 73e0f67d83)