Skip to content

fix(webui): collapse long messages, code blocks and step outputs - #5566

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/collapse-long-content
Oct 23, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/collapse-long-content

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

A pasted 60,000-character log filled about 19 screens of the chat, a 300-line code block in an answer ran 7,500 px, and expanding a long "Ran command" step showed its raw truncation JSON (escaped \n, every path a link) at 2,500 px. None of them could be collapsed. Now each opens as a short preview that fades out, with a "Show all (700 lines)" / "Expand (300 lines)" toggle under it. Nothing is cut: the full text is one click away, and Copy, Copy code and Resend always use all of it.

At an 800 px window, measured in Chrome:

Before After
700-line pasted log 15,163 px 265 px
300-line code block 7,495 px 528 px
Long command output 3,292 px 484 px

Test plan

  • npx vitest run: 145 files, 1,538 tests pass, including the new LongContent.test.tsx
  • npx tsc --noEmit -p . and npm run build pass
  • tests/electron: npx jest --ci passes (38 suites)
  • Rendered both themes at 800 px in Chrome; each toggle opens with Enter from the keyboard and flips aria-expanded
  • Paste a 700-line log into the composer and send it: the bubble shows about 9 lines and "Show all (700 lines)"
  • Ask for a 300-line script: the block caps at 20 lines while it streams, and Copy copies all 300
  • Ask GAIA to run dir /s /b C:\Windows\System32\drivers and expand the step: plain paths, one per line, under "Showing the first N and last M characters of …"
🔍 Technical details
  • Thresholds (LongContent.tsx): a user message collapses past 15 lines or 1,500 characters and shows about 9 lines. A code block collapses past 25 lines and shows 20. A step result collapses past 25 lines or 2,500 characters and shows 20.
  • Streaming: a code block caps as soon as it reaches 20 lines, so it never grows past the cap and then shrinks. If it ends at 21 to 25 lines, it opens back up when the reply finishes.
  • Expand state: the react-markdown components map moved to module scope. Inline, it handed react-markdown new component functions on every render, which remounted each CodeBlock and reset its toggle on every streamed token.
  • Fade: it is a mask-image ramp, so it needs no per-theme or per-surface colour. On the code surface the toggle is a full-width footer drawn in the code palette. Everywhere else it is the same quiet pill as "N steps · M tools".
  • Truncation envelope (elide_text in tool_output.py): the result is read as JSON. If a display cap cut the JSON short, the head, tail and counts are read field by field instead. Paths inside an envelope or a long output are no longer linked. A short result still links its paths, as before.
  • Collapsing a long message from below it scrolls the bubble back into view, so the reader doesn't end up past it.
  • ChatView.tsx is untouched (101,751 bytes with LF line endings).
  • Known limit: user messages render as markdown, so a pasted log's single line breaks still run together into a paragraph. That predates this change and is out of scope.

A 60,000-character pasted log filled 19 screens, a 300-line code block ran 7,500 px, and a long command output showed its raw truncation JSON at 2,500 px. Each now opens as a short preview with a fade and a Show all / Expand toggle; the full text stays one click away and Copy and Resend use all of it.

- User messages over 15 lines or 1,500 characters show about 9 lines.
- Code blocks over 25 lines show 20; while streaming they cap at 20 so the block never grows and then shrinks.
- Step results that are a truncation envelope render the head and tail as plain text with a note on what was omitted; outputs over 25 lines or 2,500 characters are capped at 20 lines and no longer link every path.
- The markdown components are module-level so a re-render keeps each code block's expand state.
@github-actions github-actions Bot added the electron Electron app changes label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Long pasted messages, long code blocks and long tool outputs in the Agent UI now open as a short faded preview with an expand toggle, and Copy/Resend still use the full text. The logic is sound and well tested, including the code-block expand surviving streamed tokens (fixed by moving the markdown component map out of render). I found no correctness bugs that need fixing before merge.

  • Add before/after screenshots to the PR description. This is a visual Agent UI change. The height table is useful, but it doesn't replace the rendered preview, the fade, and the toggle in both themes.
  • Two small accuracy issues, both optional: the "scroll back into view" on Show less probably does nothing, and the note on a cut-short tool output can report a shown-character count that doesn't match the omitted count.

Real-world evidence

N/A: no evidence bundle was produced for this run, and the Agent UI render is deferred to the strix-halo lane. The PR reports vitest, tsc, build and Electron jest passing, plus Chrome height measurements at 800 px, but embeds no screenshots. This verdict rests on static review of the diff and the new tests.

🔍 Technical details

Issues

🟡 No rendered screenshot evidence for an Agent UI change. The rubric asks for a Playwright run against gaia chat --ui with before→after screenshots embedded as raw raw.githubusercontent.com images. The description has a pixel-height table and says both themes were rendered, but shows neither. The three unchecked test-plan items (700-line paste, streaming 300-line script, dir /s /b step) are exactly what a screenshot would prove.

🟢 scrollIntoView runs before the collapse (MessageBubble.tsx:318-324). It's called inside the state updater, so it measures the expanded body. A reader clicking "Show less" at the bottom of a 700-line message already has the body's bottom edge in view, so block: 'nearest' doesn't scroll. The page likely still behaves because ChatView.css:236 sets overflow-anchor: auto, which keeps the toggle pinned. Either drop the call and its comment, or scroll after the commit, e.g.:

    const toggleUserExpanded = useCallback(() => {
        setUserExpanded((was) => {
            // Collapsing from far down the page would leave the reader past the message.
            if (was) requestAnimationFrame(() => userBodyRef.current?.scrollIntoView?.({ block: 'nearest' }));
            return !was;
        });
    }, []);

(Side effects inside an updater also run twice under StrictMode. It's harmless here, but another reason to move the call out.)

🟢 Envelope note on cut-short JSON (LongContent.tsx:243-251). In the field-by-field path, head.length is the length of the fragment that survived the display cap, not the server's head. The note can then say "Showing the first 280 characters of 26,249 (17,548 omitted)", and those figures don't add up. Consider dropping the "first N … last M" counts when the JSON didn't parse, and keeping only of X (Y omitted).

🟢 Streaming threshold is message-wide. StreamingContext is set for the whole assistant message, so a 22-line block that finished earlier in a reply that is still streaming shows collapsed, then pops open when the reply ends. The PR documents this. It's only worth a follow-up if it looks jumpy in practice.

Strengths

  • Hoisting MARKDOWN_COMPONENTS to module scope fixes a real remount-per-token problem, and a test pins it (caps a streaming block … keeps an expand across tokens).
  • The tests check the user-facing contract: accessible names, aria-expanded/aria-controls, and full-text Copy/Resend. They don't just check class names.
  • The envelope parser matches the actual key order and shape of elide_text in src/gaia/agents/base/tool_output.py, and rejects non-envelope JSON. Fading with mask-image avoids per-theme colours.

The Show less scroll ran inside the state updater, before the body
shrank, so it never moved the page. It now runs after the collapse
commits. A step result whose JSON was cut short no longer reports
fragment lengths that don't add up to the omitted count.
@kovtcharov

kovtcharov commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Both optional fixes are in: Show less now really scrolls the message back into view, and a cut-short tool output no longer shows character counts that don't add up. Before/after screenshots are in the PR description, and a live Agent UI check is in this comment.

🔍 Technical details
  • Show less scroll: moved out of the setUserExpanded updater into an effect that runs after the collapse commits, gated by a ref so expanding never scrolls. New test asserts scrollIntoView fires once, after the body has is-collapsed. The old code fails it.
  • Cut-short envelope note: parseTruncationEnvelope now flags partial: true on the field-by-field path, and envelopeNote then reads "Showing part of the output of 26,249 (17,548 omitted)." The full-JSON path is unchanged.
  • Streaming threshold being message-wide: left as documented; worth a follow-up only if it looks jumpy in use.
  • Checks: tsc, vitest (145 files / 1539 tests), npm run build, tests/unit/chat (2162 passed), black/isort.
  • CI: the one red check is Linux unit test_stdio_hung_server.py::test_children_of_an_exited_server_are_still_stopped, an MCP child-process timing test this frontend-only PR doesn't touch. The same test failed on the unrelated kalin/setup-plan-real-server (run 39669693854). It needs a maintainer re-run.

@kovtcharov

kovtcharov commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Checked live in the Agent UI: the 60,221-character pasted log now shows as a short preview with Show all, and a 300-line code block in an answer is capped with Expand (300 lines).

Long paste collapsed

🔍 Technical details

Live build with this branch merged; same chats as the original finding. Pasted-log bubble: 16,833 px → 285 px, toggle "Show all (60,221 characters)". Code block: 7,467 px → 528 px, toggles "Copy" and "Expand (300 lines)". Dark theme.

kovtcharov-amd pushed a commit that referenced this pull request Oct 23, 2026
…5610)

Four timing-sensitive unit tests failed 8 unrelated PRs this week
(#5537, #5539, #5562, #5563, #5564, #5565, #5566, #5568) and one of
main's last 11 completed runs. Each still guards the same bug, but no
longer races the clock on a busy runner. Every rewritten test was
checked by breaking the code: it fails on the real bug and passes 50/50
runs, including under full CPU load. The PR also keeps three tests out
of the developer's real `~/.gaia`.

## Test plan
- [x] `pytest tests/unit/mcp/client/test_stdio_hung_server.py
tests/unit/test_file_lock.py tests/unit/test_mcp_bridge_concurrency.py
tests/unit/chat/ui/test_agent_model_override.py
tests/integration/test_folder_indexing.py -n 4`: 316 passed, 3 skipped
- [x] The four de-flaked tests, run 50x each: 250/250 serial, and
250/250 under xdist (32 workers) with all 32 cores also running busy
loops. Main's versions in that same loaded run: redaction failed 10/50.
- [x] Each test fails when its bug is put back in the code (see details)
- [x] `tests/integration/test_folder_indexing.py -n 4`, 5 runs: all
pass. Main's version fails 7 to 9 tests per run.
- [x] Test 841 passes with `GAIA_HOME` set to a temp dir. Main's version
fails.
- [x] Electron `npx jest`: 1098 passed. The one failure,
`test_electron_chat_installer.js` (component size 103,725 > 102,400),
also fails on main and is unrelated.
- [ ] CI green on Linux, macOS and Windows unit lanes

<details>
<summary>🔍 Technical details</summary>

**`test_redaction_stays_fast_on_dense_escapes`** (Linux, 2.01 to 2.03 s
against a 2 s limit)
- Cause: an absolute 2 s bound. Locally the worst text takes 0.19 s. On
a 4-worker, coverage-traced runner it took about 10x that.
- Fix: time one 1M-char text against eight 125K texts with the same
total length, on the same machine. Linear code scores about 1.0 and a
quadratic scan scores 8, so the test asserts < 3. It takes the best of
up to three paired runs, and uses the lower of the wall-clock and CPU
(`thread_time`) ratios. Contention inflates wall time, and Windows
samples CPU time on ticks. The test also fails if the 1M text takes more
than 15 s of CPU, which catches a per-position rescan: that is linear
but takes minutes.
- Break checks: a quadratic prefix copy in `_candidate_windows`
(`len(text[:start].rstrip("\\"))`) gives a ratio of 5.9x and the test
fails. Main's 2 s test passed that same regression locally (1.57 s). A
per-anchor rescan without merging takes 56 s and hits the 15 s ceiling.

**`test_children_of_an_exited_server_are_still_stopped`** (Linux)
- Cause: the test slept a fixed 2 s for the child watcher. The watcher
backs off (0.5, 1, 2, 4 s…), so on a slow start its next scan came after
the launcher had exited and the child was never recorded.
- Fix: poll until `child_pid in transport._children`, with a deadline of
3 × `_CHILD_SCAN_MAX_S`.
- Break checks: never recording children fails with "never recorded".
Clearing `_children` before stopping fails with "kept running". Delaying
the watcher's first scan by 2.5 s reproduces the CI failure on main's
test, and the new test passes.
- Note for the product side: a launcher that spawns a child and exits
inside a backoff window still orphans that child. Real `npx`/`uvx`
launchers outlive the window.

**`test_the_next_waiter_takes_the_lock_within_milliseconds`** (macOS,
median 6.5 to 8.1 ms against 5 ms)
- Cause: macOS stretches `sleep(0.001)` under load, and the 5 ms median
left no headroom.
- Fix: the test wraps `_poll_interval`, which records each interval and
signals the moment the waiter starts a poll's sleep. The lock is
released right then, so the whole interval stands between the waiter and
the lock.
- Assertions: every interval the front waiter asks for is ≤ 2 ms, and
the median hand-off is < 15 ms. A 20 ms poll always waits at least 20
ms, so it fails the median even with the bound widened.
- Break checks: `_NEXT_POLL_SECONDS = 0.02` or `0.1` fails the interval
assertion. Sleeping `_POLL_SECONDS` directly, so `_poll_interval` is
bypassed, fails the median (20.8 ms).

**`test_a_dropped_idle_connection_is_logged[True]`** (Linux)
- Cause: the test asserted that `"Traceback"` was absent from the stderr
captured by `capsys`. The traceback in that run came from a fake
Lemonade server that `test_lemonade_shared_server.py` left running on
the same xdist worker (`BrokenPipeError`).
- Fix: the `serve` fixture records the bridge server's own
`handle_error` calls, and the test asserts that list is empty.
socketserver calls `handle_error` before it closes the connection, so
the check doesn't race. A plugin that writes a traceback to stderr
during the test fails main's version and passes the new one.
- Break check: making `log_error` also call the base `log_error`, and
reverting `str(args[0])`, raises `TypeError` in the handler, and the
test fails.

**Isolation fixes**
- `test_folder_indexing.py`: `temp_folder` now lives in
`isolated_gaia_home`, a per-test fake home, so `ensure_within_home`
still admits it. Parallel workers no longer share or delete
`~/.gaia/test_temp`.
- `test_issue_841…`: the test now sets `GAIA_HOME` itself, so an
inherited value can't override the patched `Path.home`.
- `tests/electron/setup.js`: `os.homedir()` points at a per-file temp
dir. It is assigned rather than spied, so `jest.restoreAllMocks()` can't
undo it. Setting `HOME` would not work, because Jest's sandboxed
`process.env` never reaches `os.homedir()`.
- The "Ignoring invalid agents section in …\.gaia\tray-config.json" log
came from `crash-loop-notification.test.cjs`, which mocks `fs` with a
config the validator rejects. The real file was never read, but the path
now names the temp home.
</details>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 46f4eca Oct 23, 2026
29 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/collapse-long-content branch October 23, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

electron Electron app changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants