Skip to content

feat(provider): graceful context-1m fallback for sub-Tier-4 accounts#15641

Closed
sjawhar wants to merge 6 commits intoanomalyco:devfrom
sjawhar:sami
Closed

feat(provider): graceful context-1m fallback for sub-Tier-4 accounts#15641
sjawhar wants to merge 6 commits intoanomalyco:devfrom
sjawhar:sami

Conversation

@sjawhar
Copy link

@sjawhar sjawhar commented Mar 2, 2026

Summary

  • Adds graceful error handling when the context-1m-2025-08-07 Anthropic beta header is rejected by accounts below Tier 4
  • On the first request, if Anthropic returns HTTP 400 with "long context beta not available", the fetch wrapper strips the header, retries immediately, and remembers to skip it for the rest of the process
  • Zero configuration required — Tier 4+ accounts get 1M context automatically, sub-Tier-4 accounts fall back to 200K seamlessly

Changes

  • packages/opencode/src/provider/provider.ts — Added _context1mDisabled flag and stripContext1m() helper in the fetch wrapper for error-based retry
  • packages/opencode/test/provider/context1m.test.ts — 9 tests covering header stripping and error detection

Context

The feat/opus-4-6-adaptive-thinking branch adds context-1m-2025-08-07 to the static Anthropic beta header, enabling 1M context for supported models. However, this breaks accounts below Tier 4 ($400 cumulative deposits) which receive a hard error. This PR makes the feature degrade gracefully.

Note: The context-1m header alone does NOT change pricing — premium rates (2× input, 1.5× output) only apply when actual input tokens exceed 200K.

sjawhar and others added 6 commits February 27, 2026 19:43
Add optional `id` field to Session.create() with strict format validation
(ses_ + 12 lowercase hex + 14 Base62). Duplicate IDs return 409 Conflict.

- Add `id` field with regex validation to Session.create schema
- Add duplicate session ID check before creation
- Add DuplicateIDError (NamedError) with 409 status mapping
- Update OpenAPI spec and regenerate SDK with id field + 409 response
- Add 6 tests: custom ID, default behavior, duplicate, invalid prefix/format

Closes anomalyco#12916

resolve: custom session id conflicts
…ounting, use plugin fork for OAuth context cap
resolve: merge conflicts in generated SDK files
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

The following comment was made by an LLM, it may be inaccurate:

I found some related PRs, but none appear to be duplicates of PR #15641. Here's what I found:

Related (but distinct) PRs:

  1. feat(provider): add 1M context window support for Anthropic models (PR feat(provider): add 1M context window support for Anthropic models #14375)

  2. feat(provider): add adaptive thinking and 1M context support for Claude Opus 4.6 (PR feat(provider): add adaptive thinking and 1M context support for Claude Opus 4.6 #12342)

    • Earlier work on context support, likely a foundation for this feature
  3. fix(provider): enable 1M context for Vertex AI Anthropic models (PR fix(provider): enable 1M context for Vertex AI Anthropic models #14055)

    • Related to context features but for Vertex AI specifically

PR #15641 is distinct from these because it specifically addresses the graceful degradation for sub-Tier-4 accounts (adding error handling and fallback logic) rather than implementing the core 1M context feature itself.

No duplicate PRs found

@sjawhar
Copy link
Author

sjawhar commented Mar 2, 2026

Closing — this PR includes unrelated merge parents. The context-1m fallback change will be included when the parent feature branch (feat/opus-4-6-adaptive-thinking) is ready.

@sjawhar sjawhar closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants