gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

--acp never answers initialize when a sandbox is enabled (stdin read as a piped prompt before the sandbox hop)

Open roidayan1 opened this issue 1 week ago • 2 comments

What happened?

With a sandbox enabled (GEMINI_SANDBOX, --sandbox, or tools.sandbox in settings), gemini --acp never answers an ACP client's initialize request when the client writes it as soon as the process starts. Without a sandbox it answers at once.

The cause: before hopping into the sandbox, the CLI reads a non-TTY stdin as a piped prompt:

https://github.com/google-gemini/gemini-cli/blob/v0.70.0/packages/cli/src/gemini.tsx#L705-L728

readStdin() clears its 1 s "nothing piped" timer at the first chunk, then waits for an end of input that an ACP stdio transport never sends. So the CLI waits forever and never starts the sandboxed process:

https://github.com/google-gemini/gemini-cli/blob/v0.70.0/packages/cli/src/utils/readStdin.ts#L35-L120

A client that holds its first write back for about 3 s does get an answer, because the timer fires first and the read ends empty, but that's a race, not a fix.

This looks like the cause of #22782 (--acp hanging, with sandbox-exec (permissive-open) in its client information), which was closed as not planned.

Steps to reproduce

  1. On macOS, start GEMINI_SANDBOX=sandbox-exec gemini --acp.
  2. Immediately write an ACP initialize request line to its stdin.
  3. No response arrives (waited 15 s). Without GEMINI_SANDBOX, the response arrives at once.

What did you expect to happen?

With a sandbox enabled, --acp hops into the sandbox and answers initialize from inside it. ACP never takes a piped prompt, so skipping the stdin read when --acp (or --experimental-acp) is set should fix it.

Client information

  • CLI version: 0.70.0 (also 0.69.0)
  • Platform: macOS (darwin arm64)
  • Sandbox: sandbox-exec (permissive-open)

The read sits inside if (sandboxConfig), before the hop, so any sandbox command should behave the same.

Login information

None needed: reproduced with a fresh GEMINI_CLI_HOME and no account configured.

roidayan1 avatar Nov 21 '26 21:11 roidayan1

There is a problem with the Gemini CLI issue triaging. Please check the action logs for details.

gemini-cli[bot] avatar Nov 21 '26 21:11 gemini-cli[bot]

Thanks for the detailed diagnosis. I can reproduce this on current main and have a fix ready that follows your suggestion: skip the pre-sandbox readStdin() when partialConfig.getAcpMode() is true (which covers both --acp and --experimental-acp), so the sandboxed process inherits stdin untouched.

It's a one-line guard plus two gemini.test.tsx cases:

  • in ACP mode, stdin isn't read and the sandbox args are unchanged
  • outside ACP mode, piped stdin is still forwarded as --prompt

I checked it end to end with the Seatbelt sandbox. With the fix, initialize gets a response; without it, nothing comes back.

Automatic triage failed on this issue (see the bot comment above). Could a maintainer triage it and, if the approach looks right, add help wanted? I'll link the PR here.

Raamia avatar Nov 22 '26 03:11 Raamia