Repository navigation
fix(acp): inject conversation secret_registry into ACP subprocess env - #3299
Conversation
ACPAgent._start_acp_server already received the conversation's state and used state.secret_registry to render the <CUSTOM_SECRETS> block in the prompt, but it skipped the registry when building the subprocess environment. Anything sent via Conversation.update_secrets() (or the equivalent payload.secrets channel that app-server callers like agent-canvas use) was therefore invisible to the ACP CLI — to make a named secret reach the subprocess you had to also build an AgentContext(secrets=...) shim around the same data. Fill any keys still absent after acp_env and agent_context.secrets straight from state.secret_registry, preserving the precedence acp_env > provider env > agent_context.secrets > secret_registry. Tests cover: a plain string secret round-trips, a LookupSecret callable resolves, acp_env wins over the same key in the registry, agent_context.secrets wins over the same key in the registry, an empty registry is a no-op, and a SecretSource that raises on lookup is silently dropped (matching the existing get_secret_value contract) instead of taking the whole spawn down. All hooks verified manually via venv binaries (ruff format/check, pycodestyle, pyright); --no-verify used because uv run rewrites uv.lock mid pre-commit stash on this repo (malformed exclude-newer = "7 days" in pyproject.toml, pre-existing on main). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED Behavioral default changes detectedThese public
|
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Taste Rating: Good taste — minimal, direct fix; precedence is preserved and the new tests cover the important registry/lookup/precedence/failure cases.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This touches ACP subprocess environment construction and secret propagation, so it can affect ACP agent behavior. I found no code issues, but per repo review policy I’m leaving a COMMENT rather than approving so a human maintainer can decide whether lightweight ACP/eval validation is needed.
VERDICT: ✅ Worth merging after maintainer/eval-risk signoff.
This review was generated by an AI agent (OpenHands) on behalf of the user.
Coverage Report •
|
||||||||||||||||||||||||||||||
… channel Refines the env-build ordering in _start_acp_server to the single-rule model: StartConversationRequest.secrets are conversation secrets. For OpenHands agents they're available through the secret registry; for ACP agents they're exposed to the ACP subprocess environment because the ACP subprocess owns execution. Precedence (lowest → highest): default_environment + os.environ baseline state.secret_registry canonical channel agent_context.secrets legacy direct-attach self.acp_env explicit override Behaviour shift: on collision between secret_registry and agent_context.secrets, the registry now wins (was: agent_context). The canonical conversation channel should beat the legacy direct- attach so OpenHands can eventually drop its AgentContext(secrets=...) shim without a behaviour break during the migration. Same-value collisions (today's OpenHands sends through both) produce identical output; only differing-value collisions change, and there are no known callers that do that. Also updates _render_suffix to render the <CUSTOM_SECRETS> block from state.secret_registry even when agent_context is absent — a conversation that ships secrets only through the canonical channel shouldn't have its agent left ignorant of env vars that are about to be injected into its subprocess. Preserves the "no agent_context + empty registry ⇒ no suffix" guard so the empty AgentContext() defaults (current_datetime, …) don't leak into the prompt. Tests: - Updated the agent_context-vs-registry precedence test to assert the new winner (registry). - Added test_init_state_renders_registry_secrets_without_agent_context pinning the new _render_suffix behaviour. - All 194 tests in test_acp_agent.py + test_agent_secrets_integration.py pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the ACP subprocess receives secrets supplied through Conversation.update_secrets() while preserving explicit acp_env precedence.
Does this PR achieve its stated goal?
Yes. I exercised the SDK as a user would: created an ACPAgent, called Conversation.update_secrets(...), sent a message, and ran the conversation against a minimal ACP-compatible subprocess that captured its environment and completed initialize, session/new, and session/prompt. On base main, QA_REGISTRY_SECRET was null in the subprocess env; on PR commit 36266de, the same flow produced QA_REGISTRY_SECRET=from-secret-registry, while QA_SHARED_SECRET remained from-acp-env, confirming registry secrets fill gaps without overriding explicit ACP env values.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully |
| CI Status | 🟡 Core checks passing; several longer Agent Server/build and sdk-tests checks still in progress when checked |
| Functional Verification | ✅ Before/after SDK conversation flow confirmed the fix |
Functional Verification
Test 1: ACP subprocess env receives conversation secret registry values
Step 1 — Reproduce / establish baseline without the fix:
Checked out origin/main at 3e5ed6e9 and ran:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_raw_flow.pyRelevant output:
{
"event": "process_start",
"env": {
"QA_ACP_ENV_SECRET": "from-acp-env",
"QA_REGISTRY_SECRET": null,
"QA_SHARED_SECRET": "from-acp-env"
}
}The same run initialized the ACP subprocess and completed the user message flow:
method":"initialize"
method":"session/new"
method":"session/prompt"
This confirms the old behavior: secrets added via conversation.update_secrets({"QA_REGISTRY_SECRET": "from-secret-registry"}) were stored on the conversation but did not reach the ACP subprocess environment.
Step 2 — Apply the PR's changes:
Checked out fix-acp-secret-registry-env at 36266de413038152e2323f60f340822ab78dc4a7.
Step 3 — Re-run with the fix in place:
Ran the same command:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_raw_flow.pyRelevant output:
{
"event": "process_start",
"env": {
"QA_ACP_ENV_SECRET": "from-acp-env",
"QA_REGISTRY_SECRET": "from-secret-registry",
"QA_SHARED_SECRET": "from-acp-env"
}
}The subprocess again completed the ACP interaction:
ACP server initialized: agent_name='qa-raw-acp', agent_version='0.0.0'
Sending ACP prompt (timeout=10s, blocks=1)
ACP prompt returned in 2.0s
This confirms the fix works: the registry-only secret is now present in the spawned ACP process. It also confirms the advertised precedence behavior for explicit ACP env values: QA_SHARED_SECRET stayed from-acp-env even though the registry provided from-secret-registry for the same key.
Issues Found
None.
This 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.
Found one precedence side effect that should be fixed before merge.
This review was generated by an AI agent (OpenHands) on behalf of the user.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/software-agent-sdk/actions/runs/26164639256
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified ACP secret-registry behavior by running SDK scripts that spawn a real ACP subprocess; registry secrets are now advertised and injected with the documented precedence.
Does this PR achieve its stated goal?
Yes. On origin/main, a registry-only secret was neither listed in the ACP suffix nor present in the spawned ACP subprocess environment. On PR commit 6e8f21bb0a37f6c3b9d04c5a332a9c7320260666, the same runtime check showed QA_REGISTRY_SECRET in the <CUSTOM_SECRETS> suffix and in the subprocess env, while acp_env, host env, registry, and agent_context.secrets precedence behaved as described.
| Phase | Result |
|---|---|
| Environment Setup | ✅ Used uv run to create/update the project .venv and import/run SDK code; no tests, linters, or formatters were run. |
| CI Status | 🟡 GitHub reports 32 successful, 4 skipped, 1 pending (QA Changes by OpenHands) at review time; 0 failing. |
| Functional Verification | ✅ Real ACP subprocess env capture confirms the fix and precedence behavior. |
Functional Verification
Test 1: registry-only conversation secret is advertised and injected
Step 1 — Reproduce / establish baseline without the fix:
Checked out origin/main (0aa2653ce52d2c2bccf39aec3e3eb68cec0c2fd1) and ran:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_runtime_check.pyRelevant output:
SUFFIX_HAS_REGISTRY_SECRET False
ENV_CAPTURE_EXISTS True
ENV_CAPTURE {"QA_ACP_OVERRIDE": "from-acp-env"}
START_PROCESS_EXITCODE -15
This confirms the bug: the registry-only secret was not rendered in the ACP suffix and did not reach the real spawned ACP subprocess env. Only the explicit acp_env override was present.
Step 2 — Apply the PR's changes:
Checked out fix-acp-secret-registry-env at 6e8f21bb0a37f6c3b9d04c5a332a9c7320260666.
Step 3 — Re-run with the fix in place:
Ran the same command:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_runtime_check.pyRelevant output:
SUFFIX_HAS_REGISTRY_SECRET True
SUFFIX_MENTIONS_CUSTOM_SECRETS True
ENV_CAPTURE_EXISTS True
ENV_CAPTURE {"QA_ACP_OVERRIDE": "from-acp-env", "QA_REGISTRY_SECRET": "from-registry"}
START_PROCESS_EXITCODE -15
This shows the fix works: the registry secret is advertised through <CUSTOM_SECRETS> and injected into the ACP subprocess environment. The -15 exit code is from the QA harness terminating the startup process after the subprocess env file was captured.
Test 2: documented same-key precedence works at the subprocess boundary
On the PR branch, ran:
OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_precedence_check.pyRelevant output:
ENV_CAPTURE_EXISTS True
ENV_CAPTURE {"QA_ACP_OVERRIDE": "from-acp-env", "QA_CONTEXT_ONLY": "from-context", "QA_HOST_SECRET": "from-host-env", "QA_SHARED_CONTEXT": "from-registry"}
START_PROCESS_EXITCODE -15
This verifies the claimed precedence in a spawned ACP subprocess: acp_env wins over registry (QA_ACP_OVERRIDE), host env wins over registry (QA_HOST_SECRET), registry wins over agent_context.secrets (QA_SHARED_CONTEXT), and context-only secrets still fill missing keys (QA_CONTEXT_ONLY).
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
Verdict: PASS
Move env.update(self.acp_env) ahead of the registry/agent_context secret-resolution loops so the existing "if name in env: continue" guards skip lookups for keys an explicit acp_env entry will override. Previously a LookupSecret in the registry (or a SecretSource in agent_context.secrets) with the same key as an acp_env entry triggered an unnecessary HTTP round-trip / warning before being overwritten. Same documented precedence: acp_env > os.environ > default_environment > secret_registry > agent_context.secrets Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Taste Rating: Good taste — centralizes registry secret injection at the ACP subprocess boundary and keeps precedence explicit. I don’t see new code issues; the previous acp_env/lookup concern appears addressed by the early name in env guard and coverage.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This changes ACP subprocess environment construction and prompt-visible secret advertisement, so it can affect agent behavior and benchmark/eval outcomes. Per repo policy, I’m leaving a COMMENT rather than approval for human maintainer/eval-risk signoff.
This review was generated by an AI agent (OpenHands) on behalf of the user.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/software-agent-sdk/actions/runs/26165579213
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified via a real SDK Conversation using an ACPAgent and a spawned fake ACP subprocess; conversation secrets now reach the ACP process env and are advertised in dynamic context.
Does this PR achieve its stated goal?
Yes. The PR set out to make the standard Conversation(..., secrets=...) / secret-registry channel work for ACP subprocesses without requiring an AgentContext(secrets=...) shim. Running the same ACP conversation harness on base showed registry secrets were absent from the subprocess env and <CUSTOM_SECRETS> was not rendered; running it on commit 9d0b2a95 showed both plain string and SecretSource registry secrets in the spawned subprocess env, <CUSTOM_SECRETS> advertised them, and acp_env still took precedence on collisions.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv run python created/used the project environment and imported the SDK successfully. |
| CI Status | 🟡 Most checks are green; qa-changes plus two Agent Server build/push jobs were still in progress when checked. |
| Functional Verification | ✅ Actual ACP conversation startup exercised initialize, session/new, and session/prompt against a spawned subprocess. |
Functional Verification
Test 1: Conversation secret registry values reach ACP subprocess env and dynamic context
Step 1 — Reproduce / establish baseline without the fix:
Checked out origin/main and ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_secret_registry_qa.py.
{
"capture": {
"QA_ACP_ONLY": "visible-acp-env",
"QA_LOOKUP_SECRET": null,
"QA_PRECEDENCE_SECRET": "from-acp-env",
"QA_REGISTRY_SECRET": null
},
"dynamic_context_has_custom_secrets": false,
"dynamic_context_mentions_lookup_secret": false,
"dynamic_context_mentions_precedence_secret": false,
"dynamic_context_mentions_registry_secret": false,
"requests_seen": ["initialize", "session/new", "session/prompt"],
"run_error_type": null
}This confirms the old behavior: the actual ACP subprocess started, but secrets supplied through the conversation secrets channel did not appear in its environment, and the ACP prompt context did not advertise them.
Step 2 — Apply the PR's changes:
Checked out PR commit 9d0b2a95f8fa54e8be5bff1dac132d4c855d284b.
Step 3 — Re-run with the fix in place:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/acp_secret_registry_qa.py again.
{
"capture": {
"QA_ACP_ONLY": "visible-acp-env",
"QA_LOOKUP_SECRET": "from-secret-source",
"QA_PRECEDENCE_SECRET": "from-acp-env",
"QA_REGISTRY_SECRET": "from-conversation-secret-channel"
},
"dynamic_context_has_custom_secrets": true,
"dynamic_context_mentions_lookup_secret": true,
"dynamic_context_mentions_precedence_secret": true,
"dynamic_context_mentions_registry_secret": true,
"requests_seen": ["initialize", "session/new", "session/prompt"],
"run_error_type": null
}This shows the fix working in the user-facing SDK path: a Conversation with an ACPAgent spawned a subprocess, the subprocess inherited both a plain registry secret and a SecretSource-resolved secret, <CUSTOM_SECRETS> was sent in dynamic context without any AgentContext, and acp_env preserved precedence for QA_PRECEDENCE_SECRET.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
The docstring on ACPAgentSettings.resolve_acp_env still documented the pre-secret-registry precedence (acp_env > provider env > agent_context.secrets) and omitted the canonical conversation-secret channel entirely. Update it to reflect what ACPAgent._start_acp_server actually does today. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@OpenHands fix failing tests |
|
I'm on it! simonrosenberg can track my progress at all-hands.dev |
|
Looked into the failing CI: The only failing test in the latest CI run was This test is a known-style timing-sensitive pause test that races
I confirmed locally:
So this is a CI flake on the blacksmith runner, not a regression from this PR. I've re-triggered the failed jobs on run This comment was created by an AI agent (OpenHands) on behalf of @simonrosenberg. |
|
OpenHands encountered an error: Request timeout after 30 seconds to https://vpuymryhoctvkggj.prod-runtime.all-hands.dev/api/conversations/13ccddd6-e7c8-4889-b252-57c453adbc06/ask_agent See the conversation for more information. |
…OpenHands#3299) Co-authored-by: Debug Agent <debug@example.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…OpenHands#3299) Co-authored-by: Debug Agent <debug@example.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
ACPAgent._start_acp_servernow injects secrets fromstate.secret_registryinto the spawned ACP subprocess environment. This makes the standardConversation.update_secrets()/payload.secretschannel work for ACP clients without requiring each caller to also build anAgentContext(secrets={...})shim.ACPAgent._render_suffixnow renders the<CUSTOM_SECRETS>block fromstate.secret_registryeven whenagent_contextis absent, so ACP servers are told which env vars are available.Same-key env precedence is now explicit:
ACPAgent.acp_envincludes provider-derived env when the agent is built viaACPAgentSettings.create_agent(). Registry/context secrets only fill missing base-env keys, so host env values are not silently shadowed.Why this belongs in the SDK
Both OpenHands' app_server and agent-canvas already use the standard conversation-secrets channel; those secrets land in
secret_registryon the agent-server side. The ACP spawn-time env builder is the shared runtime boundary that must consume that registry. Keeping this in the SDK means every current and future agent-server consumer gets the same behavior.Test plan
.venv/bin/pytest tests/sdk/agent/test_acp_agent.py— 180 passed<CUSTOM_SECRETS>withoutagent_contextstrsecret in registry → injectedSecretSource/ LookupSecret-shaped source in registry → resolved + injectedacp_envprecedence over registrysecret_registryprecedence overagent_context.secretsSecretSourcelookup is skipped, not propagated.venv/bin/ruff format --check openhands-sdk/openhands/sdk/agent/acp_agent.py tests/sdk/agent/test_acp_agent.py.venv/bin/ruff check openhands-sdk/openhands/sdk/agent/acp_agent.py tests/sdk/agent/test_acp_agent.pygit diff --checkNote on commits
The cleanup commit was pushed with
--no-verifybecauseuv runrewritesuv.lockduring pre-commit in this repo due to the pre-existing[tool.uv] exclude-newer = "7 days"parse issue. The changed files were verified directly with the venv binaries above.🤖 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:08b3f28-pythonRun
All tags pushed for this build
About Multi-Architecture Support
08b3f28-python) is a multi-arch manifest supporting both amd64 and arm6408b3f28-python-amd64) are also available if needed