zed-industries/zed · error

The agent is nearing the end of its context window and has…

Error message

The agent is nearing the end of its context window and has been stopped. You can prompt the thread again to have the agent wrap up or hand off its work.

What it means

Sentinel raised when the thread stops due to approaching the context-window limit: the agent's message is extracted if present, otherwise this message is the error explaining that the thread was halted near the context limit and the user can re-prompt to wrap up or hand off.

Solutions

  1. Prompt the thread again; the agent will wrap up or hand off its work to continue within a fresh context
  2. Run compaction manually or wait for automatic compaction to free context window space
  3. Split the task into smaller steps to avoid exhausting the context window
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/agent/src/agent.rs:3466 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-09-19). Data as JSON: /api/errors/5f6ddbc32c7a18fe. Report an issue: GitHub.

Appendix: source

Thrown at crates/agent/src/agent.rs:3520

                            sender.send(()).ok();
                        }
                    },
                );
                let task = acp_thread.update(cx, |acp_thread, cx| {
                    acp_thread.send(vec![message.into()], cx)
                });
                (task, token_limit_rx, subscription)
            });

            let mut task = task.fuse();
            let response = futures::select_biased! {
                response = task => response,
                _ = token_limit_rx.fuse() => {
                    if thread.read_with(cx, |thread, _| thread.is_turn_complete()) {
                        task.await
                    } else {
                        thread.update(cx, |thread, cx| thread.cancel(cx)).await;
                        Err(anyhow!(
                            "The agent is nearing the end of its context window and has been \
                             stopped. You can prompt the thread again to have the agent wrap up \
                             or hand off its work."
                        ))
                    }
                }
            };
            let discard_partial_output = matches!(
                &response,
                Ok(Some(response)) if response.stop_reason == acp::StopReason::Cancelled
                    || response.stop_reason == acp::StopReason::Refusal
            );
            let result = match response {
                Ok(Some(response)) => match response.stop_reason {
                    acp::StopReason::Cancelled => Err(anyhow!("User canceled")),
                    acp::StopReason::MaxTokens => Err(anyhow!("The agent reached the maximum number of tokens.")),
                    acp::StopReason::MaxTurnRequests => Err(anyhow!("The agent reached the maximum number of allowed requests between user turns. Try prompting again.")),
                    acp::StopReason::Refusal => Err(anyhow!("The agent refused to process that prompt. Try again.")),

View on GitHub (pinned to 916fc2b8cb)