GeezerVison is showing github.com — fix(opencode): add input limit for compaction (#8465) · bpd1069/opencode@8d720f9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/codex.ts -32Lines changed: 0 additions & 32 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -361,38 +361,6 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> { | 361 | 361 | } | 362 | 362 | } | 363 | 363 |
| 364 | | - if (!provider.models["gpt-5.2-codex"]) { | 365 | | - const model = { | 366 | | - id: "gpt-5.2-codex", | 367 | | - providerID: "openai", | 368 | | - api: { | 369 | | - id: "gpt-5.2-codex", | 370 | | - url: "https://chatgpt.com/backend-api/codex", | 371 | | - npm: "@ai-sdk/openai", | 372 | | - }, | 373 | | - name: "GPT-5.2 Codex", | 374 | | - capabilities: { | 375 | | - temperature: false, | 376 | | - reasoning: true, | 377 | | - attachment: true, | 378 | | - toolcall: true, | 379 | | - input: { text: true, audio: false, image: true, video: false, pdf: false }, | 380 | | - output: { text: true, audio: false, image: false, video: false, pdf: false }, | 381 | | - interleaved: false, | 382 | | - }, | 383 | | - cost: { input: 0, output: 0, cache: { read: 0, write: 0 } }, | 384 | | - limit: { context: 400000, output: 128000 }, | 385 | | - status: "active" as const, | 386 | | - options: {}, | 387 | | - headers: {}, | 388 | | - release_date: "2025-12-18", | 389 | | - variants: {} as Record<string, Record<string, any>>, | 390 | | - family: "gpt-codex", | 391 | | - } | 392 | | - model.variants = ProviderTransform.variants(model) | 393 | | - provider.models["gpt-5.2-codex"] = model | 394 | | - } | 395 | | - | 396 | 364 | // Zero out costs for Codex (included with ChatGPT subscription) | 397 | 365 | for (const model of Object.values(provider.models)) { | 398 | 366 | model.cost = { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/provider/models.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,7 @@ export namespace ModelsDev { | 47 | 47 | .optional(), | 48 | 48 | limit: z.object({ | 49 | 49 | context: z.number(), | | 50 | + input: z.number().optional(), | 50 | 51 | output: z.number(), | 51 | 52 | }), | 52 | 53 | modalities: z | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/provider/provider.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -557,6 +557,7 @@ export namespace Provider { | 557 | 557 | }), | 558 | 558 | limit: z.object({ | 559 | 559 | context: z.number(), | | 560 | + input: z.number().optional(), | 560 | 561 | output: z.number(), | 561 | 562 | }), | 562 | 563 | status: z.enum(["alpha", "beta", "deprecated", "active"]), | @@ -619,6 +620,7 @@ export namespace Provider { | 619 | 620 | }, | 620 | 621 | limit: { | 621 | 622 | context: model.limit.context, | | 623 | + input: model.limit.input, | 622 | 624 | output: model.limit.output, | 623 | 625 | }, | 624 | 626 | capabilities: { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/session/compaction.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ export namespace SessionCompaction { | 34 | 34 | if (context === 0) return false | 35 | 35 | const count = input.tokens.input + input.tokens.cache.read + input.tokens.output | 36 | 36 | const output = Math.min(input.model.limit.output, SessionPrompt.OUTPUT_TOKEN_MAX) || SessionPrompt.OUTPUT_TOKEN_MAX | 37 | | - const usable = context - output | | 37 | + const usable = input.model.limit.input || context - output | 38 | 38 | return count > usable | 39 | 39 | } | 40 | 40 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/session/compaction.test.ts +43-1Lines changed: 43 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,13 +10,19 @@ import type { Provider } from "../../src/provider/provider" | 10 | 10 |
| 11 | 11 | Log.init({ print: false }) | 12 | 12 |
| 13 | | -function createModel(opts: { context: number; output: number; cost?: Provider.Model["cost"] }): Provider.Model { | | 13 | +function createModel(opts: { | | 14 | + context: number | | 15 | + output: number | | 16 | + input?: number | | 17 | + cost?: Provider.Model["cost"] | | 18 | +}): Provider.Model { | 14 | 19 | return { | 15 | 20 | id: "test-model", | 16 | 21 | providerID: "test", | 17 | 22 | name: "Test", | 18 | 23 | limit: { | 19 | 24 | context: opts.context, | | 25 | + input: opts.input, | 20 | 26 | output: opts.output, | 21 | 27 | }, | 22 | 28 | cost: opts.cost ?? { input: 0, output: 0, cache: { read: 0, write: 0 } }, | @@ -70,6 +76,42 @@ describe("session.compaction.isOverflow", () => { | 70 | 76 | }) | 71 | 77 | }) | 72 | 78 |
| | 79 | + test("respects input limit for input caps", async () => { | | 80 | + await using tmp = await tmpdir() | | 81 | + await Instance.provide({ | | 82 | + directory: tmp.path, | | 83 | + fn: async () => { | | 84 | + const model = createModel({ context: 400_000, input: 272_000, output: 128_000 }) | | 85 | + const tokens = { input: 271_000, output: 1_000, reasoning: 0, cache: { read: 2_000, write: 0 } } | | 86 | + expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(true) | | 87 | + }, | | 88 | + }) | | 89 | + }) | | 90 | + | | 91 | + test("returns false when input/output are within input caps", async () => { | | 92 | + await using tmp = await tmpdir() | | 93 | + await Instance.provide({ | | 94 | + directory: tmp.path, | | 95 | + fn: async () => { | | 96 | + const model = createModel({ context: 400_000, input: 272_000, output: 128_000 }) | | 97 | + const tokens = { input: 200_000, output: 20_000, reasoning: 0, cache: { read: 10_000, write: 0 } } | | 98 | + expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(false) | | 99 | + }, | | 100 | + }) | | 101 | + }) | | 102 | + | | 103 | + test("returns false when output within limit with input caps", async () => { | | 104 | + await using tmp = await tmpdir() | | 105 | + await Instance.provide({ | | 106 | + directory: tmp.path, | | 107 | + fn: async () => { | | 108 | + const model = createModel({ context: 200_000, input: 120_000, output: 10_000 }) | | 109 | + const tokens = { input: 50_000, output: 9_999, reasoning: 0, cache: { read: 0, write: 0 } } | | 110 | + expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(false) | | 111 | + }, | | 112 | + }) | | 113 | + }) | | 114 | + | 73 | 115 | test("returns false when model context limit is 0", async () => { | 74 | 116 | await using tmp = await tmpdir() | 75 | 117 | await Instance.provide({ | |
|