Skip to content

docs(plans): email agent in the Agent UI — frozen sidecar + user/dev modes - #1882

Merged
kovtcharov-amd merged 4 commits into
mainfrom
docs/email-sidecar-ui-plan
Jun 29, 2026
Merged

kovtcharov-amd merged 4 commits into
mainfrom
docs/email-sidecar-ui-plan

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Why this matters

Improving the email agent and getting the fix into the Agent UI today means a freeze → `npm publish` → version-bump → re-integrate loop — slow, and a wall of patches just to test a change. This plan removes that loop and lets the UI triage personal Gmail through two modes over one shared REST contract:

  • User mode runs the exact frozen sidecar published to the Agent Hub (pinned via `binaries.lock.json`), lazily downloaded on first email use — so the Agent UI validates the shipped product, keeps the core install lightweight (no email deps), and gets crash isolation.
  • Dev mode runs the same contract from local Python source via `uvicorn --reload` — edit a `.py` and the next chat action hits new code, no freeze/publish/patch.

Both read the same `~/.gaia` Google grant, so personal Gmail works identically in each; the mode only swaps which process answers the calls.

This PR is docs-only — the implementation plan, for review before any code lands. It went through an independent architecture review and was corrected twice: the original draft wrongly assumed the renderer calls a REST sidecar (it's actually chat-loop + SSE cards, in-process today), and it has to be sequenced behind the in-flight REST capability build-out (inbox pre-scan + #1779/#1780/#1781) since the sidecar contract is triage/draft/send-only right now.

Decision needed before build

This pivots from epic #1767's in-process-mount decision (whose capstone PR #1785 was closed unmerged 2026-06-26). Needs maintainer + @itomek sign-off to supersede it, plus confirmation to remove the redundant in-process `/v1/email` mount (#1768).

Test plan

Plan for triaging personal Gmail through the Agent UI with two
interchangeable sidecar backends behind one fixed REST seam: a frozen
npm binary for users and a hot-reloading uvicorn-from-source server for
developers. Both run the same agent code against the same local Google
grant, so personal email works identically in each and improving the
agent is a one-file edit with no freeze/publish/patch loop.
@kovtcharov
kovtcharov requested review from itomek and itomek-amd June 26, 2026 22:56
@kovtcharov kovtcharov self-assigned this Jun 26, 2026
@github-actions github-actions Bot added the documentation Documentation changes label Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve ✅

This is a docs-only PR adding one design plan for running the email agent inside the Agent UI as an out-of-process sidecar, with a user mode (frozen npm binary) and a dev mode (uvicorn --reload from source) behind one fixed REST URL. The plan is well-grounded: I spot-checked its key claims against the real code and they all hold up — the server.py structure, the npm lifecycle helpers, the connector functions, the port reservations, and the hot-reload gotcha are all accurate. Safe to merge as a planning doc; the only thing worth tightening is one slightly-overstated word in the components table (the renderer email client is net-new, not "existing").

🔍 Technical details

Claims verified against the tree (all accurate):

  • build_app() exists at module scope and __main__ calls uvicorn.run(app, …) — so the plan's central observation that the existing entrypoint can't hot-reload, and dev mode must use the import-string CLI form, is correct (hub/agents/python/email/packaging/server.py:45,104).
  • Port 8131 default and the "NOT 4001 (reserved)" reservation match the package's own comments (server.py:40-41, smoke_test.py:43).
  • npm lifecycle helpers exist as named: fetchBinary, binaryExists, resolveBinaryPath, BinaryNotFoundError, Windows taskkill /T /F tree-kill (hub/agents/npm/agent-email/src/{fetch,lifecycle}.ts).
  • Connector functions exist: get_credential_sync (src/gaia/connectors/handler.py:173), list_inbox/triage_inbox/pre_scan_inbox (gaia_agent_email/tools/read_tools.py).
  • EmailSidecarManager at src/gaia/apps/webui/services/email-sidecar-manager.cjs is correctly marked NEW — no such file today, and it mirrors the existing agent-process-manager.cjs pattern.

🟢 Minor — "existing UI services" overstates the renderer side (docs/plans/email-sidecar-agent-ui.md:54). The components table lists the renderer email client under "existing UI services," and the Key-insight section frames EmailClient as already speaking HTTP to 8131. There's no /v1/email client or EmailClient in src/gaia/apps/webui/src/ yet — the renderer integration is net-new. Worth a word tweak so a reader doesn't go looking for code that isn't there; e.g. "renderer email client (new — modeled on existing UI services)". Non-blocking.

Strengths:

  • Genuinely grounded in the code — the plan names real symbols/paths/ports and they check out, which is rare for a design doc and makes it reviewable.
  • Strong fail-loud discipline throughout (no fallback dev→user, loud BinaryNotFoundError/HealthTimeoutError, no silent port reselection), matching the CLAUDE.md no-silent-fallbacks rule.
  • Correctly diagnoses the uvicorn.run(app, …) non-reloadable trap and routes around it with the import-string CLI form — no server.py change needed.
  • Testing section calls for a real round-trip and a cold-start gaia.connectors bundling check (empty-state, not a warm box), aligned with the repo's "test from the user's real initial state" guidance.

The first draft assumed the renderer calls a fixed /v1/email REST URL and
that an Electron-main sidecar manager would host it. Code review found the
UI surfaces email through the chat agent loop + SSE cards (the frontend has
no email REST client), and the agent already runs in-process in the Python
backend reading ~/.gaia/connectors/grants.json.

Reframe: the seam is the chat agent's email-tool layer and the host is the
Python UI backend (no Node backend needed). Both modes proxy over the same
HTTP path to a sidecar on :8131 — frozen binary for users, uvicorn --reload
from source for devs — keeping process isolation identical across modes and
preserving the existing SSE card pipeline.
Fold in the two product requirements and resolve every open item from the
architecture review:

- Dogfooding: user mode runs the exact Hub-published frozen binary (pinned via
  binaries.lock.json), so the Agent UI validates the shipped product. This is the
  rationale the sidecar earns over an editable in-process install.
- Lightweight UI: the sidecar is lazy-fetched on first email use, one platform
  binary only; core ships no email deps.
- Resolve open questions: use a proxy AGENT reusing agent_type=email machinery;
  remove the redundant in-process /v1/email mount (#1768) so the UI has one backend.
- Review fixes: own the dev-mode enabler (module-level app = build_app()), reuse the
  npm fetch SHA/lock integrity check instead of porting it to Python, ephemeral
  per-instance port (no fixed-8131 multi-instance clash), single-writer grant model
  (OAuth stays on backend; sidecar reads only), exact current-contract table.
- Sequence behind the in-flight REST build-out (pre-scan + #1779/#1780/#1781) and
  flag the #1767 in-process decision must be superseded with @itomek sign-off.
@kovtcharov kovtcharov changed the title docs(plans): email agent in the Agent UI — dual user/dev sidecar modes docs(plans): email agent in the Agent UI — frozen sidecar + user/dev modes Jun 26, 2026
…tion)

itomek closed #1767/#1785 because mixing an npm package requiring Node.js into the
Python-backed Agent UI is too dirty. Remove that entirely: the Python backend fetches
the binary itself (verified SHA-256 download, no npx), spawns it, and proxies over
HTTP. No Node runtime, no npm package in the UI's path. The npm package remains the
external Node-integrator channel only.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Tracking epic for the implementation: #1896 (parked until the supersede sign-off lands; blocked by the REST build-out #1778–#1781).

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Jun 29, 2026
Merged via the queue into main with commit 7a82ed9 Jun 29, 2026
28 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the docs/email-sidecar-ui-plan branch June 29, 2026 17:23
itomek-amd pushed a commit that referenced this pull request Jun 30, 2026
Before: the Agent UI could only run the email agent in-process,
importing the heavy
email deps into core — the exact Node-free objection that closed epic
#1767. After:
the Python backend runs the email agent as an out-of-process **sidecar**
it fetches
(verified), spawns, health-checks, proxies to, and tree-kills directly —
no Node.js,
no npm on the runtime path. User mode runs the published frozen binary
(SHA-256
verified against `binaries.lock.json`); dev mode runs the same REST
contract from
local source with hot reload, so prompt/tool edits show up live without
a
freeze → publish loop.

This is **additive and gated** behind `GAIA_EMAIL_AGENT_MODE` (`user`
default /
`dev`): the existing in-process path is untouched until the supersede
decision
(#1767) lands, so nothing breaks today. Routes that don't exist yet
(inbox pre-scan,
search #1781, archive/quarantine #1779, calendar #1780) are gated in the
proxy with a
loud, issue-named error — never silently faked.

Implements the approved design in `docs/plans/email-sidecar-agent-ui.md`
(#1882);
step-by-step plan + hardening addendum in
`docs/plans/email-sidecar-agent-ui-implementation.md`.

> **Depends on #1882** (the design doc). This branch builds on those
plan commits;
> they'll resolve once #1882 merges.

### What's complete (this PR)
A bulletproof, fully-tested standalone sidecar capability ready to wire:
- **Verified fetch** — SHA-256 gate (tamper → refuse),
`~/.gaia/agents/email/` cache,
  placeholder-refuse, atomic write.
- **Lifecycle** — ephemeral port (never 4001), spawn (user binary / dev
`uvicorn server:app --app-dir …`), health-poll with **service-identity**
check,
process-group tree-kill, `atexit` orphan reaping, **port-race retry**,
concurrency
lock (one sidecar under concurrent first-use), `/version` contract
handshake.
- **Proxy** — forwards triage/draft/send/health/version unchanged;
preserves the
sidecar's actionable error detail via `SidecarHTTPError`; gates the
not-yet-built
  routes.
- **No pipe deadlock** — sidecar output goes to a pruned per-port log
file, not an
  undrained PIPE.
- **Integration seam** — `EmailSidecarManager.proxy()` + context-manager
lifecycle.

### One design correction (verified live)
The design's `uvicorn packaging.server:app` does not resolve — the email
package's
`packaging/` dir collides with the PyPI `packaging` library, and adding
`packaging/__init__.py` would shadow `packaging.version` for every
dependency. Dev
mode instead loads the file as the top-level module `server` via
`uvicorn server:app --app-dir hub/agents/python/email/packaging`.

## Test plan
- [x] `python -m pytest tests/unit/test_email_sidecar_*.py` — 58 tests,
incl. **live
dev-mode spawn/health/tree-kill** and a **live real-LLM triage
round-trip**
through the manager-owned proxy against the frozen contract (skips
cleanly
      without the email wheel / Lemonade).
- [x] `python -m pytest
tests/unit/agents/email/test_connector_routes.py` — no
      regression from the new module-level `app`.
- [x] `python util/lint.py --all` — passes.
- [x] Manual dev mode: `uv pip install -e hub/agents/python/email` then
      `GAIA_EMAIL_AGENT_MODE=dev gaia chat --ui`.

## Gated / deferred (by design)
- Not wired into live `agent_type=email` sessions; in-process
`/v1/email` mount kept —
  until @itomek/maintainer sign-off on superseding #1767.
- Inbox pre-scan / search (#1781) / archive-quarantine (#1779) /
calendar (#1780)
REST routes are owned by other tasks; this PR only consumes/gates them.
- User-mode binary fetch refuses loudly while `binaries.lock.json`
carries `PENDING`
SHAs; the cold-start keyring + dogfood checks unlock once the publish
pipeline
  populates real SHAs.

---------

Co-authored-by: Tomasz Iniewicz <[email protected]>
Co-authored-by: Tomasz Iniewicz <[email protected]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jul 2, 2026
…cess /v1/email) (amd#1910)

## Why this matters

Before this PR the Agent UI's email surface was split and the heavy
email agent ran inside the UI process: the `/v1/email/*` REST routes
were served by an **in-process mount of the email wheel by default**
(only by the sidecar when `GAIA_EMAIL_AGENT_MODE` was set), and the
in-app email chat agent (`agent_type=email`) loaded live Gmail/Outlook
backends, an action DB, and a memory store **into the UI backend**.
After this PR the out-of-process **sidecar is the sole, default backend
for both surfaces**. The core UI backend no longer imports the email
wheel — it stays lightweight, crash-isolated, and **dogfoods the exact
schema-2.1 product third-party integrators consume**.

This is the deferred cutover from epic amd#1767, on the foundations from
amd#1884 and the now-complete REST 2.1 contract from amd#1883 (design: amd#1882).

### What changed (three threads a reviewer should evaluate
independently)

- **Proxy ungated → full contract.** `EmailSidecarProxy` now forwards
the full schema-2.1 surface (prescan, search, archive/unarchive,
quarantine/unquarantine, confirm, batch triage, calendar
view/preview/create/respond) returning the sidecar's envelopes
unchanged. The UI router exposes the full contract, so removing the
in-process mount does **not** shrink the external `/v1/email` surface.
- **Sidecar is the sole + default `/v1/email` surface.** The in-process
`gaia_agent_email.api_routes` mount is removed from the UI server; unset
`GAIA_EMAIL_AGENT_MODE` now defaults to **user mode** (frozen binary,
lazy-fetched + SHA-verified). No in-process fallback — a
missing/unpublished binary fails loudly with a remedy. (The separate
`gaia api` / `openai_server` mount is intentionally out of scope.)
- **`agent_type=email` flipped to the sidecar.** New `EmailProxyAgent`
keeps the local-LLM tool loop in the UI backend, but every tool is a
thin HTTP call to the sidecar. `pre_scan_inbox` returns the
**identical** `email_pre_scan` envelope so the triage card renders
unchanged. Its tool surface is the subset the REST contract serves today
(inbox pre-scan, search, calendar view, archive + undo); the unmapped
in-process tools
(labels/stars/move/trash/delete/summarize/profile/preferences/forward/send)
are not exposed in chat until their REST routes land — the agent product
still implements them, they're just not reachable over the contract yet.

## Test plan

- [x] `python -m pytest tests/unit/test_email_sidecar_*.py` — 91 pass
(proxy, router, server-wiring, manager, fetch, platform, devmode-app,
**new** proxy-agent).
- [x] `python util/lint.py --black --isort --flake8` — all pass.
- [x] Chat-path regression: `pytest
tests/unit/test_session_mail_provider.py tests/unit/test_agents_split.py
tests/unit/test_chat_preflight.py tests/unit/chat/ui/test_server.py` —
141 pass.
- [x] **End-to-end card property (no Gmail):** the proxy agent's real
`pre_scan_inbox` output, fed through the real `SSEOutputHandler`,
injects an `email_pre_scan` render payload (test
`test_pre_scan_envelope_triggers_real_sse_card_injection`).
- [x] **Live dev-mode round-trip:** spawned the dev sidecar
(`apiVersion=2.1 agentVersion=0.3.0`), drove the proxy agent's real
`pre_scan_inbox`/`search_messages` tools against live `/prescan` and
`/search`; with no mailbox connected they fail loudly with the sidecar's
verbatim "No mailbox connected…" detail (full chain: proxy agent →
shared manager → sidecar → REST → fail-loud passthrough). Clean
tree-kill on shutdown.
- [x] `create_app()` with `GAIA_EMAIL_AGENT_MODE` unset → manager mode
`user`, full contract routes mounted, no in-process mount.

To exercise locally with a connected Gmail:
```bash
uv pip install -e hub/agents/python/email
GAIA_EMAIL_AGENT_MODE=dev gaia chat --ui   # email session → "what's in my inbox" → pre-scan card via the sidecar
```

### Notes for the reviewer
- **Eval:** no `gaia eval agent` run — the change touches neither the
in-core ChatAgent prompts nor the wheel's `EmailTriageAgent`; the eval
harness targets the wheel agent (unchanged), and there is no eval path
for the new `EmailProxyAgent`. Its behavior is covered by the
integration + live tests above.
- **Reduced chat tool surface** is a deliberate, maintainer-approved
product decision (sidecar-mapped tools only) — backwards compat for
*other* Agent-UI agents (chat/code/browser/…) is untouched.
- **Follow-up:** the registry gate still requires the email wheel for
the `email` id to resolve, so a no-wheel install can use the REST
surface but not the chat agent. Decoupling that (registering proxy-agent
metadata without the wheel) is a separate change.
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.

3 participants