fix(agents): guard Windows CLI argv against ENAMETOOLONG by moving system prompt to stdin#69211
Conversation
Greptile SummaryThis PR adds a Windows command-line length guard to the CLI runner that detects when a long system prompt would push Confidence Score: 5/5Safe to merge; fixes a 100% Windows crash with correct scoping and good test coverage. The one comment is a minor observability improvement, not a blocker. All findings are P2 (style/observability). The core logic is correct, edge cases are handled, and the integration point is well-placed. No data loss, security, or correctness issues were found. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/cli-runner/helpers.ts
Line: 497-498
Comment:
**Silent no-op when argv is still too long after stripping**
If `stripped` is `null` (the system prompt flag isn't present, or it's the last token with no value), the guard returns `null` and the spawn will still hit `ENAMETOOLONG` on Windows. That failure path already existed, but now it's harder to distinguish from "guard didn't trigger" vs "guard tried and couldn't help." A debug/warn log before returning `null` here would make diagnosing lingering issues much easier.
(Consider adding a `cliBackendLog.warn(...)` before the `return null` noting that the argv limit is exceeded but the system prompt flag couldn't be found.)
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(agents): guard Windows CLI argv agai..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18a07cd4f4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Just confirmed a clean repro of the underlying issue on OpenClaw 2026.4.22 and posted details on #69158. Summary here in case it's useful to you:
On the approach in this PR The trade-off you flagged (system prompt becomes a stdin prefix rather than a dedicated Claude Code CLI's Maybe also worth considering (not a blocker): Related filings
Thanks for the clean guard + test coverage. Happy to be a Windows test target once this lands. |
18a07cd to
183078d
Compare
183078d to
3345b1b
Compare
3345b1b to
55213b5
Compare
obviyus
left a comment
There was a problem hiding this comment.
Verified the Windows argv failure path: a 40k system prompt passed as argv reproduces spawn ENAMETOOLONG, while Claude's prompt-file flag starts cleanly and preserves stdin.
Maintainer follow-up: rebased, replaced the stdin-prefix workaround with --append-system-prompt-file, updated tests/config docs/changelog, and confirmed prior review threads are resolved/outdated.
Local gate: pnpm test src/agents/cli-runner.helpers.test.ts src/agents/cli-runner.spawn.test.ts src/agents/cli-backends.test.ts, pnpm config:docs:check, pnpm config:schema:check, plus Windows spawn smoke.
|
Landed on main. Thanks @skylee-01. |
Summary
--append-system-promptas a CLI argument. WindowsCreateProcessWhas a ~32,767-char command-line limit, causingspawn ENAMETOOLONGon every message.null). Backends that usesystemPromptFileConfigKey(e.g., Codex) are unaffected. Short command lines on Windows are unaffected.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
systemPromptArg: "--append-system-prompt"to pass the full system prompt as a CLI argument. On Windows, Node.jsspawn(withoutshell: true) still assembles all argv entries into a single command-line string forCreateProcessW, which has a ~32,767-char limit. System prompts routinely exceed 10K chars, pushing the total well past the limit.systemPromptFileConfigKeymechanism (used by Codex) would avoid this, but claude-cli doesn't use it.UV_ENAMETOOLONGfrom libuv, which Node.js surfaces asspawn ENAMETOOLONG. This affects all Windows users using claude-cli as a provider backend.Regression Test Plan (if applicable)
src/agents/cli-runner.helpers.test.tsplatform: "win32") and the assembled argv exceeds 30,000 chars (the safe threshold), the system prompt is stripped from args and prepended to stdin.platformparameter, testable without spawning real processes or requiring a Windows environment.User-visible / Behavior Changes
Windows users using the claude-cli provider will no longer see
spawn ENAMETOOLONGerrors. The system prompt is moved from a dedicated CLI flag to the stdin payload as a prefix, which is a semantic compromise (the model sees it as part of the user message rather than a system prompt) but is strictly better than a 100% crash rate.Diagram (if applicable)
Security Impact (required)
Repro + Verification
Environment
systemPromptArg: "--append-system-prompt"and system prompt > ~10K charsSteps
--append-system-prompt <full system prompt>into argvCreateProcessWrejects the command line exceeding 32,767 charsExpected
Actual
spawn ENAMETOOLONGerror on every message attemptEvidence
Attach at least one:
All 29 tests in
src/agents/cli-runner.helpers.test.tspass, including 11 new tests:estimateArgvByteLength: accounts for quoting overhead (2 tests)stripSystemPromptFromArgv: removes flag+value, returns null for absent/undefined/trailing flag (4 tests)applyWindowsArgvGuard: returns null on non-Windows/short-args/missing-flag, moves system prompt to stdin on Windows with long args, handles empty stdin (5 tests)Human Verification (required)
platformparameter simulating Windows and non-Windows. Verified integration point inexecute.tswhere the guard is applied betweenbuildCliArgsandsupervisor.spawn.platformparameter.Review Conversations
Compatibility / Migration
Risks and Mitigations
systemPromptFileConfigKey(the file-based approach used by Codex).