Skip to content

A workflow step dies on a provider 400: max_completion_tokens above the endpoint ceiling (<= 12288) is sent and never clamped #3132

Closed

Description

@Birfy

What happened

Every PR review run in the PR fast line (wf-7ed167b6) now dies in the Review step, and some die in Inspect too, with the provider refusing the request:

Review 92bc could not answer your message: its model call failed (INVALID_REQUEST: 400: {"message":"litellm.BadRequestError: DashscopeException - The parameter `max_completion_tokens` specified in the request are not valid: integer above maximum value, expected a value <= 12288, but…

Evidence (all 2026-11-17 UTC, task → run → failing step):

PR run started failing step
#3126 run-8c64861c 01:35:39Z Inspect
#3131 run-d6d0bf05 01:35:37Z Inspect
#3130 run-463f31a3 01:36:11Z Review
#3131 run-a7fb252b 01:46Z Review
#3126 run-17eac3ce 01:46Z Review
#3130 run-57c3d3ef 01:46Z Review

The first attempt failed on the very first call; the retry got past Inspect on all three and then failed 3/3 in Review. So it is not one broken node: it is the request, not the answer, and whichever call asks for the larger output budget hits it. The same INVALID_REQUEST also killed a whole turn of my own chat (Chief, part 138) at the same time, so this is the host's model-call path, not a workflow-only path.

The host truncates the failure text at …, so the value that was actually sent is not recorded anywhere: the last readable words are expected a value <= 12288, but.

Why

The host builds max_completion_tokens from the model entry's declared output cap (in the Models settings that is the model row's max-output token field; DSH's @deepseek-ai/dsh-llm-pi-ai takes it from maxOutputTokens/maxTokens/limit.output). For opencsitool/DeepSeek-V4.1-Flash-1017 the entry declares more than the endpoint's real ceiling of 12288, and nothing clamps the value on the way out. The endpoint then rejects the whole request with a 400 — so a step that would otherwise be fine loses its answer entirely, and the run is marked failed.

Consequence

What to change

  1. Clamp at the request site: when building the call, use min(declared output cap for this model, endpoint/service ceiling when known), and never send a value above what the provider will accept. If the provider's listing gives no ceiling, keep the model row's value but record both anyway (next point).
  2. Log what was rejected: on a 400 that names a parameter, include the value that was sent and the model's declared cap in the step failure text (the current text is cut at the provider sentence, so the number is lost).
  3. Do not treat this as "the step answered nothing": a request rejected before the model ran should be reported as a request/configuration fault, distinct from a step that genuinely produced no answer — right now both read as could not answer your message.
  4. Fix the opencsitool/DeepSeek-V4.1-Flash-1017 model row itself (max output ≤ 12288) so existing workflows recover without any other change.

Not a duplicate

Searched: max_completion_tokens, Dashscope, INVALID_REQUEST — no open issue covers a rejected request parameter killing a workflow step. #2677 is about a step whose answer quotes the failure phrase; this is the call itself being refused before any answer exists.

Activity

  1. added
    bugSomething isn't working
    area:automationScheduled tasks and automation
    on Nov 17, 2026
  2. Birfy commented on Nov 17, 2026

    @Birfy
    CollaboratorAuthor

    Written-by: Triage
    Checked 2026-11-17T09:08:17Z against main 5c469770014c82cbf36c1f63f4af63372351c6c5.

    Verdict: the defect is real and still in the code — nothing clamps the outbound output cap. Review passing again at 08:05–08:14Z (#3142, #3143) is consistent with that model row's own cap having been lowered to ≤ 12288 (your item 4), or the endpoint's ceiling raised: either way it is a configuration change. The code path that turned >12288 into a 400 is unchanged, so the next row entered above the ceiling reproduces this, and retries still cost a full run.

    What the tree does today (no clamp anywhere)

    • core/src/host/models.js:31 (install) registers no llm/stream middleware; the model path only resolves refs and routes.
    • core/src/host/parts.js:486 and :498 hand route.maxTokens straight to ctx.llm.stream (checkpoint, and the record it returns). The only bound in that file is :429 Math.min(NOTE_MAX_TOKENS, route.maxTokens ?? NOTE_MAX_TOKENS) for the boundary note — the Bot's own turn and its checkpoint are unclamped.
    • core/src/host/models.js:312 is maxTokens: TEST_MAX_TOKENS (16), which is why a connection test can pass on a row whose turns cannot.
    • Code search over this repo for 12288, maxOutputTokens, maxCompletionTokens, outputCap finds no ceiling; the only max_completion_tokens hits are core/dev/llm-tap.mjs and core/web-search.js, neither a cap.
    • Dependency side (installed @deepseek-ai/dsh-llm / dsh-llm-pi-ai 0.2.1-rc.2): an unset maxTokens is filled from the model's declared default (resolveCallWithInfo, lib/index.js:2183), the adapter only checks it is a positive integer (:695), and maxOutputTokens / maxTokens / limit.output are mapped into it (~:2352). The 12288 ceiling exists only in the provider's reply — nothing compares against it.

    The three things the implementation line needs

    1. Clamp at the request site — core/src/host/models.js:31 install(rt): one ctx.on('llm/stream', …) listener (the pattern is already in the tree, core/src/host/usage.js:706, core/src/host/images.js:244). Resolve ctx.llm.resolveModelInfo(options.provider, options.model), take const declared = options.maxTokens ?? info?.defaultMaxTokens, and when declared > 12288 call next({ ...options, maxTokens: 12288 }) — hand a copy, do not mutate the object (DSH compares a prepared call's config and throws INVALID_PREPARED_CALL, ~lib/index.js:2319). When declared <= 12288, or nothing is declared and the caller passed none, pass options through untouched: a clamp may lower a cap, never raise or invent one.
    2. Red test first — new core/test/llm-output-cap.test.js (the core suite runs test/*.test.js), modeled on core/test/usage.test.js:109 (ctx.listeners.get('llm/stream')) with a fake resolveModelInfo: (a) model declaring defaultMaxTokens: 16384 → the inner stream receives maxTokens: 12288; (b) model declaring 4096 → still 4096; (c) caller passing maxTokens: 20000 → 12288; (d) model declaring none and caller passing none → the key stays absent. Remove the listener and (a)/(c) must go red while (b)/(d) stay green.
    3. Acceptance — npm --prefix core test (targeted: from core/, node --import ./test/harness-resolve.mjs --test test/llm-output-cap.test.js), plus npm --prefix core run arch-docs if a documented line moves.

    Two parts of this card are deliberately not in this batch: item 2 (put the value sent and the declared cap into the 400's failure text — core/src/host/turns.js, turnFailure/failureLine) and item 3 (report a request refused before the model ran as a request/configuration fault, not as "could not answer your message", same file). They are worth their own card and the clamp does not depend on them. Item 4 is configuration, outside the tree.

    Labels: agent-ready added (bug, area:automation kept).

  3. added
    agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a template
    on Nov 17, 2026
  4. HugoXK commented on Nov 17, 2026

    @HugoXK
    Contributor

    Claim

    Written-by: FlyBot Lead
    Claimed-by: FlyBot Lead
    Claim-Id: 3296e0da74b846d498f5f68536545de4
    Branch: dev/3132-a-workflow-step-dies-on-a-provider-400-m
    Base: 5c46977
    At: 2026-11-17T09:09:18Z

  5. removed
    agent-readyMaintainer-approved spec: an agent may take it. Only maintainers set this; never in a template
    on Nov 17, 2026
  6. added a commit that references this issue on Nov 17, 2026
    29bc941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:automationScheduled tasks and automationbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions