Skip to content

fix(windows): avoid spawn ENAMETOOLONG via prompt tail truncation#14

Merged
anyrobert merged 5 commits intomainfrom
feature/windows-cmdline-limit
Mar 25, 2026
Merged

fix(windows): avoid spawn ENAMETOOLONG via prompt tail truncation#14
anyrobert merged 5 commits intomainfrom
feature/windows-cmdline-limit

Conversation

@anyrobert
Copy link
Owner

Summary

Windows CreateProcess caps the full command line at ~32,767 characters. Passing a huge chat prompt as the final argv could still fail with spawn ENAMETOOLONG even when using CURSOR_AGENT_NODE + CURSOR_AGENT_SCRIPT (those only avoid cmd.exe’s ~8K limit).

Changes

  • Refactor buildAgentFixedArgs so fixed flags are separate from the prompt.
  • Estimate a pessimistic Windows cmdline length (aligned with libuv-style argv sizing) and truncate the start of the prompt while keeping the tail, with a short omission prefix when over budget.
  • Config: CURSOR_BRIDGE_WIN_CMDLINE_MAX (default 30000, clamped 4096–32700).
  • Handlers: OpenAI chat completions and Anthropic messages call the fit step before spawn; 500 with a clear message if nothing fits; X-Cursor-Proxy-Prompt-Truncated: true when truncated; console.warn with lengths.
  • Docs and version 0.6.0.

Commits

  1. refactor: extract buildAgentFixedArgs for argv without prompt
  2. feat: add Windows CreateProcess cmdline budget and prompt fitting
  3. feat: apply Windows prompt fitting before agent spawn
  4. test: cover Windows cmdline limit, env clamp, and server config
  5. docs: document Windows cmd vs CreateProcess limits and truncation

Made with Cursor

Separates fixed CLI flags from the final prompt string so Windows can
measure and truncate the prompt argument independently.

Made-with: Cursor
Introduce win-cmdline-limit with pessimistic length estimation (libuv-style
doubling for quoted argv) and tail-preserving prompt truncation when over
budget. Load CURSOR_BRIDGE_WIN_CMDLINE_MAX (clamped 4096–32700, default 30000)
into LoadedEnv and BridgeConfig.

Made-with: Cursor
Run fitPromptToWinCmdline in chat and Anthropic handlers; return 500 with a
clear error when the line cannot fit. Pass optional headers for JSON and SSE
responses (X-Cursor-Proxy-Prompt-Truncated). Log startup cmdline budget.

Made-with: Cursor
Add vitest for estimateCmdlineLength and fitPromptToWinCmdline; assert
winCmdlineMax defaults and CURSOR_BRIDGE_WIN_CMDLINE_MAX clamping; extend
BridgeConfig test fixture with winCmdlineMax.

Made-with: Cursor
Clarify CURSOR_AGENT_NODE/SCRIPT vs ~32K cap; describe
CURSOR_BRIDGE_WIN_CMDLINE_MAX and proxy behavior. Bump version to 0.6.0.

Made-with: Cursor
@anyrobert anyrobert self-assigned this Mar 25, 2026
@anyrobert
Copy link
Owner Author

closes #13

@anyrobert anyrobert merged commit bde7a4a into main Mar 25, 2026
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