Skip to content

fix(acp): key Claude auth-conflict strip on the OAuth token, not CLAUDE_CONFIG_DIR - #3589

Merged
simonrosenberg merged 2 commits into
mainfrom
fix-acp-claude-oauth-conflict-key
Jun 9, 2026
Merged

simonrosenberg merged 2 commits into
mainfrom
fix-acp-claude-oauth-conflict-key

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

There was a misconception fixed by this PR
key Claude auth-conflict strip on the OAuth token, not CLAUDE_CONFIG_DIR

  • A human has tested these changes.

AGENT:


Why

_ENV_CONFLICT_MAP stripped ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL whenever CLAUDE_CONFIG_DIR was present — using the config-dir location as a proxy for "Claude is in OAuth mode". That was a fine heuristic when CLAUDE_CONFIG_DIR was only ever set to point at an OAuth login, but per-conversation data-dir isolation (acp_isolate_data_dir, #3492) now sets CLAUDE_CONFIG_DIR purely to relocate the CLI's data/session tree — independent of auth mode. Claude also has no file-secret materialization, so the SDK never actually writes a credential into CLAUDE_CONFIG_DIR; the OAuth token arrives only as the CLAUDE_CODE_OAUTH_TOKEN env var. So the strip mis-fires:

  • Bug 1: relocating CLAUDE_CONFIG_DIR for an API-key Claude conversation would strip the working key, so _isolate_acp_data_dir had a carve-out that skipped isolation entirely for API-key Claude → no per-conversation isolation (cache/config/lock races in grouped sandboxes, More agent_status to execution_status_updates, and error state #1019) and no pause/resume continuity on cloud.
  • Bug 2: an OAuth token delivered via env without isolation never got a co-present ANTHROPIC_BASE_URL stripped → the bearer is proxied and auth breaks silently.

Both stem from keying the strip on the location rather than the credential. Surfaced landing the cloud-ACP pivot (OpenHands/OpenHands#15746); OpenHands#14722 turns acp_isolate_data_dir=True on the cloud start path, which is exactly when Bug 1 bites.

Summary

  • Re-key _ENV_CONFLICT_MAP from CLAUDE_CONFIG_DIR → CLAUDE_CODE_OAUTH_TOKEN (the actual OAuth credential).
  • Delete the _isolate_acp_data_dir Claude carve-out — relocation is now credential-blind, so API-key Claude gets the same isolation + pause/resume continuity as OAuth Claude.
  • Update tests: re-key the suppression suite on the token, add a regression test that CLAUDE_CONFIG_DIR alone no longer strips the key, and invert the isolation test (API-key Claude now relocates CLAUDE_CONFIG_DIR while keeping its key).

Net behavior: OAuth Claude → token wins, ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL stripped (now whether or not isolation is on, fixing Bug 2). API-key Claude → no token → nothing stripped, key retained, data dir relocated (fixing Bug 1).

Issue Number

Closes #3588. Part of OpenHands/OpenHands#15746.

How to Test

Unit (uv run pytest tests/sdk/agent/test_acp_agent.py::TestACPEnvConflictSuppression tests/sdk/agent/test_acp_agent.py::TestACPDataDirIsolation): 15 pass, including test_config_dir_alone_does_not_suppress_api_key (regression guard) and test_claude_isolates_under_api_key.

End-to-end (local SaaS-equivalent: OSS app_server + DockerSandboxService driving the same LiveStatusAppConversationService SaaS uses, with a runtime image built from this branch — python -m openhands.agent_server.docker.build --target source-minimal; verified the built image's imported _ENV_CONFLICT_MAP is {'CLAUDE_CODE_OAUTH_TOKEN': {...}} and the carve-out is gone):

  • Regression — OAuth Claude self-resume: create → turn-1 codeword → docker stop+start the sandbox (process restart, /workspace persists) → turn-2 recalled the codeword, same acp_session_id, no <<RESUMED CONVERSATION>> marker, CLAUDE_CONFIG_DIR relocated to /workspace/.../acp/claude-code. ✅ (re-key didn't break the OAuth path)
  • Regression — Codex self-resume: same flow, same acp_session_id, recalled. ✅
  • Fix target — API-key Claude isolation, before/after: API-key Claude (dummy ANTHROPIC_API_KEY, no OAuth token), inspect the claude-agent-acp subprocess env in the sandbox:
    • OLD image (agent-server:1.26.0-python, carve-out present): CLAUDE_CONFIG_DIR=<UNSET>, isolation_applied=False.
    • THIS branch's image: CLAUDE_CONFIG_DIR=/workspace/conversations/<id>/acp/claude-code, ANTHROPIC_API_KEY retained, isolation_applied=True. ✅

A live API-key Anthropic call wasn't exercised (no spare API key); the fix is purely env-assembly, validated at the env level above (the subprocess spawns with this env at the unauthenticated session/new, before any model call).

Video/Screenshots

N/A (backend); env-level logs above.


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:b26a08b-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-b26a08b-python \
  ghcr.io/openhands/agent-server:b26a08b-python

All tags pushed for this build

ghcr.io/openhands/agent-server:b26a08b-golang-amd64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-golang-amd64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-golang-amd64
ghcr.io/openhands/agent-server:b26a08b-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:b26a08b-golang-arm64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-golang-arm64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-golang-arm64
ghcr.io/openhands/agent-server:b26a08b-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:b26a08b-java-amd64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-java-amd64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-java-amd64
ghcr.io/openhands/agent-server:b26a08b-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:b26a08b-java-arm64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-java-arm64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-java-arm64
ghcr.io/openhands/agent-server:b26a08b-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:b26a08b-python-amd64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-python-amd64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-python-amd64
ghcr.io/openhands/agent-server:b26a08b-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:b26a08b-python-arm64
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-python-arm64
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-python-arm64
ghcr.io/openhands/agent-server:b26a08b-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:b26a08b-golang
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-golang
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-golang
ghcr.io/openhands/agent-server:b26a08b-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:b26a08b-java
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-java
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-java
ghcr.io/openhands/agent-server:b26a08b-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:b26a08b-python
ghcr.io/openhands/agent-server:b26a08beeef451b75ade5f5e53fa290115549091-python
ghcr.io/openhands/agent-server:fix-acp-claude-oauth-conflict-key-python
ghcr.io/openhands/agent-server:b26a08b-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., b26a08b-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., b26a08b-python-amd64) are also available if needed

simonrosenberg and others added 2 commits June 9, 2026 14:23
…DE_CONFIG_DIR

_ENV_CONFLICT_MAP stripped ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL whenever
CLAUDE_CONFIG_DIR was set. Since data-dir isolation (#3492) sets CLAUDE_CONFIG_DIR
regardless of auth mode, that mis-fired: relocating the config dir for an
API-key Claude conversation would have stripped the working key, so a carve-out
skipped isolation for API-key Claude entirely (no per-conversation isolation, no
pause/resume continuity). It also missed the conflict when an OAuth token arrived
via env without isolation (ANTHROPIC_BASE_URL left in place, silently breaking
the bearer).

Re-key the strip on the actual credential (CLAUDE_CODE_OAUTH_TOKEN) and drop the
carve-out: API-key Claude now gets the same isolation as OAuth Claude, and the
base_url conflict is caught whenever the OAuth token is active, isolated or not.

Closes #3588.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ation (#3588)

Re-key the suppression tests on CLAUDE_CODE_OAUTH_TOKEN; add a regression test
that CLAUDE_CONFIG_DIR alone no longer strips ANTHROPIC_API_KEY; invert the
isolation test so API-key Claude now relocates CLAUDE_CONFIG_DIR while keeping
its key.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Behavioral default changes detected

These public Field(default=...) changes differ from the latest released baseline, but they were already present on the base branch, so this PR was not auto-marked with the release-note-required label:

  • openhands.sdk.settings.model.OpenHandsAgentSettings.condenser: CondenserSettings → LLMSummarizingCondenserSettings

Action log

@simonrosenberg
simonrosenberg requested a review from VascoSch92 June 9, 2026 12:35
@simonrosenberg simonrosenberg self-assigned this Jun 9, 2026
@simonrosenberg simonrosenberg added the acp About ACP label Jun 9, 2026

all-hands-bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Taste Rating

🟢 Good taste — Elegant, targeted bug fix with no unnecessary complexity.

Analysis

This is a clean, minimal fix for a real bug. The core issue: _ENV_CONFLICT_MAP was keyed on CLAUDE_CONFIG_DIR (a location lever for data-dir isolation) rather than on the actual credential (CLAUDE_CODE_OAUTH_TOKEN). This caused the conflict strip to fire incorrectly when isolation was enabled, silently breaking API-key authentication.

The fix correctly:

  1. Keys the strip on the actual credential, not a side-effect env var
  2. Removes the special-case skip logic in _isolate_acp_data_dir that was compensating for the wrong key
  3. Allows API-key users to benefit from isolation (previously they were excluded)

No critical issues found.

Testing

The test suite is comprehensive:

  • Covers all source paths (acp_env, os.environ, registry, secrets)
  • Negative case confirms no suppression without the OAuth token
  • New regression test (test_config_dir_alone_does_not_suppress_api_key) directly covers #3588
  • test_claude_isolates_under_api_key now validates that isolation works under either auth mode — a meaningful improvement over the old skip behavior

Minor Note

The docstring at the top of _ENV_CONFLICT_MAP is detailed but worthwhile — it explains the auth conflict rationale that isn't obvious from context. The comments in _isolate_acp_data_dir are a bit verbose but don't obscure the logic.


[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW
    The change is targeted to the exact bug, tests cover the regression, and the behavior change (keeping API key instead of stripping it) is strictly an improvement. No new attack surface introduced.

VERDICT:
✅ Worth merging: Core logic is sound, fix is correct, tests are thorough.

KEY INSIGHT:
Keying auth-conflict logic on the credential itself (CLAUDE_CODE_OAUTH_TOKEN) rather than on a location side-effect (CLAUDE_CONFIG_DIR) is the right abstraction — it matches the intent and eliminates the special-case that was masking the bug.


This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/agent
   acp_agent.py113610191%714–716, 953–954, 997, 999, 1003, 1007, 1033, 1096–1097, 1102, 1169, 1483, 1486–1487, 1504–1505, 1541, 1546, 1624, 1629, 1963–1964, 2248–2251, 2255–2257, 2260–2264, 2266, 2484, 2498–2499, 2502–2504, 2512, 2516, 2520–2521, 2527–2528, 2540–2541, 2544, 2578, 2582–2584, 2588–2589, 2621, 2705, 2892–2894, 2897–2898, 2938, 3080, 3084, 3092–3094, 3132–3133, 3136, 3144–3146, 3148, 3150, 3154, 3157, 3166–3168, 3170, 3206–3207, 3225–3228, 3231, 3235–3237, 3239, 3243–3244, 3452–3453
TOTAL29660842671% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ QA Report: PASS

The ACP startup path now applies Claude data-dir isolation for API-key auth while preserving the API key, and strips API-key/proxy conflicts only when CLAUDE_CODE_OAUTH_TOKEN is present.

Does this PR achieve its stated goal?

Yes. I exercised ACPAgent.init_state() with a Claude ACP command and concrete API-key/OAuth env inputs, capturing the actual subprocess environment that would be used to start Claude ACP. Compared with origin/main, the PR fixes both target behaviors: API-key Claude now gets a per-conversation CLAUDE_CONFIG_DIR without losing ANTHROPIC_API_KEY, and OAuth-token Claude strips ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL even when isolation is off.

Phase Result
Environment Setup ✅ make build completed successfully and installed the uv-managed dev environment.
CI Status 🟡 At review time: 27 checks successful, 6 in progress, 15 skipped; no current failures reported by gh pr checks.
Functional Verification ✅ Ran the SDK ACP startup path before/after and verified the subprocess env matches the PR goal.
Functional Verification

Test 1: API-key Claude gets isolated without losing ANTHROPIC_API_KEY

Step 1 — Reproduce baseline without the fix:
Ran git switch --detach origin/main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_env_probe.py.

Relevant output:

{
  "name": "api_key_isolation_from_acp_env",
  "ANTHROPIC_API_KEY": "sk-valid",
  "CLAUDE_CONFIG_DIR": null,
  "isolation_applied": false
},
{
  "name": "api_key_isolation_from_secret_registry",
  "ANTHROPIC_API_KEY": "sk-valid",
  "CLAUDE_CONFIG_DIR": null,
  "isolation_applied": false
}

This confirms the old behavior: under API-key auth, Claude ACP kept the key but skipped CLAUDE_CONFIG_DIR relocation, so per-conversation data-dir isolation was not applied.

Step 2 — Apply the PR's changes:
Checked out fix-acp-claude-oauth-conflict-key at b26a08beeef451b75ade5f5e53fa290115549091.

Step 3 — Re-run with the fix in place:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_env_probe.py.

Relevant output:

{
  "name": "api_key_isolation_from_acp_env",
  "ANTHROPIC_API_KEY": "sk-valid",
  "CLAUDE_CONFIG_DIR": "/tmp/qa-acp-api_key_isolation_from_acp_env-.../conversations/conv-qa/acp/claude-code",
  "isolation_applied": true
},
{
  "name": "api_key_isolation_from_secret_registry",
  "ANTHROPIC_API_KEY": "sk-valid",
  "CLAUDE_CONFIG_DIR": "/tmp/qa-acp-api_key_isolation_from_secret_registry-.../conversations/conv-qa/acp/claude-code",
  "isolation_applied": true
}

This shows the fix works for both acp_env and secret_registry: isolation is applied and the API key remains present in the subprocess env.

Test 2: OAuth token strips conflicting API-key/proxy env even without isolation

Step 1 — Reproduce baseline without the fix:
On origin/main, the same probe produced:

{
  "name": "oauth_token_conflict_strip_without_isolation_from_acp_env",
  "CLAUDE_CODE_OAUTH_TOKEN": "oauth-token",
  "ANTHROPIC_API_KEY": "sk-conflict",
  "ANTHROPIC_BASE_URL": "https://proxy.example.com"
},
{
  "name": "oauth_token_conflict_strip_without_isolation_from_secret_registry",
  "CLAUDE_CODE_OAUTH_TOKEN": "oauth-token",
  "ANTHROPIC_API_KEY": "sk-conflict",
  "ANTHROPIC_BASE_URL": "https://proxy.example.com"
}

This confirms the old bug: when the OAuth token arrived without CLAUDE_CONFIG_DIR, conflicting API-key/proxy values remained in the subprocess env.

Step 2 — Apply the PR's changes:
Checked out the PR branch.

Step 3 — Re-run with the fix in place:
The PR branch produced:

{
  "name": "oauth_token_conflict_strip_without_isolation_from_acp_env",
  "CLAUDE_CODE_OAUTH_TOKEN": "oauth-token",
  "ANTHROPIC_API_KEY": null,
  "ANTHROPIC_BASE_URL": null
},
{
  "name": "oauth_token_conflict_strip_without_isolation_from_secret_registry",
  "CLAUDE_CODE_OAUTH_TOKEN": "oauth-token",
  "ANTHROPIC_API_KEY": null,
  "ANTHROPIC_BASE_URL": null
}

This confirms the strip is now keyed on the OAuth token credential and works whether values come from acp_env or secret_registry.

Test 3: CLAUDE_CONFIG_DIR alone no longer strips API-key auth

Step 1 — Reproduce baseline without the fix:
On origin/main, the probe produced:

{
  "name": "config_dir_alone_keeps_api_key",
  "CLAUDE_CONFIG_DIR": "/tmp/claude-isolated",
  "ANTHROPIC_API_KEY": null
}

This confirms the old bug: merely setting the data-dir location caused the API key to be removed.

Step 2 — Apply the PR's changes:
Checked out the PR branch.

Step 3 — Re-run with the fix in place:
The PR branch produced:

{
  "name": "config_dir_alone_keeps_api_key",
  "CLAUDE_CONFIG_DIR": "/tmp/claude-isolated",
  "ANTHROPIC_API_KEY": "sk-valid"
}

This confirms CLAUDE_CONFIG_DIR is now treated as a location setting, not as the OAuth credential signal.

Unable to Verify

I did not make a live Anthropic/Claude API call because no real Claude OAuth or Anthropic API credentials were available in this QA environment. The verified behavior is the target of this PR: the actual env assembled for the ACP subprocess before any model call.

Issues Found

None.


This QA review was created by an AI agent (OpenHands) on behalf of the user.

@simonrosenberg
simonrosenberg merged commit d078f94 into main Jun 9, 2026
59 of 62 checks passed
@simonrosenberg
simonrosenberg deleted the fix-acp-claude-oauth-conflict-key branch June 9, 2026 13:06
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
…DE_CONFIG_DIR (OpenHands#3589)

Co-authored-by: Simon Rosenberg <simon@openhands.dev>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

acp About ACP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP: _ENV_CONFLICT_MAP keyed on CLAUDE_CONFIG_DIR mis-fires — strips ANTHROPIC_API_KEY during data-dir isolation

3 participants