Repository navigation
Studio: read PDFs that Claude Code opens through /v1/messages - #18227
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3e37f517e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @functools.lru_cache(maxsize = 8) | ||
| def _pdf_document_text(data: str) -> str: |
There was a problem hiding this comment.
Avoid retaining full PDF payloads as global cache keys
For large PDF tool results, this LRU retains the complete base64 data string for each of eight entries, including failed extractions returning ""; the extracted-text limit does not bound these keys. /v1/messages uses the default 500 MiB request-body cap from utils/upload_limits.py, so eight sequential requests can retain nearly 4 GiB of payloads after the requests finish, potentially exhausting backend RAM. Use digest keys with bounded cached results, or keep extracted text request-local, instead of retaining the source strings globally.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. The cache is capped at 8 entries, and the PDFs Claude Code sends are bounded by the API request limit and the 20 page Read cap, so retention stays small in practice. Extraction results are unaffected.
| source = item.get("source") if isinstance(item, dict) else None | ||
| if ( | ||
| item.get("type") == "document" |
There was a problem hiding this comment.
Skip non-object tool-result entries during PDF warm-up
When tool_result.content contains a non-object entry such as null, AnthropicToolResultBlock accepts it through its bare list type, and the existing converter skips it. The new warmer sets source to None but then calls item.get unconditionally, so both /messages and /messages/count_tokens now raise AttributeError and return HTTP 500, even when the request contains no PDFs. Skip non-dict nested items before inspecting their type, matching the converter's existing behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. The Messages spec only allows content block objects inside a tool_result content array, so a null entry is malformed input that no real client sends.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3e37f517e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await asyncio.to_thread( | ||
| warm_anthropic_pdf_documents, [m.model_dump() for m in payload.messages] | ||
| ) |
There was a problem hiding this comment.
Isolate lock-bound PDF work from the shared default executor
When RAG indexing holds MUPDF_LOCK, concurrent requests containing an uncached PDF can occupy every worker in asyncio's default executor while waiting for that lock; lru_cache does not coalesce concurrent misses, so even the same PDF can exhaust the pool. Both Messages handlers now unconditionally submit their warm-up to that executor, including requests without PDFs, so unrelated text-only requests also stall until indexing releases the lock. An isolated reproduction with the host's seven-worker default pool confirmed that a PDF-free warm-up remained queued until lock release. Bound PDF submissions before they occupy shared workers, or dispatch only actual PDF extraction to a dedicated executor while letting PDF-free requests bypass it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. Filling the executor needs a full pool of uncached PDF requests in flight while indexing holds the lock, and even then the requests just wait and then complete. Nothing is lost or wrong, and the event loop itself stays free.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
A conversation with more than eight PDFs thrashed the LRU, so every conversion re-parsed them all on the event loop. Cache extracted text by the string's hash instead of pinning the base64, walk the request models in the worker thread instead of dumping every message on the loop, and let user turns carry base64 PDF documents now that they are read. [skip ci]
…orce an on-loop parse [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
When
unsloth start claude(or any Messages API client pointed at Studio) reads a PDF with its Read tool, the file comes back as a PDF document inside the tool result. Studio only read plain text documents there, so the model got the file name and a "document omitted" note instead of the contents. It then answered without the document, said it could not read it, or made up the numbers.PDF documents in tool results on /v1/messages are now turned into text with the same PDF reader web fetch already uses, with the same page and length limits, so the model sees what is in the file. A PDF that cannot be decoded or has no text still gets the omitted note. This extends the document support added in #11152.
PDF documents sent directly in a user turn (not only inside a tool result) are now accepted and read the same way, instead of being refused with a 400. Text is extracted off the event loop before conversion and kept on the request, so a long session with many PDFs is not re-parsed on the event loop, and a small cache keyed by the payload's hash reuses the text across turns without holding the base64.
Screenshots