Skip to content

fix(anthropic): probe Claude CLI login with the env its runs keep - #175114

Merged
RomneyDa merged 1 commit into
mainfrom
fix/claude-cli-readiness-preserve-env
Oct 17, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/claude-cli-readiness-preserve-env

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

What Problem This Solves

The Docker live CLI backend lane ("Docker live suites (Docker live CLI backend)", src/gateway/gateway-cli-backend.live.test.ts "runs the agent pipeline against the local CLI backend") fails on every 2026.10.5 candidate and on main. It passes on 2026.10.4. The parent turn's sessions_spawn is refused with:

sessions_spawn model "anthropic/claude-sonnet-4-6" is not usable: The selected account or native runtime is unavailable for anthropic/claude-sonnet-4-6. Restore that account before spawning this model.

No child starts, so cli_announce_barrier waits until cli_overall_timeout (240s). This blocks the 2026.10.5 release.

Why This Change Was Made

The lane uses Claude subscription auth through CLAUDE_CODE_OAUTH_TOKEN, with OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV='["CLAUDE_CODE_OAUTH_TOKEN"]'. It mounts no .credentials.json. CLI execution keeps preserved keys for the Claude child (src/agents/cli-runner/execute.ts), so the parent turn works.

The readiness check (probeClaudeCliAuthStatus, which runs claude auth status --json) always removed the whole Claude clear list, including the preserved token. So it reported the CLI as logged out, and no claude-cli auth mode was recorded.

Cause commit 8775756 (#166338) made a configured runtime with no recorded auth mode authoritatively missing-auth, even before the full catalog loads. Before that, availability stayed unknown and spawn was admitted. So the check and the runner disagreeing about the child's environment now refuses a login that works.

The fix makes the check use the same child environment execution uses. Keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV (JSON array or comma/space list, the same format the runner accepts) survive the clear list. Everything else is unchanged:

  • credentials not on the list, such as ANTHROPIC_API_KEY, are still removed;
  • a CLI that is really logged out still reports missing;
  • the spawn admission check still refuses unusable accounts.

User Impact

Only live CLI lanes that set OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV change behavior. Their Claude CLI readiness now matches what their runs can use. There is no change otherwise: without that variable, the check removes the same environment as before.

Evidence

  • Regression test: 2 cases in extensions/anthropic/cli-auth-seam.test.ts (JSON and list preserve formats). Both fail without the fix (2 failed / 11 passed) and pass with it (13/13). pnpm test extensions/anthropic/cli-auth-seam.test.ts --maxWorkers=1: 25.8s wall, Vitest duration 20.8s.
  • Related: pnpm test extensions/anthropic/index.test.ts extensions/anthropic/live-discovery-auth.test.ts --maxWorkers=1: 34/34 pass, 22.8s wall.
  • oxfmt --check and oxlint are clean on both touched files.
  • pnpm tsgo:extensions / pnpm tsgo:extensions:test: the only error is the pre-existing src/snapshot/local-repository.ts(1101,46) TS2554 on main. The file is untouched here, and the touched files have no errors.
  • Live failure evidence: Release Checks job 117292402768. The log shows [claude-subscription] using CLAUDE_CODE_OAUTH_TOKEN from environment, then the sessions_spawn refusal, then the 240s barrier timeout.
  • Not run: the Docker lane itself, which needs a real CLAUDE_CODE_OAUTH_TOKEN. I traced the path by code: once the check reports available, claude-cli gets an auth mode and prepareModelChoice admits the child.
  • The same commit is prepared for release/2026.10.5.

The Claude CLI readiness probe (`claude auth status`) always stripped the
Claude clear list, including CLAUDE_CODE_OAUTH_TOKEN, while CLI execution
keeps keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV for native-login
runs. Since #166338 made a configured runtime without prepared native auth
authoritatively `missing-auth`, that mismatch makes sessions_spawn refuse
an anthropic/* child pinned to claude-cli ("The selected account or native
runtime is unavailable") even though the parent turn runs. The Docker live
CLI backend lane (env-token subscription auth) hit this on every 2026.10.5
candidate and main, and its announce barrier then timed out at 240s.

Probe the same child environment execution uses: preserved keys survive the
clear list. Unlisted credentials (for example ANTHROPIC_API_KEY) stay
cleared, and a genuinely logged-out CLI still reports missing.
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@RomneyDa

Copy link
Copy Markdown
Member Author

Admin-merge evidence (2026.10.5 release blocker): the only failing checks (check-prod-types, check-test-types, check-additional-extension-package-boundary, and the ci-gate aggregate) all fail on src/snapshot/local-repository.ts(1101,46): error TS2554: Expected 1 arguments, but got 2., inherited from current main (file untouched by this PR; same error on origin/main, likely #174859). The PR's own files typecheck clean; cli-auth-seam 13/13, related anthropic tests 34/34.

@RomneyDa
RomneyDa merged commit a2e6a6b into main Oct 17, 2026
92 of 97 checks passed
@RomneyDa
RomneyDa deleted the fix/claude-cli-readiness-preserve-env branch October 17, 2026 04:58
RomneyDa added a commit that referenced this pull request Oct 17, 2026
…75114)

The Claude CLI readiness probe (`claude auth status`) always stripped the
Claude clear list, including CLAUDE_CODE_OAUTH_TOKEN, while CLI execution
keeps keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV for native-login
runs. Since #166338 made a configured runtime without prepared native auth
authoritatively `missing-auth`, that mismatch makes sessions_spawn refuse
an anthropic/* child pinned to claude-cli ("The selected account or native
runtime is unavailable") even though the parent turn runs. The Docker live
CLI backend lane (env-token subscription auth) hit this on every 2026.10.5
candidate and main, and its announce barrier then timed out at 240s.

Probe the same child environment execution uses: preserved keys survive the
clear list. Unlisted credentials (for example ANTHROPIC_API_KEY) stay
cleared, and a genuinely logged-out CLI still reports missing.

(cherry picked from commit a2e6a6b)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…enclaw#175114)

The Claude CLI readiness probe (`claude auth status`) always stripped the
Claude clear list, including CLAUDE_CODE_OAUTH_TOKEN, while CLI execution
keeps keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV for native-login
runs. Since openclaw#166338 made a configured runtime without prepared native auth
authoritatively `missing-auth`, that mismatch makes sessions_spawn refuse
an anthropic/* child pinned to claude-cli ("The selected account or native
runtime is unavailable") even though the parent turn runs. The Docker live
CLI backend lane (env-token subscription auth) hit this on every 2026.10.5
candidate and main, and its announce barrier then timed out at 240s.

Probe the same child environment execution uses: preserved keys survive the
clear list. Unlisted credentials (for example ANTHROPIC_API_KEY) stay
cleared, and a genuinely logged-out CLI still reports missing.
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…enclaw#175114)

The Claude CLI readiness probe (`claude auth status`) always stripped the
Claude clear list, including CLAUDE_CODE_OAUTH_TOKEN, while CLI execution
keeps keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV for native-login
runs. Since openclaw#166338 made a configured runtime without prepared native auth
authoritatively `missing-auth`, that mismatch makes sessions_spawn refuse
an anthropic/* child pinned to claude-cli ("The selected account or native
runtime is unavailable") even though the parent turn runs. The Docker live
CLI backend lane (env-token subscription auth) hit this on every 2026.10.5
candidate and main, and its announce barrier then timed out at 240s.

Probe the same child environment execution uses: preserved keys survive the
clear list. Unlisted credentials (for example ANTHROPIC_API_KEY) stay
cleared, and a genuinely logged-out CLI still reports missing.

(cherry picked from commit a2e6a6b)
(cherry picked from commit ad67421)
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 27, 2026
…75114)

The Claude CLI readiness probe (`claude auth status`) always stripped the
Claude clear list, including CLAUDE_CODE_OAUTH_TOKEN, while CLI execution
keeps keys named in OPENCLAW_LIVE_CLI_BACKEND_PRESERVE_ENV for native-login
runs. Since #166338 made a configured runtime without prepared native auth
authoritatively `missing-auth`, that mismatch makes sessions_spawn refuse
an anthropic/* child pinned to claude-cli ("The selected account or native
runtime is unavailable") even though the parent turn runs. The Docker live
CLI backend lane (env-token subscription auth) hit this on every 2026.10.5
candidate and main, and its announce barrier then timed out at 240s.

Probe the same child environment execution uses: preserved keys survive the
clear list. Unlisted credentials (for example ANTHROPIC_API_KEY) stay
cleared, and a genuinely logged-out CLI still reports missing.

(cherry picked from commit a2e6a6b)
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.

1 participant