Collapse cross-account copies and join threads across accounts #59
Labels
No labels
bug
enhancement
epic
needs-info
needs-triage
ready-for-agent
ready-for-human
svd:go
svd:hold
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/mail-mind-mcp#59
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
One instance can mirror several accounts, and one query searches all of them. Two gaps show when an owner combines accounts, for example iCloud forwarding to Fastmail, or Cc to two of their own addresses:
mail_searchin every mode, andmail_peoplecounts it once per account. Inside one account,similar_toalready leaves out copies by Message-ID.thread_keyandthread_linksare scoped per account, somail_threadshows only the members in the opened message's account. A conversation that spans two accounts splits in two.Proposal (decide at triage)
mail_search: whenaccountis omitted, show one row per Message-ID: the first by account order in the config. Addcopies=Nto the snippet line when N > 1. Anaccountfilter shows that account's rows as today.mail_people: count distinct Message-IDs, not rows.mail_thread: add the members of other accounts that share a Message-ID, In-Reply-To or References with the thread, each row showing its account.thread_keystays per account, so the write path and the store's per-account threading do not change.Acceptance
mail_search.mail_threadon either copy returns the members of both accounts.Agent Brief
Category: enhancement
Summary: Show one row per message across mailboxes and accounts, by a spoof-resistant collapse key, and join a thread with its copies in other accounts.
Operator rulings (2026-11-01). Where this brief differs from the issue body, the brief holds.
Dateheader, not the internal date, which differs per account.accountfilter. The issue's acceptance bullet "existing single-account behaviour does not change" now reads: row formats do not change; only duplicate rows go.inbox-role mailbox, else the lowest row id. The config's account order is not used.Already decided, so no work is needed: a consent check across accounts. ADR 0003 §8 records consent per instance, and an instance is one owner (README, "One instance per person").
Current behavior:
mail_searchreturns one row per mirrored row in every mode: keyword, semantic, hybrid andsimilar_to. A message held in two accounts, or in two mailboxes of one IMAP account, shows twice, andtotalcounts it twice.similar_toleaves out copies of its source only inside the source's account (Store.copies).mail_peoplecounts rows, so a copy counts twice.mail_evidencecomputesreceived,first,lastandrolesthe same way (ADR 0008 §2: "as mail_people computes them"), and its subject list deduplicates by Message-ID alone.mail_threadreturns only the members in the opened message's account:thread_keyandthread_linksare per account.Desired behavior:
mail_search, every mode. One row per collapse key.total,moreand the cursor count collapsed messages. When a message has N > 1 copies, its snippet line ends withcopies=N. A row with no snippet gets the linecopies=N.similar_to. It leaves out every copy of the source, in every account, by the collapse key.mail_people. It counts distinct messages: one per collapse key, and one per row that has no key.mail_evidence. It followsmail_peopleforreceived,first,lastandroles, and itssentcount follows too. Therolesbucket is the role of the row shown. The subject list deduplicates by the collapse key. ADR 0008 §2 already says "as mail_people computes them", so no ADR change is needed.mail_thread.thread_keystays per account. The write tools, the outbox and every source are unchanged. Ids stay as they are: the id shown is the id of the row shown.Key interfaces:
Store.search,Store.keyword_rankedand the semantic candidate query return collapsed results. A SQLite window function partitioned by the key is one way to do it.Store.copies(row)becomes cross-account and uses the collapse key.Store.peopleandStore.evidencecount by the key.Store.threadgains the cross-account join, or a new method does it formail_thread.Acceptance criteria:
mail_searchshows it once in keyword, semantic and hybrid modes.totalcounts it once, and its snippet line endscopies=2.mail_searchshows it once, with and withoutaccount.copiescell.inbox-role copy when there is one, else the lowest row id.similar_toon one copy leaves out the copies in every account.mail_threadon either copy returns the members of both accounts, each message once, each row ending with its account id. A one-account thread is byte-for-byte unchanged.mail_peopleandmail_evidencecount a collapsed message once.tests/test_source.pypasses: no mail-server call in the server.Out of scope:
thread_key,thread_links, the write path or the sources.⏸ SVD architect gate: dev/imap-mailmind-mcp#59 collapse-cross-account-copies-and-join-threads-across-accoun
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 effortmediumRun:
20261101T062159Z-0d1379d5Held because: CLEAN but 6 open risk(s) (2 verification · 4 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
3af5d34, before the first edit, runuv run python3 -m pytest -q -m "not integration"and record the pass/fail set. After the change, the failure set must be identical and the only additions must be tests/test_copies.py tests, all passing. [verification]Change: Spell the #59 collapse key once in store.py, next to _SELF_SENDERS (store.py:341-347). Add three helpers:
datetime() is needed because format_timestamp keeps each Date header's offset. Verified this session: datetime('...+10:00') equals datetime('...+00:00') for the same instant.
Add CREATE INDEX IF NOT EXISTS messages_copies (message_id, from_addr) to _TABLES, with no SCHEMA_VERSION bump.
Give _filters (store.py:1175-1220) an alias parameter. Add _shown_id(params): a COALESCE'd correlated subquery that picks the representative among the copies that pass the filters.
SearchParams readers:
Hybrid fuse() (semantic.py:45-51) therefore sees one id per message.
MessageRow gains a trailing copies: int = 1. copies() becomes cross-account by the key.
Counting readers:
A new Store.joined_thread(row) does one hop. It takes the own thread, the (account, thread_key) of other-account rows that are copies of members, then the union collapsed by the predicate. Store.thread stays unchanged.
In server.py, _row_line (130-141) gains account=False, which appends the account as the last cell, and a ' copies=N' or ' copies=N' snippet suffix. mail_thread uses joined_thread and sets account=spans. _ranked passes copies_within. Docstrings change.
README rows 18, 19 and 46 change. The new tests/test_copies.py mirrors the fixture and direct-call pattern of tests/test_evidence.py:36-82 and the embedder monkeypatch of tests/test_semantic.py:34-53.
Files:
src/imap_mailmind_mcp/store.py·src/imap_mailmind_mcp/server.py·README.md·tests/test_copies.pyDecision: accept the 6 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):svd:go— approve; Half-B dispatch accepts exactly this spec (open risks accepted)svd:firebesidesvd:go— approve AND authorise the Half-B fire from the phone; never on its ownsvd:skip— park it; dispatch refuses it and the issue stays for a humansvd:respec— discard this spec; the next Half-A run re-produces it with this record as prior-attempt contextSpec:
/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-collapse-cross-account-copies-and-join-threads-across-accoun.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-01-collapse-cross-account-copies-and-join-threads-across-accoun.mdspec-verify-dispatch Half B for dev/imap-mailmind-mcp#59 collapse-cross-account-copies-and-join-threads-across-accoun completed integration verify.
ed83b73a8fed83b73(absent, non-blocking). Local: 333 passed, 4 skipped, 18 deselected; ruff clean; mypy strict clean on src.ed83b73(API returned []); repo CI files (.woodpecker) are added by the architect, not tracked here. — reported as absent, not blocking (gh#633)codex-svd ship --run-id 20261101T071142Z-2fbf221e --confirm-merge)