{"record":{"id":"0d3dedd9ebba1046","repo":"zed-industries/zed","slug":"output-token-limit-reached","errorCode":null,"errorMessage":"output token limit reached","messagePattern":"output token limit reached","errorType":"exception","errorClass":"MaxOutputTokensError","httpStatus":null,"severity":"error","filePath":"crates/acp_thread/src/acp_thread.rs","lineNumber":3819,"sourceCode":"\n                            let exceeded_max_output_tokens =\n                                this.token_usage.as_ref().is_some_and(|u| {\n                                    u.max_output_tokens\n                                        .is_some_and(|max| u.output_tokens >= max)\n                                });\n\n                            if exceeded_max_output_tokens {\n                                log::error!(\n                                    \"Max output tokens reached. Usage: {:?}\",\n                                    this.token_usage\n                                );\n                            } else {\n                                log::error!(\"Max tokens reached. Usage: {:?}\", this.token_usage);\n                            }\n                            if is_same_turn {\n                                this.cancel_pending_turn_entries(cx);\n                            }\n                            return Err(anyhow!(MaxOutputTokensError));\n                        }\n\n                        let canceled = matches!(r.stop_reason, acp::StopReason::Cancelled);\n                        if canceled && is_same_turn {\n                            this.cancel_pending_turn_entries(cx);\n                        }\n\n                        if !canceled {\n                            this.snapshot_completed_plan(cx);\n                        }\n\n                        // Handle refusal - distinguish between user prompt and tool call refusals\n                        if let acp::StopReason::Refusal = r.stop_reason {\n                            this.had_error = true;\n                            if let Some((user_msg_ix, _)) = this.last_user_message() {\n                                // Check if there's a completed tool call with results after the last user message\n                                // This indicates the refusal is in response to tool output, not the user's prompt\n                                let has_completed_tool_call_after_user_msg =","sourceCodeStart":3801,"sourceCodeEnd":3837,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/acp_thread/src/acp_thread.rs#L3801-L3837","documentation":"MaxOutputTokensError displays as 'output token limit reached' (acp_thread.rs:58). The ACP agent connection reported that the turn stopped at the model's output token ceiling (exceeded_max_output_tokens distinguishes the output limit from the general max-tokens/context case). The thread logs usage, cancels pending same-turn entries, and returns this error so the truncated turn is not treated as success.","triggerScenarios":"A single assistant turn (long file generation, big tool-call sequences, heavy reasoning output) exhausts the max output tokens configured for the model/request; the stop reason maps to the max-token case and the error is returned from the turn task.","commonSituations":"Provider settings set a low output token limit; asking for one giant artifact instead of incremental edits; models with small output windows; long agentic loops where accumulated generation hits the cap.","solutions":["Raise the output token limit for the model/provider in settings","Split the work: request smaller files or stepwise edits instead of one huge generation","Continue the conversation ('continue'/'go on') to resume from the truncated output rather than restarting","Switch to a model with a larger output window if the task genuinely needs it"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match turn_task.await {\n    Err(error) if error.is::<MaxOutputTokensError>() => {\n        // Turn truncated at the output limit: prompt to continue,\n        // do not treat partial output as success.\n        show_notice(\"Output token limit reached — send 'continue' to resume.\");\n    }\n    Err(error) => return Err(error),\n    Ok(response) => return Ok(response),\n}","preventionTips":["Configure the output token limit per provider to a value that fits your artifacts","Prefer incremental edits over single giant generations","Teach clients to recognize MaxOutputTokensError and offer 'continue' instead of a dead end"],"tags":["rust","zed","agent","llm","token-limit","acp"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}