Skip to content

fix(ui): show an approved edit's diff in the Agent UI and the TUI - #6325

Merged
kovtcharov-amd merged 5 commits into
mainfrom
fix/3710-approved-edit-diff-card
Nov 2, 2026
Merged

kovtcharov-amd merged 5 commits into
mainfrom
fix/3710-approved-edit-diff-card

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Approving a file edit in the Agent UI or the TUI changed the file but never showed what changed — the CLI drew a diff, these two drew nothing. Now the edit's tool row carries a diff card in both: the Agent UI's existing DiffCard draws it, and the TUI gains a plain-text diff card instead of the "Unsupported card" fallback. The #3702 contract holds: a handler that can't draw a diff still reports the edit as a success.

The card rides the edit's own tool_result (one result per call, so it lands under the right row and is saved with the step; redrawing saved cards on reload is still #2109). Diffs over 400 lines are cut with a "Showing the first 400 of N" note so a huge edit can't bloat the stream or the saved message.

Fixes #3710

Test plan

  • python -m pytest tests/unit/chat/ui/test_edit_diff_card.py -q — 13 passed: the real edit_file tool + real handler + real translator emit render: "diff" with a schema-valid payload; no card on a no-op edit; a card never leaks to the next call (including a call whose result was skipped); a render-map card still wins; cap boundary at exactly N and N+1 lines; empty / non-string render on an event is ignored
  • python -m pytest tests/unit/chat/ui/ tests/unit/agents/test_write_display_contract.py tests/unit/agents/test_no_arg_tool_start.py hub/agents/email/python/tests/test_render_tool_to_lang_sync_2765.py tests/unit/test_email_sidecar_relay.py -q — 2966 passed, 14 skipped
  • go test ./... in tui/ — passes (new diff_test.go: hunk drawn, badge/note, missing/wrong-type unified is invalid, CRLF and ANSI escapes can't shear the card, long diff bounded with a count, narrow terminal)
  • python util/lint.py --black --isort, gofmt -l, go vet clean
  • Manual: ask GAIA to edit a file in the Agent UI, approve, see the diff card under the edit row; same in gaia-tui

Approving an edit_file changed the file but showed nothing of what
changed: the Agent-UI/TUI handler's print_diff was a no-op. It now attaches
a `diff` card ({title, unified}) to the edit's own tool_result, the canonical
translator forwards an event-level render key ahead of the tool map, and the
TUI draws the `diff` card instead of the unsupported fallback. Diffs over 400
lines are cut with a note so a huge edit cannot bloat the stream or the
persisted chat. A handler that draws nothing still returns success.

Fixes #3710
@github-actions github-actions Bot added tests Test changes tui Go terminal UI (gaia-tui) labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

An approved file edit now shows its diff in the Agent UI and the TUI, where before both showed nothing. The card attaches to the edit's own result, can't spill onto the next tool call, and huge diffs are capped. The wiring is sound and well tested.

There is one thing to fix before users see this. Every changed line in the card comes out double-spaced: a blank line follows each - and + line, as the evidence below shows. The cause is older than this PR. The edit tool builds its diff with line endings kept and then joins the lines with another newline. But this PR is the first time that output reaches the chat UIs, so it's now the feature's first impression. The same bug roughly doubles the "Showing the first 400 of N" count. It's a one-line fix in the edit tool, and it also cleans up the CLI's diff panel.

Real-world evidence

The evidence stage ran the real edit_file tool, the Agent UI's stream handler and translator, and the real TUI card code. The Agent UI screenshot is pending the strix-halo lane because this runner has no inference.

The stream event an edit now produces:

{ "type": "tool_result", "tool": "edit_file", "render": "diff",
  "data": { "title": "config.py",
            "unified": "--- a/config.py\n+++ b/config.py\n@@ -1,2 +1,2 @@\n-debug = False\n\n+debug = True\n\n port = 4200\n" } }

The read_file results on either side of it carry no render, so the card doesn't leak. The TUI draws that payload as:

┌─ config.py ──────────────────────────────────────────────────────────────────┐
│   --- a/config.py                                                            │
│   +++ b/config.py                                                            │
│   @@ -1,2 +1,2 @@                                                            │
│   -debug = False                                                             │
│                                                                              │
│   +debug = True                                                              │
│                                                                              │
│    port = 4200                                                               │
└──────────────────────────────────────────────────────────────────────────────┘

A payload missing unified gets the "Invalid diff payload: unified is required" card instead of blanking. The spot regression passed: /api/health, session create/list, and /api/chat/send streaming without a model all returned 200, and render-map cards like pre_scan_inbox → email_pre_scan still resolve.

🔍 Technical details

🟡 Important

🟡 Diff card shows every changed line followed by a blank line (src/gaia/agents/tools/file_io_tools.py:1372-1378)
difflib.unified_diff runs over splitlines(keepends=True) with lineterm="", and the output is then "\n".joined. Each content line keeps its own \n and gains another, but the ---/+++/@@ headers don't, which is why only the body is double-spaced. Since this PR makes the diff a first-class UI card, fix it here. Otherwise _DIFF_CARD_MAX_LINES and the note's "of N diff lines" count both blank lines (≈2×), and the TUI's maxCardRows budget shows half as many real lines. Drop keepends so every line is terminated exactly once:

diff = "\n".join(
    difflib.unified_diff(
        current_content.splitlines(),
        updated_content.splitlines(),
        fromfile=f"a/{os.path.basename(str(path))}",
        tofile=f"b/{os.path.basename(str(path))}",
        lineterm="",
    )
)

Add an assertion to test_edit_result_carries_a_diff_card, e.g. assert "\n\n" not in card["data"]["unified"], so the regression is caught. This loses "\ No newline at end of file" fidelity, which the card doesn't show today anyway.

🟢 Minor

🟢 TUI truncation line looks like an added line (tui/internal/ui/cards/primitives.go:496)
Inside a diff, +12 more lines (truncated) reads as a + hunk line. Use a prefix that can't be mistaken for diff content:

		b.add("  … " + itoa(n) + " more lines (truncated)")

Update the assertContains in TestDiffLongBodyIsBoundedAndCounted to match.

🟢 The 400-line cap doesn't bound size (src/gaia/ui/sse_handler.py:1011-1017)
Editing one line of a minified bundle can produce a single diff line of several MB. That goes over SSE and gets persisted with the message, which defeats the stated goal that "a huge edit can't bloat the stream." Consider a character cap alongside the line cap, as _MCP_OUTPUT_CHAR_CAP already does for MCP output.

Strengths

  • Clearing _pending_diff_card both in print_tool_usage and after each result closes off cross-call leaks. The tests cover the hard case: a call whose result was skipped.
  • The tests drive the real edit_file, handler and translator rather than stubs, and check the payload against the DiffCard schema. That's the boundary-validity check CLAUDE.md asks for.
  • The TUI renderer handles CR and ANSI escapes, narrow widths and invalid payloads, and replaces the obsolete fallback test instead of leaving it to contradict the new behavior.

Every changed line in the new diff card was followed by a blank line: the
edit tool kept each line's ending and then joined lines with another
newline. Each line is now terminated once (a line-ending-only edit still
diffs), which also halves the line count the 400-line cap and the TUI's
row budget were charging. One huge line, such as an edit to a minified
file, is now capped at 64,000 characters, and the TUI's truncation line no
longer starts with "+" where it reads as an added line.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

I pushed fixes for the review's three points: the diff card is single-spaced now, one huge line can no longer bloat the stream, and the TUI's truncation line doesn't read as an added line.

🔍 Technical details
  • edit_file still diffs with keepends=True, so an edit that only changes line endings still produces a diff. Each line's own \r\n is stripped before the join. This changes the diff field the model sees from double-spaced to single-spaced. eval: covered by RC tag.
  • print_diff gains _DIFF_CARD_MAX_CHARS = 64_000 alongside the 400-line cap, with its own note.
  • In the TUI, … N more lines (truncated) replaces +N more lines.
  • Tests: no blank line after a changed line, result["diff"] == card, a CRLF→LF-only edit still draws a card, and the character cap. The first two fail on the previous head.
  • Regression check against main: a 6,000-test pytest slice (every test that imports the SSE handler or the file I/O tools) and go test ./... in tui/. The only tests that went from pass to fail were a git init temp-dir flake and a Windows lock-file "Access denied", and both pass when re-run in isolation.

@github-actions github-actions Bot added the agents label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
.claude/skills/gaia-release ✅ ALLOW experimental experimental, community none —

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

… answer

An in-process agent's approved edit showed "Card failed to render" in the
Agent UI, because its tool_result carried the diff under result_data while
ChatView and step persistence read cards from data. The event now carries
the card under data too.

A diff card also made a turn that edited a file and then wrote nothing count
as answered, so it saved as an empty success instead of "GAIA ran its tools
but didn't write an answer." Diff cards no longer count as an answer, on the
in-process and relay paths alike.

The TUI diff card now expands tabs to 4-column stops instead of collapsing
each tab to one space.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Fixed the two regressions the verifier found. An approved edit now draws its diff in the Agent UI when the agent runs in-process, instead of "Card failed to render". A turn that edits a file and then writes no answer is back to "GAIA ran its tools but didn't write an answer." The TUI diff card also keeps tab indentation now.

🔍 Technical details
  • sse_handler: the diff tool_result now sets data alongside result_data. ChatView and step persistence both read data, so before this the card was also saved without its payload.
  • _chat_helpers: diff renders (_NON_ANSWER_RENDERS) no longer count as an answer card in _empty_answer_outcome.
  • TUI renderDiff: tabs expand to 4-column stops, measured after the +/-/space marker.
  • Tests: in-process /chat/send event shape, persistence, and edit-then-no-answer on both the in-process and relay (_dispatch_one) paths. The webui test feeds the same event through RenderCard and ChatView from a fixture that the Python test pins to the real event. Go tests cover tab stops.
  • Before/after vs main: pytest over 208 importer files shows no new failures (one test_gaia_home_storage failure was a stray-thread log in the full run and passes on rerun in run order). Vitest 2274→2276 all pass, tsc clean. Go: no regressions; TestDiffRidesTheUnsupportedFallback was removed on purpose by this PR.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit b5db823 Nov 2, 2026
84 of 85 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/3710-approved-edit-diff-card branch November 2, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ui): an approved file edit shows nothing — the diff card exists but nothing feeds it

1 participant