Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function mimeToModality(mime: string): Modality | undefined {
return undefined
}

export const OUTPUT_TOKEN_MAX = Flag.OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX || Infinity
export const OUTPUT_TOKEN_MAX = Flag.OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX || 32_000

// Maps npm package to the key the AI SDK expects for providerOptions
function sdkKey(npm: string): string | undefined {
Expand Down
18 changes: 18 additions & 0 deletions packages/opencode/test/session/compaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ describe("session.compaction.isOverflow", () => {
),
)

it.live(
"BUG: no overflow when output limit equals context (grok-4.5 shape)",
provideTmpdirInstance(() =>
Effect.gen(function* () {
const compact = yield* SessionCompaction.Service
// grok-4.5: context 500K, output 500K, no limit.input
const model = createModel({ context: 500_000, output: 500_000 })

// 31K total — a normal early-conversation size. usable must be
// context - reservedOutput (capped at OUTPUT_TOKEN_MAX = 32K), i.e. 468K.
// Regression: OUTPUT_TOKEN_MAX defaulted to Infinity, making
// usable = 500K - 500K = 0 and overflowing on every single message.
const tokens = { input: 30_000, output: 1_000, reasoning: 0, cache: { read: 0, write: 0 } }
expect(yield* compact.isOverflow({ tokens, model })).toBe(false)
}),
),
)

it.live(
"returns false when model context limit is 0",
provideTmpdirInstance(() =>
Expand Down