-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Compaction (/compact) fails with 'No API key found' when model uses codex/claude-cli OAuth runtime #95693
Copy link
Copy link
Closed
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.
Type
Fields
Priority
None yet
Summary
/compact(manual and budget-triggered auto-compaction) fails withNo API key found for provider "openai"/No API key found for provider "anthropic"when the agent's model is configured to use thecodex(or presumablyclaude-cli) harness runtime via OAuth-style synthetic auth, even though normal (non-compaction) agent turns on the same model/session succeed without any auth error.Environment
agents.defaults.models["openai/gpt-5.5"].agentRuntime.id = "codex"auth_mode: "chatgpt"(ChatGPT/Codex OAuth) stored in the per-agentcodex-home/auth.json, notauth-profiles.json.openclaw models statusshowsRuntime auth: openai via codex uses openai effective=synthetic:codex-app-server | status=usableduring normal operation.anthropic:default/openai:defaultAPI-key profile is configured; fallback modelanthropic/claude-sonnet-4-6also has no auth profile (separate known issue, not the focus here, but it does mean both primary and fallback fail the same way during compaction).Steps to reproduce
agentRuntime.id: "codex"and authenticate purely via Codex/ChatGPT OAuth (noopenai:defaultAPI-key profile inauth-profiles.json).openclaw agent) until the session approachesagents.defaults.compaction.reserveTokensFloor, or manually trigger/compact.Actual behavior
Gateway log (
compaction-diag) shows bothtrigger=budget(automatic) andtrigger=manual(/compact) attempts failing identically:Meanwhile, in the same session, regular (non-compaction) turns against
openai/gpt-5.5succeed normally using the same codex OAuth auth (winnerProvider: openai, result: success, runner: embedded), confirming the codex OAuth credential itself is valid and usable outside of the compaction path.Expected behavior
Compaction should be able to use the same codex/claude-cli synthetic/OAuth auth path that regular agent turns use, rather than requiring a separate plain API-key profile.
Root cause investigation (source-level, not just log inspection)
Traced through the bundled dist code (
compact-j1-PEvXo.js,model-auth-Aq6KQDp8.js,compaction-runtime-context-DTO0IG8s.js,harness-runtimes-BbJCcEVN.js,model-runtime-policy-DmfWB8cz.js):compact-j1-PEvXo.jscallsgetApiKeyForModel(...)→resolveApiKeyForProvider(...). When called with aprofileId, this function does correctly checkshouldDeferSyntheticProfileAuth(...), which is designed to defer to synthetic/OAuth auth (e.g. codex-app-server) instead of failing immediately.profileIdpassed in comes fromresolvedCompactionTarget.authProfileId, computed byresolveEmbeddedCompactionTarget(...)incompaction-runtime-context-DTO0IG8s.js.shouldUseCodexRuntimeProviderForCompaction) whenparams.harnessRuntime === "codex".harnessRuntimeis computed incompact-j1-PEvXo.jsasselectedHarnessRuntime = params.agentHarnessId ?? configuredHarnessRuntime, whereconfiguredHarnessRuntimecomes fromresolveAgentHarnessPolicy(...)inharness-runtimes-BbJCcEVN.js, gated by:resolveAgentHarnessPolicyultimately callsresolveModelRuntimePolicy(...)inmodel-runtime-policy-DmfWB8cz.js, which should match the configuredagents.defaults.models["openai/gpt-5.5"].agentRuntime = {id: "codex"}entry and returnsource: "model"(i.e. not"implicit").Statically, this chain looks like it should resolve
harnessRuntime: "codex"correctly from the documented config shape above, which would in turn letshouldDeferSyntheticProfileAuthkick in and avoid the hard failure. But in practice the compaction call still fails as ifharnessRuntimewere never"codex"(or as if the codex synthetic-auth deferral never returns a usable key). I was not able to pin down the exact point of divergence between the static code path and actual runtime behavior without adding instrumentation/debug logging inside the installed package, which I avoided doing on a teammate's production install.Suggested next steps for maintainers
resolveEmbeddedCompactionTargetandshouldDeferSyntheticProfileAuthprinting the resolvedharnessRuntime,authProfileId, and the outcome of the synthetic-auth deferral, to make this divergence directly observable.resolveModelRuntimePolicy'ssessionAgentIdresolution (viaresolveSessionAgentIds) might resolve to an agent id that doesn't match the one holding theagentRuntimeoverride in this scenario (e.g. when invoked from the compaction path vs. a normal turn), which would silently fall through tosource: "implicit".Workaround in use
Adding a plain API-key auth profile (
openclaw models auth paste-api-key --provider openaior--provider anthropic) alongside the OAuth profile avoids the failure, sincegetApiKeyForModelsucceeds via the plain API key path before ever needing the synthetic-auth deferral. This is a viable workaround but defeats the purpose of using Codex/ChatGPT OAuth exclusively (extra cost, separate billing).