Repository navigation
fix(rag): summarize each section on its own, and stop when abandoned - #4648
Conversation
summarize_document sent every section through the RAG chat SDK, which keeps conversation history, so section N carried sections 1..N-1 with it. On a 1,666-page PDF the third request was 79,102 tokens against a 65,536-token context and all 42 later sections failed; the abandoned tool then kept the model busy for minutes after the eval's stream had timed out. Section, single-pass and synthesis prompts are now sent with no_history, and the section loop checks for cancellation so an abandoned summary stops.
|
Verdict: Approve with suggestions Long-document summaries no longer fail partway through. Each section, and the final synthesis, is now sent to the model without the earlier conversation. Before, every request carried all the previous sections and blew past the context window from section 3 onward. A summary the agent has already given up on now stops at the next section instead of keeping the shared model busy. The fix is small, matches the root cause in the CI logs, and comes with tests that fail on main. Nothing blocks merge. One small cleanup is optional: a cancelled summary currently shows up as a generic "summary failed" error, not as a cancellation. Real-world evidenceN/A: the evidence stage produced no bundle for this PR. The change is inside a single agent tool and has no CLI, REST or UI surface of its own. The PR description quotes the failing CI run (79,102-token request against a 65,536-token context, then 42 failed sections and a 600 s timeout). The re-score of 🔍 Technical detailsIssues found 🟢 Cancellation is reported as a generic tool error ( (This also needs Strengths
|
File tools now all check the same allowed-folders rule. Before, `read_file` and `write_file` checked a path against the session's allowed folders (asking the user when it was outside), but several neighbouring tools did not: folder browsing and directory search, recent files, document and code indexing, folder watching, `list_files`, and the paths screenshots, transcripts, speech and exports are saved to. Now every one goes through the same check and the same approval prompt, so a chat scoped to its documents behaves the same whichever tool the model picks. - **One rule, not a second one.** Tools call the existing `PathValidator.validate_read` / `validate_write` through a thin helper. The validator now expands `~` before resolving symlinks and `..`, so it judges the path the tool actually opens. - **Approving a folder now covers document indexing too.** The chat agent's RAG SDK kept a separate validator, so a folder approved in the chat was still refused at indexing time. It now shares the agent's. - **Wider on purpose, and documented:** name search over the common document folders (it returns paths only, and opening one is checked), GAIA's own output folders, and `capture_skill`, which asks the user on every call. <details> <summary>🔍 Technical details</summary> - Helper: `gaia.agents.tools.path_access` (`read_access_error`, `write_access_error`, `readable_entry`). Folder walks call `readable_entry` per file, which never prompts. - Model-visible changes: refusal text from these tools is now the validator's standard message, `list_recent_files` reports `locations_not_searched`, and `search_directory` with no root searches the allowed folders instead of the whole home folder. No tool docstrings changed. - Overlap with amd#4642: both PRs add the same `~` expansion to `browse_directory`, `get_file_info`, `analyze_data_file` and `search_file_content`, with identical lines, so either merge order applies cleanly. Merging amd#4642 first is the simplest order. - Nearby open PRs: amd#4613 and amd#4648 (`rag_tools.py`), amd#4644 (`code_index_tools.py`), amd#4626 (`filesystem_tools.py`), and amd#4647 (flagship CHANGELOG). Their hunks don't overlap these, but whichever lands second may need a trivial rebase. </details> ## Test plan - [x] `pytest tests/unit/test_file_tools_allowed_folders.py hub/agents/chat/python/tests/test_chat_file_tools_allowed_folders.py`: 66 tests. For each tool, a path outside the allowed folders (direct, through `..`, and through a symlink) goes through the approval prompt and is refused, and a path inside still works. 41 of them fail on main. The ChatAgent tests live in the chat package, so the chat-agent lane runs them; the core unit lane has no `gaia_agent_chat`. - [x] Existing file, RAG, audio, screenshot, code-index, security and chat-agent unit tests pass. The two local failures (`test_persisted_grants_are_not_unioned_into_a_host_scope`, `test_backups_directory_is_owner_only`) also fail on main on this machine. - [x] black, isort, flake8 and pylint are clean on the changed files. - [ ] Follow-up after the core release that ships `path_access`: raise the chat and flagship `amd-gaia` floors to it, as the chat CHANGELOG records. - [ ] CI eval re-run, since refusal text and the default search scope are model-visible: `gaia_files`, `gaia_core`, `gaia_data`, `tool_selection`. --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Summarizing a long document failed partway through, and the failed job kept the model busy after the user's request had already timed out.
summarize_documentsent each section through the RAG chat SDK, which keeps conversation history, so section N carried every earlier section with it. Each section, the single-pass prompt and the final synthesis are now sent without history, and an abandoned summary stops at the next section.Evidence from run 37110051697 (tools lane,
safety_handbook_water, TIMEOUT at 916 s):Document has 854658 words, 1666 pages, grouped into 44 sections. Sections 1–2 summarized, thenFailed to summarize segment 3: … request (79102 tokens) exceeds the available context size (65536 tokens), and the same for segments 4–44 (42 failures). Each section is about 20k words, so the 79k-token request is the history.Streaming response timed out after 600scame first, followed byProducer thread still running after stream ended. The abandoned summary kept sending ~75k-token requests to the shared model while the next scenario ran.🔍 Technical details
AgentSDK.send(message, no_history=True)already exists. It sends only this prompt and leaves the stored history alone. All threeself.rag.chat.sendcalls insummarize_documentnow pass it. The history was also leaking whole document sections intorag.chatfor any later caller.raise_if_cancelled()before each section, outside the per-sectionexcept Exception. This is the fix(agents): abandoned tool-timeout threads leak log records and state into unrelated code #2600 mechanism.summarize_documentto answer a single question about a 1,666-page handbook. That is a tool-selection problem (model limit) and is out of scope.skill_summarize_styles(same lane) produced generic summaries with none of the document's figures. Leaked history inrag.chatmay have contributed; worth checking on the re-run.Test plan
pytest tests/unit/test_summarize_document_sections.py tests/unit/test_agent_tool_timeout.py tests/unit/agents/test_parse_error_recovery.py. The three new tests fail on main.rag_quality,tool_selectionandgaia_rag, and confirm noexceeds the available context sizefromsummarize_documentin the backend logs.