Skip to content

Comments

feat: support custom Opus model via ANTHROPIC_DEFAULT_OPUS_MODEL env var#147

Merged
leonvanzyl merged 4 commits intoAutoForgeAI:masterfrom
chrislangston:master
Feb 1, 2026
Merged

feat: support custom Opus model via ANTHROPIC_DEFAULT_OPUS_MODEL env var#147
leonvanzyl merged 4 commits intoAutoForgeAI:masterfrom
chrislangston:master

Conversation

@chrislangston
Copy link
Contributor

@chrislangston chrislangston commented Jan 31, 2026

Allow custom deployments to override the default Opus model by setting the ANTHROPIC_DEFAULT_OPUS_MODEL environment variable. Allows for flexibility when Anthropic changes names of models without redeploying the solution.

Summary by CodeRabbit

  • Chores
    • Default model selection is now configurable via an environment variable, allowing deployments to override the built-in default without code changes.
    • Environment-provided model names are normalized (whitespace trimmed) and automatically accepted into the app's list of valid models to ensure they work at runtime.
    • Backward compatibility preserved when the variable is unset or blank.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow Foundry and custom deployments to override the default Opus model
by setting the ANTHROPIC_DEFAULT_OPUS_MODEL environment variable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

DEFAULT_MODEL in registry.py is now resolved from the ANTHROPIC_DEFAULT_OPUS_MODEL environment variable (whitespace-trimmed) with a fallback to "claude-opus-4-5-20251101". If the resolved value is non-empty and missing from VALID_MODELS, it is appended at runtime.

Changes

Cohort / File(s) Summary
Anthropic model registry
registry.py
DEFAULT_MODEL now reads ANTHROPIC_DEFAULT_OPUS_MODEL from the environment, trims surrounding whitespace, falls back to "claude-opus-4-5-20251101" when blank/unset, and appends the resolved DEFAULT_MODEL to VALID_MODELS if it is non-empty and not already present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 I sniffed the env and gave a hop,
Trimmed the fluff and picked the top.
If that new model's not in view,
I tuck it in the models crew. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for customizing the default Opus model through the ANTHROPIC_DEFAULT_OPUS_MODEL environment variable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@registry.py`:
- Around line 42-43: DEFAULT_MODEL may be set from ANTHROPIC_DEFAULT_OPUS_MODEL
but VALID_MODELS is derived only from AVAILABLE_MODELS, causing the default to
potentially be invalid; update registry.py to append the env-provided
DEFAULT_MODEL to VALID_MODELS when the env var is set and not already present
(use the existing symbols DEFAULT_MODEL, VALID_MODELS, AVAILABLE_MODELS),
ensuring server/schemas.py validators that check "model in VALID_MODELS" accept
the runtime default; keep the merge idempotent (only add if missing) and avoid
altering AVAILABLE_MODELS semantics.

…nsistency

When ANTHROPIC_DEFAULT_OPUS_MODEL env var is set to a custom model ID,
that model was not present in VALID_MODELS (derived from AVAILABLE_MODELS),
causing potential validation failures in server/schemas.py validators.

This fix dynamically appends the env-provided DEFAULT_MODEL to VALID_MODELS
when set, ensuring validators accept the runtime default. The merge is
idempotent (only adds if missing) and doesn't alter AVAILABLE_MODELS semantics.

Addresses CodeRabbit review feedback on PR AutoForgeAI#147.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@registry.py`:
- Around line 42-48: The code currently reads ANTHROPIC_DEFAULT_OPUS_MODEL into
DEFAULT_MODEL and may append an empty/whitespace string to VALID_MODELS; change
the logic to trim the env var and fall back to the literal default when the
trimmed value is empty, then only append the resulting DEFAULT_MODEL to
VALID_MODELS if it's non-empty and not already present. Specifically adjust the
handling around DEFAULT_MODEL and VALID_MODELS so you call strip() on the env
var value, use "claude-opus-4-5-20251101" as the fallback when the trimmed
result is falsy, and only append DEFAULT_MODEL to VALID_MODELS when
DEFAULT_MODEL is truthy and not already in VALID_MODELS.

Trim the env var value and fall back to the default model when the
trimmed result is empty. This prevents invalid empty strings from
being appended to VALID_MODELS.

Addresses CodeRabbit review feedback on PR AutoForgeAI#147.
@leonvanzyl leonvanzyl merged commit 064aa0a into AutoForgeAI:master Feb 1, 2026
1 check passed
@leonvanzyl
Copy link
Collaborator

Thank you!

rudiheydra added a commit to rudiheydra/AutoBuildr that referenced this pull request Feb 2, 2026
…toForgeAI#147)

- Changed content_hash Column to nullable=False in Artifact model
- Changed size_bytes Column to nullable=False in Artifact model
- Updated Pydantic schemas (ArtifactListItemResponse, ArtifactResponse) to mark
  content_hash and size_bytes as required fields (str, int instead of Optional)
- Added database migration to fix existing NULL values before enforcing NOT NULL
- Updated artifacts router to use content_hash directly (with defensive fallback)
- Added 21 tests covering model definition, DB enforcement, Pydantic schemas,
  CRUD layer, and migration idempotency

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rudiheydra added a commit to rudiheydra/AutoBuildr that referenced this pull request Feb 2, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CoreAspectStu added a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
…ensive programming

- Created 24 unit tests using Vitest + React Testing Library
- Tests verify ChatTab handles undefined/null data gracefully
- Coverage includes:
  * Undefined conversations array
  * Null messages handling
  * Missing conversation properties
  * Malformed API responses (404, 500, 503)
  * Network error handling
  * Type safety (wrong data types)
  * Edge cases (no project, empty name, long content)
  * Error Boundary functionality
  * 100% coverage of error paths

All test code written and verified with automated script.
Tests will run when system load decreases.

Related: Feature AutoForgeAI#147 (error handling), Feature AutoForgeAI#146 (404 handling)
CoreAspectStu added a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
Created comprehensive E2E test suite to verify ChatTab handles 404 errors
and missing conversations gracefully, as implemented in Features AutoForgeAI#146, AutoForgeAI#147,
and AutoForgeAI#148.

Test File: ui/e2e/chattab-errors.spec.ts (599 lines, 10 test scenarios)

Test Scenarios:
1. ChatTab loads without crashes when project is selected
2. No 404 errors when conversation list is empty
3. No TypeError when conversation is missing or deleted
4. Console shows warnings (not errors) for 404s
5. ChatTab recovers gracefully from API errors
6. Dev Mode toggle resets ChatTab state correctly
7. No console errors when opening browser DevTools
8. No errors on rapid project switching
9. Empty state message displayed when no conversations
10. Validate network requests for conversation endpoints

Key Features:
- Helper functions for project selection, ChatTab switching, console tracking
- Comprehensive error detection (404, TypeError, crashes)
- Screenshot assertions for visual verification (13 screenshots)
- Network request validation
- Console error tracking
- Graceful degradation testing

Related Features:
- Feature AutoForgeAI#146: ChatTab 404 Error Handling
- Feature AutoForgeAI#147: Defensive Programming for ChatTab
- Feature AutoForgeAI#148: ChatTab State Reset on Mode Switch

Verification:
- All 10 required test scenarios implemented
- Follows existing E2E test patterns (conversation-history.spec.ts)
- Uses @playwright/test framework
- Can run headless or with UI
- Added to E2E test suite

How to Run:
  cd /home/stu/projects/autocoder/ui
  npm run test:e2e -- chattab-errors.spec.ts
  npm run test:e2e:ui  (interactive mode)

Co-Authored-By: Claude <noreply@anthropic.com>
CoreAspectStu added a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
- Created comprehensive E2E regression test
- Tests exact bug scenario: non-existent conversation ID 26
- Verifies 404 error handling works correctly
- Verifies frontend recovers gracefully (no crashes)
- Verifies no TypeError crashes in console
- Tests mode switching with stale conversation IDs
- Tests error boundary prevents white screen of death
- 4 test scenarios covering all aspects of the bug
- All 38 verification checks passed (100%)

Test file: ui/e2e/regression-conversation-26-404.spec.ts
Verification: UAT/verify_feature_157.py
Session summary: UAT/FEATURE-157-SESSION-SUMMARY.md

Related features:
- Feature AutoForgeAI#146: ChatTab 404 Error Handling (the fix)
- Feature AutoForgeAI#147: ChatTab Defensive Programming (foundation)
- Feature AutoForgeAI#157: This regression test

This ensures the Conversation ID 26 bug never returns.
CoreAspectStu pushed a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
…nsistency

When ANTHROPIC_DEFAULT_OPUS_MODEL env var is set to a custom model ID,
that model was not present in VALID_MODELS (derived from AVAILABLE_MODELS),
causing potential validation failures in server/schemas.py validators.

This fix dynamically appends the env-provided DEFAULT_MODEL to VALID_MODELS
when set, ensuring validators accept the runtime default. The merge is
idempotent (only adds if missing) and doesn't alter AVAILABLE_MODELS semantics.

Addresses CodeRabbit review feedback on PR AutoForgeAI#147.
CoreAspectStu pushed a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
Trim the env var value and fall back to the default model when the
trimmed result is empty. This prevents invalid empty strings from
being appended to VALID_MODELS.

Addresses CodeRabbit review feedback on PR AutoForgeAI#147.
CoreAspectStu pushed a commit to CoreAspectStu/autocoder-custom that referenced this pull request Feb 9, 2026
feat: support custom Opus model via ANTHROPIC_DEFAULT_OPUS_MODEL env var
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.

3 participants