zed-industries/zed · error
Project state not found for session
Error message
Project state not found for session
What it means
send_mcp_prompt resolves per-session project state via session_project_state(&session_id); when the session id is not registered in the agent's in-memory sessions/projects map, it returns a ready Err 'Project state not found for session'. The MCP prompt never reaches the server store because there is no project context to resolve it against.
Source
Thrown at crates/agent/src/agent.rs:1837
.log_err();
}
}))
.await;
}
}
fn send_mcp_prompt(
&self,
client_user_message_id: ClientUserMessageId,
session_id: acp::SessionId,
prompt_name: String,
server_id: ContextServerId,
arguments: HashMap<String, String>,
original_content: Vec<acp::ContentBlock>,
cx: &mut Context<Self>,
) -> Task<Result<acp::PromptResponse>> {
let Some(state) = self.session_project_state(&session_id) else {
return Task::ready(Err(anyhow!("Project state not found for session")));
};
let server_store = state
.context_server_registry
.read(cx)
.server_store()
.clone();
let path_style = state.project.read(cx).path_style(cx);
cx.spawn(async move |this, cx| {
let prompt =
crate::get_prompt(&server_store, &server_id, &prompt_name, arguments, cx).await?;
let (acp_thread, thread) = this.update(cx, |this, _cx| {
let session = this
.sessions
.get(&session_id)
.context("Failed to get session")?;
anyhow::Ok((session.acp_thread.clone(), session.thread.clone()))View on GitHub (pinned to bc538def45)
Solutions
- Create the session and await its completion before sending MCP prompts
- On this error, recreate the session and re-invoke the prompt
- Ensure prompts are routed to the agent instance that owns the session
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the session is registered before sending an MCP prompt
if agent.session_project_state(&session_id).is_none() {
let session = agent.create_session(project, cx).await?; // register first
session_id = session.id;
}
send_mcp_prompt(client_id, session_id, prompt_name, server_id, args, content, cx) Try / catch
match send_mcp_prompt(...).await {
Err(error) if error.to_string().contains("Project state not found") => {
// Session was never registered / was removed: recreate and retry once.
let session = recreate_session(cx).await?;
send_mcp_prompt(client_id, session.id, prompt_name, server_id, args, content, cx).await
}
other => other,
} Prevention
- Await session creation before enabling MCP prompt UI
- Invalidate cached session ids whenever the agent restarts
- Route prompts to the agent instance that created the session
When it happens
Trigger: Invoking an MCP prompt for a session id that was never created on this Agent, was removed (ended/rewound fully), or belongs to a different agent instance/process.
Common situations: Client fires the prompt before session creation resolves; agent restarted while the client kept its old session ids; two agent connections with crossed session ids; session torn down concurrently with the prompt.
Related errors
- message not found
- no thread found with ID: {id:?}
- Session not found
- output token limit reached
- not supported
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/33d500e4cabfdad5.
Report an issue: GitHub.