Skip to content

fix(tui): draw a retried step error calm, not red - #5151

Merged
kovtcharov-amd merged 8 commits into
mainfrom
fix/tui-calm-recovered-errors
Oct 28, 2026
Merged

kovtcharov-amd merged 8 commits into
mainfrom
fix/tui-calm-recovered-errors

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

This is a TUI presentation change. It overlaps the chat-view redesign in #5155 (still a draft); whichever lands second reconciles.

When the agent's own script raised an error and it fixed the script and ran it again, every attempt showed as a red failed: line, so a successful turn looked broken. Now a step error reads error in amber while the turn is still running, and error, retried once a later call of the same kind succeeds. It turns red and reads failed only when the turn ends and nothing recovered it. The one-line error stays visible in every state, and a refusal by the user is never softened.

🔍 Technical details
  • The state comes only from events already received (settleFailures), so nothing guesses about the future. A failure counts as recovered only by a later success with the same retry key: the tool plus a shell command's whole job, or the tool plus a file tool's file. A shell job is every command in a &&/||/; chain (quotes respected), the folder a cd in it moved to, and each command's program and positional words, so a flag's value counts. Bare flags, run and a pipe's right side don't count, and cmd /c, powershell -Command and bash -c key on the command they run. npm run lint does not recover npm run build, cd build && ls does not recover cd build && make, --target out pkgB does not recover --target out pkgA, and report.py does not recover clean.py. A call with no command or file to match (a fetch, a query) is never marked retried.
  • collapseActivity used to fold a failed call into the next call of the same tool, where the newer outcome replaced the failure on screen. A failed row, retried or not, no longer folds, so a retried step keeps its one-line error. Copied work text reads error, retried where the screen does.
  • The grey args/out lines are already --dev only. They are filled in only when m.dev is set (canonical.go, setToolOutputAt). The snapshots show them because the runner launches with --dev.

Test plan

  • go test ./internal/ui/chat/: a retried script error that ends in success has no red; a script error with no retry before the turn ends is red and reads failed; an error followed by a different tool's success stays red; a success before the failure does not recover it; a standing failure is never folded away; another file's success neither recovers nor hides a file tool's failure; npm run build/lint, python -m pip/pytest, cmd /c and powershell -Command pairs stay failed; a fetch or query with other args is never retried; a same-job retry recovers and keeps its error; copied text matches the screen; cd build && make/ls, ||/; chains, quoted separators, pipes and flag values (--target out pkgA/pkgB) are matched on the whole job
  • Two existing tests updated: mid-turn they now expect └ error, and failed after the turn ends

An agent that fixes its own script and runs it again was drawn as a string
of red failures, so a successful turn read as broken. A failed step now
reads "error" in amber while the turn runs, "error, retried" once a later
call of the same kind succeeds, and turns red as "failed" only when the
turn ends with nothing having recovered it.

- Same kind is the tool, plus a shell command's program and first
  argument, so a later `dir` does not recover a failed `pip install`.
- A user's denial is never softened.
- A standing failure no longer folds under the next call of the same
  tool, where the next call's outcome replaced it on screen.
@kovtcharov-amd kovtcharov-amd added the ready_for_ci Run CI workflows on draft PR without requesting review label Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
.claude/skills/contributor-triage ✅ ALLOW experimental experimental, community none —
hub/agents/email/npm ✅ ALLOW experimental experimental, community 2 medium, 1 info code.suppression, supply.undeclared_dependency
hub/agents/gaia/npm ✅ ALLOW experimental experimental 3 high body.injection.credential_request, body.injection.guardrail_bypass, body.injection.persona_override
hub/skills/data-explore ✅ ALLOW community experimental, community none —
hub/skills/document-brief ✅ ALLOW community experimental, community none —
hub/skills/research-report ✅ ALLOW community experimental, community 1 info permission.unused
hub/skills/summarize ✅ ALLOW community 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.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

A failed step the agent recovers from now shows in amber as error, then error, retried, so a turn that succeeded no longer looks broken. Only a failure nothing recovered turns red and reads failed when the turn ends, and a user's refusal stays red. The logic only uses events that have already arrived, and the new tests cover the cases that matter. go test ./internal/ui/chat/ passes locally. Nothing here blocks the merge. Three small gaps:

  • An immediate retry hides the error it recovered from. When the agent retries the same tool right away, the two rows merge into one x2 row that shows only the success. The doc and PR say the error stays visible as error, retried. A later, unrelated call of the same tool can also absorb a retried error. Either keep the error line on the merged row or soften the doc wording.
  • "Same kind of command" is loose for python -m … and similar. The match uses the program plus its first word, and for python -m pip install that word is -m. So a passing python -m pytest would mark a failed pip install as retried.
  • Copied text still says failed for a step the screen shows as error, retried.

Real-world evidence

N/A: no evidence bundle was produced for this run. This is a Go TUI change, and the automated evidence stage doesn't drive the TUI. My verdict rests on static review plus a local go test ./internal/ui/chat/ run (ok). The PR mentions --dev snapshots but doesn't embed any. A before/after capture of a retried-script turn would be worth adding before this leaves draft.

🔍 Technical details

Issues

🟢 An immediate retry folds the retried error away (tui/internal/ui/chat/model.go:3210)
standing is false once Recovery == recoveryRetried. The fold then overwrites Detail with the next call's outcome. Folding keys on activityKey (the tool name), not RetryKey. So pip install fails → dir succeeds → pip install --user succeeds gives a single x3 row with dir's outcome, and the pip error is gone. TestAShellFailureIsRecoveredOnlyByTheSameKindOfCommand asserts x2 for the back-to-back case, which contradicts the doc line "once a later call of the same kind succeeds it reads error, retried". Two options:

  • Don't fold any failed row (standing := stepFailed(*last)).
  • Fold only when stepRetryKey matches too, and keep the retried row's one-line error.

🟢 The retry key's "first argument" is often a flag (tui/internal/ui/chat/worklog.go:325)
python -m pip install x keys as run_shell_command python -m, so python -m pytest succeeding "retries" it. The same applies to cmd /c …, powershell -Command … and py -3 …. Skip leading -// words, or take the word after -m/-c:

	key := tool + " " + program
	for _, w := range words[1:] {
		key += " " + w
		if !strings.HasPrefix(w, "-") && !strings.HasPrefix(w, "/") {
			break
		}
	}

🟢 Copy text disagrees with the screen (tui/internal/ui/chat/worklog.go:131)
commitWork now settles failures, but stepText still emits the raw Detail (failed: …). Apply calmDetail(item.Detail, item.Recovery) when item.Recovery != "", so a copied transcript matches what was drawn.

🟢 Non-shell tools key on the tool name alone
For example, a failed run_python_file a.py is recovered by a passing run_python_file b.py. This is fine for the self-fix loop the PR targets. A one-line note on retryKey that this is deliberate would stop someone "fixing" it later.

Strengths

  • settleFailures works on a copy, recomputes every render, and is pinned by TestSettleFailuresLeavesTheStoredLogUntouched. No state leaks into the stored log.
  • Each state has a word (error / error, retried / failed), so it reads correctly in a terminal without colour. The colour tests check the actual red escape sequence, not just the stripped text.
  • Denied approvals are explicitly excluded from softening, and unrecovered failures are no longer folded under a later success, which fixes an old bug where a failure could vanish.

A failed run of clean.py read "error, retried" once any other script ran
cleanly, and back to back it folded under that success as "x2" with its
error gone. The retry key now includes a file tool's file_path/path
(normalized, so scripts\clean.py and ./scripts/clean.py match).
An unrecovered failure could still vanish from the finished work log:
`npm run build` failing then `npm run lint` passing drew one "x2" row with
no error, because the retry key stopped at the first word after the
program, and tools with no command or file matched on the tool name alone.

- The retry key skips flags (-m, /c, -Command) and `run`, so wrappers like
  `python -m`, `cmd /c`, `powershell -Command` and `npm run` key on the
  real subcommand.
- A call with no command or file to match on (fetch, query) is never
  marked retried; it stays red and reads failed when the turn ends.
- A failed row never folds into the next one, so a retried step keeps
  its one-line error; a failure folds under an earlier row only as a
  retry of the same call.
- Copied work text reads "error, retried" where the screen does.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

All four review findings and the verifier's are fixed in e86c51f. A failure nothing recovered now always stays on screen, red, with its error. A retried one keeps its one-line error instead of folding into an x2 row.

  • Immediate retry hid the error: fixed. A failed row no longer folds into the next call, retried or not.
  • python -m pip vs python -m pytest, plus npm run, cmd /c and powershell -Command: fixed. These now match on the real subcommand.
  • Copied text said failed: fixed. It now reads error, retried where the screen does.
  • Tools with no command, matched on the tool name alone: a file tool now matches only on the same file. A fetch or query is never marked retried, so it stays failed at turn end.
🔍 Technical details
  • retryKey: program, then the first two words that aren't flags (-x, or a /x switch up to 3 chars, so /tmp/a.py still counts as a path) or run. Quotes are stripped, so powershell -Command "npm run build" keys as powershell npm build. Returns "" when the args have no command, file_path or path, and settleFailures never matches an empty key.
  • collapseActivity: a failed last never folds. A failed item folds under an earlier row only when the two RetryKeys are equal and non-empty, so it shows as x2 of the same call with its failure visible. Two successes still fold across different files, as before (mergeTargets, e.g. Editing file: a.py, b.py x2). No error is hidden there, so I left it.
  • stepText applies calmDetail when Recovery is set.
  • TestAShellFailureIsRecoveredOnlyByTheSameKindOfCommand had asserted the bare x2. It now asserts the retried row keeps error, retried: … No module named pip.
  • New tests. Each fails with its own fix reverted (checked):
    • fold: TestASameJobRetryRecoversAndKeepsItsError, plus the updated test above
    • flag/run skipping: TestAShellFailureIsNotRecoveredByADifferentJobBehindAWrapper
    • no key, no match: TestAFailureWithNothingToMatchOnIsNeverRetried, TestRetryKeyBoundaries
    • copy text: TestCopiedWorkMatchesTheScreenForARetriedStep
  • cd tui && go vet ./... && go test ./... passes. docs/guides/tui.mdx now says "the same file or the same command" and that fetches and queries are never marked retried.

`cd build && make` failing then `cd build && ls` passing still drew the
make failure as "error, retried", and so did `cd build; npm test` before
`cd build; npm ls`. The shell tool tells the model to write commands that
way, so the retry key now reads the whole line:

- Every command joined by &&, || or ; counts, quotes respected; a cd
  becomes the folder the job runs in, and only the left side of a pipe
  counts (`npm test | tail -5` is the same job as `| tail -50`).
- Every positional word counts, so a flag's value is part of the job:
  `pip install --target out pkgA` is not settled by `... pkgB`, while an
  added valueless flag (`--user`) still recovers the same job.
- cmd /c, powershell -Command and bash -c key on the command they run.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

The verifier's last finding is fixed in 7058edc. A retried shell step is now matched on its whole command line, so cd build && ls passing no longer settles a failed cd build && make. A different value for a flag, as in --target out pkgA vs pkgB, counts as a different job.

🔍 Technical details
  • shellSegments splits outside quotes on &&, ||, ;, & and newlines, and keeps the & in 2>&1 as text. It drops a pipe's right side and empty commands.
  • commandKey joins every command in the chain, not just the last. Last-only would let make || echo done be settled by ls || echo done. A cd/pushd/Set-Location becomes the folder, in <dir>: ....
  • Pipe, deliberately: only the left side counts, so npm test | tail -5 and npm test | tail -50 are the same job.
  • Flag values: every positional word is kept rather than guessing which flags take a value (--user X vs --target out X can't be told apart without knowing each tool). A bare flag is dropped and --flag=value stays whole. So pip install X → pip install --user X still recovers, and --target out pkgA → pkgB, or -r a.txt → -r b.txt, does not. --target=out vs --target out stays failed, because it is spelled differently and so isn't provably the same job.
  • Wrappers: cmd /c|/k, powershell|pwsh -Command|-c, and bash|sh|zsh -c|-lc re-parse what follows, up to 3 levels deep.
  • Tests that fail without the fix (checked by reverting):
    • the old key: TestAChainedCommandIsRecoveredOnlyByTheSameChain, TestAFlagValueIsPartOfTheJob
    • no chain splitting: TestAChainedCommandIsRecoveredOnlyByTheSameChain, TestShellSegments
    • quote-blind splitting: TestShellSegments
    • first-two-words limit: TestAFlagValueIsPartOfTheJob
  • TestAShellFailureIsNotRecoveredByADifferentJobBehindAWrapper and the other earlier tests still pass. cd tui && go vet ./... && go test ./... passes, and gofmt is clean. docs/guides/tui.mdx now says what "the same command" means.

@kovtcharov-amd
kovtcharov-amd marked this pull request as ready for review October 28, 2026 19:16
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit d72fed9 Oct 28, 2026
77 of 78 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/tui-calm-recovered-errors branch October 28, 2026 19:16
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

A step error the agent fixes and retries no longer paints a successful turn red. It reads error in amber while the turn runs, error, retried once a matching later call succeeds, and red failed only if nothing recovered it by the end of the turn. Matching is careful: same tool, same file or same whole command job, so a different command's success never hides a real failure. The chat tests pass on this checkout (go test ./internal/ui/chat/ → ok). The PR is already merged, so the points below are follow-ups.

  • A failed step the user had approved with "always allowed" stays red even after a successful retry. Only a plain "approved" answer gets the calm treatment. A one-line change fixes it.
  • A failed file edit counts as retried after any later successful edit to the same file, even one that changed a different part of it. That's fine for the usual "fix the edit and try again" flow, and worth knowing about.

Real-world evidence

N/A: no evidence bundle for this run. This is a TUI rendering change, and the PR's proof is unit tests on the rendered rows plus snapshot updates. The verdict rests on static review and the passing Go tests. No live TUI capture was checked here.

🔍 Technical details

🟢 "always allowed" approvals are treated as refusals (tui/internal/ui/chat/worklog.go, settleFailures)
item.Approval != "" && !strings.HasPrefix(item.Approval, "approved") also skips always allowed '<scope>', which is a yes from the user. A failed always-allowed step that the agent then retries successfully still renders red failed. The docstring says only a user's refusal is never softened.

		if strings.HasPrefix(item.Approval, "denied") {
			continue
		}

(If other refusal wordings exist besides denied, list them instead. The render path already keys denial on strings.HasPrefix(item.Approval, "denied").)

🟢 File-tool retry key ignores the edit itself (retryKey)
An edit tool's key is just tool + file_path. Suppose edit_file fails on hunk A (old content not found) and a later edit_file on hunk B of the same file succeeds. Hunk A then reads error, retried even though it was never applied. This is rare and the one-line error stays visible, so it isn't blocking. Keying edits on old_content too, or accepting the current behaviour on purpose and saying so in the tui.mdx paragraph, would close it.

Strengths

  • Recovery is worked out at render time from events already received (settleFailures) and is never stored, so the live view, the finished turn and the copied work text can't drift apart. The copied text reuses calmDetail to match the screen.
  • collapseActivity no longer folds a failed row into a later call, which fixes a real loss: a failure's error line used to be overwritten by the next call's outcome.
  • The command-job matching (chains, cd, pipes, quoted separators, cmd /c / bash -c wrappers, flag values) comes with negative tests, which is what keeps a softened failure from hiding a real one.

kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 20, 2026
Before, a running turn printed raw tool calls with `args {…}` / `out
{…}` JSON, repeated the plan headline before every step, showed `Step
15/150`, and `--dev` piled more debug output onto the screen. After,
each step is one bullet that says what it did in plain words ("Read the
vendor's DPA in full", "Run a 42-line Python script that reads 3
spreadsheets"). One shimmering status line at the bottom shows what is
running now and for how long. A finished turn ends with the files it
made (size, sheets and rows, a clickable link) and a one-line recap.
Detail stays one key away with Ctrl+O, and the screen under `--dev` is
the same one every user sees.

Screenshots from the same contract-review task, run on `main` and on
this branch:
- **Before, running:** each tool call is followed by two lines of JSON,
a `✻` plan line, and `⣾ Step 7/150`.
- **After, running:** goal bullets ("Read the vendor's SLA and DPA in
full") with the file under each, then `⣟ Reasoning · 941 words… (2m
58s)`.
- **After, done:** the script write shows as a green-banded,
syntax-coloured diff. Below the answer, `Created contract_review.xlsx 7
KB · 1 sheet: Issues (13 rows)` and `✓ Read 6 files · ran 1 Python
script · 2m 48s · ↓ 7.7k tokens`.

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

- **Where a headline comes from**, best first: a `description` argument
on the call, then the agent's announced goal (not stage lines, musing,
or template text), then a summary derived from the call. The agent-side
`description` parameter is a separate, eval-gated change; this PR only
reads it if present.
- **Motion** runs on the spinner's 20 fps tick and redraws only the
status line, a waiting prompt's title, and the recap line, which sweeps
once. It is off with `reduced_motion` (new `gaia config` key),
`GAIA_TUI_REDUCED_MOTION`, `NO_COLOR`, or a non-TTY.
- Measured: about 0.2 ms per frame with 400 messages on screen, and
about 2.3 % of one core during a live turn.
- **`--dev`** turns on the control API (`--debug` is still its alias)
and changes nothing on screen.
- Transport diagnostics go to `gaia-tui.log` under `--dev`, as on main.
  - `--dev` or `--trace` puts an agent the TUI spawns at DEBUG logging.
  - The per-turn metrics block and full stats moved behind Ctrl+O.
- **Failed steps follow main's retry rule** (amd#5151): `error` while the
turn runs, `error, retried` once a later run of the same file or command
succeeds, and a red `✗ failed` only if nothing recovered it.
- **Created block:**
  - It lists only files changed during the turn.
- A path that is only named in text is looked at only under the start
folder or home, never on the network.
- Ctrl+F opens the newest file a turn made, and only documents that
cannot carry code. Ctrl+G keeps main's "reveal media in its folder".
- **Compatibility:**
  - No step denominator is shown, with or without a limit (amd#5153).
- `continue_long_turn` renders as "Keep going? · 200 steps so far on
<model>".
- Fixes amd#5089 and amd#5122 on the TUI side.
</details>

## Test plan
- [ ] `cd tui && go vet ./... && go test ./...`
- [ ] Review the golden frames in
`tui/internal/ui/chat/testdata/frames/`: running, finished, diff,
recovered error, real failure, permission prompt, 40 columns, and
over-1-hour turns
- [ ] `cd tui && make build && ./bin/gaia-tui --dev`, then run a
multi-step task. Check that bullets lead with plain words, there is no
JSON, the status line shimmers, and the Created block plus recap appear
under the answer
- [ ] Press Ctrl+O on the finished turn and check that the commands,
timings and metrics are there
- [ ] `GAIA_TUI_REDUCED_MOTION=1 ./bin/gaia-tui` shows no shimmer and no
pulse
- [ ] With a permission prompt up, `/control/v1/screen?format=plain`
still shows `once`, `deny`, `n/esc` and the `›` composer line
- [ ] `python -m pytest tests/unit/test_cli_config.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes ready_for_ci Run CI workflows on draft PR without requesting review tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant