fix: route oversized system prompt through a temp file#1104
Open
OneNobleSoul wants to merge 1 commit into
Open
fix: route oversized system prompt through a temp file#1104OneNobleSoul wants to merge 1 commit into
OneNobleSoul wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A string
system_promptof 128 KiB or more crashesconnect()with[Errno 7] Argument list too longbefore any API request is sent (#1096). The prompt is passed as a single--system-promptargv entry, and Linux caps one argv entry atMAX_ARG_STRLEN(PAGE_SIZE * 32= 128 KiB, NUL included), soexec()rejects it up front.Fix
When a string
system_promptreaches 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 inclose()(also on aconnect()that fails after the command is built), mirroring the existing temp-dir cleanup insession_resume.Threshold is 64 KiB of UTF-8, comfortably under the 128 KiB hard cap.
Testing
--system-prompt-filewith the file contents intact, a prompt just under the limit stays inline, and cleanup removes the file.pytestsuite,ruff check,ruff format --checkandmypyall pass locally.Fixes #1096