zed-industries/zed · error · MaxOutputTokensError

output token limit reached

Error message

output token limit reached

What it means

AcpThread error fired when the model's cumulative output tokens for the turn reach the configured max_output_tokens limit. It is a deliberate guard so the thread stops generating instead of silently truncating; usage is logged before the error propagates.

Solutions

  1. Prompt the thread again to continue or have it summarize its work so far
  2. Raise the max_output_tokens setting for the model if the task legitimately needs more output
  3. Reduce the requested scope per turn (smaller steps, fewer files) so output fits the budget
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/acp_thread/src/acp_thread.rs:3819 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/0d3dedd9ebba1046. Report an issue: GitHub.

Appendix: source

Thrown at crates/acp_thread/src/acp_thread.rs:4144

                            let exceeded_max_output_tokens =
                                this.token_usage.as_ref().is_some_and(|u| {
                                    u.max_output_tokens
                                        .is_some_and(|max| u.output_tokens >= max)
                                });

                            if exceeded_max_output_tokens {
                                log::error!(
                                    "Max output tokens reached. Usage: {:?}",
                                    this.token_usage
                                );
                            } else {
                                log::error!("Max tokens reached. Usage: {:?}", this.token_usage);
                            }
                            if is_same_turn {
                                this.cancel_pending_turn_entries(cx);
                            }
                            return Err(anyhow!(MaxOutputTokensError));
                        }

                        let canceled = matches!(r.stop_reason, acp::StopReason::Cancelled);
                        if canceled && is_same_turn {
                            this.cancel_pending_turn_entries(cx);
                        }

                        if !canceled {
                            this.snapshot_completed_plan(cx);
                        }

                        // Handle refusal - distinguish between user prompt and tool call refusals
                        if let acp::StopReason::Refusal = r.stop_reason {
                            this.had_error = true;
                            if let Some((user_msg_ix, _)) = this.last_user_message() {
                                // Check if there's a completed tool call with results after the last user message
                                // This indicates the refusal is in response to tool output, not the user's prompt
                                let has_completed_tool_call_after_user_msg =

View on GitHub (pinned to 916fc2b8cb)