mail_count: grouped message and unread counts under the mail_search filters #111

Closed
opened 2026-11-01 20:54:34 +00:00 by svc-agent-writer · 2 comments

This was generated by AI during triage.

Part of #106 (item 4). Decided at triage 2026-11-02: a separate mail_count tool, not a group_by parameter on mail_search.

Agent Brief

Category: enhancement
Summary: mail_count: message and unread counts grouped by sender, mailbox or triage class under the mail_search filters

Current behavior:
mail_mailboxes counts per mailbox, mail_people per sender and mail_triage per class, and none of them takes the mail_search filters. A question such as "unread this week, by sender" needs every matching row.

Desired behavior:
A new read-scope tool mail_count takes group_by (one of sender, mailbox, triage) and the same filter parameters as mail_search (account, mailbox, sender, since, before, unread, has_attachment, triage, attachment_flag, flag colour, and the full-text query), with no ranking parameters. It returns rows key | messages | unread, largest first, then a footer groups=N shown=M more=K. limit is 1 to 100, default 20, and a cursor pages the groups. A collapsed message counts once (#59). The mirror has no labels apart from mailboxes, and on JMAP a Fastmail label is a mailbox, so mailbox covers labels. The tool description says that keys are untrusted data.

Key interfaces:

  • SearchParams: reused for the filters; a grouped query in the store beside search, sharing the collapse and filter CTEs.
  • Tool registration: mail_count is in the read scope and in the test that lists the read tools.
  • The tool annotation set (read-only, idempotent) when that sub-issue has landed, or added here if it lands first.

Acceptance criteria:

  • mail_count(group_by="sender", unread=true, since=<7 days ago>) on the test store returns the senders with their unread counts, largest first.
  • A message mirrored into two accounts counts once in a sender grouping and once per mailbox in a mailbox grouping, matching #59.
  • A store with 150 distinct senders returns 20 rows, groups=150 shown=20 more=130, and the cursor reaches all 150 without repeats.
  • A full-text query restricts the counted set the same way it restricts mail_search.
  • A read token lists the tool; an evidence token does not.
  • make check passes.

Out of scope:

  • A group_by parameter on mail_search.
  • Grouping by date or by domain.
  • Label semantics beyond mailboxes.

Blocked by

  • #108 (the UTC since and before in SearchParams)
  • #112 (the role filter and case-insensitive mailbox names)

Filed under: operator word "accept" sha256:c125d0397b60

> *This was generated by AI during triage.* Part of #106 (item 4). Decided at triage 2026-11-02: a separate mail_count tool, not a group_by parameter on mail_search. ## Agent Brief **Category:** enhancement **Summary:** mail_count: message and unread counts grouped by sender, mailbox or triage class under the mail_search filters **Current behavior:** mail_mailboxes counts per mailbox, mail_people per sender and mail_triage per class, and none of them takes the mail_search filters. A question such as "unread this week, by sender" needs every matching row. **Desired behavior:** A new read-scope tool `mail_count` takes `group_by` (one of `sender`, `mailbox`, `triage`) and the same filter parameters as mail_search (account, mailbox, sender, since, before, unread, has_attachment, triage, attachment_flag, flag colour, and the full-text query), with no ranking parameters. It returns rows `key | messages | unread`, largest first, then a footer `groups=N shown=M more=K`. `limit` is 1 to 100, default 20, and a `cursor` pages the groups. A collapsed message counts once (#59). The mirror has no labels apart from mailboxes, and on JMAP a Fastmail label is a mailbox, so `mailbox` covers labels. The tool description says that keys are untrusted data. **Key interfaces:** - `SearchParams`: reused for the filters; a grouped query in the store beside `search`, sharing the collapse and filter CTEs. - Tool registration: `mail_count` is in the read scope and in the test that lists the read tools. - The tool annotation set (read-only, idempotent) when that sub-issue has landed, or added here if it lands first. **Acceptance criteria:** - [ ] `mail_count(group_by="sender", unread=true, since=<7 days ago>)` on the test store returns the senders with their unread counts, largest first. - [ ] A message mirrored into two accounts counts once in a sender grouping and once per mailbox in a mailbox grouping, matching #59. - [ ] A store with 150 distinct senders returns 20 rows, `groups=150 shown=20 more=130`, and the cursor reaches all 150 without repeats. - [ ] A full-text query restricts the counted set the same way it restricts mail_search. - [ ] A read token lists the tool; an evidence token does not. - [ ] `make check` passes. **Out of scope:** - A `group_by` parameter on mail_search. - Grouping by date or by domain. - Label semantics beyond mailboxes. ## Blocked by - #108 (the UTC `since` and `before` in `SearchParams`) - #112 (the `role` filter and case-insensitive mailbox names) Filed under: operator word "accept" sha256:c125d0397b60
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#111 mail-count-grouped-message-and-unread-counts-under-the-mail

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity standard · dispatch effort medium

Run: 20261102T122604Z-d3eea1ed

Held because: CLEAN but 4 open risk(s) (2 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. Mailbox group key and filter interaction. The lean: the key is account/mailbox (unambiguous, because account ids cannot contain '/', and it keeps 'once per mailbox' true when two accounts share a name like INBOX/Inbox); a mailbox filter restricts the groups to the names it matches; role filters messages but does not restrict their label groups. Question: accept this, or use bare mailbox names summed across accounts, and/or restrict groups to the role's own mailbox under role? [decision]
  2. Under a full-text query, mailbox grouping counts every filter-passing copy of a matched message, including a copy whose own text did not match. This mirrors mail_search's 'any copy may match the query' (store.py:1736). Question: accept, or count only copies whose own FTS row matched (SELECT id FROM hit)? [decision]
  3. The 'make check passes' scenario includes uvx pip-audit (network) and uv builds, so it was not run in the Half-A sandbox. Check: on the host, run make check on base 0068371 and then on the PR branch; it must exit 0, or show a failure set identical to base. [verification]
  4. The cost of an unscoped grouped count on a large mirror was not benchmarked. Check, if wanted after merge: time mail_count(group_by='sender') and group_by='mailbox' against the 210k-row synthetic store built by scripts/bench_search.py, and compare with mail_triage on the same store. [verification]

Change: Store: add GroupBy = Literal['sender','mailbox','triage'] and Store.count_groups(params, group_by) -> (page of (key, messages, unread), total groups) directly after triage_counts (store.py:1805-1817), mirroring its shown-row grouping. Reuse _filters/_collapse_ctes unchanged. For a query, follow search_page's _fts_candidates loop with the OperationalError fallback (store.py:1741-1800). Sender/triage group the shown rows (each message counts once, #59). Mailbox groups every filter-passing copy over json_each(COALESCE(mailboxes, json_array(mailbox))), with key account/mailbox and the mailbox filter restricting the groups. Order messages DESC, key ASC; take the total plus an OFFSET page as in Store.people (store.py:2005-2012). The SQL was prototyped in the Half-A sandbox against a temp store and gave the right results for two-account copies, JMAP labels, the FTS fallback and 151-sender paging. Server: a new READ_ONLY, SCOPE_READ tool mail_count after mail_search. Its filter params are copied verbatim from mail_search (server.py:320-354); it uses the offset cursor via _parse_cursor/_page as in mail_people, rows key | messages | unread escaped with _cell, and the footer next_cursor=X groups=N shown=M more=K in the mail_thread shape. Factor the unknown-mailbox warning (server.py:397-404) into a helper shared with mail_search, keeping its output byte-identical. Add mail_count to the exact read-tool lists in tests/test_server.py and tests/test_evidence.py, plus a README tool-table row.

Files: src/mail_mind_mcp/store.py · src/mail_mind_mcp/server.py · tests/test_mail_count.py · tests/test_server.py · tests/test_evidence.py · README.md

Decision: accept the 4 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-count-grouped-message-and-unread-counts-under-the-mail.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-count-grouped-message-and-unread-counts-under-the-mail.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#111 mail-count-grouped-message-and-unread-counts-under-the-mail **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `standard` · dispatch effort `medium` **Run:** `20261102T122604Z-d3eea1ed` **Held because:** CLEAN but 4 open risk(s) (2 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Mailbox group key and filter interaction. The lean: the key is account/mailbox (unambiguous, because account ids cannot contain '/', and it keeps 'once per mailbox' true when two accounts share a name like INBOX/Inbox); a mailbox filter restricts the groups to the names it matches; role filters messages but does not restrict their label groups. Question: accept this, or use bare mailbox names summed across accounts, and/or restrict groups to the role's own mailbox under role? [decision] 2. Under a full-text query, mailbox grouping counts every filter-passing copy of a matched message, including a copy whose own text did not match. This mirrors mail_search's 'any copy may match the query' (store.py:1736). Question: accept, or count only copies whose own FTS row matched (SELECT id FROM hit)? [decision] 3. The 'make check passes' scenario includes uvx pip-audit (network) and uv builds, so it was not run in the Half-A sandbox. Check: on the host, run `make check` on base 0068371 and then on the PR branch; it must exit 0, or show a failure set identical to base. [verification] 4. The cost of an unscoped grouped count on a large mirror was not benchmarked. Check, if wanted after merge: time mail_count(group_by='sender') and group_by='mailbox' against the 210k-row synthetic store built by scripts/bench_search.py, and compare with mail_triage on the same store. [verification] **Change:** Store: add GroupBy = Literal['sender','mailbox','triage'] and Store.count_groups(params, group_by) -> (page of (key, messages, unread), total groups) directly after triage_counts (store.py:1805-1817), mirroring its shown-row grouping. Reuse _filters/_collapse_ctes unchanged. For a query, follow search_page's _fts_candidates loop with the OperationalError fallback (store.py:1741-1800). Sender/triage group the shown rows (each message counts once, #59). Mailbox groups every filter-passing copy over json_each(COALESCE(mailboxes, json_array(mailbox))), with key account/mailbox and the mailbox filter restricting the groups. Order messages DESC, key ASC; take the total plus an OFFSET page as in Store.people (store.py:2005-2012). The SQL was prototyped in the Half-A sandbox against a temp store and gave the right results for two-account copies, JMAP labels, the FTS fallback and 151-sender paging. Server: a new READ_ONLY, SCOPE_READ tool mail_count after mail_search. Its filter params are copied verbatim from mail_search (server.py:320-354); it uses the offset cursor via _parse_cursor/_page as in mail_people, rows `key | messages | unread` escaped with _cell, and the footer `next_cursor=X groups=N shown=M more=K` in the mail_thread shape. Factor the unknown-mailbox warning (server.py:397-404) into a helper shared with mail_search, keeping its output byte-identical. Add mail_count to the exact read-tool lists in tests/test_server.py and tests/test_evidence.py, plus a README tool-table row. **Files:** `src/mail_mind_mcp/store.py` · `src/mail_mind_mcp/server.py` · `tests/test_mail_count.py` · `tests/test_server.py` · `tests/test_evidence.py` · `README.md` **Decision:** accept the 4 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-count-grouped-message-and-unread-counts-under-the-mail.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-count-grouped-message-and-unread-counts-under-the-mail.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#111 mail-count-grouped-message-and-unread-counts-under-the-mail completed integration verify.

  • PR: #145
  • Branch: feat/svd-dev-mail-mind-mcp-111-mail-count-grouped-message-and-b5813783
  • Commit: 93709193c8
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check forgejo commit statuses: absent
  • Checks: Remote: no commit statuses on 9370919 (absent, no CI in repo). Local: 964 passed, 8 skipped, 0 failed; ruff and mypy clean.
  • Warning: No remote CI statuses exist on the PR head; local verification is the only evidence.
  • Warning: I did not run the audit step of make check; I ran the full unit suite, ruff check, ruff format --check and mypy on src. The subagent reported the audit passed.
  • Warning: no CI for forgejo commit statuses: The PR head 9370919 has no commit statuses. The repo has no CI; CI files (.woodpecker/*) are added by the architect. — reported as absent, not blocking (gh#633)
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261102T123750Z-b5813783 --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#111 mail-count-grouped-message-and-unread-counts-under-the-mail completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/145 - Branch: feat/svd-dev-mail-mind-mcp-111-mail-count-grouped-message-and-b5813783 - Commit: 93709193c8630a9e15e506e5f5ede5e2970c74df - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check forgejo commit statuses: absent - Checks: Remote: no commit statuses on 9370919 (absent, no CI in repo). Local: 964 passed, 8 skipped, 0 failed; ruff and mypy clean. - Warning: No remote CI statuses exist on the PR head; local verification is the only evidence. - Warning: I did not run the audit step of make check; I ran the full unit suite, ruff check, ruff format --check and mypy on src. The subagent reported the audit passed. - Warning: no CI for forgejo commit statuses: The PR head 9370919 has no commit statuses. The repo has no CI; CI files (.woodpecker/*) are added by the architect. — reported as absent, not blocking (gh#633) - Decision: review the PR and merge? (`codex-svd ship --run-id 20261102T123750Z-b5813783 --confirm-merge`)
svc-svd-writer 2026-11-02 20:58:16 +00:00
  • closed this issue
  • removed the
    svd:go
    label
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/mail-mind-mcp#111
No description provided.