Repository navigation
fix(acp): key Claude auth-conflict strip on the OAuth token, not CLAUDE_CONFIG_DIR - #3589
Conversation
…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>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED Behavioral default changes detectedThese public
|
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
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:
- Keys the strip on the actual credential, not a side-effect env var
- Removes the special-case skip logic in
_isolate_acp_data_dirthat was compensating for the wrong key - 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_keynow 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
Coverage Report •
|
||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ 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.
…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>
HUMAN:
There was a misconception fixed by this PR
key Claude auth-conflict strip on the OAuth token, not CLAUDE_CONFIG_DIR
AGENT:
Why
_ENV_CONFLICT_MAPstrippedANTHROPIC_API_KEY/ANTHROPIC_BASE_URLwheneverCLAUDE_CONFIG_DIRwas present — using the config-dir location as a proxy for "Claude is in OAuth mode". That was a fine heuristic whenCLAUDE_CONFIG_DIRwas only ever set to point at an OAuth login, but per-conversation data-dir isolation (acp_isolate_data_dir, #3492) now setsCLAUDE_CONFIG_DIRpurely 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 intoCLAUDE_CONFIG_DIR; the OAuth token arrives only as theCLAUDE_CODE_OAUTH_TOKENenv var. So the strip mis-fires:CLAUDE_CONFIG_DIRfor an API-key Claude conversation would strip the working key, so_isolate_acp_data_dirhad 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.ANTHROPIC_BASE_URLstripped → 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=Trueon the cloud start path, which is exactly when Bug 1 bites.Summary
_ENV_CONFLICT_MAPfromCLAUDE_CONFIG_DIR→CLAUDE_CODE_OAUTH_TOKEN(the actual OAuth credential)._isolate_acp_data_dirClaude carve-out — relocation is now credential-blind, so API-key Claude gets the same isolation + pause/resume continuity as OAuth Claude.CLAUDE_CONFIG_DIRalone no longer strips the key, and invert the isolation test (API-key Claude now relocatesCLAUDE_CONFIG_DIRwhile keeping its key).Net behavior: OAuth Claude → token wins,
ANTHROPIC_API_KEY/ANTHROPIC_BASE_URLstripped (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, includingtest_config_dir_alone_does_not_suppress_api_key(regression guard) andtest_claude_isolates_under_api_key.End-to-end (local SaaS-equivalent: OSS app_server +
DockerSandboxServicedriving the sameLiveStatusAppConversationServiceSaaS 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_MAPis{'CLAUDE_CODE_OAUTH_TOKEN': {...}}and the carve-out is gone):docker stop+startthe sandbox (process restart,/workspacepersists) → turn-2 recalled the codeword, sameacp_session_id, no<<RESUMED CONVERSATION>>marker,CLAUDE_CONFIG_DIRrelocated to/workspace/.../acp/claude-code. ✅ (re-key didn't break the OAuth path)acp_session_id, recalled. ✅ANTHROPIC_API_KEY, no OAuth token), inspect theclaude-agent-acpsubprocess env in the sandbox:agent-server:1.26.0-python, carve-out present):CLAUDE_CONFIG_DIR=<UNSET>,isolation_applied=False.CLAUDE_CONFIG_DIR=/workspace/conversations/<id>/acp/claude-code,ANTHROPIC_API_KEYretained,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
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:b26a08b-pythonRun
All tags pushed for this build
About Multi-Architecture Support
b26a08b-python) is a multi-arch manifest supporting both amd64 and arm64b26a08b-python-amd64) are also available if needed