Repository navigation
fix(auth): do not admit ambient environment credentials behind declared profiles - #118457
Closed
Marvinthebored wants to merge 1 commit into
Closed
Marvinthebored wants to merge 1 commit into
Marvinthebored wants to merge 1 commit into
Conversation
…ed profiles
A provider credential present only in the process environment — named in
neither the provider entry, `auth.profiles`, nor `auth.order` — was appended to
the auth attempt list behind the operator's declared profiles. A run that left
a declared profile could therefore continue on an undeclared credential, which
may bill a different account, with no configuration authorizing the transition
and nothing reporting that it happened.
Add an explicit `authorization: "declared" | "ambient"` fact on direct auth
sources and enforce it during source selection. The field is required rather
than defaulted so every construction site is audited; `evidence` is left as
provenance, since a declared credential can legitimately be environment-sourced
via a `${VAR}` marker or a SecretRef.
An ambient credential may still serve a provider with no declared profiles (the
documented zero-config `PROVIDER_API_KEY` path), but it is no longer admitted
behind declared profiles, nor substituted for declared profiles that turned out
to be unusable. `auth.order` failover is unaffected: profiles are never filtered
by this change. The read-only availability evaluator applies the same rule so
status cannot advertise a credential the runtime refuses.
This restores the invariant that held before 1b1cebf (#104685), where an
environment candidate was reachable only when a provider had no declared
profiles. The regression shipped in 2026.7.2-beta.1 onwards; no GA release is
affected.
Reported in #117956.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Nwk2KaB6zL71xa1i3Xwgwi
Contributor
Author
|
Reported by @Peetiegonzalez in #117956, who confirmed the metered usage against the provider console and reviewed this fix before filing. Tagging for follow-ups. |
Contributor
Author
|
Closed accidentally — I deleted the fork holding this branch while cleaning up. Superseded by #118458 with the same commit. Apologies for the noise. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reported in #117956.
This is a regression in the 2026.7.2 betas
The behaviour was introduced by
1b1cebfe4218(PR #104685, "fix(openai): align authavailability with effective routes", 2026-07-11), the commit that created
prepare-auth.ts,provider-model-route-auth.tsandprovider-model-auth-source-plan.ts.Immediately before that commit, the equivalent logic in
embedded-agent-runner/run.tswas:An ambient environment credential was reachable only when the provider had no declared profiles
— the zero-config path. It was never appended behind declared profiles. After #104685 it is.
No GA release is affected, so this fix restores the v2026.7.1 invariant rather than introducing a
new policy, and it withdraws behaviour that has only ever existed in prereleases. Worth resolving
before 2026.7.2 goes GA.
Problem
A provider credential that appears only in the process environment — named in neither the
provider entry,
auth.profiles, norauth.order— is admitted to the auth attempt list and queuedbehind the operator's declared profiles. If the run leaves a declared profile for any reason, that
undeclared credential becomes the live credential for the request.
In #117956 the declared credential was a subscription auth profile, and the environment held an
ANTHROPIC_API_KEYset for other, separately-named consumers. The run produced metered API usagewhile status continued to report the profile. Nothing in config authorized that transition, and
nothing reported that it had happened.
The two credentials can bill different accounts. Moving between them is a decision the operator
should have to express, not a consequence of a variable being present in the environment.
This is also inconsistent with how OpenClaw already treats declared credentials. A stored profile
the operator omits from an explicit
auth.orderis deliberately not tried later, and the omission isreported (
docs/auth-credential-semantics.md, "Explicit auth order filtering"). An undeclaredenvironment credential was subject to no equivalent rule, so declaring less produced the less
conservative behaviour.
On the issue's "no cooldown / errorCount 0" observation
The issue reports no cooldown and
errorCount: 0on the profile, which reads as "no failoveroccurred". Those are consistent: auth-profile failure state is only updated for credential failures.
A transport-level failure moves the run to the next prepared attempt without recording anything
against the profile, so a clean profile record does not establish that the environment credential was
never reached.
What this PR establishes directly is narrower and is what it claims: with the reported configuration,
the planner admits the undeclared credential as a second physical attempt, and after this change it
does not. Whether a given run then reaches that attempt depends on failover behaviour, which is
deliberately out of scope below.
Change
Introduce an explicit authorization fact on direct auth sources and enforce it during source
selection.
provider-model-auth-source-plan.ts— newauthorization: "declared" | "ambient"onProviderModelAuthDirectSource. It is a required field: a permissive default would silentlygrant full standing to any unaudited construction site, which is how a source escapes the rule.
This is deliberately not expressed through
evidence.evidenceis provenance — where acredential was found — and is reported as such by status and probe surfaces. It cannot carry
authorization, because a declared credential is legitimately environment-sourced: a
${VAR}markeris reported as
evidence: "environment"(model-auth-availability.ts) while being fully declared.provider-model-auth-source-plan.ts— newdeclaredProfileCounton the automatic plan, beingthe number of resolved/eligible profiles before route-compatibility filtering. Route filtering
rebuilds the plan from a narrowed profile list, so
profiles.kindalone cannot distinguish "noprofiles resolved for this provider" from "the resolved profiles were filtered out". Only the
former is zero-config.
provider-model-route-auth.ts— anambientdirect source is dropped whenever the provider hasresolved profiles, in both the usable-profile branch and the fallback-only branch, and the count is
carried through route filtering so narrowing cannot re-admit it.
runtime-plan/prepare-auth.ts— classify the fallback direct source asambientonly when thecredential is environment-sourced and the provider entry declares no apiKey material (literal,
${VAR}marker, or SecretRef).evidencetagging is unchanged.model-auth-availability.ts— apply the same classification in the read-only availabilityevaluator, mirroring the runtime rule. Without this, status/model-picker surfaces would advertise a
credential the runtime refuses — preserving the status/runtime disagreement this change exists to
remove.
embedded-agent-runner/run/assistant-failover.ts— the assistant-timeout warning announcedTrying next account...before checking whether rotation had actually succeeded. It now branches onthe rotation result and names the remedy when there is no successor.
Preserved
PROVIDER_API_KEYfrom theenvironment.
${VAR}marker, and SecretRef all keep normal direct-sourcestanding.
kind === "environment"is classifiedambient, so these are unaffected.
aws-sdkauth, user locks, provider bindings, configured-auth routes — resolve as requiredownership and never reach the affected branch.
change where an ambient fallback previously followed a cooldown tier; that is the intended effect.)
Compatibility — withdraws two assertions added by #104685
Two cases added in #104685 asserted that an OAuth profile plus an ambient platform key, and an
API-key profile plus an ambient OAuth token, become distinct physical attempts. This change withdraws
the ambient half, and those cases are replaced rather than merely deleted.
They were added by the same commit that introduced the behaviour, so they codify the regression
rather than a pre-existing contract, and neither has shipped in a GA release. That PR was aligning
auth availability with effective routes; the cases fixed the mechanics of splitting attempts across
routes. This change does not dispute those mechanics — it disputes that an undeclared credential
should be eligible to participate at all.
Configurations that change (all 2026.7.2-beta only):
PROVIDER_API_KEYin the environment used as an unstated backup.models.providers.<id>.authset toapi-key/oauthwith no apiKey material, plus storedprofiles and an environment credential —
authalone does not make the environment key declared.Both now surface the declared credential's failure instead of silently switching accounts. The
supported way to express the intent already exists: create an API-key auth profile and add its id to
auth.order.<provider>(docs/concepts/model-failover.md).auth.ordercarries routing metadataonly — it does not itself hold a credential — so the profile must be created first.
Tests
runtime-plan/prepare-auth.ambient-credential.test.ts(new) — reproduces the reported configurationand asserts the attempt list contains only the declared profile, for both the indeterminate and
anthropic-messagesroute shapes. Fails onmainwith an extradirectattempt. Also covers anambient credential not being substituted for an unusable declared profile.
provider-model-route-auth.test.ts— direct coverage of each changed selector branch: ambientdropped behind usable profiles; declared fallback preserved behind usable profiles; ambient
preserved with no declared profiles; ambient not substituted for all-unavailable profiles; ambient
not re-admitted when route filtering empties the profile list.
runtime-plan/prepare-auth.test.ts— zero-config preservation, and declared provider apiKey routing.runtime-plan/prepare-auth.ambient-credential.test.ts— documentedauth.orderfailover isunaffected: with an ambient key present, multiple ordered profiles still produce every profile
attempt in order, including the documented subscription-then-API-key backup that this PR
recommends as the migration path.
These are planning-boundary regressions: they assert which credentials are eligible, not the runtime
failover that consumes them.
Not included
Rotation currently treats a transport-level failure the same as a credential failure when the harness
does not own transport, so a network fault can move a run onto the next prepared attempt. That is a
separate concern from whether a credential should have been eligible, with a different blast radius,
and is left for a follow-up.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Nwk2KaB6zL71xa1i3Xwgwi