Skip to content

fix(gaia): preserve query errors when undo history cannot be saved - #5734

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
jipeng6036-del:fix/preserve-query-error-if-undo-save-fails
Oct 26, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
jipeng6036-del:fix/preserve-query-error-if-undo-save-fails

Conversation

@jipeng6036-del

Copy link
Copy Markdown
Contributor

Summary

Keep the original query error when saving that turn's undo history also fails.

Why

A turn that raises after changing a file can lose its real error if the snapshot store also runs out of space. The sidecar then reports “This is a bug” instead of the processing failure. The original error now survives, undo still gets its warning, and both tracebacks are logged even when the copy error suppresses exception context.

Linked issue

Closes #5666

Changes

  • Retain the processing exception across the recording context's finalization, without emitting a terminal event before recording ends.
  • Add four endpoint regressions for different original exception types, suppressed undo context, terminal ordering and session-lock cleanup.
  • Document the dual-failure behavior in the SSE contract.

Test plan

  • Final regression overlay on original production: 4 failed / 9 passed; candidate endpoint suite: 13 passed.
  • Complete Linux pytest tests/unit/ -n 4 --dist=worksteal: 27508 passed / 478 skipped / 3 xfailed, with 41 passing subtests. Collection guard passed unchanged.
  • Complete flagship package suite on Linux Python 3.12.14 and Windows Python 3.12.13: 796 passed / 3 conditional skips each. Linux subprocess imports were explicitly bound to the candidate too.
  • Affected snapshot/changes/dispatch/relay contract suites: 206 passed / 2 conditional skips; flagship collection guard and capability matrix passed.
  • python util/lint.py --all: 17 passed / 1 configured nonblocking MyPy advisory; staged lane/path checks passed. Wheel/sdist builds, Twine validation and independent installed-wheel import parity passed.
  • Actual browser and HTTP/SSE proof below; native independent code/architecture review completed.
  • Next RC: watch error_recovery under the repository's no-local-Strix-Halo eval exception. Real model evals were not run here.

An additional fixture-enabled relay-query diagnostic exposes the same old fake-handler mismatch on both revisions (1 failed / 3 passed, missing set_relay_question). It is recorded separately, not counted as green. The configured contract run above retains its normal conditional query skip; the actual browser proof uses the production handler and passes.

Evidence

Exact commits, commands, versions, logs, controls and raw screenshots.

The real gaia chat --ui → browser → daemon → dev sidecar → GaiaAgent → write_file chain runs on both revisions. Only model HTTP replies and an isolated install receipt are fixtures. After the real file write, a separate 1 MiB tmpfs produces genuine snapshot ENOSPC; no production Python code is monkeypatched. This tests the user path, not real inference/GPU behavior or a frozen binary installation.

Original: undo failure hides the processing error behind the generic bug message
Candidate: the same two failures preserve the original processing error

  • Agent UI / HTTP: before/after pages, reload recovery, persisted messages and six HTTP/SSE cases cover double failure plus success/undo-only and processing-only controls.
  • CLI: launched the actual gaia chat --ui command; logs and arguments are in the evidence harness. The in-process one-shot CLI is unchanged.
  • MCP: N/A; no MCP transport or tool schema changed.

Baseline 82ad2a771c7ed5b6b26f4521b3e4eaad40820f85; candidate 529dc35fd434f9582c3490b2f7f39d1797464c6b. The manifest ties validation to all three committed blobs. The scripted processing error uses the independently tracked #5471 baseline case; this fix does not stack #5732's parser change. Hosted CI and human review are separate from these local results.

Checklist

  • Linked an issue and explained the user impact.
  • Ran required local lint and tests; recorded conditional skips and diagnostic limits.
  • Attached evidence from the affected user surface and marked the unchanged MCP surface N/A.
  • Updated behavior documentation.

AI-assisted implementation and verification; human review is pending.

@github-actions github-actions Bot added the documentation Documentation changes label Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

A turn can fail after changing a file, and saving that turn's undo history can then fail too. Before this PR, the sidecar dropped the real error and showed the generic "This is a bug" message. Now the user sees the real error, still gets the "undo may not work" warning, and both tracebacks go to the server log. The fix is small and only touches that one path, and the new test covers the outcomes that matter: the error event comes last, its text is right, and the session lock is released.

Nothing blocks this. There is one small cleanup in the technical notes.

Real-world evidence

N/A here: the CI evidence stage produced no bundle, and pytest isn't installed on this review runner, so this verdict rests on reading the code. The PR description links its own evidence: before/after Agent UI screenshots from a real gaia chat --ui → sidecar → write_file run, with genuine ENOSPC on a 1 MiB tmpfs, plus HTTP/SSE cases. That is the right evidence for this surface. I haven't re-run it.

🔍 Technical details

Issues

🟢 The same exception is logged twice when the turn itself raises SnapshotError (hub/agents/gaia/python/gaia_agent/server.py:1388-1404). Say _process() raises a SnapshotError and recorder.finish() succeeds. The except SnapshotError branch then runs logger.exception(...) on exc, and exc is the same object as process_error. The next logger.error(..., exc_info=process_error) writes the identical traceback a second time. What reaches the user is correct: one warning and one terminal error. This is only log noise. One option is to guard the second log with process_error is not exc.

            if process_error is not None:
                if process_error is not exc:
                    logger.error(
                        "%s /query run failed for run_id=%s",
                        AGENT_ID,
                        run.run_id,
                        exc_info=(
                            type(process_error),
                            process_error,
                            process_error.__traceback__,
                        ),
                    )
                handler.print_error(_terminal_error_detail(process_error))

Behavior change worth knowing about (no action needed): before this PR, a recorded turn whose own processing raised SnapshotError emitted only the status warning and no terminal error. Now it also emits an error carrying that message. That matches the "a terminal final/error is always last" rule in the contract, so it's an improvement.

Strengths

  • Capturing process_error inside the with block is the right fix. recording_turn re-raises with from e, which suppresses the original error as context, so without the explicit log the real cause would never reach the logs. The test reproduces this with raise ... from None.
  • The test is parametrized over four original error types, including SnapshotError itself. It checks that the error event is last, that it isn't the "bug" text, that both tracebacks are logged, and that the session lock is released.
  • The SSE contract doc is updated in the same change.

@kovtcharov-amd kovtcharov-amd changed the title Preserve query errors when undo history cannot be saved fix(gaia): preserve query errors when undo history cannot be saved Oct 26, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 26, 2026
Merged via the queue into amd:main with commit 2827acd Oct 26, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed flagship turn whose undo history also fails to save reports "This is a bug" and loses the real error

2 participants