feat(anthropic): migrate 1M context from beta to GA#45613
feat(anthropic): migrate 1M context from beta to GA#45613haoyu-haoyu wants to merge 3 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR migrates Anthropic's 1M context window from beta to GA by removing the The change is straightforward and the tests are well-updated. One area worth a closer look:
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-runner-extraparams.test.ts
Line: 1504-1507
Comment:
**OAuth betas silently dropped when `context1m` is the only configured beta**
The old test comment read: _"Must include the OAuth-required betas so they aren't stripped by pi-ai's mergeHeaders"_ — meaning `oauth-2025-04-20` and `claude-code-20250219` had to be pre-populated before pi-ai's own `mergeHeaders` call would clobber the `anthropic-beta` header.
In `extra-params.ts` the beta wrapper is only applied when `resolveAnthropicBetas` returns a non-empty array (line 367: `if (anthropicBetas?.length)`). With `context1m: true` and **no explicit `anthropicBeta`** config, `resolveAnthropicBetas` now returns `undefined`, so `createAnthropicBetaHeadersWrapper` is **never called**. That means `PI_AI_OAUTH_ANTHROPIC_BETAS` (which lives inside that wrapper) is never injected for this specific combination.
The scenarios and their outcomes:
| Config | Token type | Before this PR | After this PR |
|---|---|---|---|
| `context1m: true`, no `anthropicBeta` | API key | wrapper applied, default betas injected | wrapper **skipped**, no betas injected |
| `context1m: true`, no `anthropicBeta` | OAuth | wrapper applied, **oauth betas** injected | wrapper **skipped**, no oauth betas |
| `context1m: true`, `anthropicBeta: [...]` | OAuth | wrapper applied, oauth betas injected | wrapper still applied (user betas present), oauth betas still injected ✓ |
If pi-ai's `streamSimple` independently injects the oauth betas via its own mechanism, this is a no-op. But if pi-ai relied on them being pre-populated in the headers (to survive its `mergeHeaders` pass), OAuth+context1m users without an explicit `anthropicBeta` config could start seeing `401 / invalid beta` errors.
Could you confirm whether pi-ai now adds `oauth-2025-04-20` / `claude-code-20250219` unconditionally for OAuth keys, making the pre-population redundant? If not, the fix would be to always apply the wrapper for Anthropic regardless of whether user betas are empty, e.g.:
```typescript
// extra-params.ts
const anthropicBetas = resolveAnthropicBetas(merged, provider, modelId);
if (provider === "anthropic" || anthropicBetas?.length) {
agent.streamFn = createAnthropicBetaHeadersWrapper(agent.streamFn, anthropicBetas ?? []);
}
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 90bc2f2 |
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. Source and test inspection against current main shows Next step before merge Security Review detailsBest possible solution: Land this repaired PR after maintainer review and exact-head checks, while keeping broader OAuth-wrapper work such as #41461 as a separate follow-up instead of expanding this Phase 1 migration. Do we have a high-confidence way to reproduce the issue? Yes. Source and test inspection against current main shows Is this the best way to solve the issue? Yes for this PR's Phase 1 scope. The PR is the narrow maintainable fix because it removes the retired 1M beta behavior, keeps Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 36c047c0264e. |
Anthropic has graduated the 1M context window from beta to GA. This commit: - Stops injecting the context-1m-2025-08-07 beta header when context1m: true is configured - Removes the OAuth token skip logic that was needed because Anthropic previously rejected the context-1m beta with OAuth auth (OAuth now supports 1M natively) - Strips the legacy beta header from user-configured anthropicBeta arrays to prevent sending a stale header - Removes the now-unused isAnthropic1MModel helper, ANTHROPIC_1M_MODEL_PREFIXES constant, and logger import from the stream wrappers The context1m config param continues to be respected for context window sizing in context.ts — only the beta header injection is removed. Closes openclaw#45550 (Phase 1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical. Source PR: #45613 |
90bc2f2 to
ba9b5bf
Compare
Summary
Anthropic has officially graduated the 1M context window from beta to GA. This PR implements Phase 1 of #45550:
context-1m-2025-08-07is no longer added toanthropic-betawhencontext1m: truesk-ant-oat-*) now support 1M context natively — the special-case filtering that stripped the context-1m beta for OAuth is removedcontext-1m-2025-08-07in theiranthropicBetaconfig, it is silently removed to prevent sending a stale headerisAnthropic1MModel(),ANTHROPIC_1M_MODEL_PREFIXES, and the unusedlogimport are removed from the stream wrappersBackward compatibility
Fully backward compatible:
context1m: truecontinues to work for context window sizing (resolveContextTokensForModelincontext.ts)context1m: truewill silently stop sending the unnecessary beta headerFiles changed
src/agents/pi-embedded-runner/anthropic-stream-wrappers.tssrc/agents/pi-embedded-runner-extraparams.test.tsTest plan
pnpm test -- src/agents/pi-embedded-runner-extraparams.test.ts)Closes #45550 (Phase 1)