Repository navigation
fix(process): deliver secret input after an async stdin prompt - #202646
Conversation
The direct child adapter released the secret pipe when construction returned, before readiness awaited prepareInput and wrote stdin. A CLI run with an OpenClaw-held login and a stdin prompt then failed with 'secret input file descriptor 3 is unavailable'. Readiness now owns the pipe until delivery settles, as the service relay path already does.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR retains the secret-input pipe until asynchronous child readiness finishes. Example: A foreground Gateway launches a CLI child with stdin "prompt", an asynchronous prepareInput callback, and credential input on fd 3.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — suspected predecessor, not a causality claim: source commit Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a source-confirmed pipe lifetime bug still present on main, with no introduced correctness or security defect found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe process supervisor passes CLI launch parameters to the child adapter, which owns process startup, stdin, private credential delivery, output, and cleanup. flowchart TD
A[CLI runner] --> B[Process supervisor]
B --> C[Child adapter construction]
C --> D[Asynchronous readiness]
D --> E[Stdin and secret descriptor delivery]
E --> F[CLI child]
F --> B
Technical reviewBest possible solution: Keep the existing transport owner and transfer its disposal lifetime from construction to readiness, as this patch does. Do we have a high-confidence way to reproduce the issue? The source establishes a deterministic reproduction using the direct POSIX child path, stdin, secretInput, and an awaited prepareInput callback; the author reports a red-on-base regression and matching Gateway failure, which this read-only review did not rerun. Is this the best way to solve the issue? This is the smallest complete production fix: retain construction-failure cleanup, transfer the existing resource into readiness, and dispose it on either readiness outcome without changing input ordering, authority checks, or transport behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7af6a10fd328. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +43. Total +47 across 2 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 20, 2026, 1:29 PM ET / 18:29 UTC. |
|
Maintainer override: |
|
Landed. Claude CLI runs with an OpenClaw-held Claude token and a stdin prompt no longer fail with |
…law#202646) ## What Problem This Solves A Claude CLI chat that signs in with a Claude subscription token stored in OpenClaw fails background CLI runs that send their prompt on stdin with `secret input file descriptor 3 is unavailable`. It happens on Gateways that run in the foreground (`openclaw gateway run`, containers, Windows), not under a service manager. ## Why It Happens `createChildAdapter` (direct path) prepares the secret pipe with `using`, so the pipe is released when the function returns `{ adapter, ready }`. `ready` then awaits `prepareInput` (and the Windows Job) before it calls `deliverTo`, which finds the writer gone. The service relay path already hands the pipe to readiness and delivers it before stdin. ## Change Readiness now owns the secret pipe until delivery settles (`DisposableStack.move()`); a construction failure before readiness still releases it. One file, 5 lines. ## Evidence - New `src/process/supervisor/supervisor.secret-after-input.real.test.ts`: a real child reads a stdin prompt written after an async `prepareInput`, then the secret on fd 3. Red on `main` with `secret input file descriptor 3 is unavailable`, green with the fix. - Real product, tier source (`ocx src`), foreground Gateway with no service marker, one Claude CLI agent signed in with an OpenClaw-held Claude subscription token, no API key: one chat turn, then `/btw`. The background Claude CLI completion right after the turn: - `main` (`69cbf605`): `[process/supervisor] spawn failed: runId=isolated-completion-… reason=Error: secret input file descriptor 3 is unavailable`, twice. - This branch: the same flow logs no such error. Co-authored-by: Ayaan Zaidi <[email protected]>
Baseline adaptation: Transfer only the secret pipe cleanup to the existing readiness promise; preserve the baseline spawn and Windows readiness paths. (cherry picked from commit 16f4ef3) Co-authored-by: RomneyDa <[email protected]>
## What Problem This Solves
A Claude CLI chat that signs in with a Claude subscription token stored in OpenClaw fails background CLI runs that send their prompt on stdin with `secret input file descriptor 3 is unavailable`. It happens on Gateways that run in the foreground (`openclaw gateway run`, containers, Windows), not under a service manager.
## Why It Happens
`createChildAdapter` (direct path) prepares the secret pipe with `using`, so the pipe is released when the function returns `{ adapter, ready }`. `ready` then awaits `prepareInput` (and the Windows Job) before it calls `deliverTo`, which finds the writer gone. The service relay path already hands the pipe to readiness and delivers it before stdin.
## Change
Readiness now owns the secret pipe until delivery settles (`DisposableStack.move()`); a construction failure before readiness still releases it. One file, 5 lines.
## Evidence
- New `src/process/supervisor/supervisor.secret-after-input.real.test.ts`: a real child reads a stdin prompt written after an async `prepareInput`, then the secret on fd 3. Red on `main` with `secret input file descriptor 3 is unavailable`, green with the fix.
- Real product, tier source (`ocx src`), foreground Gateway with no service marker, one Claude CLI agent signed in with an OpenClaw-held Claude subscription token, no API key: one chat turn, then `/btw`. The background Claude CLI completion right after the turn:
- `main` (`22255926`): `[process/supervisor] spawn failed: runId=isolated-completion-… reason=Error: secret input file descriptor 3 is unavailable`, twice.
- This branch: the same flow logs no such error.
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 16f4ef3)
Companion disposition: no later same-path or PR follow-ups at pinned main. The existing secret-input descriptor owner and direct adapter readiness are present-equivalent; relay and cleanup callers are unchanged.
Co-authored-by: RomneyDa <[email protected]>
Plugin session forks (`runForkedTurn`, `forkSession`; for example Better Prompt and Skill Workshop reviews) always ran on the built-in runtime. On a Claude CLI chat signed in with a Claude subscription:
- With only the CLI's own `claude` login, `runForkedTurn` failed with `No API key found for provider "claude-cli"`.
- With a Claude subscription token stored in OpenClaw, `runForkedTurn` sent the token to the Anthropic API directly, which bills metered extra usage instead of the plan (`cliBackendDispatch` notes in `run/params.ts`).
- `forkSession` refused every CLI runtime: `Session forks are not supported for CLI runtime claude-cli.`
OpenClaw already has one owner for "run this embedded run on the subscription CLI": `cliBackendDispatch: "subscription-auth"` (Active Memory's recall uses it). The fork owner opts into it; no new path:
- `runSessionFork` sets `cliBackendDispatch: "subscription-auth"`. Eligibility is unchanged: subscription (oauth/token) or unresolvable credentials go to the CLI; API keys keep the request replay and its prompt cache.
- Dispatch accepts the fork's in-memory conversation (`sessionManager`), and sends the CLI only the tools that may execute (`toolExecutionAllow`; an empty list is a tool-free run).
- Dispatch now picks the CLI account the way a new CLI session does. Before, it passed only an explicit pin, so a stored Claude token never reached the CLI (`Not logged in · Please run /login`); Active Memory recalls had the same gap.
- Runs that grant the plugin's own tools or set `maxTokens` keep the direct route: neither reaches a CLI process.
- Dispatch carries the run's policy facts to the CLI: a run under another session's policy (a fork's `sandboxSessionKey`) passes that session's entry, the requester fields and `internal_system` provenance into the CLI's Gateway tool grant, so restricted-sender limits apply to the fork as to the chat's own turns.
Accepted: a CLI fork starts a fresh CLI session with the conversation as context, so it does not reuse the chat's cache, and each fork leaves one Claude session file under `~/.claude/projects`, as Active Memory's CLI recalls already do. The source chat's native session is never resumed or written.
Permission modes (maintainer decision, now in `docs/gateway/permission-modes.md`): the `sessionRoot` boundary is enforced on the built-in runtime; CLI-backed chats use the CLI's own controls, and owner turns' Gateway tools are not limited to `sessionRoot`. Live, on a Claude CLI chat in `workspace` mode, an ordinary turn and a fork both read a file outside the workspace through `mcp__openclaw__read`, and the same chat on the built-in runtime refuses both with `Path escapes sandbox root`. A CLI fork therefore has the same file access as the chat's own CLI turns.
Not covered: Gemini CLI on a Google login (OpenClaw cannot limit its tools under OAuth), and harnesses that own their login with no limited one-shot turn (Copilot, Muse, `acp-*`).
Real product, tier source (`ocx src`), isolated foreground Gateway, no API key in the environment or auth store; profiles: Claude subscription setup token, ChatGPT OAuth, Grok OAuth. Each chat: one turn ("Remember PELICAN-42"), then forks through a probe plugin.
| Route | `runForkedTurn` `[read, ls]` | `forkSession` | `runForkedTurn` cache read |
|---|---|---|---|
| `claude-cli`, Claude token | `PELICAN-42 \| FORK-READ-OK 7f3a` (dispatched to Claude CLI) | `PELICAN-42` | 6,985 |
| ChatGPT OAuth, built-in | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (cache read 9,856) | 10,112 |
| Codex app-server | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (19,584) | 8,704 |
| Grok OAuth | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (1,152) | 1,152 |
- `main` on the same Claude chat: `runForkedTurn` ran on the Anthropic API with the token (cache read 0, cache write 23,872), `forkSession` refused.
- Every route: source transcript hash, message count and native binding unchanged; the Claude source session file holds only the chat's own turn.
- Better Prompt 0.2.2 (`start` → `take` through `plugins.sessionAction`) produced an improved prompt on the Claude CLI chat and on the ChatGPT chat.
- Dispatch tests: a fork runs on the CLI with only its own tools from its in-memory session; plugin tool grants and output caps keep the passthrough.
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit b7bf937)
Release adaptation: retain staged Gateway permission-mode documentation and enforcement; omit the superseded upstream documentation exception.
Companions: #202941 and #202646 are present-equivalent (9ec8d08 and 087c816); #201554 is staged as 5647120. #202957 is not applicable (reverts a separate native-tools path). #204219, #203999, #203901, #203919, #203601 and #203271 are independent prewarm, lifecycle, recovery, review or default-routing changes; not required for the selected fork path.
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 8a592a33b7866a1306c60468e4aaf2c9fb23a93f)
What Problem This Solves
A Claude CLI chat that signs in with a Claude subscription token stored in OpenClaw fails background CLI runs that send their prompt on stdin with
secret input file descriptor 3 is unavailable. It happens on Gateways that run in the foreground (openclaw gateway run, containers, Windows), not under a service manager.Why It Happens
createChildAdapter(direct path) prepares the secret pipe withusing, so the pipe is released when the function returns{ adapter, ready }.readythen awaitsprepareInput(and the Windows Job) before it callsdeliverTo, which finds the writer gone. The service relay path already hands the pipe to readiness and delivers it before stdin.Change
Readiness now owns the secret pipe until delivery settles (
DisposableStack.move()); a construction failure before readiness still releases it. One file, 5 lines.Evidence
src/process/supervisor/supervisor.secret-after-input.real.test.ts: a real child reads a stdin prompt written after an asyncprepareInput, then the secret on fd 3. Red onmainwithsecret input file descriptor 3 is unavailable, green with the fix.ocx src), foreground Gateway with no service marker, one Claude CLI agent signed in with an OpenClaw-held Claude subscription token, no API key: one chat turn, then/btw. The background Claude CLI completion right after the turn:main(22255926):[process/supervisor] spawn failed: runId=isolated-completion-… reason=Error: secret input file descriptor 3 is unavailable, twice.