zed-industries/zed · error

session was closed before load completed

Error message

session was closed before load completed

What it means

During ACP session load, close_session completed while the load RPC was still in flight (the pending_sessions entry was removed / refcount dropped), so the load is aborted because the session no longer exists.

Solutions

  1. Avoid closing the session while its initial load RPC is still in flight
  2. Retry loading or resuming the session after the close completes
  3. Wait for the session to finish loading before issuing close_session
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/agent_servers/src/acp.rs:1277 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20). Data as JSON: /api/errors/4264245dd1b1c0e2. Report an issue: GitHub.

Appendix: source

Thrown at crates/agent_servers/src/acp.rs:1308

                                this.sessions.borrow_mut().remove(&session_id);
                                this.pending_sessions.borrow_mut().remove(&session_id);
                                return Err(Arc::new(err));
                            }
                        };

                    let (modes, config_options) =
                        config_state(response.modes, response.config_options);

                    if let Some(config_opts) = config_options.as_ref() {
                        this.apply_default_config_options(&session_id, config_opts, cx);
                    }

                    this.pending_sessions.borrow_mut().remove(&session_id);

                    {
                        let mut sessions = this.sessions.borrow_mut();
                        let Some(session) = sessions.get_mut(&session_id) else {
                            return Err(Arc::new(anyhow!(
                                "session was closed before load completed"
                            )));
                        };
                        session.session_modes = modes;
                        session.config_options = config_options.map(ConfigOptions::new);
                    }

                    Ok(thread)
                }
            })
            .shared();

        self.pending_sessions.borrow_mut().insert(
            session_id,
            PendingAcpSession {
                task: shared_task.clone(),
            },
        );

View on GitHub (pinned to 916fc2b8cb)