Repository navigation
feat(acp): materialise reserved file-content auth secrets (Codex auth.json, Gemini Vertex SA) - #3474
Conversation
….json, Gemini Vertex SA) Some ACP providers authenticate from a file on disk rather than an env var: Codex reads `$CODEX_HOME/auth.json`; Gemini (Vertex AI) reads a service-account JSON at `GOOGLE_APPLICATION_CREDENTIALS`. The user supplies the credential as a pasted blob (a reserved "file-content" secret); the SDK now materialises it to the file path the CLI expects, with the right env var pointing at it. Mechanism is declarative and registry-driven: - Add `ACPFileSecretSpec` (frozen) + a per-provider `file_secrets` tuple on `ACP_PROVIDERS`, mapping a reserved secret name -> filename + the env var that points at it (dir for Codex's CODEX_HOME, file for Gemini's GAC). Codex: `CODEX_AUTH_JSON` -> `auth.json`, env `CODEX_HOME`. Gemini: `GOOGLE_APPLICATION_CREDENTIALS_JSON` -> `gcloud-credentials.json`, env `GOOGLE_APPLICATION_CREDENTIALS`; warns if GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION are unset. - Materialisation is keyed off the configured `secret_name` (command- independent, so custom/aliased acp_command still works). Implementation: - Read the secret value from `state.secret_registry` (the canonical channel per #1022), falling back to `agent_context.secrets` (canvas-local drain). - Seed into the durable per-conversation root `<persistence_dir>/acp/{provider}/` (the same tree the regular agent persists to) — seed-if-absent, no TemporaryDirectory, 0600 files in 0700 dirs — so a token the CLI refreshes on disk survives a recycle and a stale paste never clobbers it. Falls back under the workspace when unpersisted. - Point the provider's data-dir env var at the materialised path; exclude the blob from plain env injection and the <CUSTOM_SECRETS> advertisement. - Make Codex auth detection CODEX_HOME-aware (was hardcoded to ~/.codex/auth.json) and prefer the gemini-cli `vertex-ai` auth method when the SA file is present. Part of OpenHands/agent-canvas#988; implements #1020. Depends on #1022. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 QA Report: PARTIAL
The SDK file-secret materialisation behavior works in the actual ACPAgent start path, but live Codex/Gemini provider authentication could not be exercised because those CLIs are not installed in this environment.
Does this PR achieve its stated goal?
Yes for the SDK behavior this PR set out to implement. With the PR applied, reserved file-content secrets are written to durable per-conversation/pinned/workspace fallback paths, exposed via CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS, excluded from env injection and <CUSTOM_SECRETS>, preserve existing refreshed files, and drive relocated auth-method selection. The only unverified piece is a live handoff to real Codex/Gemini CLIs, which were unavailable in the QA environment.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no test suite/linters were run locally. |
| CI Status | ⏳ At check time: 20 successful, 8 in progress, 1 skipped. |
| Functional Verification | ✅ SDK behavior verified before/after using the real ACPAgent._start_acp_server path with the external ACP subprocess/transport replaced by a stub. |
Functional Verification
Test 1: Reserved file-content secrets materialise instead of becoming plain env vars
Step 1 — Reproduce / establish baseline (without the fix):
Ran git checkout --detach origin/main && uv run python /tmp/acp_file_secret_qa.py.
Relevant output:
{
"codex": {
"CODEX_HOME": null,
"blob_exported": true,
"file_exists": false
},
"gemini": {
"GOOGLE_APPLICATION_CREDENTIALS": null,
"blob_exported": true,
"file_exists": false
},
"prompt": {
"mentions_file_blob": true,
"mentions_plain_secret": true
}
}This confirms the old behavior: the pasted file-content blobs are treated as ordinary env secrets, no credential file/path is created, and the blob name is advertised to the agent.
Step 2 — Apply the PR's changes:
Checked out 536bd064b1a2281c037eb0465a9935775ad89e7f.
Step 3 — Re-run with the fix in place:
Ran uv run python /tmp/acp_file_secret_qa.py.
Relevant output:
{
"codex": {
"CODEX_HOME": "/tmp/.../conversations/.../acp/codex",
"blob_exported": false,
"dir_mode": "0o700",
"file_content": "{\"tokens\":\"qa\"}",
"file_exists": true,
"file_mode": "0o600"
},
"gemini": {
"GOOGLE_APPLICATION_CREDENTIALS": "/tmp/.../acp/gemini-cli/gcloud-credentials.json",
"blob_exported": false,
"file_content": "{\"type\":\"service_account\",\"project_id\":\"qa\"}",
"file_exists": true,
"file_mode": "0o600"
},
"prompt": {
"mentions_file_blob": false,
"mentions_plain_secret": true
}
}This shows the fix works: Codex and Gemini file secrets are materialised to disk with restricted permissions, path env vars point to the materialised credentials, blob env vars are not injected, and the file blob is no longer advertised as a normal secret.
Test 2: Persistence, override, fallback, and auth-selection behavior
Step 1 — Baseline on origin/main:
The same baseline run produced:
{
"agent_context_drain": {
"CODEX_HOME": null,
"blob_exported": true,
"file_content": null
},
"acp_env_pin": {
"CODEX_HOME": "/tmp/.../pinned-codex-home",
"file_content": null
},
"fallback_root": {
"CODEX_HOME": null,
"file_content": null,
"under_workspace": false
},
"auth_selection": {
"codex_relocated": "openai-api-key",
"gemini_vertex": "gemini-api-key"
},
"seed_if_absent": {
"CODEX_HOME": null,
"file_content": "{\"refreshed\":true}"
}
}This shows the previous SDK path did not materialise drain secrets, did not seed files under explicit acp_env pins or workspace fallback roots, and ignored relocated Codex / Vertex credential files during auth-method selection.
Step 2 — Re-run on the PR commit:
The PR run produced:
{
"agent_context_drain": {
"CODEX_HOME": "/tmp/.../conversations/.../acp/codex",
"blob_exported": false,
"file_content": "{\"drain\":true}"
},
"acp_env_pin": {
"CODEX_HOME": "/tmp/.../pinned-codex-home",
"file_content": "{\"pinned\":true}"
},
"fallback_root": {
"CODEX_HOME": "/tmp/.../workspace/.openhands/acp/codex",
"file_content": "{\"fallback\":true}",
"under_workspace": true
},
"auth_selection": {
"codex_relocated": "chatgpt",
"gemini_vertex": "vertex-ai"
},
"seed_if_absent": {
"CODEX_HOME": "/tmp/.../conversations/.../acp/codex",
"file_content": "{\"refreshed\":true}"
}
}This confirms the PR covers the claimed edge cases: drain secrets materialise, explicit acp_env pins remain authoritative while still getting seeded, non-persisted conversations fall back under the workspace, existing refreshed files are preserved, and auth selection now recognizes relocated Codex and Vertex service-account files.
Unable to Verify
I checked for real provider CLIs with command -v codex-acp, command -v gemini, and command -v gemini-cli; none were present. Because the environment lacks those CLIs and real provider credentials, I did not perform a live Codex/Gemini authentication round-trip. The verification above exercises the SDK behavior up to the ACP subprocess handoff, which is where this PR's materialisation/env changes occur.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
…(mechanism vs policy) Split the SDK *mechanism* (write the credential file in the runtime pod, set the env var, seed-if-absent, perms, CODEX_HOME/Vertex detection) from the *policy* (which secret maps to which file/env for which CLI), so a downstream application can support other ACP servers with different file-auth schemes without an SDK change — addressing review feedback that the SDK shouldn't bake in product CLI decisions. Why keep the engine in the SDK: in cloud the ACP CLI runs in a remote runtime pod and the credential arrives only as a transmitted secret over the conversation channel; the downstream app (Canvas/OpenHands SaaS) is not in that pod and can't write its filesystem, so only the SDK can materialise the file. A read-only K8s projected-secret mount can't replace it either — Codex rewrites auth.json on token refresh, which a read-only mount breaks. So mechanism stays SDK-side; only policy moves out. Changes: - `ACPFileSecretSpec` is now a frozen pydantic model (was a dataclass) with a `subdir` field and path-traversal validators, so it serialises cleanly as a configurable field and rejects unsafe downstream-supplied paths. - Add `acp_file_secrets: list[ACPFileSecretSpec]` to `ACPAgent` and `ACPAgentSettings` (forwarded via `create_agent`), defaulting to the built-in Codex/Gemini specs via `default_acp_file_secrets()`. Downstream overrides or extends it; `[]` opts out entirely. - `_materialise_file_secrets` / `_present_file_secret_names` now iterate the agent's configured specs instead of a hardcoded global registry. - Replace `ACP_FILE_SECRETS_BY_NAME` with `default_acp_file_secrets()`. Tests: downstream custom-provider override, opt-out via `[]`, settings pass-through, subdir wiring, pydantic frozen + path-traversal rejection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ 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.
Code Review
This is a well-executed feature with a clean separation of policy (ACPFileSecretSpec / file_secrets on ACPProviderInfo) from mechanism (_materialise_file_secrets), correct 0o600/0o700 permissions from the start, and a seed-if-absent semantic that correctly handles token-refresh scenarios. The test coverage is comprehensive — including drain-channel fallback, acp_env pin precedence, non-persisted workspace fallback, and the new auth-method detection cases.
Three minor items below worth addressing before merge:
-
PR description inaccuracy — The Mechanism section says materialisation is "keyed … via the aggregated
ACP_FILE_SECRETS_BY_NAMEregistry lookup" but no such symbol exists in the implementation. The actual mechanism is theacp_file_secretslist onACPAgent(populated fromdefault_acp_file_secrets()). The description should be updated to match. -
_write_secret_filepermission window — See inline comment at line 277. -
Silent
chmod 0o700on user-pinned directories — See inline comment at line 1576.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
⚠️ QA Report: PASS WITH ISSUES
The PR successfully materialises Codex and Gemini file-content secrets through the real SDK Conversation → ACPAgent → subprocess path, but one permissions edge case contradicts the stated 0600 guarantee.
Does this PR achieve its stated goal?
Mostly yes. With the PR checked out, a real Conversation using ACPAgent launched an ACP-compatible subprocess that saw CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS pointing at materialised credential files; the raw blob secrets were not exported as env vars, and auth selection called chatgpt / vertex-ai respectively. However, when a non-empty credential file already existed, the PR preserved its contents as intended but left its existing 0644 mode unchanged, so the “0600 files in 0700 dirs” part of the goal is not fully met.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv run created the project environment and imported the SDK successfully. |
| CI Status | Run tests/sdk-tests), 5 pending; I did not run tests locally. |
| Functional Verification |
Functional Verification
I used a temporary ACP-compatible subprocess as the ACP command, then exercised the public SDK path: Conversation(agent=ACPAgent(...), secrets=...), send_message(...), and run(). The subprocess recorded the actual startup environment and on-disk credential files it received.
Test 1: Codex CODEX_AUTH_JSON before/after
Step 1 — Establish baseline without the fix:
Ran git checkout origin/main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py codex:
{
"auth_methods_called": [],
"custom_secrets_mentions_file_blob": true,
"startup": {
"CODEX_AUTH_JSON_present": true,
"CODEX_HOME": null
}
}This shows the baseline exports the blob as an env var, does not set CODEX_HOME, and cannot select the chatgpt auth method.
Step 2 — Apply the PR's changes:
Checked out acp-materialise-file-secrets at 3b2ad1a5e3420e999385b4a394b1c60222ec15df.
Step 3 — Re-run with the fix in place:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py codex:
{
"auth_methods_called": ["chatgpt"],
"custom_secrets_mentions_file_blob": false,
"startup": {
"CODEX_AUTH_JSON_present": false,
"CODEX_HOME": "/tmp/.../persist/<conversation-id>/acp/codex",
"CODEX_HOME_target_exists": true,
"CODEX_HOME_target_mode": "0o600",
"CODEX_HOME_parent_mode": "0o700",
"CODEX_HOME_target_text": "{"tokens":"qa-codex"}"
}
}This confirms the PR writes auth.json, points CODEX_HOME at the directory, excludes the blob env var/prompt advertisement, and selects chatgpt.
Test 2: Gemini Vertex service-account JSON before/after
Step 1 — Establish baseline without the fix:
Ran git checkout origin/main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py gemini:
{
"auth_methods_called": [],
"custom_secrets_mentions_file_blob": true,
"startup": {
"GOOGLE_APPLICATION_CREDENTIALS": null,
"GOOGLE_APPLICATION_CREDENTIALS_JSON_present": true
}
}This shows the baseline exports the pasted JSON blob and never points Gemini at a credential file.
Step 2 — Apply the PR's changes:
Checked out the PR branch again.
Step 3 — Re-run with the fix in place:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py gemini:
{
"auth_methods_called": ["vertex-ai"],
"custom_secrets_mentions_file_blob": false,
"startup": {
"GOOGLE_APPLICATION_CREDENTIALS": "/tmp/.../persist/<conversation-id>/acp/gemini-cli/gcloud-credentials.json",
"GOOGLE_APPLICATION_CREDENTIALS_JSON_present": false,
"GOOGLE_APPLICATION_CREDENTIALS_target_exists": true,
"GOOGLE_APPLICATION_CREDENTIALS_target_mode": "0o600",
"GOOGLE_APPLICATION_CREDENTIALS_parent_mode": "0o700",
"GOOGLE_APPLICATION_CREDENTIALS_target_text": "{"type":"service_account","project_id":"qa"}"
}
}This confirms the Vertex credential file is materialised and selected over API-key auth.
Test 3: Additional user-facing SDK scenarios
Ran these on the PR branch:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py codex-pinned→ subprocess sawCODEX_HOMEat the caller-pinned directory andauth.jsonexisted there with mode0o600.OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py codex-agent-context→ file-content secret supplied throughAgentContext.secretsmaterialised correctly and was not exported asCODEX_AUTH_JSON.OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_file_secret_qa.py codex-preserve→ pre-existingauth.jsoncontent remained{"refreshed":true}rather than being overwritten by the stale pasted blob, but the file mode remained0o644(see issue below).OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY' ...importingACPFileSecretSpec,default_acp_file_secrets, andACPAgentSettings(...).create_agent()showed the public settings surface includesCODEX_AUTH_JSONandGOOGLE_APPLICATION_CREDENTIALS_JSON.
Unable to Verify
I did not verify live Codex/Gemini authentication against the actual vendor CLIs because the environment did not provide real Codex auth.json or Gemini Vertex service-account credentials. The exercised path still launched a real subprocess through the SDK and verified the precise file/env boundary those CLIs consume.
Issues Found
- 🟠 Issue: A pre-existing non-empty credential file is preserved without tightening its mode; in QA it remained
0o644, despite the PR claiming0600credential files.
This review was generated by an AI agent (OpenHands) on behalf of the user.
test_acp_agent_settings_export_schema_has_acp_section asserts the exact set of UI fields in the 'acp' settings section. acp_file_secrets is a programmatic/downstream config knob (a list of structured specs), not an end-user form field, so drop its settings-form metadata. It stays a plain serializable field on ACPAgentSettings (round-trips, settable in code/JSON); it just no longer appears in the settings-form schema section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
- fchmod the raw fd to 0600 before writing, so secret bytes never land at a wider mode even when the file pre-existed (e.g. 0644 empty file). - Seed-if-absent branch now also chmods the preserved file to 0600 (QA found a pre-existing 0644 credential staying world-readable after restore/refresh). - Skip the dir chmod for an externally-pinned acp_env dir so a deliberately group-readable shared mount isn't silently narrowed; the credential file is still 0600. - Make the default_acp_file_secrets ordering invariant explicit in the test. - Add regressions: preserved file clamped to 0600; pinned dir perms preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified current PR head f3584113 (the PR advanced from the supplied a52db25 during QA): ACP file-content secrets now materialise to durable files, path env vars point at them, raw blob env injection/advertising is suppressed, and existing credential files are preserved.
Does this PR achieve its stated goal?
Yes. Exercising ACPAgent against a real local ACP subprocess showed the PR delivers the stated behavior for Codex and Gemini Vertex file-backed auth: on main, reserved blob secrets were only injected as plain env vars and no auth file/path env was created; on the PR, the SDK wrote auth.json / gcloud-credentials.json under the conversation root (or pinned CODEX_HOME), set CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS, selected chatgpt / vertex-ai, and kept the blob secret out of env and <CUSTOM_SECRETS> while preserving ordinary secrets.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no test/lint suite was run locally. |
| CI Status | 🟡 GitHub reported 20 successful, 0 failing, 3 skipped, and 7 pending checks at review time. |
| Functional Verification | ✅ Real SDK startup path exercised with a subprocess ACP server for Codex, Gemini, pinned env, and seed-if-absent. |
Functional Verification
Test 1: Codex CODEX_AUTH_JSON materialises to CODEX_HOME/auth.json
Step 1 — Establish baseline on main:
Ran:
git checkout --detach origin/main
uv run python /tmp/qa_acp_probe.py --scenario codex --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {},
"raw_file_secret_env_present": true,
"target_exists": false,
"suffix_contains_file_secret": true,
"requests": ["initialize", "session/new", "session/set_mode"]
}This confirms the old behavior: the pasted CODEX_AUTH_JSON blob reached the ACP subprocess as an ordinary env var, no durable auth.json was created, no CODEX_HOME was set, the blob was advertised, and no chatgpt authentication occurred.
Step 2 — Apply the PR changes:
Checked out the current PR head:
git checkout --detach origin/acp-materialise-file-secretsStep 3 — Re-run with the fix in place:
Ran:
uv run python /tmp/qa_acp_probe.py --scenario codex --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {"CODEX_HOME": "/tmp/.../conversation-root/acp/codex"},
"raw_file_secret_env_present": false,
"target_exists": true,
"target_content": "{"tokens":"qa-codex-token"}",
"target_mode": "0o600",
"target_parent_mode": "0o700",
"suffix_contains_file_secret": false,
"suffix_contains_plain_secret": true,
"requests": ["initialize", "authenticate:chatgpt", "session/new", "session/set_mode"]
}This shows the PR materialises the file under the durable conversation root, points CODEX_HOME at it, tightens permissions, suppresses the raw blob from env/prompt advertisement, keeps normal secrets available, and authenticates with chatgpt.
Test 2: Gemini Vertex service-account JSON materialises to GOOGLE_APPLICATION_CREDENTIALS
Step 1 — Establish baseline on main:
Ran:
git checkout --detach origin/main
uv run python /tmp/qa_acp_probe.py --scenario gemini --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {},
"raw_file_secret_env_present": true,
"target_exists": false,
"suffix_contains_file_secret": true,
"requests": ["initialize", "session/new", "session/set_mode"]
}This confirms the old behavior did not create a Vertex service-account file or set GOOGLE_APPLICATION_CREDENTIALS.
Step 2 — Apply the PR changes:
Checked out the current PR head.
Step 3 — Re-run with the fix in place:
Ran:
uv run python /tmp/qa_acp_probe.py --scenario gemini --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {"GOOGLE_APPLICATION_CREDENTIALS": "/tmp/.../conversation-root/acp/gemini-cli/gcloud-credentials.json"},
"raw_file_secret_env_present": false,
"target_exists": true,
"target_content": "{"type":"service_account","project_id":"qa-project"}",
"target_mode": "0o600",
"target_parent_mode": "0o700",
"suffix_contains_file_secret": false,
"suffix_contains_plain_secret": true,
"requests": ["initialize", "authenticate:vertex-ai", "session/new", "session/set_mode"]
}This shows Gemini Vertex now receives a real credentials file path and the SDK chooses vertex-ai instead of treating the pasted JSON as a plain env secret.
Test 3: Explicit acp_env pin stays authoritative and receives the file
Step 1 — Establish baseline on main:
Ran:
git checkout --detach origin/main
uv run python /tmp/qa_acp_probe.py --scenario codex-pinned --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {"CODEX_HOME": "/tmp/.../pinned-codex-home"},
"raw_file_secret_env_present": true,
"target_exists": false,
"requests": ["initialize", "session/new", "session/set_mode"]
}This confirms a pinned CODEX_HOME existed before, but the credential file was not seeded there.
Step 2 — Apply the PR changes and re-run:
Ran:
git checkout --detach origin/acp-materialise-file-secrets
uv run python /tmp/qa_acp_probe.py --scenario codex-pinned --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {"CODEX_HOME": "/tmp/.../pinned-codex-home"},
"raw_file_secret_env_present": false,
"target_exists": true,
"target_content": "{"tokens":"qa-codex-token"}",
"target_mode": "0o600",
"target_parent_mode": "0o700",
"requests": ["initialize", "authenticate:chatgpt", "session/new", "session/set_mode"]
}This confirms the explicit env pin still wins and the SDK seeds auth.json exactly where that env var points.
Test 4: Seed-if-absent preserves a refreshed credential file
Step 1 — Establish baseline on main:
Ran:
git checkout --detach origin/main
uv run python /tmp/qa_acp_probe.py --scenario codex-preseed --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {},
"raw_file_secret_env_present": true,
"target_content": "{"refreshed":true}",
"target_mode": "0o644",
"target_parent_mode": "0o755"
}This confirms the pre-existing file was not connected to the ACP subprocess before the PR.
Step 2 — Apply the PR changes and re-run:
Ran:
git checkout --detach origin/acp-materialise-file-secrets
uv run python /tmp/qa_acp_probe.py --scenario codex-preseed --fake-server /tmp/fake_acp_server.pyRelevant output:
{
"captured_env": {"CODEX_HOME": "/tmp/.../conversation-root/acp/codex"},
"raw_file_secret_env_present": false,
"target_content": "{"refreshed":true}",
"target_mode": "0o600",
"target_parent_mode": "0o700",
"requests": ["initialize", "authenticate:chatgpt", "session/new", "session/set_mode"]
}This confirms seed-if-absent works: the stale pasted blob did not overwrite the existing refreshed file, but the PR still pointed Codex at it and tightened file/directory permissions.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot
left a comment
There was a problem hiding this comment.
Code Review
This is a well-designed, security-conscious implementation that cleanly separates policy (ACPFileSecretSpec / file_secrets on ACPProviderInfo) from mechanism (ACPAgent._materialise_file_secrets). The test coverage is thorough — including drain-channel fallback, acp_env pin precedence, non-persisted workspace fallback, auth-method detection for both relocated Codex home and Vertex AI service accounts, and custom spec override. The backward-compat story (empty file_secrets tuple default, overridable acp_file_secrets list) is solid.
Previously-flagged issues — now resolved in the current code
Three issues raised in prior reviews are addressed:
- Permission window in
_write_secret_file— resolved:os.fchmod(fd, 0o600)is called on the raw fd beforeos.fdopen, so the secret content never briefly exists at wider permissions, even when the file pre-existed. - Silent
chmod(0o700)on externally-pinned directories — resolved: the call is now guarded byif not pinned:, preserving user-chosen permissions on shared/external mounts. - Seed-if-absent branch leaving pre-existing file permissions unchanged — resolved: the preserved branch now calls
target.chmod(0o600)before logging, verified bytest_seed_if_absent_does_not_clobber_existing_file.
Remaining minor items
- PR description accuracy (previously flagged): The Mechanism section still references
ACP_FILE_SECRETS_BY_NAME— a symbol that does not exist in the implementation. The actual mechanism is theacp_file_secretslist onACPAgent, populated bydefault_acp_file_secrets(). Please update the description. - Test ordering assumption (previously flagged inline):
test_default_acp_file_secrets_aggregates_all_providersasserts the exact tuple order fromdefault_acp_file_secrets(), implicitly relying onACP_PROVIDERSinsertion order. Stable in CPython 3.7+ but worth a clarifying comment or a set-based assertion for names, with order checked separately only if it truly matters. - Minor test coverage gap (new, see inline comment): the Gemini materialisation test checks file permissions (
0o600) but not the parent directory permissions (0o700), unlike the equivalent Codex test which checks both.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
Add the 0700 directory-permission assertion to the Gemini Vertex SA test for symmetry with the Codex test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ 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.
Review: feat(acp): materialise reserved file-content auth secrets
This is a well-structured feature. The declarative ACPFileSecretSpec model, the seed-if-absent semantics, the fchmod-before-write security pattern, and the exclusion of file blobs from both env injection and <CUSTOM_SECRETS> advertisement are all solid. The test suite is thorough — coverage of the drain fallback, acp_env pin precedence, downstream override, and the _select_auth_method CODEX_HOME-awareness are exactly what this class of change needs.
Two actionable items and one low-priority note below.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
There was a problem hiding this comment.
🟡 QA Report: PARTIAL
The SDK-side behavior for reserved ACP file-content secrets works in the launch path, but full real Codex/Gemini authentication could not be exercised because those provider CLIs/credentials are unavailable in this environment.
Does this PR achieve its stated goal?
Yes for the behavior that can be verified locally: when an ACP conversation starts with CODEX_AUTH_JSON or GOOGLE_APPLICATION_CREDENTIALS_JSON, the SDK now materializes the blob to durable per-conversation files, points CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS at those files, avoids exporting the blob secret as a plain env var, preserves an existing refreshed Codex auth file, clamps permissions, and selects chatgpt / vertex-ai auth when those files exist. I verified this by running the SDK launch path and capturing the environment handed to the ACP subprocess boundary before vs. after the PR. Full end-to-end provider login remains unverified because neither codex-acp nor Gemini CLI is installed here and real provider credentials are not available.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no tests/linters were run. |
| CI Status | 🟡 No failed checks observed; several Docker build/QA checks were still in progress when checked. |
| Functional Verification | ✅ SDK file materialization, env injection behavior, seed-if-absent, auth selection, and public API export were exercised with real SDK imports/calls. |
Functional Verification
Test 1: ACP launch env/file behavior for Codex and Gemini file-content secrets
Step 1 — Reproduce / establish baseline without the fix:
Checked out origin/main (cb4ebe40) and ran uv run python /tmp/qa_acp_file_secrets.py, a small SDK script that constructs an ACPAgent, supplies reserved secrets through ConversationState.secret_registry, and runs the real ACP startup path up to the subprocess-launch boundary.
Key output:
{
"codex_materialisation": {
"CODEX_HOME": null,
"auth_file_exists": false,
"env_has_CODEX_AUTH_JSON": true
},
"gemini_materialisation": {
"GOOGLE_APPLICATION_CREDENTIALS": null,
"credential_file_exists": false,
"env_has_GOOGLE_APPLICATION_CREDENTIALS_JSON": true
},
"auth_selection": {
"chatgpt_selection_with_CODEX_HOME_auth_json": "openai-api-key",
"vertex_selection_with_service_account_file": "gemini-api-key"
},
"seed_if_absent": {
"CODEX_HOME": null,
"auth_file_mode_after_start": "0o644",
"contents_after_start": "{\"refreshed\":true}"
}
}This confirms the previous behavior: reserved file-content blobs were treated like plain env vars, no credential files/path env vars were created, relocated CODEX_HOME auth was not selected, Vertex SA auth was not selected, and an existing Codex auth file was not permission-clamped by ACP startup.
Step 2 — Apply the PR's changes:
Restored PR commit b6032b55 on branch acp-materialise-file-secrets.
Step 3 — Re-run with the fix in place:
Ran the same command: uv run python /tmp/qa_acp_file_secrets.py.
Key output:
{
"codex_materialisation": {
"CODEX_HOME": "/tmp/.../conversation-state/acp/codex",
"auth_file_contents": "{\"tokens\":\"qa\"}",
"auth_file_exists": true,
"auth_file_mode": "0o600",
"codex_home_mode": "0o700",
"env_has_CODEX_AUTH_JSON": false
},
"gemini_materialisation": {
"GOOGLE_APPLICATION_CREDENTIALS": "/tmp/.../conversation-state/acp/gemini-cli/gcloud-credentials.json",
"credential_file_contents": "{\"type\":\"service_account\",\"project_id\":\"qa\"}",
"credential_file_exists": true,
"credential_file_mode": "0o600",
"credential_dir_mode": "0o700",
"env_has_GOOGLE_APPLICATION_CREDENTIALS_JSON": false
},
"auth_selection": {
"chatgpt_selection_with_CODEX_HOME_auth_json": "chatgpt",
"codex_auth_helper_available": true,
"vertex_selection_with_service_account_file": "vertex-ai"
},
"seed_if_absent": {
"CODEX_HOME": "/tmp/.../conversation-state/acp/codex",
"auth_file_mode_after_start": "0o600",
"contents_after_start": "{\"refreshed\":true}"
}
}This shows the PR fixes the SDK-side behavior: file blobs are materialized to the expected durable ACP subdirectories, path env vars are set, blob env vars are not exported, permissions are tightened, pre-existing refreshed auth contents are preserved, and auth method selection now honors relocated Codex/Vertex credential files.
Test 2: Public SDK API/settings behavior
Baseline: On origin/main, running uv run python /tmp/qa_acp_public_api.py produced:
{
"commit": "cb4ebe40",
"error": "ImportError: cannot import name 'ACPFileSecretSpec' from 'openhands.sdk' (...) ",
"import_ACPFileSecretSpec": "failed"
}PR: On b6032b55, the same script produced:
{
"commit": "b6032b55",
"custom_spec_secret_names": ["MYCLI_TOKEN_JSON"],
"default_spec_secret_names": ["CODEX_AUTH_JSON", "GOOGLE_APPLICATION_CREDENTIALS_JSON"],
"import_ACPFileSecretSpec": "ok"
}This verifies the new exported spec is usable by downstream code, defaults include the built-in Codex/Gemini specs, and an override flows through ACPAgentSettings.create_agent().
Unable to Verify
I could not verify live end-to-end provider authentication against real Codex ACP or Gemini CLI. command -v codex-acp, command -v gemini, and command -v gemini-cli returned no installed CLI, and real provider credentials are not available in this QA environment. Future QA would be stronger if AGENTS.md documented a lightweight local ACP fixture or dev command for exercising ACP auth without live provider accounts.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
…error; reject '.' subdir - _materialise_file_secrets now re-raises on OSError (read-only/full mount) instead of silently continuing, so init_state surfaces a typed ConversationErrorEvent(ACPInitError) instead of a cryptic downstream auth failure. + regression test. - ACPFileSecretSpec.subdir validator rejects '.'/whitespace (would drop the credential into the shared acp/ root where two specs could collide). + tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ 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.
Code Review: feat(acp): materialise reserved file-content auth secrets
This is a well-structured, security-conscious implementation. The declarative ACPFileSecretSpec model provides a clean separation of policy from mechanism, and the _materialise_file_secrets approach correctly handles the full lifecycle: seed-if-absent, permission clamping, env-var injection, and advertising suppression.
Previously-flagged issues — confirmed resolved in current commit
All four issues raised in earlier reviews are addressed:
- Permission window in
_write_secret_file✅ —os.fchmod(fd, 0o600)is called on the raw fd beforeos.fdopen, so the secret content never exists at wider permissions even on pre-existing empty files. - Silent
chmod(0o700)on externally-pinned directories ✅ — Guarded byif not pinned:on line 1583, preserving user-chosen permissions on shared/external mounts. - Seed-if-absent branch missing
chmod✅ —target.chmod(0o600)is called (line 1589) before the "already present" log, so refreshed/restored credential files are always clamped to0o600. - Silent
continueonOSError✅ — Theexcept OSErrorblock now logs and re-raises (lines 1606–1611), surfacing materialisation failures as a typedACPInitErrorrather than silent auth failures.
Remaining item from prior reviews
PR description accuracy (flagged in multiple prior reviews, still open): The Mechanism section of the PR description references ACP_FILE_SECRETS_BY_NAME — a symbol that does not exist in the implementation. The actual mechanism is the acp_file_secrets list on ACPAgent, populated from default_acp_file_secrets(). A one-line description update before merge would remove a stale reference that could confuse future readers of the PR history.
New observation
See inline comment on _materialise_file_secrets regarding the intermediate acp/ directory created by parents=True.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the SDK-side ACP file-secret behavior by launching real ACPAgent conversations against an env-probe ACP subprocess; reserved Codex/Gemini blobs are now materialized to files with the expected env vars and permissions.
Does this PR achieve its stated goal?
Yes. On main, reserved file-content secrets were passed through as ordinary environment variables (CODEX_AUTH_JSON / GOOGLE_APPLICATION_CREDENTIALS_JSON) and no credential files were available to the subprocess. On this PR, the same user-level Conversation(..., secrets=...) flow created durable per-conversation credential files, set CODEX_HOME / GOOGLE_APPLICATION_CREDENTIALS to the paths the CLIs expect, omitted the blob env vars, preserved seed-if-absent files, honored pinned CODEX_HOME, and selected the file-backed auth methods.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv run bootstrapped the repo environment and built editable SDK packages successfully. |
| CI Status | 🟡 At review time: 23 checks successful, 5 still in progress (qa-changes + image builds), 7 skipped. |
| Functional Verification | ✅ Real SDK Conversation/ACPAgent launches verified the changed runtime behavior; no functional issues found. |
Functional Verification
Test 1: Codex CODEX_AUTH_JSON materializes to $CODEX_HOME/auth.json
Step 1 — Establish baseline on main:
Ran cd /tmp/qa-sdk-main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py codex:
{
"env": {
"CODEX_AUTH_JSON": "{"tokens":"pasted"}",
"CODEX_HOME": null,
"PLAIN_TOKEN": "plain-token"
},
"paths": {}
}This confirms the old behavior: the pasted Codex blob reached the subprocess as a plain env var and no auth.json file was present for Codex to read.
Step 2 — Apply the PR's changes:
Checked out PR branch acp-materialise-file-secrets at ddab8c050316f280e44886973d95933ee5fa1620.
Step 3 — Re-run with the fix in place:
Ran cd pr-repo && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py codex:
{
"env": {
"CODEX_AUTH_JSON": null,
"CODEX_HOME": "/tmp/qa-acp-codex-.../persist/12345678123456781234567812345678/acp/codex",
"PLAIN_TOKEN": "plain-token"
},
"paths": {
"codex_auth": {
"content": "{"tokens":"pasted"}",
"exists": true,
"mode": "0o600",
"path": "/tmp/qa-acp-codex-.../acp/codex/auth.json"
},
"codex_home_mode": "0o700"
}
}This shows the SDK now writes the blob to the durable conversation acp/codex/auth.json, sets CODEX_HOME to that directory, preserves unrelated plain secrets, and does not export CODEX_AUTH_JSON as a plain env var.
Test 2: Gemini Vertex service-account JSON materializes to GOOGLE_APPLICATION_CREDENTIALS
Step 1 — Establish baseline on main:
Ran cd /tmp/qa-sdk-main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py gemini:
{
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": null,
"GOOGLE_APPLICATION_CREDENTIALS_JSON": "{"type":"service_account"}",
"GOOGLE_CLOUD_LOCATION": "us-central1",
"GOOGLE_CLOUD_PROJECT": "qa-project"
},
"paths": {}
}This confirms Gemini would not receive a service-account file path before the PR.
Step 2 — Apply the PR's changes:
Used the PR checkout at ddab8c050316f280e44886973d95933ee5fa1620.
Step 3 — Re-run with the fix in place:
Ran cd pr-repo && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py gemini:
{
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/tmp/qa-acp-gemini-.../persist/12345678123456781234567812345678/acp/gemini-cli/gcloud-credentials.json",
"GOOGLE_APPLICATION_CREDENTIALS_JSON": null,
"GOOGLE_CLOUD_LOCATION": "us-central1",
"GOOGLE_CLOUD_PROJECT": "qa-project"
},
"paths": {
"google_credentials": {
"content": "{"type":"service_account"}",
"exists": true,
"mode": "0o600"
},
"google_credentials_dir_mode": "0o700"
}
}This confirms the PR creates the Vertex credentials file, points GOOGLE_APPLICATION_CREDENTIALS at it, and omits the pasted blob env var.
Test 3: Seed-if-absent and pinned CODEX_HOME
Step 1 — Establish baseline on main:
Ran cd /tmp/qa-sdk-main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py seed and ... pinned:
// seed baseline
{"env":{"CODEX_AUTH_JSON":"{"tokens":"stale-paste"}","CODEX_HOME":null},"paths":{}}
// pinned baseline
{"env":{"CODEX_AUTH_JSON":"{"tokens":"pinned"}","CODEX_HOME":"/tmp/qa-acp-pinned-.../pinned-codex-home"},"paths":{"codex_auth":{"exists":false}}}This shows old behavior did not seed the credential file, even when CODEX_HOME was already pinned.
Step 2 — Apply the PR's changes:
Used the PR checkout at ddab8c050316f280e44886973d95933ee5fa1620.
Step 3 — Re-run with the fix in place:
Ran cd pr-repo && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_file_secret_probe.py seed and ... pinned:
// seed-if-absent
{
"env": {"CODEX_AUTH_JSON": null, "CODEX_HOME": "/tmp/qa-acp-seed-.../acp/codex"},
"paths": {"codex_auth": {"content": "{"tokens":"refreshed-on-disk"}", "mode": "0o600"}}
}
// pinned CODEX_HOME
{
"env": {"CODEX_AUTH_JSON": null, "CODEX_HOME": "/tmp/qa-acp-pinned-.../pinned-codex-home"},
"paths": {"codex_auth": {"content": "{"tokens":"pinned"}", "mode": "0o600"}, "codex_home_mode": "0o755"}
}This confirms a pre-existing refreshed file is preserved (and permission-clamped) instead of being overwritten by the stale paste, and an explicit CODEX_HOME pin remains authoritative while still receiving auth.json.
Test 4: File-backed auth method selection
Step 1 — Establish baseline on main:
Ran cd /tmp/qa-sdk-main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_auth_selection.py:
{
"codex_CODEX_HOME_auth": "openai-api-key",
"gemini_vertex_sa": "gemini-api-key"
}This confirms the old selection ignored relocated Codex auth and Vertex SA files, falling back to API-key auth.
Step 2 — Apply the PR's changes:
Used the PR checkout at ddab8c050316f280e44886973d95933ee5fa1620.
Step 3 — Re-run with the fix in place:
Ran cd pr-repo && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_auth_selection.py:
{
"codex_CODEX_HOME_auth": "chatgpt",
"gemini_vertex_sa": "vertex-ai"
}This confirms auth selection now prefers the materialized file-backed methods.
Unable to Verify
I did not authenticate against real Codex or Gemini cloud services because no provider credentials/accounts were available in the QA environment. Instead, I verified the SDK behavior those CLIs depend on by launching a real ACPAgent subprocess and inspecting the exact env vars and credential files visible to that subprocess.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
…dir to 0700 parents=True may create the intermediate acp/ dir under the process umask (e.g. 0o755); the leaf-subdir chmod only covered <subdir>. Also clamp acp/ to 0700 (guarded by not pinned; stop at acp/ — its parent is the persistence layer's). + test assertion. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ 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.
Overall Assessment
This is a well-designed, security-conscious implementation that solves a real problem: ACP providers like Codex (ChatGPT subscription) and Gemini Vertex AI authenticate from files on disk rather than environment variables, and these credential files need to live in a durable, per-conversation location so they survive pod recycling.
The implementation is clean and extensible. All previous review threads have been addressed. Below are a few remaining observations.
✅ What's done well
_write_secret_file: Thefchmodbefore writing is the right approach — the secret content never exists on disk at wider than0600permissions, even for pre-existing files. Correct handling of theO_CREAT | O_TRUNC+fchmodordering.- Seed-if-absent: Preserving CLI-refreshed tokens on pod recycle (Codex rewrites
auth.jsonon refresh) is the right call. Thetarget.stat().st_size > 0guard prevents an empty file from being treated as a valid credential. - Path traversal guards:
ACPFileSecretSpec._validate_filenameand_validate_subdirreject.., absolute paths, and degenerate values. The.strip()catch on whitespace-only subdirs closes a subtle gap. - Fail-fast on
OSError: Re-raising rather thancontinueensures a write failure surfaces as aConversationErrorEvent, not a silent mis-auth. - Advertisement exclusion: Dropping file-content secrets from
_render_suffixis correct — advertising a blob value as an env-var name would actively mislead the agent. - Extensibility: Downstream callers can override
acp_file_secretsonACPAgentwith custom specs, no SDK change needed. Clean separation of mechanism (SDK) vs. policy (specs). - Test coverage: The suite is comprehensive — permissions, seed-if-absent, pinned
acp_env, fallback workspace root,OSErrorpropagation, advertisement filtering, downstream override, and empty-spec opt-out.
🟡 Minor observations
_acp_file_secret_dir uses os.path.abspath rather than Path.resolve()
os.path.abspath resolves against os.getcwd(), which is fine in the containerized environment where persistence_dir and workspace.working_dir are always absolute in practice. Path(root).resolve() would be slightly more idiomatic and would also canonicalise symlinks, but either is correct here. Not a blocker.
acp_file_secrets field type: list vs. tuple
ACPProviderInfo.file_secrets is a tuple[ACPFileSecretSpec, ...], signalling immutability. The ACPAgent.acp_file_secrets field uses list[ACPFileSecretSpec]. Pydantic handles both, but tuple would better communicate "this is a fixed policy, not something you mutate in-place." If a downstream caller passes acp_file_secrets=[custom_spec], they're already constructing a new list, so tuple on the field wouldn't be a burden. Non-blocking, but worth considering for the next revision.
_read_conversation_secret empty-string fallthrough
if name in state.secret_registry.secret_sources:
value = state.secret_registry.get_secret_value(name)
if value:
return valueAn empty string in the registry falls through to agent_context.secrets. The semantics (empty = not provided) are correct, but this could surprise a caller who explicitly stored "" in the registry intending to indicate "credential cleared." A brief inline comment explaining the intent would prevent future confusion.
default_acp_file_secrets() ordering depends on ACP_PROVIDERS insertion order
The ordering test (assert specs == ACP_PROVIDERS["codex"].file_secrets + ACP_PROVIDERS["gemini-cli"].file_secrets) explicitly documents this is intentional and relies on Python 3.7+ dict insertion order. If a new provider is inserted between codex and gemini-cli in the future, the ordering changes and any downstream code that relied on positional access would silently break. The test is a good safety net, but the docstring could add a note that ordering is insertion-order-stable.
No validation that the pasted blob is valid JSON for the target CLI
Codex and Gemini Vertex AI both expect valid JSON blobs. A mistyped paste writes whatever the user provided, and the CLI fails at auth time with a cryptic error. This is a UX gap, not a security gap, and is hard to validate generically (the SDK doesn't know the schema). A validate_content callable on ACPFileSecretSpec could be added later as a follow-up. Out of scope for this PR, but worth tracking.
Summary
This PR is solid. The security properties are correct, the design is clean, and the test suite is thorough. The minor observations above are all non-blocking.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
There was a problem hiding this comment.
✅ QA Report: PASS
The SDK-side ACP file-content secret behavior works as described: Codex and Gemini credential blobs are materialized to durable files, path env vars are set, blob env injection/advertisement is suppressed, and refreshed files are preserved.
Does this PR achieve its stated goal?
Yes. I exercised the ACP agent startup path with realistic conversation secrets and verified the PR changes convert reserved file-content secrets into on-disk credentials (CODEX_HOME/auth.json and GOOGLE_APPLICATION_CREDENTIALS) instead of exporting the pasted blob as a normal env var. I also verified Gemini now selects vertex-ai when the materialized service-account file exists, and Codex seed-if-absent preserves an existing refreshed auth.json while clamping permissions.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv run python built/imported the SDK successfully in the repo environment |
| CI Status | 🟡 21 checks passing, 7 still pending/in progress, 3 skipped at time of QA |
| Functional Verification | ✅ Core SDK behavior verified with before/after probes; real external provider CLIs unavailable |
Functional Verification
Test 1: Codex CODEX_AUTH_JSON materialization and env behavior
Step 1 — Establish baseline on origin/main:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/openhands-qa-3474/acp_file_secret_probe.py after checking out origin/main.
Relevant output:
codex_registry.has_CODEX_HOME = false
codex_registry.auth_file_exists = false
codex_registry.exports_CODEX_AUTH_JSON = true
codex_registry.exports_PLAIN_TOKEN = plain-value
agent_context.auth_file_contents = null
agent_context.exports_CODEX_AUTH_JSON = true
agent_context.has_CODEX_HOME = false
This confirms the old behavior: the pasted Codex auth blob was treated as an ordinary env var and no CODEX_HOME/auth.json was created.
Step 2 — Apply the PR's changes:
Checked out 14348e23c6a33d8bfa2ae4ae5e53031f62974ead.
Step 3 — Re-run with the fix in place:
Ran the same command.
Relevant output:
codex_registry.has_CODEX_HOME = true
codex_registry.CODEX_HOME_under_persistence = true
codex_registry.auth_file_exists = true
codex_registry.auth_file_contents = {"refresh_token":"qa-token"}
codex_registry.auth_file_mode = 0o600
codex_registry.codex_home_mode = 0o700
codex_registry.exports_CODEX_AUTH_JSON = false
codex_registry.exports_PLAIN_TOKEN = plain-value
agent_context.auth_file_contents = {"from":"context"}
agent_context.exports_CODEX_AUTH_JSON = false
agent_context.has_CODEX_HOME = true
This shows the fix works for both state.secret_registry and agent_context.secrets: the blob is written under the conversation persistence root, CODEX_HOME points there, the file/dir permissions are restricted, and the blob is no longer injected as an env var.
Test 2: Codex seed-if-absent preserves refreshed credentials
Baseline on origin/main:
The same probe pre-created auth.json as 0644 and then started ACP with a stale pasted blob.
seed_if_absent.has_CODEX_HOME = false
seed_if_absent.preserved_contents = {"refreshed":true}
seed_if_absent.auth_file_mode = 0o644
seed_if_absent.exports_CODEX_AUTH_JSON = true
This shows main did not manage the file for the ACP subprocess and left a too-wide credential mode untouched.
PR result:
seed_if_absent.has_CODEX_HOME = true
seed_if_absent.preserved_contents = {"refreshed":true}
seed_if_absent.auth_file_mode = 0o600
seed_if_absent.exports_CODEX_AUTH_JSON = false
This confirms the existing refreshed token is not clobbered by the stale paste, while file permissions are tightened and CODEX_HOME is supplied.
Test 3: Gemini Vertex service-account materialization and auth selection
Step 1 — Establish baseline on origin/main:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/openhands-qa-3474/acp_gemini_probe.py with GOOGLE_APPLICATION_CREDENTIALS_JSON plus a GEMINI_API_KEY in the conversation secret registry.
has_GOOGLE_APPLICATION_CREDENTIALS = false
gac_file_exists = false
exports_GOOGLE_APPLICATION_CREDENTIALS_JSON = true
exports_GEMINI_API_KEY = gemini-key
authenticate_calls[0].kwargs.method_id = gemini-api-key
This confirms the old behavior: the SA JSON blob was exported as a normal env var, no credentials file existed, and ACP auth fell back to the API-key method.
Step 2 — Apply the PR's changes:
Checked out 14348e23c6a33d8bfa2ae4ae5e53031f62974ead.
Step 3 — Re-run with the fix in place:
Ran the same command.
has_GOOGLE_APPLICATION_CREDENTIALS = true
gac_under_persistence = true
gac_file_exists = true
gac_file_contents = {"type":"service_account","project_id":"qa"}
exports_GOOGLE_APPLICATION_CREDENTIALS_JSON = false
exports_GEMINI_API_KEY = gemini-key
authenticate_calls[0].kwargs.method_id = vertex-ai
This shows Gemini's reserved file-content secret is written to the per-conversation file, GOOGLE_APPLICATION_CREDENTIALS points at it, the raw JSON blob is not exported, and the ACP auth method changes to vertex-ai even when an API key is also present.
Test 4: <CUSTOM_SECRETS> advertisement excludes file-content blobs
Baseline on origin/main:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/openhands-qa-3474/acp_suffix_probe.py.
suffix_contains_CODEX_AUTH_JSON = true
suffix_contains_PLAIN_TOKEN = true
This confirms the old prompt advertised the file blob as a referenceable env secret.
PR result:
suffix_contains_CODEX_AUTH_JSON = false
suffix_contains_PLAIN_TOKEN = true
This confirms the PR keeps ordinary secrets advertised while hiding file-content blobs that are materialized instead of injected.
Test 5: Real provider launch attempt
On the PR commit, I attempted a real Codex ACP launch without transport patching:
OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY' ... ACPAgent(acp_command=['codex-acp'])._start_acp_server(...) ... PY
Observed output:
launch_outcome = failed
error = FileNotFoundError: [Errno 2] No such file or directory: 'codex-acp'
auth_file_exists_after_attempt = true
auth_file_contents = {"refresh_token":"qa-token"}
The environment does not have the external codex-acp provider CLI installed, so I could not verify a full provider handshake. The useful SDK-side side effect still occurred before launch failure: the reserved secret was materialized to auth.json.
Unable to Verify
A full end-to-end handshake with real Codex/Gemini ACP provider processes could not be verified because neither codex-acp nor gemini was installed in this QA environment, and real provider credentials are not available. Future QA runs would benefit from AGENTS.md guidance for installing/running disposable ACP provider CLIs with non-production credentials.
Issues Found
None.
This PR review was generated by an AI agent (OpenHands) on behalf of the user.
…secrets # Conflicts: # tests/sdk/agent/test_acp_agent.py
….json, Gemini Vertex SA) (OpenHands#3474) Co-authored-by: Debug Agent <debug@example.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Simon Rosenberg <simon@openhands.dev>
What
Implements agent-canvas#1020 (part of the ACP-on-Cloud epic OpenHands/OpenHands#15746).
Some ACP providers authenticate from a file on disk rather than an env var: Codex reads
$CODEX_HOME/auth.json; Gemini (Vertex AI) reads a service-account JSON atGOOGLE_APPLICATION_CREDENTIALS. The user supplies the credential as a pasted blob (a reserved file-content secret); the SDK materialises it to the file path the CLI expects, in the runtime pod, before the subprocess is spawned.Builds on #3464 (#1022) — provider creds ride
state.secret_registry.Design — mechanism (SDK) vs policy (overridable data)
Per the #1020 discussion, this separates the two concerns so the SDK owns the mechanism (which must run in-pod) while the policy is overridable data a downstream app can supply without an SDK release:
ACPFileSecretSpec(frozen, exported) — declarativesecret_name → filename + subdir + env_var(+points-to dir/file)mapping, with path-traversal validation. This is the policy.ACPAgent.acp_file_secrets/ACPAgentSettings.acp_file_secrets(forwarded viacreate_agent) — the configurable list of specs.default_acp_file_secrets()supplies built-in convenience defaults for the supported providers (Codex / Gemini Vertex); a downstream app may override or extend them to support another file-auth ACP server with no SDK change, or pass[]to opt out entirely.CODEX_AUTH_JSON→auth.json, envCODEX_HOME=<dir>.GOOGLE_APPLICATION_CREDENTIALS_JSON→gcloud-credentials.json, envGOOGLE_APPLICATION_CREDENTIALS=<file>; warns ifGOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATIONare unset.Why the engine stays SDK-side: in cloud the CLI runs in a remote runtime pod and the credential arrives only as a transmitted secret — the downstream app (canvas browser / OpenHands backend) has no filesystem access to the pod, and a read-only K8s projected-secret mount can't replace it (Codex rewrites
auth.jsonon refresh). Materialising into a writable, durable, per-conversation dir is the only thing that survives. It's also a no-op locally: it only acts when a reserved secret is present, otherwise detection falls back to the host login files unchanged.Implementation (
ACPAgent)For each configured spec whose secret is present:
state.secret_registry(canonical channel), falling back toagent_context.secrets(canvas-local drain) —_read_conversation_secret.<persistence_dir>/acp/{subdir}/— the same tree the regular agent persists to — seed-if-absent, noTemporaryDirectory,0600files in0700dirs (incl. the sharedacp/parent). So a token Codex rewrites on refresh survives a recycle, and a stale paste never clobbers the live one. Falls back under the workspace when unpersisted.CODEX_HOME/GOOGLE_APPLICATION_CREDENTIALS) at the materialised path; the blob is excluded from plain env injection and the<CUSTOM_SECRETS>advertisement. An explicitacp_envpin still wins, and the credential is seeded where that pin points.init_statesurfaces a typedConversationErrorEvent(ACPInitError)instead of a cryptic downstream auth failure.CODEX_HOME-aware Codexchatgptdetection (was hardcoded to~/.codex/auth.json); prefer the gemini-clivertex-aimethod when the SA file is present.Tests
auth.json+ Gemini Vertex SA materialise to the right per-conversation path; env vars point at them (dir vs file);0600/0700perms (file, leaf dir, andacp/parent); blob not injected / not advertised.0600.agent_context.secrets(drain) as well as the registry;acp_envpin wins and seeds where it points; workspace fallback when unpersisted.acp_file_secrets=[]opts out (blob flows through as a plain env var); settings pass-through.OSErrorpropagates (fail-fast);ACPFileSecretSpecrejects../absolute/./whitespace paths._select_auth_method:CODEX_HOME-awarechatgpt;vertex-aipreferred whenGOOGLE_APPLICATION_CREDENTIALSexists.Validated end-to-end against the containerized agent-server image: Codex authenticates via the materialised
auth.json→CODEX_HOME→chatgpt, and completes a real tool-using turn (Claude Code via the env-token path also green).Follow-ups (not this PR)
acp_file_secretsfor the selected provider, with product-level coverage that the right Codex/Gemini specs are sent.openhands-sdkcore vs. relocate toopenhands-agent-server(both run in-pod). In core today becauseACPAgentlives there and policy-as-data keeps core CLI-agnostic.🤖 Generated with Claude Code
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:20333b3-pythonRun
All tags pushed for this build
About Multi-Architecture Support
20333b3-python) is a multi-arch manifest supporting both amd64 and arm6420333b3-python-amd64) are also available if needed