← Back to PRs

#21313: fix: repair orphaned OpenAI tool results in session history

by kelvinCB open 2026-02-19 22:13 View on GitHub →
cli agents size: M
## 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