Skip to content

Anthropic: wire explicit service tier params#45453

Merged
vincentkoc merged 11 commits intomainfrom
vincentkoc-code/anthropic-service-tier-followup
Mar 29, 2026
Merged

Anthropic: wire explicit service tier params#45453
vincentkoc merged 11 commits intomainfrom
vincentkoc-code/anthropic-service-tier-followup

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

@vincentkoc vincentkoc commented Mar 13, 2026

Summary

  • Problem: Anthropic fast mode already shaped direct public Anthropic requests via service_tier, but explicit Anthropic serviceTier / service_tier model params were still ignored.
  • Why it matters: users could not explicitly pin direct Anthropic requests to standard_only or auto, and explicit Anthropic tiers could not reliably override /fast defaults.
  • What changed: added explicit Anthropic service-tier parsing and payload injection for direct public Anthropic requests, including OAuth-authenticated sk-ant-oat-* traffic on the same public API path; explicit service tiers now beat fast-mode defaults, while caller-provided payload values still win.
  • What did NOT change (scope boundary): proxied Anthropic-compatible providers and non-public Anthropic base URLs still do not get service-tier injection.
  • Also included: a one-line src/config/io.ts fix from current main to remove a duplicate sourceConfig key that broke pnpm check after the rebase.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

  • Root cause: Anthropic explicit service-tier params were parsed nowhere in the embedded runner, so only fastMode could shape service_tier. After rebasing onto current main, there was also a wrapper-order bug where explicit serviceTier still lost to fastMode until the composition order was corrected.
  • Missing detection / guardrail: there was no regression coverage for explicit Anthropic serviceTier on OAuth, for explicit-tier-versus-fast-mode precedence, or for the proxied-base-url skip path.
  • Prior context (git blame, prior PR, issue, or refactor if known): fix: inject anthropic service_tier for OAuth auth #55922 removed the stale Anthropic OAuth fast-mode exclusion. This follow-up aligns explicit Anthropic service-tier behavior with that current direct-public-API path.
  • Why this regressed now: Anthropic fast mode was implemented first as a narrow path; explicit Anthropic service tiers never got parity wiring and the stale draft predates the OAuth fast-mode fix.
  • If unknown, what was ruled out: N/A.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Seam / integration test
  • Target test or file: src/agents/pi-embedded-runner-extraparams.test.ts
  • Scenario the test should lock in: explicit Anthropic serviceTier and service_tier params inject into direct public Anthropic payloads, explicit tiers override fast-mode defaults, OAuth follows the same path, and proxied base URLs still skip injection.
  • Why this is the smallest reliable guardrail: the bug lives in post-plugin stream-wrapper composition, so the payload-mutation seam is the narrowest place that proves the real request-shaping behavior.
  • Existing test that already covers this (if any): the file already covered Anthropic fast-mode payload shaping and caller-provided payload preservation.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

  • Direct public Anthropic requests now respect explicit serviceTier / service_tier model params.
  • When both Anthropic fastMode and explicit serviceTier are set, the explicit service tier wins.
  • OAuth-authenticated direct Anthropic requests now follow the same explicit-tier path as API-key traffic.

Diagram (if applicable)

Before:
explicit serviceTier -> ignored
fastMode -> service_tier
OAuth explicit serviceTier -> ignored

After:
caller payload service_tier -> wins
explicit serviceTier -> service_tier
fastMode -> fallback service_tier only when explicit tier is absent

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 24.13.0 + pnpm
  • Model/provider: Anthropic direct public API requests
  • Integration/channel (if any): N/A
  • Relevant config (redacted): agents.defaults.models["anthropic/claude-sonnet-4-5"].params.serviceTier

Steps

  1. Configure a direct Anthropic model with params.serviceTier: standard_only or params.service_tier: standard_only.
  2. Run the embedded reply path for that model, with and without fastMode: true, and with both direct API-key and sk-ant-oat-* OAuth auth.
  3. Inspect the outbound Anthropic payload.

Expected

  • The payload includes service_tier: "standard_only".
  • If fastMode: true is also configured, the explicit serviceTier still wins.
  • Proxied Anthropic-compatible base URLs still receive no Anthropic service_tier injection.

Actual

  • Before this change, only fastMode shaped Anthropic service_tier; explicit Anthropic serviceTier config was ignored, and the stale draft still had precedence/scope bugs after #55922.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: traced the embedded-runner stream-wrapper path, rebased the PR onto current main, reproduced the stale precedence bug with focused Vitest filters, then added/updated payload-mutation coverage for explicit Anthropic tiers, OAuth, snake_case aliasing, and proxied-base-url skips.
  • Edge cases checked: caller-provided payload values still win; explicit Anthropic service tiers override fastMode; proxied base URLs still skip injection.
  • What you did not verify: live Anthropic API execution in this worktree.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: explicit Anthropic serviceTier could accidentally affect unsupported Anthropic-compatible proxy paths.
    • Mitigation: the wrapper still gates on provider === "anthropic", api === "anthropic-messages", and the direct public Anthropic base URL.
  • Risk: rebasing onto current main could leave the branch red on unrelated compile drift.
    • Mitigation: fixed the duplicate sourceConfig key introduced on current main, reran pnpm check, and reran pnpm build on the final tree.

@vincentkoc vincentkoc force-pushed the vincentkoc-code/anthropic-service-tier-followup branch from 14952ac to f1c9349 Compare March 29, 2026 23:35
@vincentkoc vincentkoc marked this pull request as ready for review March 29, 2026 23:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1c934936d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/pi-embedded-runner/anthropic-stream-wrappers.ts
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 29, 2026

Greptile Summary

This PR wires explicit serviceTier / service_tier model params into the direct-Anthropic request path so users can pin requests to standard_only or auto without relying solely on the /fast shortcut. The composition order in applyPostPluginStreamWrappers (service-tier wrapper applied before fast-mode wrapper) is correct: because streamWithPayloadPatch chains onPayload callbacks inner-first, the explicit service tier's patch fires before the fast-mode patch, giving it proper precedence. The io.ts duplicate-key fix and the six new payload-mutation tests are clean additions.

One structural issue to address:

  • createBedrockNoCacheWrapper and isAnthropicBedrockModel were accidentally appended to anthropic-stream-wrappers.ts (lines 428–440). Identical implementations of both functions already exist in bedrock-stream-wrappers.ts, and extra-params.ts still imports them from \"./bedrock-stream-wrappers.js\". The new exports in anthropic-stream-wrappers.ts are therefore unreachable dead code in the wrong file and should be removed before merge.

Confidence Score: 4/5

Safe to merge after removing the two duplicate Bedrock utility exports accidentally included in anthropic-stream-wrappers.ts.

The core logic — service-tier resolution, wrapper composition, precedence over fast mode — is correct and well-tested. The only concrete defect is createBedrockNoCacheWrapper and isAnthropicBedrockModel being exported from anthropic-stream-wrappers.ts as dead code when the identical functions already live in bedrock-stream-wrappers.ts. Since no caller picks them up from the new location this does not affect runtime behavior today, but it is misleading, creates a maintenance hazard, and should be cleaned up before the branch lands.

src/agents/pi-embedded-runner/anthropic-stream-wrappers.ts — remove the two duplicate Bedrock utility functions added at the end of the file.

Important Files Changed

Filename Overview
src/agents/pi-embedded-runner/anthropic-stream-wrappers.ts Adds createAnthropicServiceTierWrapper, resolveAnthropicServiceTier, and the normalizer helper — all correct. Also appends duplicate createBedrockNoCacheWrapper and isAnthropicBedrockModel that already exist identically in bedrock-stream-wrappers.ts and are never imported from here; these are dead code in the wrong file.
src/agents/pi-embedded-runner/extra-params.ts Wires resolveAnthropicServiceTier and createAnthropicServiceTierWrapper into applyPostPluginStreamWrappers. Service-tier wrapper is applied before the fast-mode wrapper, making it the inner layer; per streamWithPayloadPatch chaining semantics the inner onPayload fires first, so an explicit tier correctly wins over a fast-mode default.
src/agents/pi-embedded-runner-extraparams.test.ts Adds six targeted tests covering camelCase and snake_case params, OAuth path, explicit-tier-over-fast-mode precedence, and the proxied-base-URL skip. Good coverage for the new behavior.
src/config/io.ts One-line fix removing a duplicate sourceConfig key that caused a pnpm check failure after the rebase; straightforward and correct.
CHANGELOG.md Adds an Unreleased entry for the new explicit Anthropic service-tier support. Entry is well-placed and follows the existing format.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/anthropic-stream-wrappers.ts
Line: 428-440

Comment:
**Dead duplicate exports accidentally landed in this file**

`createBedrockNoCacheWrapper` and `isAnthropicBedrockModel` added here are byte-for-byte copies of the same exports that already live in `bedrock-stream-wrappers.ts`. `extra-params.ts` continues to import them from `"./bedrock-stream-wrappers.js"` (line 22), so these new exports are never consumed — they are dead code in the wrong file.

This appears to be a copy-paste artifact from an earlier draft. The two functions should be removed from `anthropic-stream-wrappers.ts`; no callers will pick them up from here as long as the import in `extra-params.ts` points to `bedrock-stream-wrappers.js`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(config): drop duplicate healed sourc..." | Re-trigger Greptile

Comment thread src/agents/pi-embedded-runner/anthropic-stream-wrappers.ts Outdated
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Mar 29, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24f8cfaf9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/pi-embedded-runner/extra-params.ts
@vincentkoc vincentkoc merged commit 475defd into main Mar 29, 2026
18 of 23 checks passed
@vincentkoc vincentkoc deleted the vincentkoc-code/anthropic-service-tier-followup branch March 29, 2026 23:54
Alix-007 pushed a commit to Alix-007/openclaw that referenced this pull request Mar 30, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
alexjiang1 pushed a commit to alexjiang1/openclaw that referenced this pull request Mar 31, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
Tardisyuan pushed a commit to Tardisyuan/openclaw that referenced this pull request Apr 30, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* Anthropic: add explicit service tier wrapper

* Runner: wire explicit Anthropic service tiers

* Tests: cover explicit Anthropic service tiers

* Changelog: note Anthropic service tier follow-up

* fix(agents): make Anthropic service tiers override fast mode

* fix(config): drop duplicate healed sourceConfig

* docs(anthropic): update fast mode service tier guidance

* fix(agents): remove dead Anthropic Bedrock exports

* fix(agents): avoid cross-provider Anthropic tier warnings

* fix(agents): avoid cross-provider OpenAI tier warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant