fix(core): propagate resolved output limit into model request generation by clopca · Pull Request #47532 · anomalyco/opencode · GitHub
Skip to content

fix(core): propagate resolved output limit into model request generation - #47532

Open
clopca wants to merge 1 commit into
anomalyco:v2from
clopca:bedrock-output-limit
Open

fix(core): propagate resolved output limit into model request generation#47532
clopca wants to merge 1 commit into
anomalyco:v2from
clopca:bedrock-output-limit

Conversation

@clopca

@clopca clopca commented Sep 5, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #46595
Related: #47398 (same code site, reproduced on @ai-sdk/openai-compatible), #29363

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

SessionModelRequest.prepare built the model request with generation: undefined unless a session.context hook set a generation value. The model's resolved limit.output was never projected into the request, so no protocol received a maxTokens:

The fix always emits generation with maxTokens resolved in this precedence order: session.context hook value → model.defaults.generation.maxTokensmodel.route.defaults.generation.maxTokensresolved.limit.output. Hook and provider defaults keep winning; the catalog limit only fills the gap. Each protocol already serialized generation.maxTokens into its native field (inferenceConfig.maxTokens, max_tokens, max_output_tokens, generationConfig.maxOutputTokens), so no protocol changes are needed.

This is a re-submission of #46601, rebased on current v2 (the original was auto-closed by the compliance bot because the checklist section was missing). The SessionModelRequest.context options test block that the original PR extended was removed upstream in #46639, so the regression test now lives in the SessionRunnerLLM scenario harness.

How did you verify your code works?

  • New scenario in packages/core/test/session-runner.test.ts ("projects the resolved output limit into the request while preserving hook overrides"): asserts request.generation equals { maxTokens: <limit.output> } with no hooks, and that a hook-provided maxTokens/temperature win over the catalog limit. Confirmed it fails on v2 without the source change and passes with it.
  • Updated two existing expectations that asserted generation was undefined (session-compaction.test.ts, session-runner.test.ts).
  • bun run test test/session-compaction.test.ts test/session-model-request.test.ts test/session-runner.test.ts in packages/core: 218 pass, 0 fail.
  • bun typecheck across the monorepo (33 packages) clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The prepared model request only carried generation values set by hooks or
context, so a model's configured limit.output never reached the provider.
On Bedrock the request was sent without inferenceConfig.maxTokens and the
service applied a much lower implicit budget; with adaptive thinking the
whole budget could be consumed by reasoning, truncating responses at
4,096 tokens despite limit.output=128000.

Project maxTokens with explicit precedence: hook/context override, model
defaults, route defaults, then resolved.limit.output.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant