Repository navigation
feat(tui): run the readiness gate on every agent launch - #2487
Conversation
Every way the daemon path can fail — daemon down, token rotated, version gate, model missing, mailbox not connected — reached the user as a raw HTTP status, discovered one wall at a time. The gate now reports all of it as checkable rows with a remedy per failure. Its own review caught remedies that damaged what they claimed to fix: the mailbox fixes named commands that OVERWRITE existing scopes, turning 'can read, cannot send' into 'can send, cannot read' — and the row then went green over a mailbox that was worse off. A relay 503 also decoded as 'Lemonade unreachable', sending users to the wrong component entirely.
The preflight gate was built, tested and merged, but nothing imported it, so no user could reach it: pressing enter on an installed agent went straight to chat and the first sign of a missing model or a disconnected mailbox was a failed turn mid-conversation. The gate now sits on the launch path — the four generic checks plus the agent's extras run, an all-green screen holds ~800ms and hands off to the same launch path the hub used to call directly, and a proved-broken row keeps the user on a screen with a command they can run. Two decisions worth naming: The gate runs on EVERY launch and nothing is cached. Every row is a fact with no expiry notice — the daemon can be killed, its token rotates on restart, Lemonade can unload the model, a mailbox grant can be revoked from the web — so a remembered pass would open a chat that cannot answer while claiming it had been verified. A pass costs one attach plus two relayed GETs. ConnectMailboxMsg becomes an instruction screen, not a connector flow. The TUI has no OAuth screen and half of one would fork the flow that owns tokens, scopes and grants (`gaia connectors`), so the host shows the exact command the mailbox row already computed — scope union and agent grant included — and re-checks on `r`. With no provider connected the choice stays the user's: the Gmail command is copy-pasteable and Outlook points at its one-time Microsoft setup, because that provider needs an app registration first and the Gmail scopes are wrong for it. Subprocess-transport agents are not gated: every precondition is probed through the daemon relay, so the gate could only answer "not installed" — four wrong rows with four wrong remedies over a launch that works. The control snapshot reports the new view so automation can wait on it instead of racing the render.
… agent Review found the launch this seam was supposed to make impossible. The gate's async results are unexported types, so root forwards them blind to whichever gate is mounted: back out of a slow check on Email, launch a second hub agent, and Email's report lands on that gate — five rows for the wrong agent, and if that report is all-green the gate hands off and opens a chat for an agent nothing ever probed. The report is exported and names its agent, so root now drops any result that belongs to a gate the user already left. The regression test reproduces it end to end (it fails with "a stale report launched chat" without the guard), and replaces a test that could not see the bug: after esc the view is already the hub, so its guard short-circuited before the agent id was ever compared. Also from the review: The mailbox hand-off gave up the wrong lines when the terminal was too short. The command sits in the middle of the screen, so trimming by position — from either end — could keep the paragraph explaining the problem and drop the one command that fixes it. Lines are now dropped by what they are: explanation first, then the alternative path, never the command or the way out. Verified at 24, 16, 12 and 10 rows. `closeGate`'s comment claimed it cancelled everything the screen started. It does not: preflight.Model.Init has a value receiver, so the first probe's cancel func dies with the call and only a pointer-receiver initialiser in that package can fix it. The comment now says so instead of vouching for a guarantee that isn't there. Smaller: the fits test measured the chat view for its own "all ready" case and asserted only a row count both views satisfy by self-truncating, so it could pass while dropping the content it existed to protect — every case now names what must survive at 80x24. A reconnect command that names a different provider than the mailbox it is for is flagged rather than presented under a title that vouches for it. ctrl+c out of the hand-off no longer leaves the view pointing at a torn-down model. And the fake transport's start/ensure counters are asserted: a blocked gate must start nothing, and `f` on a stopped sidecar must start it exactly once.
|
Verdict: Approve with suggestions. This wires the TUI readiness gate onto the launch path so a user can actually reach it, and the gate re-probes on every launch instead of trusting a cached pass — the right call, since the daemon token, the loaded model, and a mailbox grant can all go stale between launches. The abandoned-gate fix (a report now names its agent so a slow check for agent A can't green-light agent B) closes a real hand-off hole. The code is unusually careful: fail-loudly throughout, thorough tests (61 confirmation cases, 45 daemon-route cases, plus new Two things the maintainer should weigh before merge, neither a code defect:
Real-world evidence
🔍 Technical details🟡 Important — API/SSE gated tools now deny by default (behavior change) 🟢 Scope/description mismatch (process note, not code) No correctness defects found in the paths I read. Spot checks that held up:
Strengths
|
kovtcharov-amd
left a comment
There was a problem hiding this comment.
The gate additions are good, but the title/body claim "runs on every launch" and that isn't quite true yet.
RunAgent (tui/internal/ui/app.go) — the entry point for both gaia tui run <id> and gaia tui chat --agent <id> — bypasses the preflight gate for daemon-transport agents. The interactive branch builds chat.NewChatModel(...) directly and never constructs RootModel, so beginPreflight is never reached; gaia tui run email (email is TransportDaemon) opens a daemon-backed chat with no probe — the missing-model / disconnected-mailbox failure the gate exists to prevent still surfaces mid-conversation. (#2488 does gate the one-shot half.)
Fix: run the same probe headlessly inside RunAgent before building the chat model / running the one-shot, refusing on a blocker (surface the blocker to stderr + non-zero exit for the one-shot; render the gate for the interactive case), keeping the subprocess-transport carve-out beginPreflight already has. Alternatively, if gating these headless paths is out of scope here, retitle and correct the body so it stops claiming "every launch" — but since the one-shot branch reproduces the exact bug in the motivation, gating it is the honest fix.
The readiness gate was built, tested and merged — and nothing imported it, so no user could reach it. Pressing enter on an installed agent still went straight to chat, and the first sign of a missing model or a disconnected mailbox was a failed turn mid-conversation. The gate now sits on the launch path.
It runs on every launch and caches nothing: the daemon can be killed, its token rotates on restart, the model server can unload the model and a mailbox grant can be revoked from the web, so a remembered pass would open a chat that cannot answer while claiming it had been verified.
Review caught the launch this seam exists to prevent — backing out of a slow check and launching a second agent let the first agent's all-green report hand off and open a chat for an agent nothing had probed. Reports now name their agent and stale ones are dropped.
Test plan
cd tui && make lint && go test ./... -count=1 -race