Repository navigation
fix(ui): never stream the agent's JSON envelope into the chat - #5121
Conversation
A reply that called a tool with a long argument (a write_file carrying a
whole file) reached the TUI as a raw {"thought": ...} line above the tool
rows. The stream filter flushed any tool-call JSON past 2 KB as text, and
a plan envelope whose head the cleanup regex ate leaked its tail.
The handler now recognises the response envelope at the head of the
stream (optionally fenced), holds it until its closing brace with a
string-aware, resumable scan, and drops it; an "answer" field is still
emitted as the answer. Ordinary JSON answers and text that merely starts
with "{" are untouched.
|
Verdict: Approve with suggestions Long tool calls (a file write that carries the whole file) no longer show up as raw One gap is left, and it's worth a quick follow-up but doesn't block merge. If the model writes a long tool call that isn't strictly valid JSON (a The flagship eval is deferred to the combined run on main, as the description says. That run needs to happen, since this changes what streams to the screen. Real-world evidenceOn the real The adjacent cancel, confirm-tool, session-messages, and permissions routes all returned HTTP 200 with the expected results, and no saved message contained 🔍 Technical details🟡 A malformed long envelope still leaks raw (
The suggestion needs a module-level 🟢 A truncated real JSON answer is dropped silently ( At end of stream, any unclosed object whose first key is in 🟢 Unexplained In the plain-JSON run, the Strengths
|
# Conflicts: # src/gaia/ui/sse_handler.py
The envelope filter held every leading JSON object until its closing brace, so an answer-first reply no longer streamed token by token as the answer decoder on main does. Answer-first envelopes now go to that path; every other envelope is still held and filtered.
Main's lint fails black on `sse_handler.py` since #5121: a module-level regex sits one blank line above the class. This adds the second blank line. ## Test plan - [ ] `python -m black --check src/gaia/ui/sse_handler.py` passes
…5131) When a hosted model wrote its tool calls as text (DeepSeek's DSML markup), every call streamed into the answer area while it was being written: up to 50 times in one turn, with long Python mangled by Markdown into headings. Long calls in GAIA's own JSON format either leaked the same way or sat behind a bare "Reading the tool results · 90s" timer. Now the call is held back and dropped, and the activity line says what is being written and how big it is ("Writing Python code — 4,210 characters so far"), never its content. Markup quoted in a code block, or a tag named in prose, still shows. Stacked on #5121 (the JSON-envelope half of this filter); pairs with #5103, which makes the agent run DSML calls instead of answering with them. This changes what the LLM's output looks like to the user, not what the LLM sees; the flagship eval that runs on main covers it. ## Test plan - [x] `python -m pytest tests/unit/chat/ui/test_sse_tool_call_text.py tests/unit/chat/ui/test_sse_handler.py tests/unit/test_model_phase_progress.py tests/unit/test_tool_call_progress.py` - [x] Replayed the SSE streams captured from the affected Agent UI runs through the new filter: no DSML, tool JSON or code reaches a `chunk` event, and every final answer still streams - [x] Drove the Agent UI with a scripted DSML `run_python` reply: before, the code scrolled past as headings; after, only the narration line and "Writing Python code — N characters so far" show - [x] `python util/lint.py --black --isort`
Main is red on three jobs and rc15 is blocked on it. Answers the model
wraps in `{"thought": ..., "answer": ...}` stopped streaming after #5121
held every envelope until it closed, so the chat sat blank through a
long answer and Stop kept nothing; they now stream from the first token
again while thoughts and tool calls stay hidden. The Chat Agent job
failed because the frozen `run_python` adversarial tests still
intercepted `subprocess.run` after #5104 moved Python jobs to `Popen`.
Code Quality failed on two pylint findings in the Agent UI MCP control
server; the unused `host` is now checked, so loopback-only transport
settings refuse a network address instead of silently applying.
## Test plan
- [x] `python -m pytest tests/unit/test_json_answer_decoding.py
tests/unit/chat/ui/test_sse_handler.py
tests/unit/chat/ui/test_sse_tool_call_text.py
tests/unit/test_model_phase_progress.py
tests/unit/test_tool_call_progress.py` (397 passed; the 5 streaming
cases fail on main)
- [x] Every test file touching `sse_handler`, JSON answers, or
`agent_ui_control` (2180 passed)
- [x] `tests/unit/test_run_python_frozen_adversarial.py
tests/unit/test_run_python_frozen.py` (103 passed; 19 fail on main)
- [x] `python util/lint.py --black --isort --pylint`
- [ ] CI: Unit Tests, Chat Agent Tests, Code Quality
- [ ] Flagship eval: this changes what streams to the chat; covered by
the combined run on main
When a hosted model answered with a tool call carrying a long argument, such as a file write with the whole file in it, the chat showed a raw
{"thought": …}line above the tool rows. The stream filter gave up on tool-call JSON past 2 KB and printed it as text, and a reply with a plan could leak its tail. Now the agent's response JSON is held until it closes and then dropped, however long it is and however it is split or fenced. Ananswerinside it still shows, and ordinary answers that are or contain JSON are left alone. This changes what streams from the model to the screen, so it needs the flagship eval. The combined eval on main will cover it.Test plan
python -m pytest tests/unit/chat/ui/test_sse_handler.py tests/unit/messaging/test_slack_event_contract.py tests/unit/test_model_phase_progress.pypasses. Fourteen of the new cases fail onmain.{line that is not JSON, and real JSON answers, which must still show.cd tui && go test ./internal/ui/chat/passes.