Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

Centralizes all model metadata into knownModels.ts and fixes a bug where previousResponseId was incorrectly passed between different models or contexts.

Changes

1. Centralized Model Constants (knownModels.ts)

  • Fixed GPT_MINI model ID: Changed to gpt-5.1-codex-mini (correct LiteLLM name)
  • Eliminated duplication: ID strings auto-constructed from provider + providerModelId
  • Removed string constant exports: Callers now use KNOWN_MODELS.SONNET.id directly
  • Programmatic MODEL_NAMES: Auto-groups models by provider via .reduce()
  • Type-safe keys: KnownModelKey derived from object keys, never out of sync
  • Integration test: Verifies all models exist in models.json

2. Fixed previousResponseId Bug

Problem: We were passing previousResponseId from any previous OpenAI message, causing:

  • APICallError: Previous response with id 'resp_...' not found when switching models
  • Invalid response IDs for non-reasoning models
  • Expired response IDs

Solution: Now only pass previousResponseId when:

  1. Current model uses reasoning (reasoningEffort is set)
  2. Previous message was from the same model
  3. Stop searching if we find a different model (context changed)

3. Test Improvements

  • Updated PROVIDER_CONFIGS to use KNOWN_MODELS constants
  • Added multi-turn integration test for CODEX model
  • Verifies responseId persistence across conversation turns

Benefits

  • Single source of truth: Only edit one place to update model versions
  • No manual maintenance: All derived collections auto-update
  • Regression prevention: Integration test catches model data issues
  • Bug fix: Prevents APICallError when using reasoning models

Testing

make typecheck  # ✅ All checks pass
TEST_INTEGRATION=1 bun x jest tests/models/knownModels.test.ts  # ✅ 2/2 passed

Generated with mux

root and others added 3 commits November 14, 2025 02:00
- Fix GPT_MINI to use correct model ID (gpt-5.1-codex-mini)
- Remove duplicated string constant exports (SONNET, GPT, etc.)
  - Callers now use KNOWN_MODELS.SONNET.id directly
  - Export KNOWN_MODELS object for direct access
- Build MODEL_NAMES programmatically from KNOWN_MODELS
  - Groups by provider automatically
  - No manual duplication needed
- Add integration test verifying all known models exist in models.json
  - Tests run outside IPC layer
  - Catches missing/renamed models early

Generated with `mux`
Fixes APICallError when switching models or using non-reasoning models.

Previously, we would pass previousResponseId from any previous OpenAI
assistant message, causing errors when:
- Switching between models (e.g., gpt-5.1-codex → gpt-5-pro)
- Using models without reasoning support
- Response IDs expired or invalid

Now we:
1. Only extract previousResponseId when current model uses reasoning
2. Only use it if the previous message was from the same model
3. Stop searching if we encounter a different model (conversation context changed)

This prevents "Previous response with id 'resp_...' not found" errors
when the response ID is invalid for the current model/context.

Generated with `mux`
- Add integration test for multi-turn conversations with reasoning models
  - Verifies previousResponseId is passed correctly between turns
  - Tests GPT_CODEX specifically to catch response ID bugs
  - Validates responseId exists in assistant message metadata
- Update PROVIDER_CONFIGS to use KNOWN_MODELS constants
  - Ensures tests use the same model IDs as production code
  - Prevents drift between test models and known models

Generated with `mux`
@ammar-agent ammar-agent force-pushed the centralize-model-constants branch from c3807ea to 563e808 Compare November 14, 2025 02:23
@ammar-agent ammar-agent force-pushed the centralize-model-constants branch from 563e808 to 8fb9ad1 Compare November 14, 2025 02:24
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammar-agent ammar-agent force-pushed the centralize-model-constants branch 2 times, most recently from 4d4a2a3 to b141d20 Compare November 14, 2025 02:26
@ammar-agent ammar-agent force-pushed the centralize-model-constants branch from b141d20 to 7ca2a67 Compare November 14, 2025 02:26
_Generated with `mux`_
The E2E test failure was caused by MODEL_ABBREVIATIONS being sorted
alphabetically, which made gpt-5.1-codex the first model in the LRU
instead of the default anthropic:claude-sonnet-4-5.

Fix: Ensure defaultModel is always first in DEFAULT_MODELS array.

_Generated with `mux`_
@ammario ammario merged commit 7829bf1 into main Nov 14, 2025
13 checks passed
@ammario ammario deleted the centralize-model-constants branch November 14, 2025 16:31
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