Skip to content

fix(tui): clear flagship conversation context over stdio - #3650

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:codex/review-tui-clear
Sep 19, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:codex/review-tui-clear

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The TUI now clears the flagship's actual conversation and waits for acknowledgment before removing the visible transcript.

Why

Previously /clear erased only the screen; prior instructions still influenced the next task.

Linked issue

Closes #3636

Changes

Adds an acknowledged stdio reset while preserving the running process, model, skills and permission state. Failed resets retain the transcript and show an error.

Test plan

  • python -m pytest hub/agents/gaia/python/tests/test_stdio.py -q — 67 passed.
  • go test ./internal/client ./internal/ui/chat and go vet ./internal/client ./internal/ui/chat — passed.
  • Black, isort and diff checks passed.

Evidence

The new regression failed before the fix because prior instructions remained in context. A real Python stdin/stdout subprocess handles two turns, a reset and a fresh turn; the fresh turn sees no old history. Go tests cover the transport acknowledgment and UI success/failure state. Inference is deterministic in this contract test; live model quality and rendered terminal screenshots were not evaluated.

Checklist

  • Linked the issue and explained the impact.
  • Ran targeted regression tests and lint; read back the changes.
  • Updated relevant documentation where behavior is described.
  • Maintainer review and CI completion.

Compatibility follow-up

Legacy subprocess and mock connections retain screen clearing with an explicit notice that agent context is unchanged. Canonical resets show progress while awaiting acknowledgement.

  • New UI regressions fail on the prior implementation; client/chat suites and go vet pass.
  • Live compiled TUI: gaia-clear.exe chat --subprocess mock-clear.exe --query before-clear-marker --control-port 8819, followed by /clear via the control API, displayed:
View cleared. This connection cannot reset the agent's conversation
context; that context is unchanged.

The process exited cleanly via Ctrl+C. Canonical context-reset evidence remains the real Python stdio round trip described above.

@github-actions github-actions Bot added the tui Go terminal UI (gaia-tui) label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Request changes

/clear now really resets the flagship's memory of the conversation instead of just wiping the screen — the right fix for #3636, and the acknowledged round trip (transcript stays put if the reset fails) is exactly the careful shape this deserves.

One thing to fix before merge: /clear stops working entirely for agents that aren't the flagship. Any agent started with --subprocess or --mock speaks the older event dialect, and for those the new path refuses the reset and leaves the transcript on screen with an error — so there is now no way to clear the view at all on those connections, where previously it worked. Please keep a screen-clear fallback for transports that can't reset agent-side context (with a visible note that the agent's own context is untouched), rather than refusing outright.

Smaller: while the reset is in flight the UI shows nothing at all — no spinner, no "working" line — because this path skips the per-turn state reset every other turn does. Harmless when the agent answers in milliseconds, but a wedged agent looks frozen for the full 20-second timeout.

Real-world evidence

No evidence-bundle.md was produced for this run, so the verdict rests on static review plus the tests I ran locally: go test ./internal/client ./internal/ui/chat passes, and the new Go and Python tests do cover the wire contract end to end (a real Python subprocess handling turns, a reset, and a fresh turn that sees empty history). What's missing is the surface a user actually touches — a real gaia-tui session showing /clear against the flagship, then a follow-up question that proves the earlier instruction is gone. The repo has a driving-the-tui skill for exactly this; worth attaching that transcript rather than re-running the unit tests.

🔍 Technical details

🟡 /clear is now broken for every non-canonical subprocess agent (tui/internal/ui/chat/clear.go:17)

*SubprocessClient satisfies ConversationResetter unconditionally, so the type assertion succeeds even for a legacy-dialect child, and ClearConversation then fails at tui/internal/client/clear.go:19 with "this subprocess does not support clearing conversation context". handleConversationCleared keeps the transcript and appends an error, so gaia-tui chat --subprocess <cmd> (documented in tui/README.md:185) and --mock lose screen-clearing altogether. The TranscriptResetter fallback below is now unreachable for these clients.

Suggest making the capability explicit so the UI can branch synchronously:

// in tui/internal/client/clear.go, alongside ClearConversation
// SupportsConversationReset reports whether this transport can clear
// agent-owned context; a legacy-dialect child has no control query for it.
func (s *SubprocessClient) SupportsConversationReset() bool { return s.canonical }

then gate the async path on it:

	if resetter, ok := m.client.(client.ConversationResetter); ok && resetter.SupportsConversationReset() {

with SupportsConversationReset() bool added to the ConversationResetter interface. Unsupported transports then fall through to the existing transcript clear — ideally with a RoleStatus line saying the agent's own context was not reset, which keeps the fail-loudly intent without removing the function.

🟢 No feedback while the reset is in flight (tui/internal/ui/chat/clear.go:18-26)

The path sets m.streaming = true but never calls m.updateViewport(), never batches m.spinner.Tick, and leaves m.activity, m.queryStart and m.logPeakRows holding the previous turn's values. Nothing redraws until conversationClearedMsg lands, so a slow or wedged child gives a frozen screen with the composer silently queueing. startMemoryFetch (memoryview.go:61) is the established pattern for an async control round trip — it batches the tick. Resetting m.activity = nil, m.logPeakRows = 0 and m.queryStart = time.Now() also prevents the live region drawing the last turn's work log under a runaway clock if it does get rendered.

🟢 Cross-language constant has no pointer to its twin (tui/internal/client/clear.go:16)

memory.go:14 documents the same coupling ("Must match MEMORY_DUMP_QUERY in … exactly — the wire text is the contract"). Worth the same one-liner here so a rename on either side is caught:

// Must match CLEAR_CONVERSATION_QUERY in
// hub/agents/gaia/python/gaia_agent/stdio.py exactly — the wire text is the contract.
const clearConversationQuery = "\x00gaia:clear_conversation\x00"

🟢 Direct attribute access where the module is otherwise defensive (hub/agents/gaia/python/gaia_agent/stdio.py:1074)

_record_turn reaches for getattr(agent, "conversation_history", None) and logs when it is absent; the new branch does agent.conversation_history.clear(). Every real agent defines it, so this only changes the failure text — but a mismatched agent now reports a bare AttributeError over the wire instead of something actionable. Either is defensible; worth a deliberate choice rather than an accident.

Strengths

  • The acknowledgement contract is the right call: the transcript survives a failed reset, and "conversation_cleared" must come back before the screen is wiped, so an older agent can't silently swallow the reset and leave stale context in the prompt.
  • test_clear_conversation_over_real_stdio_process drives a genuine stdin/stdout child rather than a mock — it proves the wire text actually round-trips, which is precisely the "mocks prove we called it, not that the call is valid" trap CLAUDE.md calls out.
  • Preserving the child process, model, loaded skills and permission state is asserted in both languages, and documented in tui/README.md — the cheap implementation (restart the child) would have quietly cost the ~2.5s warm-turn property.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

The acknowledged round-trip design is sound: Python clears history and emits conversation_cleared, Go refuses to wipe the transcript until it receives that ack, and the turnSeq guard prevents a stale acknowledgment from racing a subsequent turn. The m.streaming gate in updateViewport ensures the "Clearing conversation" activity item is never rendered after settlement. Tests cover the failure path, old-protocol agents, legacy/mock transports, and concurrent clears.


🟡 The new stdio sentinel is undocumented in the SPEC — the wire-protocol contract is incomplete

SPEC.md explicitly documents the agent's other stdio commands (/model <id>, /provider). The new \x00gaia:clear_conversation\x00 sentinel and its conversation_cleared acknowledgment are a new wire-protocol extension in the same category. An integrator building a custom stdio client would have no way to discover this capability from the published reference. test_clear_conversation_over_real_stdio_process cements it as a public contract, not an internal detail. CLAUDE.md requires updating every bundled doc that describes a changed surface — only tui/README.md and CHANGELOG.md received the update.

🔍 Technical details

hub/agents/gaia/npm/SPEC.md already describes the stdio TUI's extended commands:

"The stdio TUI also supports Local, Fireworks AI, and AMD LLM Gateway through Lemonade. /model lists downloaded local and discovered cloud chat models; /model <id> switches the live client while preserving conversation and skills."

The new sentinel belongs in a parallel paragraph — the protocol guarantee (null-byte-delimited, out-of-band, never forwarded to the LLM, acknowledged by {"type":"final","answer":"conversation_cleared"}), the version caveat (old agents return a non-conversation_cleared final event and the TUI surfaces an error rather than wiping the view), and what is and is not preserved (model, skills, permissions — not memory).

hub/agents/gaia/npm/README.md is less critical but may also want a one-liner under the TUI section, since /clear is now meaningfully different from the silent view-wipe it was before.

Kalin Ovtcharov and others added 2 commits September 17, 2026 14:48
amd#3699 moved TTFT off the model and onto the event, so clearing reset two
fields that no longer exist — the package did not build. Mirrors startTurn
instead: the step count and the pre-scan card flag.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

The /clear implementation is solid. Conversation history is now cleared on the agent side (not just the TUI transcript), with an acknowledged round-trip that prevents premature erasure. The sentinel protocol (\x00gaia:clear_conversation\x00) is clearly named and matched across Python and Go. Legacy --subprocess and --mock connections degrade gracefully with an explicit status note. tui/README.md and CHANGELOG.md are updated; SPEC.md and SKILL.md don't document internal TUI protocol sentinels (consistent with the existing MEMORY_DUMP_QUERY not being there either), so no update is needed.

Test coverage is thorough: the Python unit test verifies model/skill/permission state survives the clear; the subprocess integration test runs a real Python process and checks turn isolation; and the Go tests cover the acknowledgment protocol, the "agent not yet started" early-exit, and both error and old-agent failure modes. The fix commit (totalSteps, preScanRenderedThisTurn) correctly brings the per-turn reset in clearConversation in line with startTurn.

No blocking issues found.

🔍 Technical details

One observation (not blocking): ClearConversation in tui/internal/client/clear.go:23 has a !s.canonical guard that is unreachable via the interface contract — the caller in clear.go:350 only enters that branch when SupportsConversationReset() returns true, which requires s.canonical. This is harmless defense-in-depth.

The settleTurn() path intentionally does not call cancelFn() before setting it to nil (per the comment at model.go:1261). The defer cancel() inside the clearConversation closure is what actually cancels the context, so there is no leak — this is consistent with the existing design.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 19, 2026
Merged via the queue into amd:main with commit 1cc3274 Sep 19, 2026
45 checks passed
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Sep 19, 2026
Main's allowlist fixes (amd#3593) keep refusing under this branch's ask-first
model: each guard it added is tagged as an outright refusal, so none of
them turns into a yes/no prompt. The /agents switch (amd#3987) and the
conversation-clear test (amd#3650) now use the full-access names, and a
saved-default notice is shown once rather than again on every switch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tui): clear the flagship conversation behind the stdio transport

2 participants