Skip to content

feat(tui): run the readiness gate on every agent launch - #2487

Merged
kovtcharov-amd merged 3 commits into
claudia/task-a140d608from
claudia/task-d7cba3d9
Jul 27, 2026
Merged

kovtcharov-amd merged 3 commits into
claudia/task-a140d608from
claudia/task-d7cba3d9

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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
  • Launching an agent shows the gate, not chat; proceeding reaches chat; cancelling returns to a hub with a valid selection
  • Start a check, cancel, launch a different agent → the first agent's report cannot green-light the second
  • A failing precondition keeps the user on the gate with a runnable command

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.
@github-actions github-actions Bot added documentation Documentation changes devops DevOps/infrastructure changes mcp MCP integration changes cli CLI changes tests Test changes agents agent::email Email agent changes tui Go terminal UI (gaia-tui) daemon Daemon supervisor / sidecar control plane sidecar Agent sidecar contract / harness labels Jul 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 test_no_silent_fallbacks), and matching docs.

Two things the maintainer should weigh before merge, neither a code defect:

  • The confirmation change flips a default that affects gaia api and the API SSE stream, not just the TUI. Gated tools (shell, file writes, email send/delete) that used to auto-approve on those one-way streams now deny unless the operator sets GAIA_AUTO_APPROVE_TOOLS=1. That's the correct security posture and it's well documented — but it's a behavior change for anyone running unattended agents through the API today, so it deserves a release note.
  • Scope vs. title. The PR reads as "run the readiness gate on every launch," but the diff is ~32.7k lines spanning the whole TUI port, daemon hub install/uninstall, the confirmation overhaul, and a new MCP server. The description sells only the gate. If these are genuinely one shippable unit that's fine, but a reviewer can't tell that from the description alone.

Real-world evidence

⚠️ The automated evidence harness errored before producing anything (evidence-bundle.md: auth/install/rate-limit — the changed surface was not exercised). This PR touches exactly the surfaces the rubric wants shown live — a new TUI launch screen, new gaia hub list|install|uninstall CLI commands, and interactive confirmation prompts — and none of them were run here. This verdict rests on static review alone. Before merge, the test-plan items (the go test ./... -race run and the four manual launch/cancel/blocker walkthroughs) should be confirmed on a real terminal, and the eventual strix-halo lane should capture the gate screen. No fabricated evidence to relay.

🔍 Technical details

🟡 Important — API/SSE gated tools now deny by default (behavior change)
src/gaia/api/sse_handler.py:24 and the base OutputHandler.confirm_tool_execution (src/gaia/agents/base/console.py) change the default from auto-approve to deny. This is a deliberate #2210 security fix and is the right default, but it changes runtime behavior for gaia api / any host on the one-way SSE stream: previously-silent approvals now become {"status": "denied"} tool results unless GAIA_AUTO_APPROVE_TOOLS=1 is set. Not a blocker — flag it in the release notes / CHANGELOG so unattended-agent operators aren't surprised.

🟢 Scope/description mismatch (process note, not code)
The PR body describes only the gate-on-launch seam; the diff bundles the TUI daemon transport, hub install/uninstall (src/gaia/daemon/sidecars/install.py), the confirmation overhaul (src/gaia/agents/base/console.py), and src/gaia/mcp/servers/tui_mcp.py. If intentional, one grouped "this PR also lands…" list in the description would save the reviewer reconstructing scope from 153 files.

No correctness defects found in the paths I read. Spot checks that held up:

  • root/preflight.go:144 updatePreflight correctly discards a result whose Report().AgentID ≠ the pending agent, and the value-receiver Init caveat is documented rather than papered over.
  • install.py re-validates the agent-id slug against _ID_RE on every mutating entry (:232) before it becomes a path segment, and assert_no_live_process_in (:287) backstops the registry's pid-only liveness check before any dir rewrite — path-traversal and live-binary-swap are both closed.
  • Denial reasons are bound to the tool (_last_denial = (tool_name, reason)) and reset before each wait, so one tool's explanation can't leak into another's {"status":"denied"} result.

Strengths

  • Consistent fail-loudly discipline: every remedy names what/how/where, and test_no_silent_fallbacks.py pins it.
  • The deny-by-default consent model is carefully layered (TTY check on both stdin/stdout, unattended vs unaskable vs user-said-no messages, per-instance "always allow" sets that never leak across consoles), and format_confirmation_args tolerates malformed tool_args rather than crashing the one path meant to protect the user.
  • Docs kept in lockstep — cli.mdx documents the new gaia hub commands and the deny-by-default behavior alongside the code.

@kovtcharov
kovtcharov changed the base branch from main to claudia/task-a140d608 July 25, 2026 10:58

@kovtcharov-amd kovtcharov-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kovtcharov-amd
kovtcharov-amd merged commit 51b7588 into claudia/task-a140d608 Jul 27, 2026
76 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claudia/task-d7cba3d9 branch July 27, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes agents cli CLI changes daemon Daemon supervisor / sidecar control plane devops DevOps/infrastructure changes documentation Documentation changes mcp MCP integration changes sidecar Agent sidecar contract / harness tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants