Repository navigation
Description
Problem
A stage plan run on claude-sonnet-5-5 ends with StructuredOutputValidationError: 0 schema violation(s). Cause: the request sets no max_tokens, and the gateway sends the Anthropic default of 4096 output tokens. The reply is cut at 4096 tokens and holds no part.
Live run on 2026-11-09 (release 0.100.0 code, tool_choice auto, slot analysis, model claude-sonnet-5-5, window 200000, no fallback used): devops roadmap stage --plan --item 3599 made 15 requests, all answered by claude-sonnet-5-5.
- Requests 1 to 13 offered 13 tools. The model made 2 to 5 tool calls in each. The input grew from 54,455 to 105,412 tokens.
- Request 14 offered only the output tool
final_result. The run counts the window withtokens_of, which errs high, and it passedtool_stop(200000)= 150,000 at a real input of about 105,000. The model still asked forread_fileandsearch_code. Those tools were not offered, so pydantic-ai sent the retry prompt "Unknown tool name: 'read_file'. Available tools: 'final_result'". This used the one output retry (_REPLY_RETURNS= 1). - Request 15 ended with
finish_reasonlength, 4096 output tokens and no part. pydantic-ai raisedUnexpectedModelBehavior: "Model token limit (provider default) exceeded before any response was generated." The words "provider default" show that the request carried nomax_tokens(last_max_tokensis None). investigate(src/devops_cli/roadmap/refine/refine_investigation.py) turns this intoInvestigationStopped(schema_broken=True), because the last reply holds no function tool call.ToolboxClient._stopped(src/devops_cli/roadmap/stage/stage_toolbox.py) raisesStructuredOutputValidationError(violations=trace.violations).trace.violationscounts only retry prompts whose content is a list. The retry prompt here is text, so the count is 0. A run that fails for any other reason without a list of violations also reads "0 schema violation(s)".
_claude_group_model (src/devops_cli/ai/pydantic_ai_bridge.py) builds the model with profile={"supports_forced_tool_choice": False} and no settings. The setting ai.max_tokens is read only for the Ollama path (_resolve_ollama_model). The gateway entry claude-sonnet-5-5 in k8s/llm/gateway/config.yaml sets no max_tokens. A StageProposal with the plan texts, the groups and the pull request body does not fit in 4096 tokens, so any Sonnet run that reaches its final reply with a full plan is cut. Not verified: the content of the cut reply (it reached the client as no part).
The fault was hidden before #4216: the call went to deepseek-v4.1-flash-1017 as the fallback (#4205). The 1 violation failures (#4004, #3576, #3592, #3612, #4028, #4043) are not explained by this run. Not verified.
Expected
A stage run on a Claude group can send a reply of the size of a plan. The message of a stop by the output limit names the limit, and not "0 schema violation(s)".
Acceptance criteria
- A test builds the model of a Claude gateway group with
resolve_pydantic_ai_model("gateway:claude-sonnet-5-5")and asserts thatmodel.settings["max_tokens"]is set to a value above 4096 (the value is a named constant). It fails today becausemodel.settingsholds nomax_tokens. - A test runs
investigatewith a model that answersfinish_reasonlengthwith no part, and asserts that the message of the error names the output token limit. Today the error isStructuredOutputValidationErrorwith 0 violations and a message that names none. uv run devops roadmap stage --plan --item 3599, with the Service config, does not stop withModel token limit (provider default). Today it does.
Existing tool considered
- pydantic-ai
ModelSettings(max_tokens=...)onOpenAIChatModel(settings=...)(library already in use, installed version has thesettingsargument). It covers the cause with one argument in_claude_group_model. - The same cap in the gateway entry (
litellm_params.max_tokens) would also cover other callers of the group. Not verified that LiteLLM applies it as a default when the request sets none; decide with a live call. Do not copy the cap into both places. - fix(roadmap): a model call of an implement step has no output cap and a runaway reply holds the tier for 25 minutes #2869 (closed) put an output cap into the model settings of the implement agent. This issue follows that pattern.
- No new tool is built.
Cost
Tokens to build: about 40,000 (one setting, a constant, two tests). Tokens to keep: none. Tokens to fix a second fault, if the run then shows one: unknown. Elapsed time: about 1 hour, plus one live stage run on Sonnet (about 2.5 USD, 15 requests of up to 106,000 input tokens).
Related
#4204 (placeholder replies; its follow-up cause was DeepSeek, #4205), #4205 (the fallback hid the 400), #4216 (tool_choice auto for a Claude group), #3529 (a return request and the window limit), #2869 (output cap of the implement agent).
Source: #4204
Proposed design
Problem statement
A stage plan run on the Claude group claude-sonnet-5-5 sends no max_tokens, so the gateway applies the Anthropic default of 4096 output tokens. The final reply of a plan does not fit in 4096 tokens, so the model output is cut and holds no part. The run then fails with StructuredOutputValidationError: 0 schema violation(s), a message that hides the real cause, the output token limit.
Acceptance criteria
Requirement: Claude group output cap
The model of a Claude gateway group SHALL set max_tokens in its model settings to a named constant above 4096.
Scenario: Claude group model has max_tokens
- WHEN A test builds the model with
resolve_pydantic_ai_model("gateway:claude-sonnet-5-5") - THEN
model.settings["max_tokens"]equals the named constant, and the constant is above 4096
Requirement: Output limit stop names the limit
The error of an investigation that ends with finish_reason length and no part MUST name the output token limit in its message.
Scenario: Cut reply gives a message that names the limit
- WHEN A test runs
investigatewith a model that answersfinish_reasonlengthwith no part - THEN The error message names the output token limit and does not read "0 schema violation(s)"
Requirement: Other model stops keep their class
A stop that is not caused by the output token limit SHALL keep its current error class and message.
Scenario: Schema break without a limit stop
- WHEN A test runs
investigatewith a model that breaks the schema of its reply and does not reach the output limit - THEN The error stays
StructuredOutputValidationErrorwith the same message as before
Existing Tool Considered
The library pydantic-ai, already in use, covers the cause: OpenAIChatModel(settings=ModelSettings(max_tokens=...)) sets the cap with one argument in _claude_group_model (src/devops_cli/ai/pydantic_ai_bridge.py:89). The same cap in the gateway entry (litellm_params.max_tokens) would also cover other callers, but nobody verified that LiteLLM applies it when the request sets none. No new tool is built. The cost of the own code is about 40,000 tokens to build (one setting, one constant, the error mapping and tests), no tokens to keep, and about 1 hour of elapsed time.
Key questions
- Where does the cap go: the model settings in
_claude_group_model, or the gateway entry ink8s/llm/gateway/config.yaml?: Put the cap in the model settings of_claude_group_model. The library documents the setting, the issue verified the cause in this code path, and a live check of the gateway default is not needed. Do not copy the cap into the gateway entry. (best practice) [sources: src/devops_cli/ai/pydantic_ai_bridge.py:81, k8s/llm/gateway/config.yaml, openspec/changes/archive/2026-10-31-2869-step-output-cap-and-call-timeout/design.md]- Chosen: Model settings in
_claude_group_model. One argument, covered by the library, and it follows the pattern of fix(roadmap): a model call of an implement step has no output cap and a runaway reply holds the tier for 25 minutes #2869 for the implement agent. - Rejected:
litellm_params.max_tokensin the gateway entry. Not verified that LiteLLM applies it as a default when the request sets none. It would also need a gateway rollout. - Rejected: Both places. The issue says not to copy the cap into both places, because the two values can drift apart.
- Chosen: Model settings in
- How does the error of a stop by the output limit name the limit?: In
_stopped_outcomeofrefine_investigation.py, detect theUnexpectedModelBehaviorwhose message holds "token limit", or whose last reply hasfinish_reasonlength. Return anInvestigationStoppedwithschema_broken=Falseand a message that names the output token limit. ThenToolboxClient._stoppedraisesRoadmapStageErrorand notStructuredOutputValidationError. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py, src/devops_cli/roadmap/stage/stage_toolbox.py]- Chosen: Detect the limit stop in
_stopped_outcomeand setschema_brokento false. The typed field already decides the error class in_stopped, so one change fixes the message for all callers ofinvestigate. A budget-limit stop already hasschema_brokenfalse and a message that names the limit (change 3037). - Rejected: Count text retry prompts as violations in
trace.violations. This would change the count for other failures and would not name the limit.
- Chosen: Detect the limit stop in
- What value does the named constant hold?: Use 32000 as a named constant in
src/devops_cli/config/constants.py(for exampleCONST_AI_CLAUDE_GROUP_MAX_OUTPUT_TOKENS). It is about 8 times the 4096 default, far above a plan with its groups and pull request body, and below the total stage output budgetCONST_ROADMAP_STAGE_MAX_OUTPUT_TOKENS(50000 in change 3037), so the run's ownoutput_tokens_limitstill bounds the whole run. It equals the cap that change 3206 set for an implement step (32000). The Anthropic per-request maximum for Sonnet was not verified here (the docs page could not be fetched); the value is a cap and not a target, so a lower model maximum would show as a 400 in the live run of criterion 3. (best practice) [sources: openspec/changes/archive/2026-11-02-3206-raise-job-caps/proposal.md, openspec/changes/archive/2026-11-02-3037-the-stage-job-plans-with-a/tasks.md, openspec/changes/archive/2026-10-31-2869-step-output-cap-and-call-timeout/design.md]- Chosen: 32000. Fits a full plan with margin, follows the precedent of perf(roadmap): raise the soft caps and request timeouts of the jobs #3206, and stays under the stage output budget of 50000.
- Rejected: 16384. The first cap of fix(roadmap): a model call of an implement step has no output cap and a runaway reply holds the tier for 25 minutes #2869, later raised in perf(roadmap): raise the soft caps and request timeouts of the jobs #3206 because it was too tight for large replies; a plan with reasoning could meet it again.
- Rejected: Window quarter (50000). Equals the whole stage output budget, so one reply could use the full run budget.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 9, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(roadmap)scope of the title gives the scope.Every stage run on a Claude model that reaches a full plan is cut and fails, blocking the workflow.It unblocks all Claude-based stage plan runs that produce replies above 4096 tokens.The fix is one settings argument in _claude_group_model plus a clearer error message and two tests.Both target Claude gateway groups and structured replies, but #3140 fixes tool_choice incompatibility while this sets max_tokens to lift the 4096 output cap.devops-cli-service commentedon Nov 9, 2026
Status set to Ready at 7411967 (see proposed design in issue body).
devops-cli-service commentedon Nov 9, 2026
Released in v0.100.2: https://github.com/dan-petty/devops-cli/releases/tag/v0.100.2
devops-cli-service commentedon Nov 9, 2026
Live since 2026-11-09 14:13 UTC