#21313: fix: repair orphaned OpenAI tool results in session history
cli
agents
size: M
Cluster:
Error Handling in Agent Tools
## Summary
- enable transcript tool-use/result pairing repair for OpenAI runs
- keep OpenAI tool-call-id sanitization disabled
- add policy test to lock behavior
## Why
OpenAI Responses rejects orphan `function_call_output` items when no matching prior function call exists. In long-lived sessions with corrupted/trimmed history this can surface as errors like:
- `Invalid 'input[N].call_id': empty string`
- `No tool call found for function call output with call_id ...`
Enabling existing pairing repair for OpenAI drops orphan tool results before provider submission, preventing hard-fail requests.
## Validation
- `pnpm test src/agents/transcript-policy.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR enables OpenAI transcript tool-use/result pairing repair to fix errors with orphaned `function_call_output` items in long-lived sessions with corrupted history. The core change adds `isOpenAi` to the `repairToolUseResultPairing` condition in `src/agents/transcript-policy.ts:106`.
**Key changes:**
- Enabled tool pairing repair for OpenAI provider (main fix for the stated problem)
- Added multi-device Chrome extension relay support with named connections
- Updated browser client and CLI to support relay name parameter
- Modified extension UI to accept custom relay names
**Found issues:**
- Duplicate relay name detection logic at line 585 of `extension-relay.ts` is broken - the Map is keyed by `connectionId` but the code checks `extensionConnections.has(requestedName)` which will never find duplicates
<h3>Confidence Score: 3/5</h3>
- This PR is mostly safe but has one bug that prevents duplicate relay name detection from working
- The core transcript policy fix appears correct and well-tested. However, the extension relay multi-device feature contains a logic bug where duplicate name detection won't work due to checking the wrong Map key. This won't cause runtime errors but will allow duplicate relay names when it shouldn't.
- Pay close attention to `src/browser/extension-relay.ts` line 585 for the duplicate name detection bug
<sub>Last reviewed commit: d679359</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23549: fix: extend repairToolUseResultPairing and allowSyntheticToolResult...
by imjszhang · 2026-02-22
85.3%
#12487: fix(agents): strip orphaned tool_result when tool_use is sanitized ...
by skylarkoo7 · 2026-02-09
84.5%
#8345: fix: prevent synthetic error repair from creating tool_result for d...
by vishaltandale00 · 2026-02-03
83.3%
#7525: Agents: skip errored tool calls during pairing
by justinhuangcode · 2026-02-02
83.3%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
83.1%
#19094: Fix empty tool_call_id and function names in provider transcript pa...
by yxshee · 2026-02-17
83.1%
#19415: fix(agents): enable repairToolUseResultPairing for OpenAI models
by wu-tian807 · 2026-02-17
83.0%
#4844: fix(agents): skip error/aborted assistant messages in transcript re...
by lailoo · 2026-01-30
82.7%
#6687: fix(session-repair): strip malformed tool_use blocks to prevent per...
by NSEvent · 2026-02-01
81.9%
#4700: fix: deduplicate tool_use IDs and enable sanitization for Anthropic
by marcelomar21 · 2026-01-30
81.7%