zed-industries/zed · error
Session not found
Error message
Session not found
What it means
run_turn looks session_id up in agent.sessions to obtain the Thread and AcpThread entities; a miss logs 'Session not found in run_turn' and returns a ready Err task — the per-turn closure f that would start generation is never invoked.
Source
Thrown at crates/agent/src/agent.rs:2147
self.0
.update(cx, |this, cx| this.load_thread(id, project, cx))
}
fn run_turn(
&self,
session_id: acp::SessionId,
cx: &mut App,
f: impl 'static
+ FnOnce(Entity<Thread>, &mut App) -> Result<mpsc::UnboundedReceiver<Result<ThreadEvent>>>,
) -> Task<Result<acp::PromptResponse>> {
let Some((thread, acp_thread)) = self.0.update(cx, |agent, _cx| {
agent
.sessions
.get_mut(&session_id)
.map(|s| (s.thread.clone(), s.acp_thread.clone()))
}) else {
log::error!("Session not found in run_turn: {}", session_id);
return Task::ready(Err(anyhow!("Session not found")));
};
log::debug!("Found session for: {}", session_id);
let response_stream = match f(thread, cx) {
Ok(stream) => stream,
Err(err) => return Task::ready(Err(err)),
};
Self::handle_thread_events(
response_stream,
acp_thread.downgrade(),
Some(self.clone()),
cx,
)
}
fn handle_thread_events(
mut events: mpsc::UnboundedReceiver<Result<ThreadEvent>>,
acp_thread: WeakEntity<AcpThread>,View on GitHub (pinned to bc538def45)
Solutions
- Only enqueue turns after session creation has resolved
- On this error, recreate the session and resend the turn
- Serialize session teardown with pending turn dispatch so turns cannot race removal
Defensive patterns
Strategy: try-catch
Validate before calling
// Only enqueue turns for sessions the agent actually holds
if !agent.has_session(&session_id) {
let session = agent.create_session(project, cx).await?;
session_id = session.id;
}
agent.run_turn(session_id, cx, move |thread, cx| thread.send(prompt, cx)) Try / catch
match run_turn(...).await {
Err(error) if error.to_string() == "Session not found" => {
// Recreate the session and replay the turn once.
let session = agent.create_session(project, cx).await?;
agent.run_turn(session.id, cx, replay_closure).await
}
other => other,
} Prevention
- Enqueue turns only after session creation resolves
- Drop queued turns when a session is torn down instead of letting them race
- On reconnect, rebuild the session map before resuming the conversation
When it happens
Trigger: Sending a chat turn for a session id not present in the in-memory sessions map: never created in this agent, removed after ending, or stale after an agent restart.
Common situations: Client reconnect after agent restart while reusing pre-restart ids; session ended concurrently with a queued turn; turn dispatched during session teardown.
Related errors
- message not found
- no thread found with ID: {id:?}
- Project state not found for session
- output token limit reached
- not supported
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/743f61c5802c77a6.
Report an issue: GitHub.