Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Nov 14, 2025

Problem

OpenAI sometimes invalidates stored previousResponseId values that were working moments ago. When this happens mid-stream, the frontend automatically retries, but the retry would include the same invalid ID and fail again, creating an unrecoverable error loop.

Solution

Track invalidated response IDs in memory when OpenAI rejects them with previous_response_not_found. When buildProviderOptions constructs the next request (during frontend retry), filter out any IDs that have been marked as lost.

Also fixed ripgrep stdin detection: bash tool now redirects stdin from /dev/null so CLI tools don't treat it as a pipe.

Changes

  • StreamManager: Added lostResponseIds Set to track invalidated OpenAI response IDs
  • StreamManager.recordLostResponseIdIfApplicable(): Detect previous_response_not_found errors during streaming and extract the rejected ID from the error message
  • StreamManager.isResponseIdLost(): Public API for checking if an ID is invalid
  • buildProviderOptions(): Filter out lost IDs when extracting previousResponseId from message history
  • bash.ts: Prepend exec </dev/null to all commands to close stdin (fixes ripgrep treating stdin as a pipe)

Testing

  • Unit tests for lost ID tracking and extraction logic
  • Existing bash tool tests verify stdin behavior
  • Manually verified fix resolves the unrecoverable error

Generated with mux

@ammar-agent ammar-agent changed the title 🤖 fix: retry when openai drops previous response 🤖 fix: handle lost OpenAI previousResponseIds on frontend retry Nov 14, 2025
@ammario ammario merged commit f73e14e into main Nov 14, 2025
13 checks passed
@ammario ammario deleted the fix-chat-missing-response-id branch November 14, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants