Repository navigation
fix: make code review prompt transport stdin-safe - #375
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fe1078234
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| !!config.stdinMode && | ||
| (options.useStdin === true || | ||
| options.prompt.includes("\0") || | ||
| Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES) |
There was a problem hiding this comment.
Preserve large prompts for buildSpawnArgs callers
When a prompt exceeds this threshold, buildSpawnArgs() now silently omits the prompt from argv and switches to the agent's stdin args, but its return type has no signal that the caller must pipe options.prompt. I checked packages/superintendent/src/runtime/agent-runner.ts, which calls buildSpawnArgs(input.agent, { prompt: input.prompt, ... }) and then starts the process with stdin: "inherit" rather than passing input.prompt; large Codex/Claude/Kimi/Goose prompts will therefore be lost or hang waiting for terminal stdin instead of being delivered to the agent. Either keep this automatic fallback inside spawn/spawnStreaming where stdin is wired, or expose/use stdin metadata so existing buildSpawnArgs callers can provide the input.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed by the later scoped design: buildSpawnArgs() no longer automatically switches large prompts to stdin, so callers such as superintendent/SDK keep receiving the prompt in argv unless they explicitly opt in.
| !!config.stdinMode && | ||
| (options.useStdin === true || | ||
| options.prompt.includes("\0") || | ||
| Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES) |
There was a problem hiding this comment.
Serialize Kimi stdin before auto-switching
For large kimi prompts that do not explicitly request stdin, this new threshold now selects the Kimi stdin path from packages/agent-spawn/src/configs/kimi.ts, which adds --input-format stream-json, while spawn()/spawnStreaming() still pipe the raw prompt string as stdin. I checked the Kimi CLI docs/FAQ, which says --input-format stream-json input must be valid JSONL, so a normal large text prompt will be rejected or misread; only auto-switch Kimi to a text stdin mode, or JSONL-encode the user message before using this mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed by the scoped design in c0b224dc and covered further in 3fd42f96: code-review does not opt kimi into raw-text stdin, so its stream-json stdin protocol is not fed a plain review prompt.
| @@ -1,8 +1,15 @@ | |||
| import type { CliSpawnConfig } from "./types.js"; | |||
|
|
|||
| const MAX_SAFE_PROMPT_ARG_BYTES = 96 * 1024; | |||
There was a problem hiding this comment.
Lower the argv cutoff on Windows
With this cutoff, prompts between roughly 32 KiB and 96 KiB still stay in argv, which is unsafe on Windows: I checked the Windows CreateProcess documentation, and the entire command line is capped at 32,767 characters including the terminating null. For an ASCII Codex prompt around 40 KiB, spawn() will not switch to stdin and can still fail with a command-line-too-long error despite the new fallback; make the threshold platform-aware or below the Windows limit before keeping the prompt in argv.
Useful? React with 👍 / 👎.
| !!config.stdinMode && | ||
| (options.useStdin === true || | ||
| options.prompt.includes("\0") || | ||
| Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES) |
There was a problem hiding this comment.
This automatic fallback also affects buildSpawnArgs(), but that API still only returns argv/env and gives callers no way to know they must pipe options.prompt. Existing non-test callers such as packages/superintendent/src/runtime/agent-runner.ts and src/sdk/ralph.ts build argv with buildSpawnArgs() and run with stdin: "inherit", so prompts over this threshold are removed from argv and never delivered to the agent (or the process waits on terminal stdin). Please keep the automatic size-based switch inside the spawn paths that wire stdin, or extend buildSpawnArgs() and update its callers to carry the stdin input.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4d2bc9659
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| ): Promise<SpawnResult> { | ||
| return spawn(agent, { prompt, ...options }); | ||
| return spawn(agent, { prompt, ...options, useStdin: true }); |
There was a problem hiding this comment.
Don't force stdin for every review provider
When code review spawns a subagent with agent: "kimi" or agent: "goose", this unconditional useStdin switches to provider-specific stdin modes that are not equivalent to passing the prompt in argv: Kimi's config adds --input-format stream-json, whose docs say stdin must be JSONL, while Goose's config still emits --text plus --instructions - even though the official goose run docs define --text <TEXT> and --instructions <FILE> with - for stdin. Fresh evidence beyond the prior large-prompt findings is that this line now forces that path for every code-review subagent, including small prompts, so those supported reviewers can fail or misread the raw rendered prompt.
Useful? React with 👍 / 👎.
| !!config.stdinMode && | ||
| (options.useStdin === true || | ||
| options.prompt.includes("\0") || | ||
| Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES) |
There was a problem hiding this comment.
Avoid auto-switching Goose to an invalid argv shape
For any Goose spawn whose prompt exceeds this new threshold, buildCliArgs() now selects gooseSpawnConfig.stdinMode, but that config still keeps the normal promptFlag (--text) and appends --instructions -, producing goose run ... --text --instructions -. I checked the Goose CLI docs for run: --text takes the direct prompt text, while --instructions takes a file path with - for stdin, so this auto path leaves --text without its required value and can make large Goose prompts fail even though small prompts continue to use --text <prompt>.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed by the scoped design in c0b224dc and retained after alias resolution: code-review does not opt goose into raw-text stdin, avoiding the invalid --text --instructions - path.
| !!config.stdinMode && | ||
| (options.useStdin === true || | ||
| options.prompt.includes("\0") || | ||
| Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES) |
There was a problem hiding this comment.
This still routes oversized prompts through stdin for buildSpawnArgs(), but that API only returns argv/env and has no way to tell callers to pipe the original prompt. Existing callers such as packages/superintendent/src/runtime/agent-runner.ts and src/sdk/ralph.ts pass these args to resolvePoeCommandExecution with stdin: "inherit", so a >96 KiB prompt now becomes codex exec - ... with no input. Please either keep buildSpawnArgs() from auto-omitting prompts, or extend its result and update all non-spawn() callers to pass stdin: "pipe" plus the prompt when stdin mode is selected.
There was a problem hiding this comment.
Addressed in c0b224dc: buildSpawnArgs() no longer implicitly changes large prompts to stdin transport, so existing external callers retain argv-delivered prompts. Code-review orchestration now explicitly opts into stdin only for plain-text-safe codex and claude-code agents; kimi and goose remain on their existing argument paths. Added regressions covering the public args behavior and both structured-input agents.
| export function shouldUseTextStdinForCodeReview(agent: string): boolean { | ||
| return agent === "codex" || agent === "claude-code"; | ||
| } |
There was a problem hiding this comment.
agent is still the raw configured value here. The repo accepts aliases like claude and resolves them to claude-code in @poe-code/agent-defs; spawn() also resolves aliases later, but this check runs before that. With --agent claude/POE_DEFAULT_AGENT=claude, the large code-review prompt still goes through argv and can hit the same E2BIG failure. Please normalize before deciding stdin eligibility (and cover the alias case in tests).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0b224dc22
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -0,0 +1,3 @@ | |||
| export function shouldUseTextStdinForCodeReview(agent: string): boolean { | |||
| return agent === "codex" || agent === "claude-code"; | |||
There was a problem hiding this comment.
Normalize aliases before deciding stdin transport
When the code-review agent is configured with a valid alias or different casing such as --agent claude or POE_DEFAULT_AGENT=CLAUDE, this helper returns false even though spawn() later resolves that value to the claude-code CLI. In that scenario the orchestrator/subagent review prompt, which includes the PR diff and can be large, is still sent as an argv argument instead of stdin, so the new stdin-safe path is bypassed for a documented alias that otherwise works.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 3fd42f96: the code-review stdin selector now resolves the configured agent through the existing getSpawnConfig() alias/case-normalization path before choosing raw-text stdin. Added orchestrator and nested-reviewer regression coverage for claude and CLAUDE, while retaining structured-input exclusions for kimi and goose.
Summary
codexandclaude-codeagents, including documented aliases/case variantsbuildSpawnArgs()behavior stable, so external callers do not silently lose oversized promptskimiandgoose, whose stdin modes require different protocol/argument handlingMotivation
While running the Yo todo dry-run against real review chores, code review exposed prompt-transport failures:
E2BIG: argument list too long, posix_spawn 'codex'when sent via argv.An initial broad fallback in
agent-spawnwas rejected during review becausebuildSpawnArgs()callers cannot provide stdin input and structured-input agents (kimi/goose) cannot accept raw review prompt text through their configured stdin modes. The final implementation confines stdin selection to code-review calls for compatible plain-text agents and resolves aliases through the existing spawn-config resolution path.Validation
npm exec -- vitest run packages/agent-spawn/src/agent-spawn.test.ts packages/agent-code-review/src/mcp.test.ts packages/agent-code-review/src/review.test.ts(96passed)npm run lint:eslintnpm run lint:typesnpx prettier --checkon changed TypeScript filesnpm run testsuite (10903passed,1skipped)