Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor(acp): stop forwarding acp_env; route ACP creds via Secrets panel (#1050)

simonrosenberg5eb519c014b7
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.ts
index f628d539d1..e14c7bbd1e 100644
--- a/__tests__/api/agent-server-adapter.test.ts
+++ b/__tests__/api/agent-server-adapter.test.ts
@@ -480,7 +480,9 @@ describe("buildStartConversationRequest", () => {
// @spec LLD-001 β€” Frontend always sends its chosen default model
describe("llm.model fallback β€” frontend always sends its chosen default", () => {
type ModelPayload = {
- agent_settings: Record<string, unknown> & { llm: Record<string, unknown> };
+ agent_settings: Record<string, unknown> & {
+ llm: Record<string, unknown>;
+ };
};
function getModelFrom(
@@ -510,10 +512,19 @@ describe("buildStartConversationRequest", () => {
// SettingsValue includes scalars so inline literals are type-safe here.
it.each([
["undefined", { ...DEFAULT_SETTINGS.agent_settings, llm: {} }],
- ["an empty string", { ...DEFAULT_SETTINGS.agent_settings, llm: { model: "" } }],
- ["whitespace only", { ...DEFAULT_SETTINGS.agent_settings, llm: { model: " " } }],
+ [
+ "an empty string",
+ { ...DEFAULT_SETTINGS.agent_settings, llm: { model: "" } },
+ ],
+ [
+ "whitespace only",
+ { ...DEFAULT_SETTINGS.agent_settings, llm: { model: " " } },
+ ],
// No llm key at all β€” SettingsValue accepts plain scalars.
- ["absent (no llm block)", { schema_version: 1, agent_kind: "openhands", agent: "CodeActAgent" }],
+ [
+ "absent (no llm block)",
+ { schema_version: 1, agent_kind: "openhands", agent: "CodeActAgent" },
+ ],
// Mirrors a fresh user who skipped onboarding: server returns {}.
["entirely empty", {}],
])(
@@ -795,7 +806,9 @@ describe("buildRuntimeServicesSystemSuffix", () => {
expect(suffix).toContain("http://localhost:18000");
expect(suffix).toContain("http://localhost:18001");
expect(suffix).toContain("http://localhost:18001/api/automation/docs");
- expect(suffix).toContain("X-Session-API-Key: $OPENHANDS_AUTOMATION_API_KEY");
+ expect(suffix).toContain(
+ "X-Session-API-Key: $OPENHANDS_AUTOMATION_API_KEY",
+ );
expect(suffix).not.toContain("X-API-Key: $OPENHANDS_AUTOMATION_API_KEY");
expect(suffix).toContain("</RUNTIME_SERVICES>");
// The "don't guess" line should reference the actual agent-server URL
@@ -1170,6 +1183,9 @@ describe("buildStartConversationRequest β€” ACP discriminator", () => {
agent_kind: "acp",
acp_server: "claude-code",
acp_command: [],
+ // Legacy persisted value: provider creds no longer ride acp_env β€”
+ // they flow through the Secrets panel (request.secrets). A stale
+ // acp_env left on saved settings must be dropped, not forwarded.
acp_env: { ANTHROPIC_API_KEY: "user-set-via-api" },
acp_model: "claude-opus-4-5",
agent: "CodeActAgent",
@@ -1218,9 +1234,9 @@ describe("buildStartConversationRequest β€” ACP discriminator", () => {
"@agentclientprotocol/claude-agent-acp",
]);
expect(acpPayload.agent_settings.acp_model).toBe("claude-opus-4-5");
- expect(acpPayload.agent_settings.acp_env).toEqual({
- ANTHROPIC_API_KEY: "user-set-via-api",
- });
+ // acp_env is no longer a forwarded ACP setting β€” a stale value on saved
+ // settings is dropped rather than leaked into the conversation request.
+ expect(acpPayload.agent_settings.acp_env).toBeUndefined();
expect(acpPayload.agent_settings.llm).toBeUndefined();
expect(acpPayload.agent_settings.condenser).toBeUndefined();
});
diff --git a/__tests__/utils/acp-command.test.ts b/__tests__/utils/acp-command.test.ts
index a151fc0836..bf269a2724 100644
--- a/__tests__/utils/acp-command.test.ts
+++ b/__tests__/utils/acp-command.test.ts
@@ -108,8 +108,8 @@ describe("parseCommand", () => {
// the persisted ``acp_command`` β€” that would leak a host env var
// into settings on every save. The tokenizer reads ``$NAME`` as
// a literal substring of the token, so the user's typed text
- // survives verbatim. Users who actually want env vars in the
- // subprocess should set ``acp_env`` instead of inlining them.
+ // survives verbatim. Provider credentials belong in the Secrets
+ // panel (request.secrets), never inlined into the command.
const result = parseCommand("npx $ANTHROPIC_API_KEY");
expect(result).toEqual(["npx", "$ANTHROPIC_API_KEY"]);
// Pin the no-leak contract: no ``sk-…`` token sneaks through
diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.ts
index d8ee2e36fc..8a4728fa3a 100644
--- a/src/api/agent-server-adapter.ts
+++ b/src/api/agent-server-adapter.ts
@@ -368,7 +368,6 @@ type ConversationSettingsPayload = SettingsRecord & {
const ACP_SETTINGS_KEYS = [
"acp_command",
"acp_args",
- "acp_env",
"acp_model",
"acp_session_mode",
"acp_prompt_timeout",
@@ -622,6 +621,10 @@ function buildConfiguredOpenHandsAgentSettings(
for (const key of ACP_SETTINGS_KEYS) {
delete agentSettings[key];
}
+ // ``acp_env`` is no longer a forwarded ACP setting (provider creds ride the
+ // Secrets panel), but a legacy value may linger on persisted settings β€”
+ // scrub it so it never leaks onto the OpenHands payload.
+ delete agentSettings.acp_env;
return {
...agentSettings,
diff --git a/src/types/settings.ts b/src/types/settings.ts
index f80ce03e86..c11344a3e9 100644
--- a/src/types/settings.ts
+++ b/src/types/settings.ts
@@ -118,7 +118,9 @@ export type SettingsScope = "personal";
* - ``"acp"``: the conversation is driven by an external ACP subprocess
* (Claude Code / Codex / Gemini CLI / Custom). The LLM / condenser / MCP
* settings are inert; ``acp_command`` / ``acp_args`` / ``acp_model`` /
- * ``acp_env`` / ``acp_server`` apply instead.
+ * ``acp_server`` apply instead. Provider credentials are supplied through the
+ * Secrets panel (``request.secrets`` / ``agent_context.secrets``), never
+ * through a per-agent env channel.
*/
export type AgentKind = "openhands" | "acp";