fix(opencode): repair tool pairing and strip thoughts for GPT-OSS models
21
10d ago+747+747+012345678901234567890123456789-0-0-0123456789
Problem
When using Google Antigravity with GPT-OSS models (such as \gpt-oss-120b-medium) in OpenCode:
- Multi-turn interactions and interactive tool calls (e.g. \question\ with options) require matching \id\ values between \unctionCall\ and \unctionResponse. Without paired IDs, calls fail or responses cannot be matched.
- The Antigravity backend can return \ hought\ and \ houghtSignature\ blocks, which GPT-OSS models do not support, causing subsequent turn rejections.
- If thoughts are stripped leaving completely empty text parts, Gemini schema validation fails on empty contents.
Solution
- Added
epairGptOssToolPairing\ to \packages/opencode/src/plugin/request-helpers.ts:- Pairs function calls and function responses with the same name in chronological document order, ensuring earlier orphaned responses cannot steal future call IDs.
- Generates or preserves consistent \ ool-call-N\ identifiers across calls and matching responses.
- Strips \ hought, \ houghtSignature, and \ hought_signature\ from parts when sending to \gpt-oss-*\ models.
- Preserves media parts (\inlineData, \ileData) and ensures parts that become completely empty receive fallback \ ext: '.'\ to satisfy schema validation.
- Integrated
epairGptOssToolPairing\ into \prepareAntigravityRequestIn\ in \packages/opencode/src/plugin/request.ts\ when target model is GPT-OSS. - Added comprehensive unit tests in
equest-helpers.test.ts\ and integration tests in
equest.test.ts.
Verification
- All 182 tests passed in
equest-helpers.test.ts\ - All 149 tests passed in
equest.test.ts\ - Biome check passed with 0 errors and 0 warnings
Summary by cubic
Fixes multi-turn tool calls and rejected turns when using Google Antigravity with GPT-OSS models like gpt-oss-120b-medium.
- Pairs
functionCallandfunctionResponseparts with matchingtool-call-NIDs in document order, preserving existing IDs and avoiding collisions. - Strips
thoughtandthoughtSignaturefrom parts for GPT-OSS models, which reject them. - Replaces parts left empty after stripping with a
.text fallback unless they carryinlineDataorfileData.