Skip to content

feat(tui): show what needs you when you open the email agent - #2599

Merged
itomek-amd merged 5 commits into
tmi/2580-attention-intfrom
tmi/issue-2582-attention-view
Jul 29, 2026
Merged

itomek-amd merged 5 commits into
tmi/2580-attention-intfrom
tmi/issue-2582-attention-view

Conversation

@itomek

@itomek itomek commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Closes #2582

Everything else in this epic is plumbing. The agent can now work out what needs you — a colleague waiting on a reply, a proposed meeting, an unreviewed message, an open action item — and until this PR there was nowhere for any of it to appear. grep -ril briefing tui/ returned zero; the TUI is chat plus an agent catalog, with no home surface at all. You still had to open a chat and ask, which is the thing #2580 set out to remove. Now opening the email agent renders what needs you, unprompted.

The design constraint that shaped this came from a live measurement, not a guess. The obvious implementation is to render the pre-scan envelope. That would have been wrong: the envelope carries per-message rows only for urgent, actionable, suggested_archives and needs_review, while informational — 98 of 100 messages on a real mailbox — collapses to a bare count. A meeting proposal in confidently-informational mail would have been computed and then silently dropped at the envelope boundary. The aggregator therefore calls triage_inbox_impl and detect_waiting_on_you_impl directly, and there is a test for exactly that case.

The honesty rules are the substance here, not polish. This surface is the last place the epic's founding bug could reappear, so: the empty state states what was actually scanned and admits truncation rather than claiming the mailbox is clear; a cached result always shows its age, and the server's stale flag upgrades that to a failed-refresh warning; a partial mailbox failure surfaces the connector error instead of rendering a short list as complete; and a malformed payload degrades to a visible invalid card rather than collapsing into the honest empty state, where it would be indistinguishable from a genuinely quiet inbox.

Test plan

  • python -m pytest tests/unit/agents/email/ hub/agents/email/python/tests/ — 1747 passed
  • cd tui && go build ./... && go vet ./... && go test ./... — all packages ok, including the integration suite
  • python util/lint.py --all — clean
  • Constraint-2 case: a meeting proposal inside a confidently-informational message still reaches the view — test_meeting_in_confidently_informational_message_is_surfaced
  • Go render paths: populated, honest-empty, stale, fresh-cache, partial-failure, section-cap, malformed payload
  • Renders on open with no prompt, and does not race an initial query — TestFetchAttentionOnOpenForEmailAgentWithNoInitialQuery
  • Live TUI evidence — screenshots of the populated, honest-empty and disconnected-mailbox states, plus an id-set diff proving zero mutation. Not yet run; tracked as the remaining gate.
A stated deviation from the acceptance criteria

The issue's checklist names the merged signals as "briefing, action items, meeting requests, and the inbound waiting-on-you detector". This ships four item kinds: meeting_request, waiting_on_you, needs_review, action_item — needs_review in place of a distinct briefing headline.

That is deliberate. The briefing is its own surface (#2525, already merged) and reproducing its summary here would be a second summary of the same data; the coverage line already carries the honest denominator. needs_review — messages the classifier was not confident about, from #2584 — is genuinely something that needs you and had nowhere to appear. Recording it as a decision rather than letting a superset read as full compliance.

Notes for the reviewer

itomek added 5 commits July 28, 2026 17:24
Adds the frozen request/response models for the read-only "what needs
you" attention view (#2582): AttentionItemKind, AttentionItem,
AttentionCoverage, EmailAttentionResult, EmailAttentionResponse.

Additive bump over 2.7 -- no existing shape changes. The coverage
fields mirror #2584's pre-scan honesty fields (scanned, total_unread,
scan_truncated, degraded, mailbox_errors) so the eventual renderer can
state what was actually covered, and cache_age_seconds/stale ensure a
cached result is never presented as current.
Adds build_attention_view_impl, which merges the four attention
signals -- waiting-on-you, meeting proposals, needs-review, and open
action items -- by calling triage_inbox_impl and
detect_waiting_on_you_impl directly, never the pre-scan envelope.
EmailPreScanResult.informational_count is a bare count with no rows,
so a meeting proposal in a confidently-classified informational
message would be silently invisible if this view depended on it
instead.

Extracts the needs_review routing rule out of pre_scan_inbox_impl into
a shared needs_review_decision() so the aggregator and the pre-scan
envelope can never silently diverge on which messages count as
needs-review.

Also documents in EmailAttentionResult that an empty items list is not
itself a "nothing needs you" claim -- a consumer must read coverage
first, mirroring the #2584 lesson one layer down.
Adds the REST surface for the attention-view read-model: computed on
open, cached for ATTENTION_CACHE_TTL_SECONDS (120s), with a stale
fallback to the last known-good result when a refresh fails and every
connected mailbox is unreachable. A cold cache with no prior success
propagates the connector error instead, matching /prescan's existing
403/502/503 handling.

Moves the whole contract set together, per the #2584 precedent on this
base branch: CONTRACT.md prose + version-history row, the regenerated
openapi.email.json and specification.html, the npm TypeScript mirror,
and the capability matrix (23 REST functional verbs, up from 22).

Also fixes an unused local (`confident`) left behind by the earlier
needs_review_decision extraction.
Adds RenderEmailAttention, decoding the GET /v1/email/attention
envelope into a card with a section per signal (meeting proposals,
waiting on you, needs review, action items).

Honesty rules carried into the renderer, not just the contract:
- The empty state states what was actually scanned, and admits
  truncation when the scan hit its ceiling -- never an unqualified
  whole-mailbox claim (the #2584 lesson, one layer up).
- A populated card also gets a coverage footer for the same reason.
- cache_age_seconds > 0 always shows an age note (cached results are
  normal here); the server's own `stale` flag upgrades that to a
  stronger "last refresh attempt failed" warning.
- A partial mailbox failure reuses the pre-scan card's warning banner,
  extracted into a shared renderMailboxErrorBanner so the two cards
  can't drift on this wording.

null/{} and a mismatched `kind` degrade to a visible invalid-card
fallback rather than silently rendering as the honest empty state.
Wires the email agent's chat screen to GET the attention view with no
user prompt, the moment it opens (and only then -- a launch with an
initial query never races the fetch against the answer the user is
actually waiting on).

client.AttentionFetcher is the daemon-relayed SSEClient's
GET /v1/<agent>/attention -- an optional-capability interface, same
pattern as AgentResponder, so a subprocess-mode client (no HTTP relay
to ask) is skipped rather than treated as a fetch error.

A failed fetch (no mailbox connected, daemon unreachable) surfaces as
a RoleStatus note, not a turn-ending RoleError -- this is a best-effort
side-channel read, never a requirement for the chat surface to work.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agent::email Email agent changes tui Go terminal UI (gaia-tui) sidecar Agent sidecar contract / harness labels Jul 28, 2026
@itomek

itomek commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Evidence

Live TUI run on a Linux box against the real Gmail mailbox (527 unread at start). Sidecar confirmed serving this branch — api: v2.8 with its source path inside the test clone — so the stale-build trap (#2588) did not fire. TUI driven under tmux via the loopback control API: resize first, full-screen captures, and the API's wait rather than sleeping.

Text frames are the definitive record. The box is headless with no ANSI-to-image renderer available, so there are no PNGs. Senders and subjects are redacted to shapes; the raw captures contain real mail and are deliberately not published.

1. Populated — rendered on open, unprompted

┌─ Attention · 100 scanned ────────────────────────────────────────
│   MEETING PROPOSALS                                          1  │
│   1  <sender-1>              <subject-1>                        │
│      looks like it's proposing a meeting or a time to talk      │
│                                                                  │
│   ACTION ITEMS                                                6  │
│   1  (action item)  <subject-2> — due by Friday                  │
│   2–6 (action item)  <subject-3..6>                              │
│                                                                  │
│   100 of 527 unread scanned (of the 100 most recent — older      │
│   mail may exist).                                                │
└────────────────────────────────────────────────────────────────┘

No user action taken. The coverage footer is the point: it says what it looked at rather than implying it looked at everything.

2. Honest empty

┌─ Attention · 1 scanned ──────────────────────────────────────────
│   Nothing needs you.                                             │
│   1 of 528 unread scanned (of the 1 most recent — older mail     │
│   may exist)                                                      │
└────────────────────────────────────────────────────────────────┘

This is the state that matters most, and it behaves: "Nothing needs you" arrives qualified by exactly what was covered — 1 of 528 — so it can never be mistaken for a clear inbox. A live mailbox with persistent action history never empties naturally, so the state was induced by requesting a 1-message window against a fresh local state DB, using the real credentials. Method stated rather than the state faked.

3. Disconnected mailbox

Two honest surfaces, both captured. A preflight gate before entering chat:

[!]   Mailbox             not connected
      Email Triage cannot do anything until it can read a mailbox...
      f connect a mailbox · r re-check · d details · enter start anyway · esc back

and, on choosing to continue anyway, the view itself:

[!] attention view unavailable: the daemon relay refused the 'email' attention
    view (HTTP 503: No mailbox connected — connect Google or Microsoft in
    Settings → Connectors before viewing the attention view.)

The error is surfaced with a remedy. A partial list is never rendered as if complete.

Mailbox integrity

  • STARRED: byte-identical before and after — same md5 (9a2d…aca51), 4 of 4 items unchanged.
  • INBOX / UNREAD: 99 of 100 ids common, exactly one dropped and one new — one message arrived during the ~20-minute window, and the capped 100-item view shifts accordingly.

No archive, label, star, read/unread, delete, draft or send occurred at any point. Reported as measured rather than rounded to "no change".

@itomek
itomek marked this pull request as ready for review July 29, 2026 13:01
@itomek
itomek requested a review from kovtcharov-amd as a code owner July 29, 2026 13:01

@itomek-amd itomek-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.

Approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek itomek self-assigned this Jul 29, 2026

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-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.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd
itomek-amd merged commit e3b3ed4 into tmi/2580-attention-int Jul 29, 2026
21 checks passed
@itomek-amd
itomek-amd deleted the tmi/issue-2582-attention-view branch July 29, 2026 14:29
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jul 29, 2026
…nto main (amd#2604)

Closes amd#2581
Closes amd#2582

Recovers two pieces of the amd#2580 epic that never reached `main`.

**What happened.** amd#2582's attention view was reviewed and merged as PR
amd#2599 — but into `tmi/2580-attention-int`, a temporary integration
branch, rather than into `main`. It reads as MERGED on the PR list, so
it looked shipped; it wasn't. That branch also carried amd#2581's
waiting-on-you detector, whose own PR (amd#2593) was left open and
conflicting. This brings both to `main` together, updated against
everything that has landed since.

**Nothing here is new work.** Every line was already reviewed and passed
a live-mailbox testing gate as amd#2593 and amd#2599 — including three rounds
of adversarial verification on the detector's precision, and TUI
captures of the populated, honest-empty and disconnected-mailbox states.
This is a re-delivery of stranded work, not a fresh change.

Together these complete the epic: the agent works out what needs you,
and the TUI shows it on open, unprompted.

## Test plan

- [ ] `python -m pytest tests/unit/agents/email/ tests/unit/email/
hub/agents/email/python/tests/ tests/test_email_openapi_conformance.py
tests/unit/agents/test_email_agent.py` — 2176 passed
- [ ] `python util/lint.py --all` — all blocking gates pass
- [ ] `cd tui && go build ./... && go vet ./... && go test ./...` —
clean
- [ ] Tool count is **64**, derived by regenerating the capability
matrix and independently by hand; both agree
- [ ] Schema version is **2.8** with amd#2589's 2.7 content intact —
verified, not assumed
- [ ] `needs_review` routing and `is_meeting_request` still work
*together* — `test_meeting_item_carries_flag_through_pre_scan`

<details>
<summary>Merge notes — what was resolved and how</summary>

Twelve files conflicted. Generated artifacts (`CAPABILITY_MATRIX.md`,
`openapi.email.json`, `specification.html`) were **regenerated** and
then diffed against the hand-resolution to confirm agreement, rather
than hand-merged. The rest were resolved to the combined state — never
`--ours`/`--theirs`.

Two things worth a reviewer's eye:

- **`read_tools.py`** combined this branch's shared
`needs_review_decision()` extraction with main's inline routing, which
encoded the same rule. Git's auto-merge left a dead local and a
duplicated import behind — non-conflicting but wrong — both removed.
- **`contract.py` / `CONTRACT.md` / `read_tools.py`** came out
byte-identical to the pre-merge tip, because this branch had already
written its own `is_meeting_request` field independently before main's
version landed.

</details>

<details>
<summary>Three stale tests fixed, one of them carefully</summary>

**`test_signal_firing_subset_is_25_rows` → 19.** That 25 was the
denominator behind three rounds of adversarial precision work on the
detector, so it was not updated on faith. The pre-amd#2589 heuristic was
reconstructed as a standalone module and diffed across all 104
promotional corpus rows: **exactly 6 rows dropped, 0 newly fired.** All
six matched `meeting noun 'call' with concrete time` before and `without
a concrete time or invite` after — the "ACTION REQUIRED … expires 4PM"
marketing template (`1677f2af`, `28226131`, `5f720d3d`, `9c0cdaf3`,
`c7a9b9eb`, `d964ff4d`). None involved the direct-ask signals. This is
amd#2589's proximity rule working as designed. The provenance is recorded
in the module comment, and the historical 25 / 15-of-15 / 24-of-25
figures in the surrounding commentary are deliberately left intact —
they document a real prior verifier run at that denominator.

**`GET /v1/email/attention` had no conformance test** — added, following
the existing `/briefing` and `/search` patterns, plus the
503-without-mailbox case.

**`list_waiting_on_you` was missing from `EXPECTED_TOOLS`** — added.

</details>

<details>
<summary>Known limitations, carried forward unchanged</summary>

From amd#2581, documented in the module docstring rather than only in
review: marketing sent *into* a thread you have genuinely corresponded
in can still qualify as awaiting your reply, roughly one time in four.
The thread history is real, so corroboration cannot reject it; only a
message-level promotional judgement could, and the existing one is
label-driven and near-inert on unlabelled mail. Tightening corroboration
further costs recall on genuine correspondence. Shipped knowingly.

Also unchanged: the module trusts the backend-supplied `From` header on
prior messages with no authentication check. Real spoofing defences sit
upstream at the provider.

**Separately observed, not fixed here:**
`tests/test_email_openapi_conformance.py` sits outside the `tests/unit/`
network guard, so on a machine with a live Lemonade server a real
embedding call succeeds and poisons a process-global cache, making 5
memory tools register in a later test. Confirmed pre-existing and
environment-dependent by pointing `LEMONADE_BASE_URL` at an unreachable
host — the failure vanishes. Same family as amd#2600.

</details>
kovtcharov-amd pushed a commit that referenced this pull request Sep 5, 2026
`on.pull_request.branches` matches the PR's BASE branch, not its head, so
`branches: [ main ]` meant "only when merging into main". Every PR stacked on
a feature branch fell outside the filter and the jobs were never created —
nothing failed, nothing showed as skipped, the checks page was simply missing
them. #2599 merged email-agent changes with zero email tests, zero unit tests
and zero lint behind a green page.

Drops the filter from the 34 workflows that carried it. `paths:` filters and
`push:` triggers are untouched, so a workflow still only runs for the code it
covers and still only runs on main for pushes.

`util/check_workflow_triggers.py` (wired into `lint.py --all`) fails the build
if the filter comes back; lint.yml now watches `.github/workflows/**` so a
workflows-only PR actually runs that gate.
kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Sep 12, 2026
…md#3372)

Before: a pull request based on any branch other than `main` ran no unit
tests, no lint and no agent suites, and its checks page looked healthy
the whole time — nothing failed, nothing showed as skipped, the jobs
simply never existed. amd#2599 merged email-agent changes that way, with
zero email tests, zero unit tests and zero lint behind a green page.
After: those workflows run on every pull request regardless of base, so
a stacked PR is held to the same bar as one opened against `main`. This
matters right now because 42 open PRs are sitting on CI results that
can't be trusted until it lands.

The cause is that `on.pull_request.branches` matches the PR's **base**
branch, not its head, so `branches: [ main ]` meant "only when merging
into main". 34 workflows carried it, including `lint`, `test_unit`,
`test_security` and `dependency-review`.

Nothing is left main-only. Scoping stays where it belongs — every
`paths:` filter is preserved byte-for-byte, so a workflow still only
runs for the code it covers, and the 5 workflows whose `branches:`
filter sits under `push:` are untouched, since restricting *pushes* to
`main` is correct. A PR into the `release` branch would now run CI too;
that is the desired behaviour and costs nothing today, because `release`
is force-pushed from a tag by `update-release-branch.yml` and has never
once been a PR target. Excluding it would just recreate this bug for the
first backport anyone opens.

To stop it regressing, `util/check_workflow_triggers.py` fails the build
if the filter reappears, and `lint.yml` now watches
`.github/workflows/**` so a workflows-only PR actually runs that gate —
without it the guard would itself be invisible on the change most likely
to trip it.

Fixes amd#2767

## Test plan

- [x] Stacked-PR A/B on a throwaway base branch, same touched file in
both arms. Control (no fix, amd#3303): 10 checks, none of them lint, unit
or email. Treatment (this fix, amd#3304): 56 checks including `Run Code
Quality Checks`, `Unit Tests`, `Test Email Agent`, `Skill Audit` and
`Dependency Review`. Both were drafts, so every job then short-circuited
on its existing `draft == false` guard — the point is that the check
runs exist at all, which in the control they do not.
- [x] `python util/check_workflow_triggers.py` passes on all 72
workflows, and fails with the file name and issue number when the filter
is reintroduced.
- [x] `python -m pytest tests/unit/test_check_workflow_triggers.py` — 12
passed.
- [x] `python util/lint.py` — black, isort, flake8, security
suppressions, agent conventions, dependabot, workflow triggers, doc
versions all pass. (Pylint reports 9 pre-existing
`os.killpg`/`os.geteuid` no-member errors on untouched files; those are
Windows-only false positives and CI runs Linux.)
- [x] Every touched workflow re-parsed with `yaml.safe_load`; confirmed
all 35 `push:` triggers are still scoped to `main` and no `paths:`
filter changed.

Co-authored-by: Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes documentation Documentation 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