Skip to content

feat: add Claude Opus 4.6 support with known-model fallbacks#9834

Closed
tinybluedev wants to merge 1 commit intoopenclaw:mainfrom
tinybluedev:feat/claude-opus-4-6-support
Closed

feat: add Claude Opus 4.6 support with known-model fallbacks#9834
tinybluedev wants to merge 1 commit intoopenclaw:mainfrom
tinybluedev:feat/claude-opus-4-6-support

Conversation

@tinybluedev
Copy link

@tinybluedev tinybluedev commented Feb 5, 2026

Summary

Adds support for Claude Opus 4.6 (released 2026-02-05) with a 1M token context window.

Problem

When Anthropic releases a new model, OpenClaw crashes with Unknown model: anthropic/claude-opus-4-6 because:

  1. The upstream @mariozechner/pi-ai model catalog hasn't been updated yet
  2. ModelRegistry.find() returns undefined
  3. resolveModel() has no fallback for known Anthropic models
  4. The model normalizer doesn't recognize opus-4.6 as a shorthand

Changes

Immediate Opus 4.6 support

  • src/agents/defaults.ts — Update DEFAULT_MODEL to claude-opus-4-6, DEFAULT_CONTEXT_TOKENS to 1M
  • src/config/defaults.ts — Update opus alias to anthropic/claude-opus-4-6
  • src/agents/model-selection.ts — Add opus-4.6claude-opus-4-6 normalization

Future-proof fallback mechanism

  • src/agents/model-catalog.ts — Add KNOWN_MODEL_FALLBACKS array that injects model entries when the upstream pi-ai catalog is missing them. Prevents allowlist/status check failures.
  • src/agents/pi-embedded-runner/model.ts — Add ANTHROPIC_MODEL_FALLBACKS map in resolveModel(). When ModelRegistry.find() returns nothing for a known Anthropic model, the fallback constructs a proper model entry with correct API, pricing, and context window. This is the crash fix.

Why a fallback map?

The root cause is a dependency chain: OpenClaw → pi-coding-agent → pi-ai → models.generated.js. When Anthropic drops a new model, this chain can take days to update. The fallback map lets OpenClaw support new models immediately. Adding future models is a one-liner in each fallback map.

Testing

Tested on a live OpenClaw instance (macOS, Anthropic OAuth). Config set to anthropic/claude-opus-4-6 — gateway restarts cleanly, model resolves correctly, no crash.

Greptile Overview

Greptile Summary

This PR updates OpenClaw’s Anthropic defaults to target claude-opus-4-6 (1M context) and adds two fallback mechanisms to avoid crashes when the upstream pi-ai model catalog lags behind new Anthropic releases:

  • src/agents/model-selection.ts normalizes the shorthand opus-4.6 to claude-opus-4-6.
  • src/agents/model-catalog.ts injects a known model entry for Opus 4.6 when it’s missing from the discovered catalog.
  • src/agents/pi-embedded-runner/model.ts adds a hardcoded Anthropic model map intended to be used when ModelRegistry.find() returns nothing.

Main concern: in resolveModel(), the new Anthropic fallback is currently ordered after a generic providerCfg fallback that often triggers first, so known Anthropic models can still resolve to the wrong API/model definition even though the crash is avoided.

Confidence Score: 3/5

  • This PR is close to mergeable but has a functional ordering issue that can resolve Anthropic models incorrectly in common configurations.
  • The changes are localized and the intent is clear, but resolveModel()’s fallback ordering can bypass the intended Anthropic fallback and return a generic model definition for anthropic/claude-opus-4-6. There’s also a cache-reset logic issue in loadModelCatalog() that contradicts its stated behavior.
  • src/agents/pi-embedded-runner/model.ts; src/agents/model-catalog.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

- Update DEFAULT_MODEL to claude-opus-4-6 (1M context window)
- Update opus alias to anthropic/claude-opus-4-6
- Add opus-4.6 shorthand to normalizeAnthropicModelId
- Add KNOWN_MODEL_FALLBACKS in model-catalog.ts to inject models
  when the upstream pi-ai catalog hasn't been updated yet
- Add ANTHROPIC_MODEL_FALLBACKS in resolveModel() to prevent
  'Unknown model' crashes when pi-ai is behind on new releases

This ensures OpenClaw can immediately support newly released
Anthropic models without waiting for upstream pi-ai package
updates. The fallback mechanism is reusable for future model
releases.
Copilot AI review requested due to automatic review settings February 5, 2026 18:54
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 5, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +136 to +139
// Fallback: check known Anthropic models when upstream catalog is behind.
// This prevents crashes when a new model is released but pi-ai hasn't
// been updated yet.
if (normalizeProviderId(provider) === "anthropic") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fallback never triggers

In resolveModel(), the ANTHROPIC_MODEL_FALLBACKS check is unreachable for unknown Anthropic models because the earlier if (providerCfg || modelId.startsWith("mock-")) branch will always run when an Anthropic provider config exists (which it typically does). That branch returns a generic openai-responses model, so a user configuring anthropic/claude-opus-4-6 will still resolve to the wrong API/model instead of your Anthropic fallback.

This means the crash may be avoided, but the resolved model will be incorrect (wrong api, baseUrl, pricing, etc.) in the common case where cfg.models.providers.anthropic is set.

Also appears at src/agents/pi-embedded-runner/model.ts:119-134 (generic providerCfg fallback preceding the Anthropic fallback).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/model.ts
Line: 136:139

Comment:
**Fallback never triggers**

In `resolveModel()`, the `ANTHROPIC_MODEL_FALLBACKS` check is unreachable for *unknown* Anthropic models because the earlier `if (providerCfg || modelId.startsWith("mock-"))` branch will always run when an Anthropic provider config exists (which it typically does). That branch returns a generic `openai-responses` model, so a user configuring `anthropic/claude-opus-4-6` will still resolve to the wrong API/model instead of your Anthropic fallback.

This means the crash may be avoided, but the resolved model will be incorrect (wrong `api`, `baseUrl`, pricing, etc.) in the common case where `cfg.models.providers.anthropic` is set.

Also appears at `src/agents/pi-embedded-runner/model.ts:119-134` (generic providerCfg fallback preceding the Anthropic fallback).

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Additional Comments (2)

src/agents/pi-embedded-runner/model.ts
Incorrect provider config lookup

providerCfg is fetched via providers[provider], but elsewhere in this function you normalize provider IDs (and configs may be keyed by normalized IDs). If a caller passes an unnormalized provider string (e.g. different casing/alias), providers[provider] will be undefined even when the provider is configured, and you’ll fall through to Unknown model (or other fallbacks) incorrectly. Use the same normalized key you computed (normalizedProvider) when looking up providerCfg to keep behavior consistent.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/model.ts
Line: 119:122

Comment:
**Incorrect provider config lookup**

`providerCfg` is fetched via `providers[provider]`, but elsewhere in this function you normalize provider IDs (and configs may be keyed by normalized IDs). If a caller passes an unnormalized provider string (e.g. different casing/alias), `providers[provider]` will be `undefined` even when the provider is configured, and you’ll fall through to `Unknown model` (or other fallbacks) incorrectly. Use the same normalized key you computed (`normalizedProvider`) when looking up `providerCfg` to keep behavior consistent.

How can I resolve this? If you propose a fix, please make it concise.

src/agents/model-catalog.ts
Cache isn’t really reset

When models.length === 0, the code sets modelCatalogPromise = null inside the async initializer, but still returns the already-created promise to the caller. This means callers will still receive a cached empty result for that invocation (and potentially continue using it) despite the comment implying it won’t be cached. If the intent is “don’t cache empties”, you need to avoid returning an empty modelCatalogPromise in the first place (or re-run load before returning).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-catalog.ts
Line: 114:117

Comment:
**Cache isn’t really reset**

When `models.length === 0`, the code sets `modelCatalogPromise = null` inside the async initializer, but still returns the already-created promise to the caller. This means callers will still receive a cached empty result for that invocation (and potentially continue using it) despite the comment implying it won’t be cached. If the intent is “don’t cache empties”, you need to avoid returning an empty `modelCatalogPromise` in the first place (or re-run load before returning).

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for Claude Opus 4.6 (released February 5, 2026) with a 1 million token context window and implements a future-proof fallback mechanism to prevent crashes when new Anthropic models are released before the upstream pi-ai package catalog is updated.

Changes:

  • Updates default model to claude-opus-4-6 with 1M context window
  • Adds opus-4.6 shorthand normalization and model alias
  • Implements two-tier fallback system (model catalog and model resolver) to handle missing upstream model entries

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/agents/defaults.ts Updates DEFAULT_MODEL to claude-opus-4-6 and DEFAULT_CONTEXT_TOKENS to 1M
src/config/defaults.ts Updates the "opus" alias to point to claude-opus-4-6
src/agents/model-selection.ts Adds opus-4.6 shorthand normalization to claude-opus-4-6
src/agents/model-catalog.ts Adds KNOWN_MODEL_FALLBACKS array that injects claude-opus-4-6 when missing from upstream catalog
src/agents/pi-embedded-runner/model.ts Adds ANTHROPIC_MODEL_FALLBACKS map in resolveModel() to construct model entries when ModelRegistry.find() returns nothing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NagliNagli
Copy link

this is very urgent, CC @IanCarroll

@gumadeiras
Copy link
Member

The root cause is a dependency chain: OpenClaw → pi-coding-agent → pi-ai → models.generated.js. When Anthropic drops a new model, this chain can take days to update.

not true; pi has already added opus 4.6 (minutes after Anthropic's announcement). The dependency chain is by design. Will be available in the next OpenClaw release

@gumadeiras gumadeiras closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments