Skip to content

Commit 7e0b599

Browse files
authored
fix: surface Codex input prompts across runtimes (#126387)
* fix: surface Codex input prompts across runtimes Codex structured input now reaches bounded Gateway questions in native and ACP runs, with exact turn ownership, explicit unsupported outcomes, and cancellation fencing. Consume the published ACPX elicitation support. * chore: align elicitation helpers with current guards Use protocol-specific helper names required by current main and update the reservation regression to the generalized input owner. * fix: formalize structured input SDK surface Expose one documented, frozen agent-harness structured-input contract with runtime and subpath coverage, replacing the accidental function-property API. * fix: satisfy elicitation architecture gates Register the real-process ACPX fixture as an executable test root and move shared structured-input types into the boundary leaf to keep Knip and Madge clean. * fix: remove structured input lint suppression Preserve the rejected control and invisible-character ranges with an explicit code-point check so the production suppression inventory stays closed.
1 parent 33e6daa commit 7e0b599

61 files changed

Lines changed: 4280 additions & 562 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/knip.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ const config = {
677677
// Copied as executable runtime internals by the package artifact manifest.
678678
"src/runtime-internals/mcp-command-line.mjs!",
679679
"src/runtime-internals/mcp-proxy.mjs!",
680+
// Spawned by the real-process elicitation regression through CODEX_PATH.
681+
"test/fixtures/codex-app-server.mjs!",
680682
]),
681683
[`${BUNDLED_PLUGIN_ROOT_DIR}/azure-speech`]: bundledPluginWorkspace(),
682684
[`${BUNDLED_PLUGIN_ROOT_DIR}/browser`]: bundledPluginWorkspace([

‎docs/plugins/codex-harness-runtime.md‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,48 @@ intentionally exact-match only: a changed command, arguments, tool payload, or
267267
cwd creates a fresh approval.
268268

269269
Codex MCP tool approval elicitations route through OpenClaw's plugin approval
270-
flow when Codex marks `_meta.codex_approval_kind` as `"mcp_tool_call"`. Codex
271-
`request_user_input` registers a provider-neutral gateway question for the
272-
originating session. The Control UI renders the gateway question card, and a
273-
single non-secret choice uses typed channel buttons when the channel supports
274-
them. Button taps, Control UI answers, and the next queued plain-text reply all
275-
resolve the same gateway record before OpenClaw returns the app-server answer.
276-
Codex auto-resolution and attempt aborts bound the wait and cancel the record.
277-
Secret questions stay entirely on the warned text-reply path. Other MCP
278-
elicitation requests fail closed.
270+
flow when Codex marks `_meta.codex_approval_kind` as `"mcp_tool_call"`.
271+
Plugin, account, Computer Use, and MCP approval classification runs before
272+
ordinary input handling. A denied policy or unmappable approval schema returns
273+
an explicit decline and never becomes a general-purpose form.
274+
275+
OpenClaw supports app-server MCP elicitation modes `form`, `openai/form`, and
276+
`url`. Standard and extended forms can contain at most 12 fields. OpenClaw
277+
normalizes field names to Gateway-safe question IDs, retains the original names
278+
in accepted content, and presents fields in sequential batches of up to three.
279+
Each field may offer at most four choices; fields and choices over those limits
280+
are declined rather than truncated. Supported fields are free-form strings,
281+
string `enum` or `oneOf` choices, booleans, numbers and integers, and
282+
multi-select string arrays. Free-form string values are limited to 4,096
283+
characters. String length, `email`, `uri`, `date`, and
284+
`date-time` constraints and numeric or array bounds are validated before an
285+
accepted response is returned. Optional fields, required fields, and valid
286+
defaults retain their schema meaning.
287+
288+
`openai/form` also supports a single-select `openai/imagePicker` field with up
289+
to four bounded item IDs and titles. OpenClaw uses only those IDs and titles; it
290+
does not fetch or render item images. An unknown extended field type produces a
291+
visible operator message and an explicit decline. This visible fallback is part
292+
of the `openai/form` capability contract.
293+
294+
URL elicitations are shown as literal text with explicit Continue and Decline
295+
choices. OpenClaw does not fetch or open the URL. URLs are limited to 2,048
296+
characters, must use HTTP or HTTPS, cannot include credentials, and cannot
297+
contain control or invisible characters. Invalid URLs produce a visible
298+
explanation and an explicit decline.
299+
300+
Codex `request_user_input` and ordinary MCP elicitations share one per-turn
301+
interactive queue. The Control UI renders each non-secret Gateway question, and
302+
a single choice uses typed channel buttons when the channel supports them.
303+
Button taps, Control UI answers, and the next queued plain-text reply resolve
304+
the same exact app-server request. `serverRequest/resolved` selects a request by
305+
its outer string-or-integer JSON-RPC ID; attempt abort, timeout, and cleanup
306+
cancel the current owner. Late answers cannot resolve a queued replacement.
307+
308+
Only an explicit field `isSecret: true` or Codex question
309+
`isSecret: true` enables secret handling. Secret form fields are requested one
310+
at a time through the warned ephemeral text-reply path and never create durable
311+
Gateway question records. OpenClaw does not infer secrecy from field names.
279312

280313
For the general plugin approval flow that carries these prompts, see
281314
[Plugin permission requests](/plugins/plugin-permission-requests).

‎docs/plugins/sdk-agent-harness.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ choice/free-form answers back into the runtime's native response shape. The
375375
helper keeps channel/TUI presentation consistent while each harness keeps its
376376
own protocol parsing and pending-request lifecycle.
377377

378+
For schema-backed forms and literal URL confirmation, use the
379+
`agentHarnessStructuredInput` runtime surface from the same subpath. It
380+
snapshots bounded own data without invoking accessors, compiles supported
381+
primitive fields into Gateway questions, and executes them with batching,
382+
secret-input, timeout, and cancellation fencing. Harnesses keep ownership of
383+
their protocol envelope and must pass the exact turn signal and active-owner
384+
check; `run(...)` returns an answered, declined, cancelled, or unsupported
385+
outcome for the adapter to translate.
386+
378387
Each prepared attempt also receives a versioned `params.hostCapabilities`
379388
object. Use `bindToolSurface(...)` before exposing plugin-built OpenClaw tools,
380389
and use its policy and approval operations for native actions. A native action

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Use `isLoopbackHost(host)` when a plugin must accept only the local machine. It
224224
| `plugin-sdk/runtime-env` | Narrow runtime env, logger, timeout, retry, and backoff helpers |
225225
| `plugin-sdk/browser-config` | Private-local after July 2026; Supported browser config facade for normalized profile/defaults, CDP URL parsing, and browser-control auth helpers |
226226
| `plugin-sdk/agent-harness-task-runtime` | Private-local after July 2026; Generic task lifecycle and completion delivery helpers for harness-backed agents using a host-issued task scope |
227-
| `plugin-sdk/agent-harness-runtime` | Agent-harness runtime helpers. `acquireSessionWriteLock`, `resolveSessionWriteLockAcquireTimeoutMs`, `resolveSessionWriteLockOptions`, and `SessionWriteLockAcquireTimeoutConfig` are deprecated no-op compatibility exports scheduled for removal in the 2026.10 release train. They no longer block or create lock sidecars; harnesses should rely on OpenClaw's per-session lane plus the durable writer claim and in-transaction fence. |
227+
| `plugin-sdk/agent-harness-runtime` | Agent-harness runtime helpers, including the bounded `agentHarnessStructuredInput` form/URL compilation and execution surface. `acquireSessionWriteLock`, `resolveSessionWriteLockAcquireTimeoutMs`, `resolveSessionWriteLockOptions`, and `SessionWriteLockAcquireTimeoutConfig` are deprecated no-op compatibility exports scheduled for removal in the 2026.10 release train. They no longer block or create lock sidecars; harnesses should rely on OpenClaw's per-session lane plus the durable writer claim and in-transaction fence. |
228228
| `plugin-sdk/codex-mcp-projection` | Private-local after July 2026; Bundled Codex helper for projecting user MCP server config into Codex thread config; not for third-party plugins |
229229
| `plugin-sdk/native-hook-relay-runtime` | Private-local bundled runtime helper for retained native direct-child hook policy; not for third-party plugins |
230230
| `plugin-sdk/codex-session-transcript-runtime` | Private-local bundled Codex helper for serializing transcript-mirror writes; not for third-party plugins |

‎docs/tools/acp-agents-setup.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ Restart the gateway after changing this value.
283283

284284
## Permission configuration
285285

286-
ACP sessions run non-interactively — there is no TTY to approve or deny file-write and shell-exec permission prompts. The acpx plugin provides two config keys that control how permissions are handled:
286+
ACP sessions run without an interactive TTY for file-write and shell-exec
287+
permission prompts. This does not disable ACP form or URL elicitation during a
288+
channel-delivered turn: those requests use transient Gateway questions instead.
289+
The acpx plugin provides two config keys that control harness permissions:
287290

288291
These ACPX harness permissions are separate from OpenClaw exec approvals and separate from CLI-backend vendor bypass flags such as Claude CLI `--permission-mode bypassPermissions`. ACPX `approve-all` is the harness-level break-glass switch for ACP sessions.
289292

‎docs/tools/acp-agents.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,15 @@ work. The delivery path depends on that shape.
631631
session, and ACP output is delivered back to that same
632632
channel/thread/topic.
633633

634+
When an ACP agent requests structured input during a delivered turn,
635+
OpenClaw presents supported form fields as transient Gateway questions in
636+
batches of up to three. Single- and multi-select fields support up to four
637+
choices. URL requests show the literal HTTP(S) URL with explicit Continue
638+
and Decline choices; OpenClaw does not fetch or open it. Explicitly secret
639+
fields use a warned, ephemeral text-reply prompt and are never stored in a
640+
Gateway question record. Malformed or unsupported requests produce a
641+
visible explanation and are declined instead of returning empty answers.
642+
634643
What OpenClaw sends to the harness:
635644

636645
- Normal bound follow-ups are sent as prompt text, plus attachments only when the harness/backend supports them.
@@ -840,6 +849,7 @@ see [ACP agents - setup](/tools/acp-agents-setup).
840849
| `sessions_spawn sandbox="require" is unsupported for runtime="acp" ...` | `sandbox="require"` requested for ACP runtime. | Use `runtime="subagent"` for required sandboxing, or use ACP with `sandbox="inherit"` from a non-sandboxed session. |
841850
| `Cannot apply --model ... did not advertise model support` | The target harness does not expose generic ACP model switching. | Use a harness that advertises ACP `models`/`session/set_model`, use Codex ACP model refs, or configure the model directly in the harness if it has its own startup flag. |
842851
| Missing ACP metadata for bound session | Stale/deleted ACP session metadata. | Recreate with `/acp spawn`, then rebind/focus thread. |
852+
| ACP input request is declined or cancelled | The form/URL is malformed, exceeds field/choice limits, uses unsupported constraints, or the owning turn ended. | Read the visible decline reason, retry with a standard primitive form or valid HTTP(S) URL, and keep the originating turn active while answering. |
843853
| `PermissionPromptUnavailableError: Permission prompt unavailable in non-interactive mode` | `permissionMode` blocks writes/exec in non-interactive ACP session. | Set `plugins.entries.acpx.config.permissionMode` to `approve-all` and restart gateway. See [Permission configuration](/tools/acp-agents-setup#permission-configuration). |
844854
| ACP session fails early with little output | Permission prompts are blocked by `permissionMode`/`nonInteractivePermissions`. | Check gateway logs for `AcpRuntimeError`. For full permissions, set `permissionMode=approve-all`; for graceful degradation, set `nonInteractivePermissions=deny`. |
845855
| ACP session stalls indefinitely after completing work | Harness process finished but ACP session did not report completion. | Update OpenClaw; current acpx cleanup reaps OpenClaw-owned stale wrapper and adapter processes on close and Gateway startup. |

‎docs/tools/permission-modes.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ For app-server setup, auth order, and native Codex runtime details, see [Codex h
6363

6464
## ACPX harness permissions
6565

66-
ACPX sessions are non-interactive, so they cannot click a TTY permission prompt. ACPX uses separate harness-level settings under `plugins.entries.acpx.config`:
66+
ACPX sessions have no interactive TTY for permission prompts. Supported ACP
67+
form and URL requests can still reach the operator as Gateway questions during
68+
a channel-delivered turn; those are separate from permission approval. ACPX
69+
uses separate harness-level settings under `plugins.entries.acpx.config`:
6770

6871
| Setting | Values | Meaning |
6972
| --------------------------- | --------------- | ------------------------------------------- |

‎extensions/acpx/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dependencies": {
1111
"@agentclientprotocol/claude-agent-acp": "0.62.0",
1212
"@agentclientprotocol/codex-acp": "1.1.7",
13-
"acpx": "0.13.0",
13+
"acpx": "0.13.1",
1414
"smol-toml": "1.7.1",
1515
"zod": "4.4.3"
1616
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import fs from "node:fs/promises";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import { afterEach, expect, it, vi } from "vitest";
5+
import { AcpxRuntime, createAgentRegistry, createFileSessionStore } from "./runtime.js";
6+
7+
const temporaryDirectories: string[] = [];
8+
9+
afterEach(async () => {
10+
vi.unstubAllEnvs();
11+
await Promise.all(
12+
temporaryDirectories
13+
.splice(0)
14+
.map((directory) => fs.rm(directory, { force: true, recursive: true })),
15+
);
16+
});
17+
18+
it("round-trips codex-acp request_user_input through real processes without empty answers", async () => {
19+
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-acpx-elicitation-"));
20+
temporaryDirectories.push(stateDir);
21+
const codexAcpPath = path.resolve("node_modules/@agentclientprotocol/codex-acp/dist/index.js");
22+
const appServerPath = path.resolve("extensions/acpx/test/fixtures/codex-app-server.mjs");
23+
vi.stubEnv("CODEX_PATH", appServerPath);
24+
const runtime = new AcpxRuntime({
25+
cwd: process.cwd(),
26+
sessionStore: createFileSessionStore({ stateDir }),
27+
agentRegistry: createAgentRegistry({
28+
overrides: { codex: [process.execPath, codexAcpPath] },
29+
}),
30+
permissionMode: "deny-all",
31+
elicitationModes: ["form", "url"],
32+
timeoutMs: 5_000,
33+
});
34+
const handle = await runtime.ensureSession({
35+
sessionKey: "agent:elicitation:acp:process",
36+
agent: "codex",
37+
mode: "oneshot",
38+
});
39+
const onElicitation = vi.fn(async (_request, context) => {
40+
expect(context.requestId).not.toBeUndefined();
41+
expect(context.signal.aborted).toBe(false);
42+
return { action: "accept" as const, content: { question: "round-trip" } };
43+
});
44+
const text: string[] = [];
45+
46+
try {
47+
for await (const event of runtime.runTurn({
48+
handle,
49+
text: "ask",
50+
mode: "prompt",
51+
requestId: "process-turn",
52+
onElicitation,
53+
})) {
54+
if (event.type === "text_delta") {
55+
text.push(event.text);
56+
}
57+
}
58+
} finally {
59+
await runtime.close({ handle, reason: "test-complete" });
60+
}
61+
62+
expect(onElicitation).toHaveBeenCalledOnce();
63+
expect(text.join("")).toContain('"answers":{"question":{"answers":["round-trip"]}}');
64+
expect(text.join("")).not.toContain('"answers":{}');
65+
});

‎extensions/acpx/src/runtime.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,76 @@ describe("AcpxRuntime fresh reset wrapper", () => {
199199
expect(ensureSpy).not.toHaveBeenCalled();
200200
});
201201

202+
it("advertises elicitation modes and forwards the exact handler through every delegate", async () => {
203+
const onElicitation = vi.fn(async () => ({ action: "cancel" as const }));
204+
const handle = (sessionKey: string) => ({
205+
sessionKey,
206+
backend: "acpx",
207+
runtimeSessionName: sessionKey,
208+
acpxRecordId: sessionKey,
209+
});
210+
const runThrough = async (runtime: AcpxRuntime, sessionKey: string) => {
211+
for await (const event of runtime.runTurn({
212+
handle: handle(sessionKey),
213+
text: "ask",
214+
mode: "prompt",
215+
requestId: `request:${sessionKey}`,
216+
onElicitation,
217+
})) {
218+
void event;
219+
}
220+
};
221+
const baseStore = (agentCommand: string): TestSessionStore => ({
222+
load: vi.fn(async (sessionId: string) => ({ acpxRecordId: sessionId, agentCommand })),
223+
save: vi.fn(async () => {}),
224+
});
225+
226+
const defaultRuntime = makeRuntime(baseStore(CODEX_ACP_COMMAND), {
227+
elicitationModes: ["form", "url"],
228+
});
229+
const defaultTurn = vi
230+
.spyOn(defaultRuntime.delegate, "runTurn")
231+
.mockImplementation(async function* () {
232+
yield { type: "done" };
233+
});
234+
await runThrough(defaultRuntime.runtime, "agent:codex:acp:default");
235+
236+
const bridgeRuntime = makeRuntime(baseStore(DOCUMENTED_OPENCLAW_BRIDGE_COMMAND), {
237+
elicitationModes: ["form", "url"],
238+
mcpServers: [{ name: "tools", command: "mcp-tools" }] as never,
239+
});
240+
const bridgeDelegate = bridgeRuntime.bridgeSafeDelegate as typeof bridgeRuntime.delegate;
241+
const bridgeTurn = vi.spyOn(bridgeDelegate, "runTurn").mockImplementation(async function* () {
242+
yield { type: "done" };
243+
});
244+
await runThrough(bridgeRuntime.runtime, "agent:openclaw:acp:bridge");
245+
246+
const managedRuntime = makeRuntime(baseStore(CODEX_ACP_COMMAND), {
247+
elicitationModes: ["form", "url"],
248+
openclawToolsMcpBridgeEnabled: true,
249+
mcpServers: [{ name: "openclaw-tools", command: "node", args: [], env: [] }],
250+
});
251+
const managedDelegate = (
252+
managedRuntime.runtime as unknown as {
253+
resolveManagedToolsDelegateForSession(sessionKey: string): typeof managedRuntime.delegate;
254+
}
255+
).resolveManagedToolsDelegateForSession("agent:codex:acp:managed");
256+
const managedTurn = vi.spyOn(managedDelegate, "runTurn").mockImplementation(async function* () {
257+
yield { type: "done" };
258+
});
259+
await runThrough(managedRuntime.runtime, "agent:codex:acp:managed");
260+
261+
for (const turn of [defaultTurn, bridgeTurn, managedTurn]) {
262+
expect(turn).toHaveBeenCalledOnce();
263+
expect(turn.mock.calls[0]?.[0].onElicitation).toBe(onElicitation);
264+
}
265+
for (const delegate of [defaultRuntime.delegate, bridgeDelegate, managedDelegate] as Array<{
266+
options?: { elicitationModes?: readonly string[] };
267+
}>) {
268+
expect(delegate.options?.elicitationModes).toEqual(["form", "url"]);
269+
}
270+
});
271+
202272
it("adds the OpenClaw session key to both managed tools MCP bridges", () => {
203273
const baseStore: TestSessionStore = {
204274
load: vi.fn(async () => undefined),

0 commit comments

Comments
 (0)