This repository was archived by the owner on Sep 23, 2026. It is now read-only.
Repository navigation
fix(kosong): omit empty anthropic-beta header when no beta features declared - #2580
Merged
Merged
Conversation
…eclared The Anthropic provider built the anthropic-beta header unconditionally, so once adaptive thinking removed the interleaved-thinking beta the request still carried 'anthropic-beta: ""'. Some backends reject an empty header value. Only set the header when betas are present; user-supplied extra_headers still take precedence.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the Anthropic chat provider in Kosong to avoid sending an empty anthropic-beta header when no beta features are declared (notably after adaptive thinking removes the interleaved-thinking beta), and updates tests and changelogs to reflect/cover the behavior.
Changes:
- Only add the
anthropic-betaheader when the effectivebeta_featureslist is non-empty (while preserving user override precedence viaextra_headers). - Tighten/extend API snapshot tests to assert header omission and override semantics.
- Add corresponding changelog entries across the repo and docs.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/kosong/src/kosong/contrib/chat_provider/anthropic.py | Builds extra_headers such that anthropic-beta is omitted when no betas are present. |
| packages/kosong/tests/api_snapshot_tests/test_anthropic.py | Updates adaptive-thinking assertion and adds a new test for empty/override header behavior. |
| packages/kosong/CHANGELOG.md | Notes the Anthropic header omission fix in Kosong’s changelog. |
| docs/zh/release-notes/changelog.md | Adds release note entry (ZH) describing the behavior change. |
| docs/en/release-notes/changelog.md | Adds release note entry (EN) describing the behavior change. |
| CHANGELOG.md | Adds top-level changelog entry for the Kosong fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+348
to
+350
| # `anthropic-beta` value is rejected by some backends. | ||
| extra_headers["anthropic-beta"] = ",".join(str(e) for e in betas) | ||
| extra_headers.update(generation_kwargs.pop("extra_headers", {})) |
NLPark-Cran
referenced
this pull request
in NLPark-Cran/cran-code
Aug 18, 2026
Brings kosong 0.56.0 (omit empty anthropic-beta header, #2580/#2581). Conflicts resolved keeping cran-code branding; duplicate definitions from the double-merge artifact removed; test snapshots updated for the 10-attempt retry default; compaction-hook test factory updated for the post-compaction StatusUpdate emission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
No linked issue — this comes from a verification report against kosong 0.55.0 showing the Anthropic provider still sends an empty
anthropic-betaheader.Description
Problem:
Anthropic._streamed_requestbuilt theanthropic-betaheader unconditionally:When adaptive thinking removes the
interleaved-thinking-2025-05-14beta (Opus 4.6+/Sonnet 4.6+ path inwith_thinking),betasbecomes[]and the request still carriesanthropic-beta: "". An empty header value is rejected or mishandled by some backends/gateways.Fix (
packages/kosong/src/kosong/contrib/chat_provider/anthropic.py): only set theanthropic-betaheader whenbetasis non-empty. Merge precedence is unchanged — user-suppliedextra_headersstill override the generated header, and an explicitly providedanthropic-betainextra_headersis still sent even whenbetasis empty. As a side benefit, an explicitbeta_features=Noneno longer crashesstr.join.Tests (
packages/kosong/tests/api_snapshot_tests/test_anthropic.py):test_anthropic_opus_46_adaptive_thinkingnow asserts the header is absent entirely (previously only checked it didn't contain the interleaved-thinking value).test_anthropic_beta_header_omitted_when_emptycovers: default construction sendsanthropic-beta: interleaved-thinking-2025-05-14; an emptiedbeta_features=[]omits the header; user-suppliedextra_headers={"anthropic-beta": ...}still wins.Changelog entries added to
CHANGELOG.md,packages/kosong/CHANGELOG.md, anddocs/{en,zh}/release-notes/changelog.md.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.