Skip to content

fix(process): deliver secret input after an async stdin prompt - #202646

Merged
obviyus merged 1 commit into
mainfrom
fix/secret-input-after-stdin
Nov 21, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/secret-input-after-stdin

Conversation

@obviyus

@obviyus obviyus commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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.

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.
@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Construction disposes the pipe before secret delivery, producing "secret input file descriptor 3 is unavailable".
  • After: Readiness retains the pipe so the child can receive both the prompt and credential.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source-correct, with a meaningful real-child regression, but the supplied runtime evidence does not establish successful completion after the fix.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Background CLI runs using an OpenClaw-held credential can fail before completion when prompt preparation yields asynchronously.
Reason: The maintainer-authored direction restores the existing credential-delivery contract through a focused lifetime correction without adding configuration or a competing implementation.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit 54dc4a898817 by Peter Steinberger; no PR verified.

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
Reviewed head: 26bdb512e403dd14a11d9c3cac9d85c9cda2908c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted after-fix Gateway logs or terminal output showing the same credential-bearing background CLI run actually completes; remove API keys, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Disposable secret descriptor ownership keeps the original intent (b1cbc7e: Provide reopenable one-shot credential pipes while closing untransferred descriptors after construction failure.)
  • Adapter publication before readiness keeps the original intent (54dc4a8: Attach output subscribers before waiting for private-input delivery, preserving launcher output and cleanup ownership.)
  • Asynchronous preparation before stdin keeps the original intent (cbc53ac: Await worker-backed preparation before private input while preserving effect-boundary checks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 237111e adds src/process/supervisor/adapters/child.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 237111eabf61; files: src/process/supervisor/adapters/child.ts)

PR surface

Source +4, Tests +43. Total +47 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 1 43 0 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 49 2 +47

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: The reported and source-confirmed failure prevents credential-bearing background CLI runs from starting on the affected direct-child path.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The reported and source-confirmed failure prevents credential-bearing background CLI runs from starting on the affected direct-child path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the affected background CLI run's successful after-fix completion output.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 20, 2026, 1:29 PM ET / 18:29 UTC.

@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: checks-fast-baseline-ratchets (job 136478952921) did not run its check. GitHub's annotation: "The hosted runner lost communication with the server." It ran 47 minutes and never finished the "Run baseline ratchets" step. The two openclaw/ci-gate failures only report that job. Not caused by this PR, which changes src/process/supervisor/adapters/child.ts and adds one test. All 54 other required checks pass; the exact-head local review is clean.

@obviyus
obviyus merged commit 16f4ef3 into main Nov 21, 2026
135 of 139 checks passed
@obviyus
obviyus deleted the fix/secret-input-after-stdin branch November 21, 2026 03:49
@obviyus

obviyus commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Landed. Claude CLI runs with an OpenClaw-held Claude token and a stdin prompt no longer fail with secret input file descriptor 3 is unavailable on foreground Gateways: readiness now owns the secret pipe until delivery. Proof: a real-child regression test (red on main, green here) and a live foreground Gateway run where main logged the error twice and this branch logged none.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
## 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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant