You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto-fallback to stdin when prompt exceeds ARG_MAX #306
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).
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.
The change automatically switches large prompts (>64 KiB UTF-8) to stdin for CLI agents that declare stdinMode, and applies the same decision in both buildSpawnArgs and spawn.
Validation passed: targeted agent-spawn tests, typecheck, agent-spawn build, eslint, and the full pre-push npm test run.
Activity
poe-code-agent commentedon May 13, 2026
Implemented this in PR #307.
The change automatically switches large prompts (>64 KiB UTF-8) to stdin for CLI agents that declare
stdinMode, and applies the same decision in bothbuildSpawnArgsandspawn.Validation passed: targeted agent-spawn tests, typecheck, agent-spawn build, eslint, and the full pre-push
npm testrun.