Skip to content

feat(mcp): maild computes the conversations waiting on a reply - #83

Merged
bketelsen merged 1 commit into
mainfrom
agent-pim/waiting
Oct 19, 2026
Merged

bketelsen merged 1 commit into
mainfrom
agent-pim/waiting

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

Plan 0012's Phase 3 (M8.5, ADR-0042). maild, not the model, picks the conversations waiting on a reply.

This PR is based on #82 and contains its commit (18795a6), so merge #82 first. This PR's own commit is 33e3e87.

What changes

thread.awaitingReply (callers local, session and agent): conversations waiting on the user. The newest message decides, leaving out drafts and messages only in Drafts, Trash or Junk. That message must:

  • be from someone other than its account's identities;
  • have one of those identities in To; Cc alone does not count;
  • have no List-Id and no List-Unsubscribe, and not come from a no-reply local part (noreply, no-reply, donotreply, do-not-reply, mailer-daemon or postmaster, compared without case);
  • not be \Answered, muted or from a blocked sender;
  • be in an inbox (Gmail's INBOX label counts);
  • be dated at least waitingDays and less than withinDays days before now.

The limits:

  • limit: 1 to 25, default 5;
  • waitingDays: 0 to 30, default 0;
  • withinDays: 1 to 90, default 30.

thread.awaitingOthers: the user's own newest message, to someone who isn't any account's identity, not muted, in the same window. limit defaults to 10 and waitingDays to 5.

Both:

  • put VIPs first (the sender, or any recipient in To or Cc), then the newest;
  • answer total before limit, with up to 10 recipients and their count;
  • keep an agent to its scope.

Also:

  • store.NewestMessages finds each thread's newest eligible message in one window-bounded query;
  • mailctl waiting [--others];
  • MCP tools threads_awaiting_reply and threads_awaiting_others, each taking time_zone for its dates;
  • docs: the spec's tool rows, the Methods and callers table, and plan 0012's Phase 3 status, with the timing below as evidence.

Tests

  • internal/engine/awaiting_test.go:
    • a thread that breaks only one rule, for each rule;
    • the boundaries: exactly 30 days is left out, 29 days 23 hours 59 minutes is kept, and exactly waitingDays is kept;
    • an alias identity, and a Gmail account for the INBOX label versus All Mail only;
    • VIP order, total against limit, and 10 versus 11 recipients;
    • an agent's scope;
    • each param at both ends of its range and one past each.
  • internal/lodge/mcp_waiting_test.go: both tools through kittest and the SDK client, Berlin dates, and every limit at and past its value.
  • cmd/mailctl/waiting_test.go.

Timing

On tools/uifixture -n 50000 -seed 7 (Strix Halo), 20 runs after one warm-up, limit 25, waitingDays 0:

withinDays awaitingReply p95 (matches) awaitingOthers p95
30 41.5 ms (1,647) 28.8 ms
90 66.4 ms (7,439) 65.4 ms

Two notes on the fixture:

  • mailgen writes no sent mail, so nothing matches awaitingOthers, but it scans the same window.
  • mailgen addresses [email protected], so the fixture account was given that identity.

Gates

make check, make build-windows and make ui-check (nsl) pass. The app's only change is in generated types.

🤖 Generated with Claude Code

Plan 0012's Phase 3 (ADR-0042). thread.awaitingReply answers the
threads waiting on the user: the newest message, past drafts and what is
only in Drafts, Trash or Junk, is from someone else to one of its
account's identities in To, from no list or no-reply sender, not
answered, muted or blocked, and in an inbox. thread.awaitingOthers
answers the user's own mail with no reply since. Both put VIPs first,
then the newest, take a window of days, and keep an agent to its scope.

store.NewestMessages finds each thread's newest eligible message in one
query over the window. mailctl waiting prints both. /mcp/mail gains
threads_awaiting_reply and threads_awaiting_others, with time_zone for
their dates.

A test per rule and boundary, a Gmail INBOX label among them; the tools
and their limits through kittest and the SDK client. On 50,000 mailgen
messages each method answers in p95 under 70 ms at 90 days.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bketelsen
bketelsen merged commit 35538da into main Oct 19, 2026
6 checks passed
@bketelsen
bketelsen deleted the agent-pim/waiting branch October 19, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant