Skip to content

fix: route oversized system prompt through a temp file#1104

Open
OneNobleSoul wants to merge 1 commit into
anthropics:mainfrom
OneNobleSoul:fix/large-system-prompt-arg-too-long
Open

fix: route oversized system prompt through a temp file#1104
OneNobleSoul wants to merge 1 commit into
anthropics:mainfrom
OneNobleSoul:fix/large-system-prompt-arg-too-long

Conversation

@OneNobleSoul

Copy link
Copy Markdown

Summary

A string system_prompt of 128 KiB or more crashes connect() with [Errno 7] Argument list too long before any API request is sent (#1096). The prompt is passed as a single --system-prompt argv entry, and Linux caps one argv entry at MAX_ARG_STRLEN (PAGE_SIZE * 32 = 128 KiB, NUL included), so exec() rejects it up front.

Fix

When a string system_prompt reaches the limit, write it to a temp file and pass it via --system-prompt-file — the same flag already used for {"type": "file"} prompts, so nothing changes on the CLI side. Smaller prompts still go inline. The temp file is tracked on the transport and removed in close() (also on a connect() that fails after the command is built), mirroring the existing temp-dir cleanup in session_resume.

Threshold is 64 KiB of UTF-8, comfortably under the 128 KiB hard cap.

Testing

  • New unit tests: an oversized prompt routes to --system-prompt-file with the file contents intact, a prompt just under the limit stays inline, and cleanup removes the file.
  • Full pytest suite, ruff check, ruff format --check and mypy all pass locally.

Fixes #1096

A string system_prompt of 128 KiB or more made connect() die with
"[Errno 7] Argument list too long" before any request went out: the
prompt was passed as a single --system-prompt argv entry and Linux caps
one entry at MAX_ARG_STRLEN (PAGE_SIZE * 32 = 128 KiB). Prompts that size
now get written to a temp file and passed via --system-prompt-file,
reusing the path that already exists for {"type": "file"} prompts. The
temp file is removed in close().

Fixes anthropics#1096
Copilot AI review requested due to automatic review settings July 10, 2026 08:31

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

system_prompt over 131,071 bytes dies with 'Argument list too long' before any API request

2 participants