Skip to content

[Bug]: Output limits are merged per field and window exhaustion is read as a complete response #4164

Backlog

Description

@ningmao-hlyz

Describe the bug

Two places read output limits per field or per known value instead of as one concept.

GenerateOptions.mergeOptions() falls back per field for maxTokens and maxCompletionTokens. A request that overrides one of them keeps the other from the model defaults, so the merged options carry two output limits although the caller supplied one.

FinishReasons.indicatesOutputLimit() did not recognize Anthropic's model_context_window_exceeded. That value means the response filled the context window, and Anthropic's stop-reason guidance treats that response as truncated. The helper only covered length, max_tokens and the Responses API incomplete cause.

To Reproduce

GenerateOptions merged = GenerateOptions.mergeOptions(
    GenerateOptions.builder().maxTokens(64).build(),
    GenerateOptions.builder().maxCompletionTokens(16000).build());
System.out.println(merged.getMaxTokens());           // 64
System.out.println(merged.getMaxCompletionTokens()); // 16000, inherited from the defaults

On a build before #4567:

FinishReasons.indicatesOutputLimit("model_context_window_exceeded", Map.of()); // false

Expected behavior

A request-supplied output limit replaces both inherited limits; a request that supplies neither keeps both defaults; a request that supplies both keeps both.

A response that stopped at its output limit, or filled the context window, is reported as truncated.

Error messages

Neither path throws. With two limits present, HarnessContextBuilder.inputLimit and JevRouteCatalog fold them with Math.max, so the inherited default becomes the reserved output budget and the input budget loses that room; OpenAIChatFormatter writes both into the request body. With the truncation value missed, ConversationCompactor.toValidatedSummary accepted a summary cut at the window and replaced the history it was summarizing. MemoryConsolidator and ReasoningContext.isTruncated read the same helper.

Environment (please complete the following information):

  • AgentScope-Java Version: 2.1.0-SNAPSHOT, 7b87b5969
  • Java Version: 17
  • OS: Windows

Additional context

Truncation values checked across adapters: DashScope length, Gemini MAX_TOKENS, OpenAI Chat Completions length, Responses incomplete plus the cause in metadata, Anthropic max_tokens and model_context_window_exceeded. Anthropic was the only adapter missing from the helper, and the SDK this repo builds against (3.14.0) exposes it as StopReason.MODEL_CONTEXT_WINDOW_EXCEEDED.

The truncation half is fixed in #4567 (26f8b946a). The merge half is in #4564.

Activity

  1. changed the title [-][Bug]: Request output limits retain the other inherited token limit[/-] [+][Bug]: Output limits are merged per field and window exhaustion is read as a complete response[/+] on Dec 2, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions