Repository navigation
Studio: keep what you typed with a document when a long chat is compacted - #12238
Conversation
NilayYadav
left a comment
There was a problem hiding this comment.
Review + reproduction evidence
Pinned review: ec868659e2a4bae1493f0981407b49dd71194909. No blocking findings.
I reproduced the flow by hand on fresh upstream main (ca5e2fd) and on this branch. Setup: Studio installed with install.sh --local on a Modal L4, unsloth/Qwen3-4B-Instruct-2507-GGUF Q4_K_M at context 8192, Chromium. The user steps: attach a 24-clause supply contract PDF, type "Review this contract as the buyer's lawyer and answer every question in Spanish.", then ask one long English follow-up. Studio shows the compaction notice on turn 2 on both sides. After that I asked "Which language and which role did I ask you to use for your answers?" and "What is the notice period for termination?".
- main: "You asked me to provide answers in English, and you have not specified a role for me to adopt." The follow-up came back in English. The typed instruction was dropped together with the document.
- PR head: "You asked me to review the contract as the buyer's lawyer and to answer every question in Spanish." The follow-up came back in Spanish, as the buyer's lawyer.
- Adjacent flow, the same instruction typed without an attachment: compaction on turn 6 on both sides. Both sides still answered "You initially asked me to answer in Spanish and to act as the buyer's lawyer", so nothing changed for chats without attachments.
- Tests, merge base with the new test file vs this head: 10 of the new cases fail on main and pass here, 156 are unchanged, and 0 fail on head. On a 5 MB document turn the fit is faster (132 ms vs 275 ms), because only the typed words are tokenised now. A 5 MB turn without an attachment costs about 23 ms more for the scan.
- Two red upstream jobs (
Repo tests (CPU, studio),workflow-trigger lint) fail onlytest_every_playwright_driver_is_invoked_by_cionplaywright_user_message_time.py. #12173 added that file on main, so the failure is not caused by this diff.
Known limit, as the description says: a line the user types that looks exactly like a composer header (for example [PDF: title] on its own line) is treated as one, and the rest of that turn is left out of the carried block. The composer sends typed words and attachment text as one string, so the backend cannot tell them apart. That would need the attachment text sent as its own content part, which is a separate change.
Conclusion: the issue is real and this branch fixes it. The two red CI jobs come from main; the other upstream jobs are still pending.

When you attach a PDF, Word or Excel file, a text file or a long paste and type an instruction with it, like "review this as the buyer's lawyer and answer in Spanish", that instruction was lost once the chat grew long and was compacted. The typed words and the document text were judged as one message, and any real document is too big for the note of earlier instructions that Studio keeps, so the instruction went with it. Asked afterwards, the model said it should answer in English.
Now only the words you typed are kept in that note and the document text is left out, the same way an instruction typed with an image already survives. Text you type yourself in brackets or tags stays as it is. What is kept ends at the first header Studio puts in front of an attached file, so if you type a line that looks exactly like one, such as
[PDF: name]on its own line, that line and what follows it are left out too. That is rare.