Skip to content

fix: make code review prompt transport stdin-safe - #375

Merged
kamilio merged 5 commits into
mainfrom
fix/large-prompts-via-stdin
Jun 2, 2026
Merged

kamilio merged 5 commits into
mainfrom
fix/large-prompts-via-stdin

Conversation

@kamilio

@kamilio kamilio commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • pipe code-review orchestrator and nested-reviewer prompts through stdin for plain-text-safe codex and claude-code agents, including documented aliases/case variants
  • keep public buildSpawnArgs() behavior stable, so external callers do not silently lose oversized prompts
  • avoid raw-text stdin for kimi and goose, whose stdin modes require different protocol/argument handling
  • refresh the generated pipeline schema required by CI

Motivation

While running the Yo todo dry-run against real review chores, code review exposed prompt-transport failures:

  1. A large Codex review prompt failed with E2BIG: argument list too long, posix_spawn 'codex' when sent via argv.
  2. Nested review-agent runs needed stdin-safe execution in the code-review workflow.

An initial broad fallback in agent-spawn was rejected during review because buildSpawnArgs() 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 (96 passed)
  • npm run lint:eslint
  • npm run lint:types
  • npx prettier --check on changed TypeScript files
  • pre-push hook: full npm run test suite (10903 passed, 1 skipped)

@poe-code-agent poe-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@kamilio kamilio changed the title fix(agent-spawn): send large prompts via stdin fix: make code review prompt transport stdin-safe Jun 2, 2026

@poe-code-agent poe-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes: buildSpawnArgs callers can drop large prompts.

!!config.stdinMode &&
(options.useStdin === true ||
options.prompt.includes("\0") ||
Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/agent-code-review/src/mcp.ts Outdated
}
): Promise<SpawnResult> {
return spawn(agent, { prompt, ...options });
return spawn(agent, { prompt, ...options, useStdin: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@poe-code-agent poe-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes: buildSpawnArgs callers can still drop large prompts.

!!config.stdinMode &&
(options.useStdin === true ||
options.prompt.includes("\0") ||
Buffer.byteLength(options.prompt, "utf8") > MAX_SAFE_PROMPT_ARG_BYTES)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@poe-code-agent poe-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes: claude alias still uses argv for large review prompts.

Comment on lines +1 to +3
export function shouldUseTextStdinForCodeReview(agent: string): boolean {
return agent === "codex" || agent === "claude-code";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@poe-code-agent poe-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kamilio
kamilio merged commit c1bb517 into main Jun 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant