Repository navigation
Fix read tool context overflow on notebooks containing images - #65
Merged
Merged
Conversation
Reading a .ipynb dumped the raw JSON into context, and embedded matplotlib figures are ~380 KB of base64 each — one user's notebook produced a 1.4 MB tool result and the provider rejected the request with "Range of input length should be [1, 1006592]". Since each payload sits on a single JSON line, paging with from/to couldn't dodge it either. `read` now renders notebooks with every image/* (and application/pdf) payload replaced by a size-recording placeholder, and any remaining output over 4,000 chars truncated, so a giant text/plain dump can't reproduce the same failure. Cell sources, stream text and execution counts are untouched. Invalid JSON falls back to cutting over-long lines at 2,000 chars. from/to index the rendered text, keeping line numbers stable across reads. The offending file goes from 1,458,837 chars to 6,485. 11 new tests; workspace fmt, clippy -D warnings, cargo doc and 631 tests pass.
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.
Reading a .ipynb dumped the raw JSON into context, and embedded matplotlib figures are ~380 KB of base64 each — one user's notebook produced a 1.4 MB tool result and the provider rejected the request with "Range of input length should be [1, 1006592]". Since each payload sits on a single JSON line, paging with from/to couldn't dodge it either.
readnow renders notebooks with every image/* (and application/pdf) payload replaced by a size-recording placeholder, and any remaining output over 4,000 chars truncated, so a giant text/plain dump can't reproduce the same failure. Cell sources, stream text and execution counts are untouched. Invalid JSON falls back to cutting over-long lines at 2,000 chars.from/to index the rendered text, keeping line numbers stable across reads. The offending file goes from 1,458,837 chars to 6,485.
11 new tests; workspace fmt, clippy -D warnings, cargo doc and 631 tests pass.