Problem
spawn(...) passes the prompt as an argv element by default (useStdin: false). For agents whose spawn config declares promptFlag (e.g. codex exec <prompt>), large prompts cause the kernel to reject the spawn with E2BIG ("Argument list too long") before the agent starts.
On Linux the per-arg limit is typically ~128KB; total argv+envp is ~2MB. We hit this in an automations workflow that passes a rendered PR diff + reviewer profile (~150KB) into codex via spawn("codex", { prompt, ... }).
Current workaround
Callers explicitly opt in: spawn("codex", { prompt, useStdin: true }). This works because codexService.supportsStdinPrompt === true and codexSpawnConfig.stdinMode = { omitPrompt: true, extraArgs: ["-"] } are already wired through in packages/agent-spawn/src/spawn.ts.
Suggestion
Automatically switch to stdin when both:
spawnConfig.stdinMode is defined (i.e. the adapter supports it), and
Buffer.byteLength(options.prompt, "utf8") exceeds a safe threshold (~64KB leaves headroom for env, mcp args, mode flags).
Sketch:
```ts
const PROMPT_STDIN_FALLBACK_BYTES = 64 * 1024;
function resolveStdinMode(spawnConfig, options) {
if (!spawnConfig.stdinMode) return undefined;
if (options.useStdin) return spawnConfig.stdinMode;
if (Buffer.byteLength(options.prompt, "utf8") > PROMPT_STDIN_FALLBACK_BYTES) {
return spawnConfig.stdinMode;
}
return undefined;
}
```
Used in both buildSpawnArgs and spawn in packages/agent-spawn/src/spawn.ts. Callers without useStdin: true would silently get the stdin path for large prompts instead of a kernel rejection.
Alternative
Make the failure mode obvious: detect at spawn time, throw a clear error pointing callers at useStdin: true. Less magic, but still better than a bare E2BIG.
Problem
spawn(...)passes the prompt as an argv element by default (useStdin: false). For agents whose spawn config declarespromptFlag(e.g.codex exec <prompt>), large prompts cause the kernel to reject the spawn withE2BIG("Argument list too long") before the agent starts.On Linux the per-arg limit is typically ~128KB; total argv+envp is ~2MB. We hit this in an automations workflow that passes a rendered PR diff + reviewer profile (~150KB) into codex via
spawn("codex", { prompt, ... }).Current workaround
Callers explicitly opt in:
spawn("codex", { prompt, useStdin: true }). This works becausecodexService.supportsStdinPrompt === trueandcodexSpawnConfig.stdinMode = { omitPrompt: true, extraArgs: ["-"] }are already wired through inpackages/agent-spawn/src/spawn.ts.Suggestion
Automatically switch to stdin when both:
spawnConfig.stdinModeis defined (i.e. the adapter supports it), andBuffer.byteLength(options.prompt, "utf8")exceeds a safe threshold (~64KB leaves headroom for env, mcp args, mode flags).Sketch:
```ts
const PROMPT_STDIN_FALLBACK_BYTES = 64 * 1024;
function resolveStdinMode(spawnConfig, options) {
if (!spawnConfig.stdinMode) return undefined;
if (options.useStdin) return spawnConfig.stdinMode;
if (Buffer.byteLength(options.prompt, "utf8") > PROMPT_STDIN_FALLBACK_BYTES) {
return spawnConfig.stdinMode;
}
return undefined;
}
```
Used in both
buildSpawnArgsandspawninpackages/agent-spawn/src/spawn.ts. Callers withoutuseStdin: truewould silently get the stdin path for large prompts instead of a kernel rejection.Alternative
Make the failure mode obvious: detect at spawn time, throw a clear error pointing callers at
useStdin: true. Less magic, but still better than a bareE2BIG.