Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.

fix(kosong): omit empty anthropic-beta header when no beta features declared - #2580

Merged
7Sageer merged 1 commit into
mainfrom
fix/kosong-empty-anthropic-beta-header
Aug 3, 2026
Merged

7Sageer merged 1 commit into
mainfrom
fix/kosong-empty-anthropic-beta-header

Conversation

@7Sageer

@7Sageer 7Sageer commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

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-beta header.

Description

Problem: Anthropic._streamed_request built the anthropic-beta header unconditionally:

extra_headers = {
    **{"anthropic-beta": ",".join(str(e) for e in betas)},
    **(generation_kwargs.pop("extra_headers", {})),
}

When adaptive thinking removes the interleaved-thinking-2025-05-14 beta (Opus 4.6+/Sonnet 4.6+ path in with_thinking), betas becomes [] and the request still carries anthropic-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 the anthropic-beta header when betas is non-empty. Merge precedence is unchanged — user-supplied extra_headers still override the generated header, and an explicitly provided anthropic-beta in extra_headers is still sent even when betas is empty. As a side benefit, an explicit beta_features=None no longer crashes str.join.

Tests (packages/kosong/tests/api_snapshot_tests/test_anthropic.py):

  • test_anthropic_opus_46_adaptive_thinking now asserts the header is absent entirely (previously only checked it didn't contain the interleaved-thinking value).
  • New test_anthropic_beta_header_omitted_when_empty covers: default construction sends anthropic-beta: interleaved-thinking-2025-05-14; an emptied beta_features=[] omits the header; user-supplied extra_headers={"anthropic-beta": ...} still wins.

Changelog entries added to CHANGELOG.md, packages/kosong/CHANGELOG.md, and docs/{en,zh}/release-notes/changelog.md.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

…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.
Copilot AI review requested due to automatic review settings August 3, 2026 07:21

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Copilot AI left a comment

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.

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-beta header when the effective beta_features list is non-empty (while preserving user override precedence via extra_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", {}))
@7Sageer
7Sageer added this pull request to the merge queue Aug 3, 2026
Merged via the queue into main with commit 0876334 Aug 3, 2026
23 checks passed
@7Sageer
7Sageer deleted the fix/kosong-empty-anthropic-beta-header branch August 3, 2026 07:31
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants