zed-industries/zed · error
Parent thread no longer exists
Error message
Parent thread no longer exists
What it means
NativeThreadEnvironment keeps the parent as a WeakEntity<Thread>. If the parent thread entity was dropped before create_subagent_thread runs, the weak upgrade fails and spawning a subagent from it is impossible.
Source
Thrown at crates/agent/src/agent.rs:3047
.update(cx, |thread, cx| thread.set_title(title, cx));
Task::ready(Ok(()))
}
}
pub struct NativeThreadEnvironment {
agent: WeakEntity<NativeAgent>,
thread: WeakEntity<Thread>,
acp_thread: WeakEntity<AcpThread>,
}
impl NativeThreadEnvironment {
pub(crate) fn create_subagent_thread(
&self,
label: String,
cx: &mut App,
) -> Result<Rc<dyn SubagentHandle>> {
let Some(parent_thread_entity) = self.thread.upgrade() else {
anyhow::bail!("Parent thread no longer exists".to_string());
};
let parent_thread = parent_thread_entity.read(cx);
let current_depth = parent_thread.depth();
let parent_session_id = parent_thread.id().clone();
if current_depth >= MAX_SUBAGENT_DEPTH {
return Err(anyhow!(
"Maximum subagent depth ({}) reached",
MAX_SUBAGENT_DEPTH
));
}
let subagent_thread: Entity<Thread> = cx.new(|cx| {
let mut thread = Thread::new_subagent(&parent_thread_entity, cx);
thread.set_title(label.into(), cx);
thread
});
View on GitHub (pinned to bc538def45)
Solutions
- Cancel pending subagent spawns when the parent session closes.
- Keep the parent thread entity alive (store the Entity handle) for the duration of any tool call that may spawn subagents.
- Propagate the error to the caller as a cancelled run; do not retry with the same weak handle.
Defensive patterns
Strategy: type-guard
Validate before calling
// keep a strong handle alive for the duration of any spawn-capable tool call
let parent = environment.parent_thread().upgrade();
if parent.is_none() {
// parent gone: report cancelled instead of spawning
} Type guard
fn parent_thread_alive(parent: &WeakEntity<Thread>) -> bool {
parent.upgrade().is_some()
} Try / catch
match env.create_subagent_thread(label, cx) {
Ok(handle) => handle,
Err(e) if e.to_string().contains("Parent thread no longer exists") => {
// treat as cancelled run; do not retry
return Ok(());
}
Err(e) => return Err(e),
} Prevention
- Hold Entity<Thread> (not WeakEntity) across await points where subagents may spawn.
- Cancel spawn-capable tool calls when the parent session closes.
When it happens
Trigger: The parent thread is dropped (session closed, all strong handles released) while a tool call was still trying to spawn a subagent; async latency between the spawn request and its execution.
Common situations: User closes the panel/thread while the agent is mid-tool-call; tests dropping parent entities eagerly; cancellation races.
Related errors
- Maximum subagent depth ({}) reached
- No subagent session found with id {session_id}
- User canceled
- The agent is nearing the end of its context window and has b
- Resuming subagent sessions is not supported
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/8c008c18dec5b2ca.
Report an issue: GitHub.