Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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

Moved model_not_found detection logic from error handling into the categorizeError method to eliminate code duplication.

Problem

There were two bugs related to model_not_found error handling:

  1. Code duplication: The model_not_found detection logic existed in two places:

    • In categorizeError (but it returned 'api' for 404s)
    • In error handling (as a workaround to override 'api' to 'model_not_found')
  2. Potential retry spam: If the workaround code was bypassed, 404 errors would be classified as 'api', which is not in the NON_RETRYABLE_STREAM_ERRORS list, leading to retry spam.

Solution

Refactored categorizeError to directly return 'model_not_found' for both:

  • OpenAI: 400 with error.code === 'model_not_found'
  • Anthropic: 404 with error.type === 'not_found_error'

Removed the duplicate override logic from error handling, leaving only the error message enhancement.

Benefits

  • Single source of truth for error classification
  • Prevents retry spam because model_not_found is in NON_RETRYABLE_STREAM_ERRORS
  • Cleaner code with no duplication
  • Maintainable - future changes only need to happen in one place

Test Coverage

Backend (IPC layer integration tests):

  • ✅ Anthropic 404 errors are classified as model_not_found
  • ✅ OpenAI 400 errors are classified as model_not_found

Frontend (unit tests in retryEligibility.test.ts):

  • model_not_found is in NON_RETRYABLE_STREAM_ERRORS list
  • isEligibleForAutoRetry returns false for model_not_found errors

Generated with cmux

Moved model_not_found detection logic from error handling into
the categorizeError method to eliminate code duplication. This ensures
consistent error classification across all error handling paths.

Previously, the logic existed in two places:
1. In categorizeError (but returned 'api' for 404s)
2. In error handling (as a workaround to override 'api' to 'model_not_found')

Now categorizeError directly returns 'model_not_found' for both:
- OpenAI: 400 with error.code === 'model_not_found'
- Anthropic: 404 with error.type === 'not_found_error'

This prevents retry spam because model_not_found is in the
NON_RETRYABLE_STREAM_ERRORS list in retryEligibility.ts.

## Test Coverage

**Backend (IPC layer integration tests)**:
- ✅ Anthropic 404 errors are classified as model_not_found
- ✅ OpenAI 400 errors are classified as model_not_found

**Frontend (unit tests in retryEligibility.test.ts)**:
- ✅ model_not_found is in NON_RETRYABLE_STREAM_ERRORS list
- ✅ isEligibleForAutoRetry returns false for model_not_found errors

Generated with `cmux`
Removed manual loadTokenizerModules() calls from 8 integration test files.
The tokenizer is already preloaded globally in tests/setup.ts via the
preloadTestModules() function, which runs once per Jest worker.

This eliminates duplication and ensures consistent test initialization
across all integration tests.

Files cleaned up:
- anthropic1MContext.test.ts
- forkWorkspace.test.ts
- modelNotFound.test.ts
- openai-web-search.test.ts
- resumeStream.test.ts
- sendMessage.test.ts
- streamErrorRecovery.test.ts
- truncate.test.ts

Generated with `cmux`
@ammario ammario changed the title 🤖 refactor: consolidate model_not_found error classification 🤖 fix: correctly classify (and not retry) model not found errors Nov 8, 2025
@ammario ammario enabled auto-merge November 8, 2025 17:01
@ammario ammario added this pull request to the merge queue Nov 8, 2025
Merged via the queue into main with commit e37906b Nov 8, 2025
13 checks passed
@ammario ammario deleted the fix-retry-spam branch November 8, 2025 17:15
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