mail_search(mailbox=...) scans every row on 0.10.3: #112 acceptance fails on a large store #142
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#142
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?
What happened
On 0.10.3,
mail_search(mailbox=...)scans every message row. On a live store of about 249,000 messages and 34 mailboxes,mail_search(mailbox='inbox', limit=20)took 47 to 62 seconds in each of four runs.mail_search(role='inbox', limit=20)took 1.5 to 3.5 seconds in the same runs.#112 asked for the
mailboxfilter to take about as long as therolefilter. It does not, so #112's acceptance fails on a large store. A caller that filters bymailboxnow waits close to a 60-second client timeout.Cause
#137 (
28839b9) changed themailboxfilter instore.pyto this:casefoldis a Python function registered withcreate_function. No index can servecasefold(m.mailbox), so SQLite calls the Python function, plusjson_each, once per row. In 0.10.1 the filter comparedm.mailboxdirectly.The
rolefilter stays fast, because it joinsmailboxeson(account, name).Possible direction (not decided)
Fold the requested name against the small
mailboxestable first;mailbox_names()already reads it. Then filtermessageswithm.mailbox IN (<exact names>), which an index can serve. Keep thejson_eacharm only for rows from sources with stable ids. A test can assert the query plan uses an index formailbox=.Evidence
sha256:f9cbf180…b6f9, schema v13.apicontainer on the local endpoint while the sync worker ran. Times are wall-clock per call.mailbox=inbox: 62.28, 51.46, 46.94 and 47.25 s.role=inbox: 3.53, 1.68, 1.52 and 1.51 s.Acceptance criteria
mail_search(mailbox=...)resolves the requested name case-insensitively against themailboxestable first and filtersmessageswith an indexable predicate (m.mailbox IN (<exact names>)), keeping ajson_each(m.mailboxes)arm only where a row carries several mailboxes.mail_search(mailbox='inbox')andmail_search(role='inbox')run within the same order of magnitude (or asserts the query plan uses the mailbox index); at the base the plan is a full scan with the per-rowcasefoldcall.tests/test_store.pystays green.Filed under: operator word "ready-for-agent" sha256:7990aa64d598
Triaged 2026-11-03 (backlog wave 5, batch T-C2). Route:
ready-for-agent(CONV-40 rule 2:src/mail_mind_mcp/store.pyplustests/test_store.py, direction given, red side measured in the body).Premise re-verified at main after v0.10.5:
store.py:1615–1621still filters withcasefold({alias}.mailbox) = ? OR EXISTS (SELECT 1 FROM json_each({alias}.mailboxes) …), the per-row Python call this issue measured; the 2026-11-02 commits onstore.py(#137, #139, #140, #143, #145) did not change it. Body hygiene: acceptance criteria,Filed under:line.Filed under: operator word "ready-for-agent" sha256:7990aa64d598
⏸ SVD architect gate: dev/mail-mind-mcp#142 mail-search-mailbox-scans-every-row-on-0-10-3-112-acceptance
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
substrate· dispatch efforthighRun:
20261103T005914Z-373020a9Held because: CLEAN but 5 open risk(s) (3 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
4d90734: 11 files, 8 of them one-line 14->15 test literals, and the api waits until the index exists)? Or without a bump (store.py, test_mailbox_search.py, test_store.py, README.md only; routes standard/medium; but a short post-deploy window where the api runs the new query before the writer builds the index, during which the multi-mailbox arm table-scans and is slower than base)? [decision]873e646did. Never drop the assertion; the casefold-count assertion is version-independent. [verification]uv run python3 -m pytest -q -m "not integration"on the pristine base and again after the change; the failure set must be unchanged apart from the two new passing tests. [verification]Change: Replace the mailbox term in Store._filters (store.py:1615-1621) with three arms. (1) The raw exact name: m.mailbox = ?. (2) (m.account, m.mailbox) IN (_FOLDED_MAILBOXES), where _FOLDED_MAILBOXES = SELECT x.account, x.name FROM mailboxes x WHERE casefold(x.name) = ?. (3) m.id IN (_SEVERAL_MAILBOXES), where _SEVERAL_MAILBOXES = SELECT y.id FROM messages y, json_each(y.mailboxes) j WHERE json_array_length(y.mailboxes) > 1 AND casefold(j.value) = ?. Prefix every arm with + when keyset=True. Define both constants in the _SELF_SENDERS shape (store.py:459-463), using the uncorrelated row-value IN pattern at store.py:2051-2053. Add CREATE INDEX IF NOT EXISTS messages_memberships ON messages (mailboxes) WHERE json_array_length(mailboxes) > 1 to _V5_INDEXES (store.py:2438-2443), not _TABLES. Bump SCHEMA_VERSION to 15, following #139
4d90734. Change the 14 literals to 15 across 8 test files, add DROP INDEX messages_memberships at tests/test_store.py:411, and add a v15 sentence to README.md:105 and :278. Leave count_groups' join (1849-1852) and server._unknown_mailbox unchanged. Add two tests to tests/test_mailbox_search.py: a 50k-row test asserting the plan and the casefold call count, and a v14->v15 reader-waits test. The prototype was verified in the sandbox: base 65,090 casefold calls with a SCAN m plan; fix 210 calls with covering-index plans; 0.019s vs role 0.016s on 50k rows with 6 KB bodies.Files:
src/mail_mind_mcp/store.py·tests/test_mailbox_search.py·tests/test_store.py·tests/test_embed_scans.py·tests/test_copy_collapse.py·tests/test_recipients.py·tests/test_evidence.py·tests/test_attachment_vectors.py·tests/test_utc_dates.py·tests/test_attachments.py·README.mdDecision: accept the 5 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-03-mail-search-mailbox-scans-every-row-on-0-10-3-112-acceptance.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-03-mail-search-mailbox-scans-every-row-on-0-10-3-112-acceptance.mdsvc-svd-writer referenced this issue2026-11-03 02:13:08 +00:00
spec-verify-dispatch Half B for dev/mail-mind-mcp#142 mail-search-mailbox-scans-every-row-on-0-10-3-112-acceptance completed integration verify.
f866448b93f866448: ci/woodpecker/pr/validation pending. Local full suite 1060 passed, 8 skipped; filtered suites 450 passed; ruff and mypy clean. One blocker: PR body says Closes #142, must be Refs.Closes #142toRefs #142; the spec forbidsClosesbecause the operator closes #142 after live timing on the 249k-row store.Closes #142toRefs #142; the spec forbidsClosesbecause the operator closes #142 after live timing on the 249k-row store.; no denial signature; evidence: PR #154 body: "Closes #142"; spec Agent Adjustments: "The PR refers to #142 withRefs, neverCloses"Closes #142toRefs #142; the spec forbidsClosesbecause the operator closes #142 after live timing on the 249k-row store.; edit the PR title or body by hand, then re-run integrate or run the own-execution gate.Live verification passed (gate risk 3). The fix shipped in #154 (
f83345a) and is in every release from v0.10.6.mailmind-pierson starbase-syd, image 0.12.1 (sha256:fce38287…1264), schema v17,messages_membershipspresent, 249,117 messages.mail_search(..., limit=20)calls per filter over the local endpoint in the api container, with the sync worker running. Times are wall-clock per call.mailbox='inbox'role='inbox'On 0.10.3 the mailbox filter took 46.94 to 62.28 s. It now falls in the same range as the role filter, so #112's acceptance holds on a large store. The first mailbox run is a cold cache.
Closing.