Repository navigation
feat(tui): reopen past sessions and see which ones need you - #5237
kovtcharov wants to merge 3 commits into
Conversation
Quitting the terminal UI used to lose the conversation from view: there was no way to list past sessions, reopen one, or tell that one was paused on a permission prompt. /sessions and `gaia tui --resume[=<id>]` now list recent sessions with title, age and status (waiting on you first; eval and scheduled runs hidden unless asked for), and reopening one redraws its transcript and restarts the agent on its saved history, so the model remembers it too. - The flagship stdio agent already keeps each session's model transcript in ~/.gaia/tui/history/<id>.sqlite3. With --session-kind it now also keeps <id>.json (title, kind, status, pid, turns) and <id>.jsonl (one readable line per finished turn) beside it, and holds <id>.lock for its life. The lock, not the pid, marks a session open: it dies with the process and a reused pid cannot fake it. Layout pinned in tests/fixtures/stdio/gaia_stdio_wire.json. - A failed listing write is logged and reported on the wire; it never costs the user's turn or hangs exit. - Bare --resume shows the list before the first chat opens, and the chat keeps receiving events while the list covers it mid-session. - A flagship running through the background service (hub/installer build) keeps no sessions yet; /sessions and --resume say so. Closes amd#5230
|
The red "Unit Tests (macOS, py3.12)" is a pre-existing flake in an unrelated test, not this change: 1 of 22,202 tests failed, 🔍 Technical details
|
|
Verdict: Approve with suggestions You can now list past terminal sessions, see which one is stuck on a permission prompt, and reopen one with the agent's memory intact. The design holds up: a lock file decides whether a session is open, a crashed turn is shown as stopped mid-turn, and a failed write to the session listing never costs the user a turn. Nothing blocks a merge. One thing to fix:
Real-world evidenceN/A: no evidence bundle was produced for this run. The PR body reports a live Windows Terminal session: remembering a codeword across 🔍 Technical details🟡
🟢 🟢 🟢 Probing the lock can briefly block a reopen ( Strengths
|
…esume GAIA_HISTORY_FILE pinned the flagship's transcript before this PR and was then silently overridden by the TUI's own --history-file. It is honoured again: a file the session list can reopen (<id>.sqlite3 in the session store) stays listed, any other path is kept unlisted with a note in the chat saying why, and --resume refuses to run while the variable is set. - An empty --resume= (a script's unset variable) is refused instead of starting a new session. - The agent retries its session lock briefly, so the TUI probing whether a session is open can never turn a free session away. - A non-JSON line on the wire is logged and still reaches the host, never dropped by the session listing.
|
Addressed the review in ee73f55: all four suggestions are taken, none disputed.
The macOS unit-test red is the unrelated 🔍 Technical details
|
Before: after the daemon restarted on a new port, Cancel, Respond, Confirm and the full-access toggle in the TUI failed with "connection refused", which says nothing about what happened. After: the TUI finds the restarted daemon and says plainly that the restart ended the agent session and nothing was sent; the next message starts a fresh session there. A run cannot be carried over, because the daemon stops its sidecars on shutdown and the next one starts fresh. Lands after v0.25.0. Sending a new message already re-read `instance.json` (through `EnsureAgent`) before this change. What was broken was every call made against the session the TUI already held. Reproduced by `TestCancelAfterADaemonRestartSaysTheRunEnded` and `TestDoDoesNotCarryARunScopedCallToARestartedDaemon`: on main the first fails with "connection refused", and the second can't compile because main has no way to tell run-scoped calls apart. Both pass here. ## Test plan - [x] `go vet ./...` clean; `go test -p 1 ./internal/daemon/ ./internal/client/ ./internal/ui/preflight/` passes - [x] Run-scoped calls (cancel, answer, confirmation, follow-up, permission decision, full access) are never sent to a restarted daemon; the client still learns the new instance - [x] Other relayed calls ensure the agent on the restarted daemon, then replay (`TestDoEnsuresTheAgentBeforeReplayingARelayCallToARestartedDaemon`) - [x] A call whose connection drops after a daemon received it is never replayed (`TestDoNeverReplaysARequestThatReachedTheDaemon`) - [x] A replacement that fails its checks keeps its typed `VersionError`/`StaleError` in the chain, plus the original failure - [x] Live, real TUI against a fake daemon that, like the real one, has no sidecar after a restart (isolated homes): `/full-access confirm` after the restart said "GAIA's daemon restarted, which ended the agent session this belonged to. Nothing was sent", and the restarted daemon received no `/bypass`. The next message ensured the agent and was answered. Main says "actively refused it". <details> <summary>🔍 Technical details</summary> - `Client.Do` re-reads `instance.json` only on a dial failure (`*net.OpError` with `Op == "dial"`, reachable through the new `RequestError.Unwrap`). The new instance goes through the same `verify` and `CheckVersion` as attach. - `Request.RunScoped` marks calls about state in a running sidecar. They return `DaemonRestartedError` together with the new instance. Other `/v1/<agent>/…` calls run `ensureOn` (split out of `EnsureAgent`, with its agents-floor check) on the new daemon first. - A restart on the same port shows up as a rotated token (401) rather than a refused connection; that path takes the same step, so it is covered too (`TestDoDoesNotCarryARunScopedCallAcrossASamePortRestart`). - `SSEClient.do` keeps whichever instance answered, so the six calls that used to drop it also follow a plain token rotation. - The client test fake answers 503 "no running sidecar" after a restart until the agent is ensured, the way the real daemon does. - The log names the dial's own failure (refused, timed out, unreachable). - No overlap with amd#5264/amd#5282 (daemon close) or amd#5237 (sessions). </details>
Keeps both [Unreleased] CHANGELOG entries and points the --resume reference at the guide's new home, docs/guides/tui.mdx.
|
Synced with #5155's branch in c77acd3 (it had moved on and conflicted): both The one red check, "Test GAIA CLI on Linux (Full Integration)", isn't caused by this PR. Since |
Quitting the terminal UI loses the conversation from view: you can't list past sessions, reopen one, or tell that a session is stuck on a permission prompt. Now `/sessions` and `gaia-tui --resume` list recent sessions with title, age and status (running, waiting on you, done, failed). Sessions waiting on you come first, and eval and scheduled runs stay hidden unless asked for. Reopening a session redraws its transcript and restarts the agent on its saved history, so GAIA remembers the conversation, not just the screen. Closes amd#5230. Replaces amd#5237, which was stacked on the still-open amd#5155; this works on main without it. **Not covered yet:** a flagship installed as an Agent Hub binary runs through the background service, which keeps no sessions. There, `/sessions` and `--resume` say so instead of showing an empty list. The terminal installers' agent and a source checkout run over stdio and are covered. <details> <summary>🔍 Technical details</summary> - **Store:** reuses the per-session transcript the stdio agent already keeps (`~/.gaia/tui/history/<id>.sqlite3`). With `--session-kind`, the agent also writes `<id>.json` (title, kind, status, pid, turns) and `<id>.jsonl` (one readable line per finished turn) beside it, so the TUI lists and redraws sessions without reading SQLite. - **Open vs. closed:** the agent holds `<id>.lock` for its whole life, and the TUI tests that lock (`filelock.Held`) rather than the pid. A killed window releases it, and a reused pid can't fake it. Reopening claims the session at once, and a second window is refused. - **Contract:** `tests/fixtures/stdio/gaia_stdio_wire.json` → `session_index`, checked by both the Python and Go tests; described in spec §10.4. - **`GAIA_HISTORY_FILE`** still pins every launch. It's listed only when it's a session file the list can reopen, and `--resume` refuses to run while it's set. - **Failures:** a listing write that fails is logged and shown as a status line. It never costs a turn and never hangs exit. - **UI:** the list is its own component (`ui/sessions`). `chat/model.go` gains only two `case`s in `submit`; `/sessions` joins the help panel's Commands block, so the panel still fits 40 rows. </details> ## Test plan - [x] `go test ./...` and `go vet ./...` in `tui/` with an isolated `GAIA_HOME`/`GAIA_TUI_HOME` and Lemonade pointed at an unused port, including golden frames for the list at 100 and 40 columns, all kinds, empty, and under NO_COLOR - [x] `pytest` on `test_session_index.py`, `test_stdio.py` and `test_stdio_wire_contract.py` (163 passed); black, isort and flake8 clean; internal doc links pass - [x] Live drive on Windows (this branch's `gaia-tui`, this checkout's stdio agent, isolated memory): - told it a codeword, and hit a write prompt while the session read `waiting`, then denied it - quit mid-conversation; the session closed cleanly - wiped memory, relaunched with bare `--resume`: the list opened before any chat, the session reopened with its transcript, and it answered the codeword from the reopened history (memory held nothing before the question) - [ ] Reopen a session on macOS and Linux --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
Quitting the terminal UI used to lose the conversation from view: you couldn't list past sessions, reopen one, or tell that a session was stuck on a permission prompt. Now
/sessionsandgaia tui --resumelist recent sessions with title, age and status (running, waiting on you, done, failed). Sessions waiting on you come first, and eval and scheduled runs are hidden unless you ask for them. Reopening a session redraws its transcript and restarts the agent on its saved history, so GAIA remembers the conversation, not just the screen.Builds on #5155 (this PR targets its branch and will retarget to
mainwhen it merges); lands after v0.25.0. Agent UI counterpart: #5221.Closes #5230
Not covered yet: a GAIA installed from the Agent Hub or by the desktop installer talks to the TUI through the background service, which keeps no sessions. There,
/sessionsand--resumesay so instead of showing an empty list. Supporting it needs the HTTP sidecar to persist sessions too, which is a follow-up.🔍 Technical details
~/.gaia/tui/history/<id>.sqlite3,--history-file). With the new--session-kind, the agent also writes<id>.json(title, kind, status, pid, turns) and<id>.jsonl(one readable line per finished turn) beside it. The Agent UI database isn't used: the TUI flagship never wrote to it.<id>.lockfor its whole life. A session counts as open while that lock is held, not while its pid is alive, because a killed window releases the lock and a reused pid can't fake it. Reopening a session claims it immediately, and a second window trying to open it is refused.tests/fixtures/stdio/gaia_stdio_wire.json→session_index, checked by both the Python and Go tests; described in spec §10.4.ui/sessions).chat/model.gochanged only by twocases insubmit. The help panel's/row was shortened to two lines so the panel still fits 40 rows without scrolling.Test plan
go vet ./...andgo test ./...intui/, including golden frames for the list at 100 and 40 columns, all kinds, empty, and under NO_COLORpytestontest_session_index.py,test_stdio.py,test_stdio_wire_contract.py,test_transport_dispatch.pyandtests/unit/test_amd_gaia_urls.py(173 passed); black, isort and flake8 clean on the touched Python fileswaiting), denied it, quit mid-conversation, relaunched with--resume, picked the session, and it answered the codeword from the reopened history. Also checked--resume=<prefix>directly,/sessionsat 40 columns, and refusal of a session open in another window.--resume). This machine's embedded Lemonade was swapped to an older version mid-session, so the readiness gate blocked it; covered by root unit tests meanwhile