Skip to content

Fix read tool context overflow on notebooks containing images - #65

Merged
PTFOPlayer merged 1 commit into
masterfrom
feat/ipynb-notebook-reads
Oct 19, 2026
Merged

PTFOPlayer merged 1 commit into
masterfrom
feat/ipynb-notebook-reads

Conversation

@PTFOPlayer

Copy link
Copy Markdown
Owner

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.

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.
@PTFOPlayer
PTFOPlayer merged commit a49a001 into master Oct 19, 2026
11 checks passed
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