Skip to content

feat(amazon-bedrock-mantle): add known context windows for open-weight Mantle models#68725

Open
wirjo wants to merge 4 commits intoopenclaw:mainfrom
wirjo:feat/bedrock-mantle-opus-47
Open

feat(amazon-bedrock-mantle): add known context windows for open-weight Mantle models#68725
wirjo wants to merge 4 commits intoopenclaw:mainfrom
wirjo:feat/bedrock-mantle-opus-47

Conversation

@wirjo
Copy link
Copy Markdown
Contributor

@wirjo wirjo commented Apr 18, 2026

Problem

Mantle's /v1/models endpoint returns only model IDs — no token limit metadata. Discovery hardcodes contextWindow: 32000 for every model, which is wrong for most:

  • MiniMax M2/M2.1: 1,000,000 (gets 32K)
  • Qwen3 Coder: 256,000 (gets 32K)
  • DeepSeek V3.x, GLM 4.x, Nemotron: 128,000 (gets 32K)

This causes the same premature context overflow and wrong compaction thresholds as #65952 (the amazon-bedrock equivalent).

Fix

Add a KNOWN_CONTEXT_WINDOWS lookup table for open-weight models currently available on Mantle. Raise the default fallback from 32K → 128K for unknown models.

MiniMax M2 / M2.1              → 1,000,000
Qwen3 Coder (480B/Next/30B)    → 256,000
Qwen3 235B / 32B               → 128,000
DeepSeek V3.1 / V3.2           → 128,000
GLM 4.6 / 4.7 / 4.7 Flash      → 128,000
NVIDIA Nemotron (all variants)  → 128,000

Claude models are intentionally excluded — they use a separate Anthropic-native endpoint on Mantle (/anthropic/v1/messages), not the OpenAI-compatible /v1/chat/completions endpoint that this extension handles. Claude model metadata is managed by the amazon-bedrock extension (#65952).

Changes

File Change
extensions/amazon-bedrock-mantle/discovery.ts +41/-2 — context window map, resolveKnownContextWindow(), default bump

Single file, no type system changes.

References

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 18, 2026

Greptile Summary

Adds Claude Opus 4.7 support on Bedrock Mantle by enriching model discovery with a static context-window map, an image-input allowlist, and reasoning pattern entries for the new Claude generation. The tests are well-structured and cover the new code paths. Two minor P2 observations about the allowlist design are noted inline.

Confidence Score: 5/5

Safe to merge — all findings are P2 style suggestions with no correctness impact on current behavior.

The changes are well-scoped, all current models are covered correctly, and the new test suite directly validates context windows, image input, and reasoning flags. The only issues are maintenance-oriented P2 concerns about how future Claude models will be handled.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/amazon-bedrock-mantle/discovery.ts
Line: 51-56

Comment:
**Inconsistent matching strategy vs. stated intent**

The PR description states "all Claude models on Mantle support image input," but `resolveInputModalities` uses an explicit allowlist with `modelId.includes(p)`. Meanwhile, `REASONING_PATTERNS` uses short substrings like `"claude-opus-4-7"` that naturally cover future variants. A new Claude model added to Mantle but not to `IMAGE_INPUT_MODELS` will silently get `input: ["text"]` — contradicting the stated intent. A `modelId.includes("anthropic.claude")` pattern check would be consistent with `REASONING_PATTERNS`' approach and eliminate the need to keep two parallel lists in sync.

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

---

This is a comment left during a code review.
Path: extensions/amazon-bedrock-mantle/discovery.ts
Line: 39-45

Comment:
**Two parallel lists to keep in sync**

`IMAGE_INPUT_MODELS` and the keys of `KNOWN_CONTEXT_WINDOWS` are identical, which means every new Claude model on Mantle requires updating both structures. Since `resolveInputModalities` already iterates, consider deriving image support directly from `KNOWN_CONTEXT_WINDOWS` (i.e., `Object.keys(KNOWN_CONTEXT_WINDOWS).some((k) => modelId.includes(k))`) or consolidating into a single model metadata map to reduce the maintenance surface.

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

Reviews (1): Last reviewed commit: "feat(amazon-bedrock-mantle): add Claude ..." | Re-trigger Greptile

Comment on lines +51 to +56
function resolveInputModalities(modelId: string): Array<"text" | "image"> {
if (IMAGE_INPUT_MODELS.some((p) => modelId.includes(p))) {
return ["text", "image"];
}
return ["text"];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Inconsistent matching strategy vs. stated intent

The PR description states "all Claude models on Mantle support image input," but resolveInputModalities uses an explicit allowlist with modelId.includes(p). Meanwhile, REASONING_PATTERNS uses short substrings like "claude-opus-4-7" that naturally cover future variants. A new Claude model added to Mantle but not to IMAGE_INPUT_MODELS will silently get input: ["text"] — contradicting the stated intent. A modelId.includes("anthropic.claude") pattern check would be consistent with REASONING_PATTERNS' approach and eliminate the need to keep two parallel lists in sync.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/amazon-bedrock-mantle/discovery.ts
Line: 51-56

Comment:
**Inconsistent matching strategy vs. stated intent**

The PR description states "all Claude models on Mantle support image input," but `resolveInputModalities` uses an explicit allowlist with `modelId.includes(p)`. Meanwhile, `REASONING_PATTERNS` uses short substrings like `"claude-opus-4-7"` that naturally cover future variants. A new Claude model added to Mantle but not to `IMAGE_INPUT_MODELS` will silently get `input: ["text"]` — contradicting the stated intent. A `modelId.includes("anthropic.claude")` pattern check would be consistent with `REASONING_PATTERNS`' approach and eliminate the need to keep two parallel lists in sync.

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

Comment on lines +39 to +45
const IMAGE_INPUT_MODELS = [
"anthropic.claude-opus-4-7",
"anthropic.claude-opus-4-6-v1",
"anthropic.claude-sonnet-4-6",
"anthropic.claude-sonnet-4-5-20250929-v1:0",
"anthropic.claude-haiku-4-5-20251001-v1:0",
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Two parallel lists to keep in sync

IMAGE_INPUT_MODELS and the keys of KNOWN_CONTEXT_WINDOWS are identical, which means every new Claude model on Mantle requires updating both structures. Since resolveInputModalities already iterates, consider deriving image support directly from KNOWN_CONTEXT_WINDOWS (i.e., Object.keys(KNOWN_CONTEXT_WINDOWS).some((k) => modelId.includes(k))) or consolidating into a single model metadata map to reduce the maintenance surface.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/amazon-bedrock-mantle/discovery.ts
Line: 39-45

Comment:
**Two parallel lists to keep in sync**

`IMAGE_INPUT_MODELS` and the keys of `KNOWN_CONTEXT_WINDOWS` are identical, which means every new Claude model on Mantle requires updating both structures. Since `resolveInputModalities` already iterates, consider deriving image support directly from `KNOWN_CONTEXT_WINDOWS` (i.e., `Object.keys(KNOWN_CONTEXT_WINDOWS).some((k) => modelId.includes(k))`) or consolidating into a single model metadata map to reduce the maintenance surface.

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

…t models

Mantle's /v1/models endpoint returns only model IDs with no token limit
metadata. All models get a hardcoded 32K context window, which is wrong
for most models (MiniMax M2: 1M, Qwen Coder: 256K, etc.).

Add a KNOWN_CONTEXT_WINDOWS lookup table for open-weight models
currently available on Mantle and raise the default fallback from
32K to 128K for unknown models.

Note: Claude models are NOT included — they use the separate
/anthropic/v1/messages endpoint on Mantle, not the OpenAI-compatible
/v1/chat/completions endpoint that this extension handles. Claude
model metadata is managed by the amazon-bedrock extension.
@wirjo wirjo force-pushed the feat/bedrock-mantle-opus-47 branch from ecbaa9c to ab9b0d0 Compare April 18, 2026 23:37
@wirjo wirjo changed the title feat(amazon-bedrock-mantle): add Claude Opus 4.7 support with correct model metadata feat(amazon-bedrock-mantle): add known context windows for open-weight Mantle models Apr 18, 2026
Copy link
Copy Markdown

@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.

Reviewed commit: ecbaa9c795

ℹ️ 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".

Comment on lines +47 to +48
function resolveKnownContextWindow(modelId: string): number | undefined {
return KNOWN_CONTEXT_WINDOWS[modelId];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match known Claude context windows against ID variants

resolveKnownContextWindow does an exact key lookup, so any Mantle ID variant (for example a prefixed or suffixed Claude ID such as ...-v1:0) falls through to the 128K default even when it belongs to a model family you already marked as 1M/200K elsewhere in this change. In those cases discovery returns inconsistent metadata (reasoning/image may match by substring while context does not), which can cause unnecessary prompt truncation for affected Claude IDs.

Useful? React with 👍 / 👎.

@wirjo
Copy link
Copy Markdown
Contributor Author

wirjo commented Apr 18, 2026

@vincentkoc Ready for review — no CI failures, single-extension change. Happy to address any feedback.

wirjo added 2 commits April 19, 2026 01:47
Cross-referenced against known Mantle model list. Added:
- qwen.qwen3-next-80b-a3b-instruct (128K)
- qwen.qwen3-vl-235b-a22b-instruct (128K)
- mistral.mistral-large-3-675b-instruct (128K)
- mistral.devstral-2-123b (128K)

Reordered entries by context window size (1M first) for readability.
Models at 128K default (GPT-OSS, Kimi, Mistral small, etc.) are
intentionally omitted — the 128K fallback handles them correctly.
Validated against live Mantle /v1/models endpoint (39 models).
Added missing entries:
- anthropic.claude-opus-4-7 (1M) — appears in /v1/models; uses
  /anthropic/v1/messages for inference, not Chat Completions
- minimax.minimax-m2.5 (1M)
- nvidia.nemotron-super-3-120b (128K)
- zai.glm-5 (128K)
Consistent with openclaw#65952. 200K matches the Claude model floor —
ensures new models get a sensible default without table updates.
@wirjo
Copy link
Copy Markdown
Contributor Author

wirjo commented Apr 19, 2026

Raised default from 128K → 200K, consistent with #65952. Claude is the most popular model family and 200K is the floor for all current Claude models — this future-proofs against new releases without requiring table updates.

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 1, 2026

Codex review: needs changes before merge.

Summary
The PR adds a static context-window lookup for selected Amazon Bedrock Mantle models and changes the discovered-model fallback context window.

Reproducibility: yes. The discoverMantleModels fetch seam can mock /v1/models: current main returns 32K for IDs like minimax.minimax-m2.5, while this PR would over-advertise omitted 128K models through the 200K fallback and under-advertise nvidia.nemotron-super-3-120b.

Next step before merge
An automated repair can make the narrow provider metadata, test, and changelog updates already identified; no product or security decision is needed.

Security
Cleared: The diff only changes static provider model metadata and does not add dependencies, scripts, secret handling, permissions, or downloaded code execution paths.

Review findings

  • [P2] Keep the Mantle fallback conservative — extensions/amazon-bedrock-mantle/discovery.ts:18
  • [P2] Set Nemotron Super to the known 256K value — extensions/amazon-bedrock-mantle/discovery.ts:58
  • [P3] Add the required changelog note — extensions/amazon-bedrock-mantle/discovery.ts:18
Review details

Best possible solution:

Land a rebased Mantle-local metadata update that maps known open-weight model IDs, keeps fallback behavior conservative, preserves the current Claude Anthropic Messages handling, and adds focused tests plus a changelog entry.

Do we have a high-confidence way to reproduce the issue?

Yes. The discoverMantleModels fetch seam can mock /v1/models: current main returns 32K for IDs like minimax.minimax-m2.5, while this PR would over-advertise omitted 128K models through the 200K fallback and under-advertise nvidia.nemotron-super-3-120b.

Is this the best way to solve the issue?

No, not as written. A static known-context-window table is the right narrow shape, but this branch needs conservative fallback semantics, aligned Nemotron metadata, and release-note/test coverage before merge.

Full review comments:

  • [P2] Keep the Mantle fallback conservative — extensions/amazon-bedrock-mantle/discovery.ts:18
    The final commit raises every unlisted /v1/models result to 200K, but the earlier patch explicitly omitted GPT-OSS, Kimi, Mistral small, and similar 128K models because a 128K fallback covered them. With the new fallback, those unlisted models can be advertised above their real limit, delaying compaction until provider context errors. Keep the fallback at 128K or add explicit lower-window entries for every omitted model.
    Confidence: 0.91
  • [P2] Set Nemotron Super to the known 256K value — extensions/amazon-bedrock-mantle/discovery.ts:58
    This table assigns nvidia.nemotron-super-3-120b a 128K window, while the merged Bedrock discovery table for the same model ID uses 256K. If Mantle returns this ID, discovery still underreports the window and triggers premature compaction; align the value or document evidence that Mantle differs.
    Confidence: 0.78
  • [P3] Add the required changelog note — extensions/amazon-bedrock-mantle/discovery.ts:18
    This is a user-visible provider feature because discovered Mantle model context windows change runtime compaction behavior, but the PR only changes discovery code. Add a CHANGELOG.md entry under the active release so the provider behavior ships documented.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.88

Acceptance criteria:

  • pnpm test extensions/amazon-bedrock-mantle/discovery.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/amazon-bedrock-mantle/discovery.ts extensions/amazon-bedrock-mantle/discovery.test.ts CHANGELOG.md
  • pnpm check:changed

What I checked:

  • Current main still uses the 32K Mantle discovery fallback: discoverMantleModels maps every /v1/models row without provider metadata to DEFAULT_CONTEXT_WINDOW, which is still 32000 on current main. (extensions/amazon-bedrock-mantle/discovery.ts:18, 3980eaa1c22e)
  • PR raises fallback to 200K and uses exact model-id lookup: The PR head sets DEFAULT_CONTEXT_WINDOW = 200_000, adds KNOWN_CONTEXT_WINDOWS, and uses resolveKnownContextWindow(m.id) ?? DEFAULT_CONTEXT_WINDOW; the helper is an exact map lookup. (extensions/amazon-bedrock-mantle/discovery.ts:18, 3957b971b6c5)
  • PR history makes the 200K fallback unsafe: Patch 2 says GPT-OSS, Kimi, Mistral small, and similar 128K models were intentionally omitted because a 128K fallback covered them; patch 4 then raises that fallback to 200K without adding explicit lower-window entries. (extensions/amazon-bedrock-mantle/discovery.ts:18, 3957b971b6c5)
  • Merged Bedrock metadata lists Nemotron Super as 256K: The standard Bedrock discovery table on current main maps nvidia.nemotron-super-3-120b to 256_000, while the PR's Mantle table maps the same ID to 128_000. (extensions/amazon-bedrock/discovery.ts:83, 3980eaa1c22e)
  • Current main has a separate Mantle Claude route: Current main appends Claude Opus 4.7 as an anthropic-messages Mantle model with image input, 1M context, and 128K max output; the repair must preserve this route instead of treating Claude as ordinary OpenAI-compatible discovery metadata. (extensions/amazon-bedrock-mantle/discovery.ts:361, 3980eaa1c22e)
  • Changelog has related Bedrock/Mantle entries but no Mantle context-window note: The changelog includes prior Bedrock and Mantle provider changes, including the merged Bedrock context-window entry, but no entry for this PR's user-visible Mantle context-window behavior. (CHANGELOG.md:2196, 3980eaa1c22e)

Likely related people:

  • wirjo: History shows prior merged Mantle provider work (#61296, #61563) and the related merged Bedrock context-window PR fix(amazon-bedrock): add known model context windows to discovery #65952, so this person is strongly connected to the affected discovery behavior beyond authoring this PR. (role: introduced behavior and related provider metadata owner; confidence: high; commits: dbac5fa258d9, 0793136c6361; files: extensions/amazon-bedrock-mantle/discovery.ts, extensions/amazon-bedrock-mantle/discovery.test.ts, extensions/amazon-bedrock/discovery.ts)
  • steipete: Current local blame and recent history show broad provider/discovery restoration and refactor maintenance around the affected files, including the current main copy used for this review. (role: recent maintainer and adjacent provider-code maintainer; confidence: medium; commits: 051171ba8f2d, 775b78e186c4, 19de5d1b569d; files: extensions/amazon-bedrock-mantle/discovery.ts, extensions/amazon-bedrock/discovery.ts, src/plugin-sdk/provider-entry.ts)

Remaining risk / open question:

  • Mantle model context-window values depend on vendor/catalog facts that should be rechecked during repair before shipping a static table.
  • The PR branch predates current main's Mantle Claude Anthropic Messages route, so any rebase or automated repair must preserve that route.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3980eaa1c22e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant