fix: name max_buffer_size in the buffer-overflow error message - #1222
Open
CryptoKylan wants to merge 1 commit into
Open
fix: name max_buffer_size in the buffer-overflow error message#1222CryptoKylan wants to merge 1 commit into
CryptoKylan wants to merge 1 commit into
Conversation
When a CLI stdout message exceeds `max_buffer_size` the reader raises fatally and the session ends, but the error never mentions the option that fixes it. Users land on "modify the installed package" (as anthropics#416 described) instead of a one-line options change. Requested by @tmaxwell-anthropic on anthropics#98. anthropics#416 carried this alongside a default increase and was withdrawn, so the uncontroversial half was never landed. This PR does not change the default. Appending the guidance to the guard's message does not work: CLIJSONDecodeError truncates its `line` argument to 100 chars, so anything folded into it is cut off. Instead `hint` is an optional keyword appended after the truncated line, where it always survives. It is opt-in, so every existing call site and message is byte-identical.
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.
When a CLI stdout message exceeds
max_buffer_size, the reader raises fatally and the session ends — but the error never mentions the option that fixes it. Users reasonably conclude they have to patch the installed package (as #416 described) rather than pass one option.Requested by @tmaxwell-anthropic on #98:
#416 carried this change alongside a default increase and was withdrawn, so the uncontroversial half was never landed. This PR does not change the default.
Why this touches
_errors.pySimply appending the guidance to the guard's message does not work.
CLIJSONDecodeErrortruncates itslineargument to 100 characters:That argument is meant to hold the offending JSON line; the buffer guard passes a human-readable message instead. Anything appended there is cut off mid-sentence:
So
hintis an optional keyword appended after the truncated line, where it always survives. It defaults toNone, so every existing call site and rendered message is byte-identical — this is strictly additive.Before / after
Before:
After:
On the default
The same comment on #98 also asked:
Two reasons for caution, offered as input rather than as part of this PR:
len()over astr, i.e. code points rather than bytes (max_buffer_size and import byte limits count characters instead of UTF-8 bytes #1165), so a raised limit can cost up to ~4x its nominal value for multibyte content.Happy to follow up with a separate PR if you would like the default raised.
Testing
python -m pytest tests/— 1410 passed, 5 skippedpython -m ruff check src/ tests/ scripts/— cleanpython -m ruff format --check src/ tests/ scripts/— cleanpython -m mypy src/ scripts/— no issues in 31 source filesAdded coverage: the hint survives
linetruncation,hintdefaults toNone, and the buffer-overflow error namesmax_buffer_size.