Skip to content

Fix #107: Use configured tier model on Ollama/custom endpoints instead of Claude ID - #328

Open
zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-107-dennis
Open

zwanski-start wants to merge 1 commit into
AutoForgeAI:masterfrom
zwanski-start:swarm/issue-107-dennis

Conversation

@zwanski-start

Copy link
Copy Markdown

Closes #107

Problem

With Ollama (or any custom ANTHROPIC_BASE_URL) configured via .env, the agent still requested claude-opus-4-5-20251101 and got a 404. The model passed to the CLI comes from the stored UI setting (api_model or model, falling back to DEFAULT_MODEL). That value is a full Claude ID. The Claude CLI applies ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU}_MODEL only to the tier aliases (opus/sonnet/haiku), not to explicit IDs, so the Claude ID went straight to Ollama. Switching to Sonnet in the UI hit the same problem.

Fix

  • client.py: new resolve_model_for_endpoint(model, sdk_env). When ANTHROPIC_BASE_URL is set (and Vertex is off) and the model is a claude-* ID, it is replaced with the matching tier override (opus → ANTHROPIC_DEFAULT_OPUS_MODEL, sonnet → ..._SONNET_..., haiku → ..._HAIKU_...). Non-Claude model names, missing or blank overrides, Vertex, and the plain Anthropic API are left alone. It's applied in create_client, the single point where the model reaches the SDK, so the single-agent, parallel, testing and scheduled paths are all covered.
  • The Ollama/Alternative API startup log lines now print the model actually used, which makes this kind of mismatch easy to spot.

Verification

  • Added TestResolveModelForEndpoint (9 cases) to test_client.py: venv/bin/python -m pytest test_client.py passes (30 tests).
  • ruff check . is clean and python test_security.py passes.
  • mypy client.py reports only a pre-existing unused-ignore on the effort= line (it depends on the local SDK version and is unrelated).

Assumptions

  • Settings-UI providers (Ollama/GLM/etc. selected in the UI) already pass api_model and set all three overrides, so this only changes behavior for .env-configured endpoints, or when a Claude ID still reaches a custom endpoint.
  • Proxies that really serve Claude models usually set no tier overrides, or set them to Claude IDs, so they keep working.

🤖 Generated with Claude Code

… endpoints

The UI/stored model (e.g. claude-opus-4-7) was passed verbatim via --model.
The Claude CLI only applies ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU}_MODEL to
tier aliases, so Ollama and other custom endpoints received a Claude model
ID they don't serve (404 model not found). When ANTHROPIC_BASE_URL is set
(non-Vertex), resolve a claude-* model to the matching tier override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zwanski-start

Copy link
Copy Markdown
Author

🔍 QA report: ✅ Passed

Tester: Ken (cubefarm agent, in a fresh session) · Round: 1 · Author: Dennis

The fix works: with Ollama set up through .env (ANTHROPIC_BASE_URL plus tier overrides), a stored Claude model ID such as claude-opus-4-5-20251101, or a Sonnet pick, is now replaced with the matching ANTHROPIC_DEFAULT_*_MODEL. Before, it was sent as is and got a 404. A side-by-side check of create_client confirms master sends the Claude ID and this branch sends qwen2.5-coder. Plain Anthropic, Vertex and Settings-UI providers are unchanged. Lint, tests, the UI build and a server smoke test show no regressions; the remaining test and mypy failures are the same on master.

Check Details
✅ Issue #107 repro: .env Ollama setup with a stored Claude opus ID Called create_client with ClaudeSDKClient mocked and get_effective_sdk_env patched to the issue's env. Master passed model=claude-opus-4-5-20251101; the PR passes qwen2.5-coder and logs "Ollama Mode: Using local model 'qwen2.5-coder'".
✅ Issue repro: picking Sonnet in the UI claude-sonnet-4-6 now resolves to the ANTHROPIC_DEFAULT_SONNET_MODEL value. On master it was sent unchanged.
✅ No regression for plain Anthropic, Vertex and Settings-UI Ollama No base URL: claude-opus-4-7 unchanged. CLAUDE_CODE_USE_VERTEX=1: unchanged. Settings-UI Ollama with api_model qwen3-coder: unchanged.
✅ Edge case: missing tier override claude-haiku-4-5 with no haiku override passes through unchanged, as the PR states. The new log line shows that model name, so a mismatch is visible.
✅ Code review Small pure function, applied in create_client, which every agent path uses. Log lines print only the model name, no secrets. Security allowlist and middleware untouched. 9 new unit tests cover the cases.
✅ Python test suite compared with master 153 passed, 21 failed (test_devserver_security.py). The failure list is identical with master's client.py and test_client.py, so the failures come from elsewhere.
✅ Server boots, REST routes and WebSocket uvicorn on 127.0.0.1:5345 with an isolated HOME. GET / 200, /api/settings 200, /api/projects 200, POST /api/projects with {} returns 422. Creating a project and a feature returned 200. The dashboard showed the WebSocket as Live.
✅ UI renders in the browser Dashboard and dependency graph rendered with the test feature. No console errors or warnings. This is a backend-only change, so the UI e2e suite was not needed.
🧪 Commands run
Command Result
ruff check . All checks passed
mypy . 24 errors in 9 files, same as master (the client.py unused-ignore is pre-existing)
python -m pytest -q test_client.py 30 passed
python -m pytest -q 153 passed, 21 failed (same 21 failures on master)
python test_security.py ALL TESTS PASSED
python test_security_integration.py ALL INTEGRATION TESTS PASSED
python repro.py (create_client with SDK mocked, PR vs master client.py) PR: Claude IDs mapped to qwen2.5-coder; master: Claude IDs sent unchanged (bug reproduced)
npm --prefix ui run build success
npm --prefix ui run lint 0 errors, 6 pre-existing warnings
uvicorn server.main:app --port 5345 + curl route probes 200/200/200/422 as expected

No browser screenshots were taken in this round.

Posted by cubefarm · merges automatically once GitHub's checks pass

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.

Ollama mode tries to load claude-opus-4.5

1 participant