Skip to content

fix(provider): cap OUTPUT_TOKEN_MAX at 32K so usable() stays above zero - #3

Open
NormalDudeBro wants to merge 1 commit into
bb-deeplearning:codemaxxxingfrom
NormalDudeBro:fix/grok45-output-token-max
Open

fix(provider): cap OUTPUT_TOKEN_MAX at 32K so usable() stays above zero#3
NormalDudeBro wants to merge 1 commit into
bb-deeplearning:codemaxxxingfrom
NormalDudeBro:fix/grok45-output-token-max

Conversation

@NormalDudeBro

Copy link
Copy Markdown

Summary

\OUTPUT_TOKEN_MAX\ in the provider transform defaults to \Infinity\ when the \OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX\ env flag is unset.

For models whose \limit.output\ equals \limit.context\ with no \limit.input\ (e.g. \xai/grok-4.5: 500K/500K), \usable()\ in \session/overflow.ts\ computes:

\
usable = max(0, context - maxOutputTokens(model)) = max(0, 500K - 500K) = 0
\\

With \usable() = 0, \isOverflow()\ returns \count >= 0\ — true for every single message. Every finished step triggers auto-compaction, and the auto-continue step triggers another, repeating until the user aborts.

This restores the 32K output-reservation cap as the default (the fork's own compaction tests document \usable = context - output = 200K - 32K = 168K). The \OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX\ env flag remains as an explicit override.

Tests

  • Regression test in \ est/session/compaction.test.ts\ for the grok-4.5 shape (context 500K, output 500K, no input limit): 31K usage must not overflow.
  • \�un test test/session/compaction.test.ts\ — 49 pass
  • \�un test test/plugin/cloudflare.test.ts test/session/llm.test.ts\ — 18 pass
  • \�un typecheck\ (opencode package) — clean

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant