Skip to content

Retry Anthropic requests after deprecated anthropic-beta header rejection#3657

Merged
lpcox merged 4 commits into
mainfrom
copilot/fix-api-proxy-deprecated-header
May 23, 2026
Merged

Retry Anthropic requests after deprecated anthropic-beta header rejection#3657
lpcox merged 4 commits into
mainfrom
copilot/fix-api-proxy-deprecated-header

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 23, 2026

Anthropic now rejects deprecated anthropic-beta values such as context-1m-2025-08-07, which causes Copilot CLI requests to fail with a 400 and exhaust retries. This change teaches the API proxy to detect that specific rejection, strip only the invalid beta value, and retry once.

  • Proxy retry path

    • Detect Anthropic 400 responses matching:
      Unexpected value(s) \` for the `anthropic-beta` header`
    • Retry the same request once after removing only the rejected beta value
    • Remove the header entirely when stripping leaves it empty
  • In-memory learning

    • Cache rejected beta values for the lifetime of the proxy process
    • Proactively remove learned deprecated values from subsequent Anthropic requests to avoid the extra round-trip
  • Observability

    • Emit warning logs when deprecated beta values are stripped, including whether the strip happened on the retry path or from cached knowledge
  • Regression coverage

    • Add focused proxy tests for:
      • first-hit 400 -> strip -> single retry
      • subsequent requests proactively stripping learned deprecated values
// Before
anthropic-beta: context-1m-2025-08-07,other-beta

// After Anthropic rejects context-1m-2025-08-07
anthropic-beta: other-beta

Copilot AI changed the title [WIP] Fix API proxy to auto-strip deprecated anthropic-beta header values Retry Anthropic requests after deprecated anthropic-beta header rejection May 23, 2026
Copilot finished work on behalf of lpcox May 23, 2026 21:53
Copilot AI requested a review from lpcox May 23, 2026 21:53
@lpcox lpcox marked this pull request as ready for review May 23, 2026 21:59
Copilot AI review requested due to automatic review settings May 23, 2026 21:59
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.06% 96.13% 📈 +0.07%
Statements 95.89% 95.96% 📈 +0.07%
Functions 97.96% 97.96% ➡️ +0.00%
Branches 89.60% 89.64% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/config-writer.ts 83.0% → 85.6% (+2.54%) 83.0% → 85.6% (+2.54%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

This was referenced May 23, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the API proxy’s Anthropic request handling to recover from upstream 400s caused by deprecated anthropic-beta header values by stripping the rejected value, retrying once, and caching learned deprecated values for subsequent requests.

Changes:

  • Detect Anthropic 400 responses indicating a deprecated anthropic-beta value, strip only the rejected value, and retry the request once.
  • Cache deprecated beta values in-memory and proactively strip them from later requests, with warning logs for both retry and cached-strip paths.
  • Add regression tests covering the retry behavior and the proactive stripping behavior.
Show a summary per file
File Description
containers/api-proxy/proxy-request.js Adds deprecated anthropic-beta detection, single-retry stripping behavior, in-memory caching, and warning logs.
containers/api-proxy/server.proxy.test.js Adds focused tests for Anthropic deprecated beta handling and introduces per-test reset plumbing for the new cache.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread containers/api-proxy/server.proxy.test.js Outdated
Comment thread containers/api-proxy/proxy-request.js
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

lpcox and others added 2 commits May 23, 2026 15:56
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

✅ Smoke Test Results

  • GitHub API: ✅ 2 PR entries verified
  • GitHub check: ✅ playwright_check PASS
  • File verify: ✅ smoke-test file exists

Overall: PASS — Claude engine validation complete.

💥 [THE END] — Illustrated by Smoke Claude

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

PR #3657: Retry Anthropic requests after deprecated anthropic-beta header rejection
Author: @Copilot | Assignees: @lpcox, @Copilot

GitHub MCP - Successfully queried PRs
GitHub.com connectivity - Pre-step data unavailable
File write/read - File not found at expected path
BYOK inference - Running successfully in offline mode

Note: Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com

Status: ⚠️ PARTIAL (inference working, pre-step validation incomplete)

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

📡 API Proxy OTEL Tracing Smoke Test Results

Scenario 1: Module Loadingotel.js loaded successfully, exports: startRequestSpan, setTokenAttributes, endSpan, endSpanError, shutdown, isEnabled + internals

Scenario 2: Test Suite — All 32 OTEL tests passed (span creation, token attributes, parent context, OTLP export, file export)

Scenario 3: Env Var Forwardingsrc/services/api-proxy-service.ts forwards OTEL_EXPORTER_OTLP_ENDPOINT and GITHUB_AW_OTEL_TRACE_ID to api-proxy container

Scenario 4: Token Tracker Integrationtoken-tracker-http.js has onUsage callback (OTEL hook point confirmed)

⚠️ Scenario 5: OTEL Diagnostics — No OTEL span file found (api-proxy OTEL not yet active in this run). Token usage tracking confirmed working (2,975 bytes logged).

Summary

All infrastructure tests passing. OTEL module, test suite, env forwarding, and integration points are validated. OTEL tracing not yet active in runtime (expected during development — requires endpoint config and explicit activation).

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions
Copy link
Copy Markdown
Contributor

PR titles: Refactor agent volume assembly into focused mount modules; Refactor Squid config generation into focused modules; Retry Anthropic requests after deprecated anthropic-beta header rejection
✅ GitHub PR review
❌ Safe Inputs GH CLI (safeinputs-gh unavailable)
✅ Playwright, file write/read, discussion, build
❌ Tavily search (no search tool exposed)
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

Smoke test FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Runtime Version Test Results

The chroot environment test compared runtime versions between the host and the chrooted environment:

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.15.0 v22.22.3 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: Tests did not fully pass. Python and Node.js versions differ between the host runner environment and the chrooted agent container.

Context: These version differences are expected when the agent container uses a different base image (Ubuntu 22.04) than the GitHub Actions runner. The chroot test verifies that runtimes are accessible and functional within the chroot environment, even if versions differ.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

Service Connectivity Test Results

Redis: Connection timeout
PostgreSQL (pg_isready): No response
PostgreSQL (SELECT 1): Connection timeout

Overall: FAIL — All service checks failed. Services are unreachable at host.docker.internal.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx 1/1 passed ✅ PASS
Node.js execa 1/1 passed ✅ PASS
Node.js p-limit 1/1 passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

All builds and tests completed successfully across all 18 projects in 8 ecosystems.

Generated by Build Test Suite for issue #3657 · ● 14.8M ·

@lpcox lpcox merged commit 881da1d into main May 23, 2026
68 of 72 checks passed
@lpcox lpcox deleted the copilot/fix-api-proxy-deprecated-header branch May 23, 2026 23:19
@github-actions github-actions Bot mentioned this pull request May 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

GitHub MCP – PR #3657: Retry Anthropic requests after deprecated anthropic-beta header rejection
GitHub.com – HTTP 200
File I/O – Write/read verified

Status: PASS 🎉

@lpcox

📰 BREAKING: Report filed by Smoke Copilot

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API proxy: auto-strip deprecated anthropic-beta header values on 400 rejection

3 participants