You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 Remove OpenAI reasoning workarounds - use previousResponseId properly (#300)
## Summary
Removes all OpenAI-specific workarounds for reasoning + web_search bugs
by properly using `previousResponseId` for conversation state
management.
## Problem
The codebase had 266 lines of workarounds to handle OpenAI itemId
errors:
- `openaiReasoningMiddleware.ts` - filtered reasoning parts from
messages
- `openaiReasoningFetch.ts` - intercepted HTTP requests to strip itemIds
- Both files implemented complex logic to work around state management
issues
The original itemId errors occurred because we were **filtering
reasoning parts** while still sending `previousResponseId`, causing
OpenAI to reference missing items.
## Solution
**Use OpenAI's Responses API as designed**: Send `previousResponseId`
WITHOUT filtering anything. OpenAI manages reasoning state internally.
### Changes
- ✅ Enable `previousResponseId` in providerOptions (was disabled)
- ✅ Delete `openaiReasoningMiddleware.ts` (128 lines)
- ✅ Delete `openaiReasoningFetch.ts` (138 lines)
- ✅ Remove middleware wrappers from providerFactory and aiService
- ✅ **Keep reasoning parts in transformModelMessages** - OpenAI needs
them for `previousResponseId` to work
- ✅ Simplify OpenAI provider initialization
- ✅ Update tests to expect reasoning parts preserved
### Root Cause
The bug was **always fixable** with proper use of `previousResponseId`.
The fix works with both:
- Old SDK versions ([email protected], @ai-sdk/[email protected]) ✅ tested
- New SDK versions ([email protected], @ai-sdk/[email protected]) ✅ tested
The workarounds were unnecessary - we just needed to use the API
correctly.
### Key Insight (Credit: Codex)
Codex correctly identified that `transformModelMessages` was still
stripping reasoning parts, which would defeat the purpose of using
`previousResponseId`. The complete fix required:
- Enabling `previousResponseId` in provider options
- Keeping reasoning parts in messages sent to OpenAI
- Removing all workaround code
## Testing
```bash
TEST_INTEGRATION=1 bun x jest tests/ipcMain/openai-web-search.test.ts
```
- ✅ Test passes consistently in ~50-90 seconds
- ✅ No itemId errors
- ✅ Reasoning + web_search works correctly
- ✅ All type checks pass
- ✅ Tested with both old and new SDK versions
## Impact
- **-266 lines** of workaround code deleted
- **-59 lines** total net change
- **0 lines** of new complexity added
- Zero jank 🎉
_Generated with `cmux`_
0 commit comments