mail_changes envelope and mail_people: emit parseable addresses only #129

Closed
opened 2026-11-02 04:50:25 +00:00 by piers · 3 comments
Owner

Observation

dev/people-mind-mcp#39: on a 150,000-change mailbox, one mail_changes envelope row (envelope=true) carries an address cell whose normalised handle contains internal whitespace (the people-mind client lowercases and strips the ends, splits on ,, and rejects any remaining whitespace). Every other row of the page parsed. No value was logged; the finding is a count from a structure-only probe.

The consumer side is being made tolerant (#39 there). Question for this side: should the envelope columns emit only addresses that parse as local@domain with no whitespace, dropping or quoting the rest, so every consumer sees one shape? A header like "first last"@example or a display name leaking into the address field are the likely sources.

Fix candidate

In the envelope formatter, pass each address through the same parse the mirror uses for the people table and emit - for a cell with no parseable address. Document the rule in the mail_changes docstring.

Blocked by

None.

## Observation dev/people-mind-mcp#39: on a 150,000-change mailbox, one `mail_changes` envelope row (`envelope=true`) carries an address cell whose normalised handle contains internal whitespace (the people-mind client lowercases and strips the ends, splits on `,`, and rejects any remaining whitespace). Every other row of the page parsed. No value was logged; the finding is a count from a structure-only probe. The consumer side is being made tolerant (#39 there). Question for this side: should the envelope columns emit only addresses that parse as `local@domain` with no whitespace, dropping or quoting the rest, so every consumer sees one shape? A header like `"first last"@example` or a display name leaking into the address field are the likely sources. ## Fix candidate In the envelope formatter, pass each address through the same parse the mirror uses for the `people` table and emit `-` for a cell with no parseable address. Document the rule in the `mail_changes` docstring. ## Blocked by None.

This was generated by AI during triage.

Agent Brief

Category: bug
Summary: mail_changes envelope cells and mail_people rows emit only addresses that parse: an @ and no whitespace. Every other value is left out.

Current behavior:

Reproduced on main at 538ef5f.

  • The mail_changes envelope (envelope=true, ADR 0008 §3) emits the from cell as the stored from_addr, lowercased, with no check. A quoted local part ("first last"@example) is stored as first last@example, and that value reaches the cell. A group address with no host is stored with no @, and it reaches the cell too. For example, _envelope with from_addr="First Last@Example.test" gives first last@example.test, and from_addr="undisclosed-recipients" gives undisclosed-recipients.
  • The to and cc cells already apply the rule. evidence.addresses() drops any address that has whitespace or no @.
  • mail_people lists correspondents grouped on the raw messages.from_addr in Store.people(). It returns the same unparseable values as rows, and counts them in total.

People Mind rejects such a value (dev/people-mind-mcp#39).

Correction to the issue text: the mirror has no people table, and no parse runs for mail_people. The parse to reuse is the rule in evidence.addresses().

Desired behavior:

One rule for both tools: an address parses when it contains an @ and no whitespace. This is the rule evidence.addresses() already applies to To and Cc.

  • mail_changes with envelope=true: the from cell holds the lowercased address when it parses, and - when it does not. The to and cc cells do not change.
  • mail_people: a correspondent whose from_addr does not parse is not a row. Apply the filter in the Store.people() query, not after paging, so total, more and next_cursor stay consistent with the rows.
    • Stored from_addr values pass through sanitize_line, so the only whitespace they can hold is a space. To be safe, the SQL predicate also excludes tab, LF and CR.
  • The mail_changes and mail_people docstrings each state the rule in one short sentence.
  • The README rows for both tools state it too.

Key interfaces:

  • _envelope(row) in the server: the from cell goes through the parse rule.
  • evidence.addresses(stored): keep its behavior. If you add a one-address helper beside it (for example evidence.address(value) -> str | None), addresses() should use the same predicate, so that one rule exists.
  • Store.people(...): the WHERE clause gains the parse predicate beside m.from_addr != ''. The signature does not change.

Acceptance criteria:

  • An envelope test: an add row with from_addr first last@example.test emits - as its from cell, and a row with from_addr undisclosed-recipients emits -. A row with a normal address is unchanged.
  • The existing envelope tests still pass unchanged: test_envelope_cells_are_addresses_only and test_envelope_leaves_other_kinds_and_the_default_unchanged.
  • A Store.people() test: messages from a@example.test, first last@example.test and nohost give one row, a@example.test, and total == 1. A paging case confirms total counts only parseable rows.
  • The existing people tests still pass: test_people_pages_excludes_self_and_filters_the_tail, test_people_and_status and test_people_count_a_copy_once.
  • One test pins the Python rule and the SQL predicate to the same cases, so they cannot drift.
  • make check is green. Tests run as uv run python3 -m pytest.

Primary files (current paths; they may move):

  • src/mail_mind_mcp/server.py (_envelope, the mail_changes and mail_people docstrings)
  • src/mail_mind_mcp/evidence.py (only if you add a shared one-address helper)
  • src/mail_mind_mcp/store.py (Store.people)
  • tests/test_evidence.py
  • tests/test_store.py
  • README.md (the mail_changes and mail_people rows)

Out of scope:

  • Quoting or repairing an unparseable address. The cell is -, or there is no row.
  • Changing what ingest stores in from_addr, or any schema change or migration. Stored rows stay as they are.
  • mail_evidence. It takes an address as an argument, and an unparseable argument simply finds no evidence.
  • The owner-exclusion rules (exclude, exclude_sent, include_self), and any new field or tool. ADR 0008 needs no amendment, because §3 already says the cells hold addresses only.
  • Logging any address. Logs keep counts and codes only.
> *This was generated by AI during triage.* ## Agent Brief **Category:** bug **Summary:** `mail_changes` envelope cells and `mail_people` rows emit only addresses that parse: an `@` and no whitespace. Every other value is left out. **Current behavior:** Reproduced on `main` at `538ef5f`. - The `mail_changes` envelope (`envelope=true`, ADR 0008 §3) emits the **from** cell as the stored `from_addr`, lowercased, with no check. A quoted local part (`"first last"@example`) is stored as `first last@example`, and that value reaches the cell. A group address with no host is stored with no `@`, and it reaches the cell too. For example, `_envelope` with `from_addr="First Last@Example.test"` gives `first last@example.test`, and `from_addr="undisclosed-recipients"` gives `undisclosed-recipients`. - The **to** and **cc** cells already apply the rule. `evidence.addresses()` drops any address that has whitespace or no `@`. - `mail_people` lists correspondents grouped on the raw `messages.from_addr` in `Store.people()`. It returns the same unparseable values as rows, and counts them in `total`. People Mind rejects such a value (dev/people-mind-mcp#39). Correction to the issue text: the mirror has no `people` table, and no parse runs for `mail_people`. The parse to reuse is the rule in `evidence.addresses()`. **Desired behavior:** One rule for both tools: an address parses when it contains an `@` and no whitespace. This is the rule `evidence.addresses()` already applies to To and Cc. - `mail_changes` with `envelope=true`: the from cell holds the lowercased address when it parses, and `-` when it does not. The to and cc cells do not change. - `mail_people`: a correspondent whose `from_addr` does not parse is not a row. Apply the filter in the `Store.people()` query, not after paging, so `total`, `more` and `next_cursor` stay consistent with the rows. - Stored `from_addr` values pass through `sanitize_line`, so the only whitespace they can hold is a space. To be safe, the SQL predicate also excludes tab, LF and CR. - The `mail_changes` and `mail_people` docstrings each state the rule in one short sentence. - The README rows for both tools state it too. **Key interfaces:** - `_envelope(row)` in the server: the from cell goes through the parse rule. - `evidence.addresses(stored)`: keep its behavior. If you add a one-address helper beside it (for example `evidence.address(value) -> str | None`), `addresses()` should use the same predicate, so that one rule exists. - `Store.people(...)`: the WHERE clause gains the parse predicate beside `m.from_addr != ''`. The signature does not change. **Acceptance criteria:** - [ ] An envelope test: an `add` row with `from_addr` `first last@example.test` emits `-` as its from cell, and a row with `from_addr` `undisclosed-recipients` emits `-`. A row with a normal address is unchanged. - [ ] The existing envelope tests still pass unchanged: `test_envelope_cells_are_addresses_only` and `test_envelope_leaves_other_kinds_and_the_default_unchanged`. - [ ] A `Store.people()` test: messages from `a@example.test`, `first last@example.test` and `nohost` give one row, `a@example.test`, and `total == 1`. A paging case confirms `total` counts only parseable rows. - [ ] The existing people tests still pass: `test_people_pages_excludes_self_and_filters_the_tail`, `test_people_and_status` and `test_people_count_a_copy_once`. - [ ] One test pins the Python rule and the SQL predicate to the same cases, so they cannot drift. - [ ] `make check` is green. Tests run as `uv run python3 -m pytest`. **Primary files (current paths; they may move):** - `src/mail_mind_mcp/server.py` (`_envelope`, the `mail_changes` and `mail_people` docstrings) - `src/mail_mind_mcp/evidence.py` (only if you add a shared one-address helper) - `src/mail_mind_mcp/store.py` (`Store.people`) - `tests/test_evidence.py` - `tests/test_store.py` - `README.md` (the `mail_changes` and `mail_people` rows) **Out of scope:** - Quoting or repairing an unparseable address. The cell is `-`, or there is no row. - Changing what ingest stores in `from_addr`, or any schema change or migration. Stored rows stay as they are. - `mail_evidence`. It takes an address as an argument, and an unparseable argument simply finds no evidence. - The owner-exclusion rules (`exclude`, `exclude_sent`, `include_self`), and any new field or tool. ADR 0008 needs no amendment, because §3 already says the cells hold addresses only. - Logging any address. Logs keep counts and codes only.
svc-agent-writer changed title from mail_changes envelope: an address cell can contain internal whitespace; emit parseable addresses only to mail_changes envelope and mail_people: emit parseable addresses only 2026-11-02 05:02:56 +00:00
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#129 mail-changes-envelope-and-mail-people-emit-parseable-address

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: 20261102T050631Z-c903172d

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

Open risks:

  1. make check was not run at spec time. Its audit step needs network access (uvx pip-audit), and uv is absent in the Half-A sandbox. Check: on the host, on the PR branch, run make check. lint, type, test and audit must all exit 0, and the test pass set must equal the pre-change set plus the new tests. [verification]
  2. The consumer-side outcome can be shown only after merge and deploy. Check: re-run the dev/people-mind-mcp#39 structure-only probe over a full mail_changes envelope page (and mail_people) against the deployed instance. It must count zero cells whose handle has internal whitespace or no '@'. [verification]

Change: evidence.py: add address(value) -> str | None above addresses() (evidence.py:148). It returns the lowercased value when the value has an '@' and no whitespace (str.isspace). Rewrite the addresses() loop to use it, with no behaviour change. server.py: in _envelope (server.py:511), the from cell becomes evidence.address(row.from_addr) or "", so the existing cell or "-" path emits -. Add one sentence each to the mail_changes docstring (lines 484-486) and the mail_people docstring (lines 593-595), keeping "untrusted". store.py: add a module-level SQL helper _address_parses(column), mirroring _same_message/_copy_key at store.py:257-286. It is instr '@' > 0 AND NOT (space, char(9), char(10) or char(13)). Append it to where in Store.people (store.py:1843), so the COUNT(*) total and the paged rows share the filter. Update README.md rows 49-50 by one clause each. No schema, ingest, mail_evidence or ADR change.

Files: src/mail_mind_mcp/evidence.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/store.py · tests/test_evidence.py · tests/test_store.py · README.md

Decision: accept the 2 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-changes-envelope-and-mail-people-emit-parseable-address.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-changes-envelope-and-mail-people-emit-parseable-address.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#129 mail-changes-envelope-and-mail-people-emit-parseable-address **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:** `20261102T050631Z-c903172d` **Held because:** CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. `make check` was not run at spec time. Its audit step needs network access (uvx pip-audit), and uv is absent in the Half-A sandbox. Check: on the host, on the PR branch, run `make check`. lint, type, test and audit must all exit 0, and the test pass set must equal the pre-change set plus the new tests. [verification] 2. The consumer-side outcome can be shown only after merge and deploy. Check: re-run the dev/people-mind-mcp#39 structure-only probe over a full mail_changes envelope page (and mail_people) against the deployed instance. It must count zero cells whose handle has internal whitespace or no '@'. [verification] **Change:** evidence.py: add `address(value) -> str | None` above `addresses()` (evidence.py:148). It returns the lowercased value when the value has an '@' and no whitespace (str.isspace). Rewrite the `addresses()` loop to use it, with no behaviour change. server.py: in `_envelope` (server.py:511), the from cell becomes `evidence.address(row.from_addr) or ""`, so the existing `cell or "-"` path emits `-`. Add one sentence each to the mail_changes docstring (lines 484-486) and the mail_people docstring (lines 593-595), keeping "untrusted". store.py: add a module-level SQL helper `_address_parses(column)`, mirroring `_same_message`/`_copy_key` at store.py:257-286. It is instr '@' > 0 AND NOT (space, char(9), char(10) or char(13)). Append it to `where` in `Store.people` (store.py:1843), so the COUNT(*) total and the paged rows share the filter. Update README.md rows 49-50 by one clause each. No schema, ingest, mail_evidence or ADR change. **Files:** `src/mail_mind_mcp/evidence.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/store.py` · `tests/test_evidence.py` · `tests/test_store.py` · `README.md` **Decision:** accept the 2 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-changes-envelope-and-mail-people-emit-parseable-address.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mail-changes-envelope-and-mail-people-emit-parseable-address.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#129 mail-changes-envelope-and-mail-people-emit-parseable-address completed integration verify.

  • PR: #130
  • Branch: feat/svd-dev-mail-mind-mcp-129-mail-changes-envelope-and-mail-c29c2a3f
  • Commit: 2c58e39581
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check forgejo-commit-statuses: absent
  • Checks: PR #130 at 2c58e39: no Forgejo commit statuses (no CI configured, absent). Local make check green (ruff, mypy, 813 passed, pip-audit clean).
  • Warning: No remote CI exists for dev/mail-mind-mcp; local make check is the only gate.
  • Warning: Open risk 2 (post-deploy dev/people-mind-mcp#39 probe) remains an operator check after release.
  • Warning: no CI for forgejo-commit-statuses: No commit statuses on PR head 2c58e39 and the repo has no CI config (CLAUDE.md: CI files are added by the architect); no run in history. — reported as absent, not blocking (gh#633)
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261102T052155Z-c29c2a3f --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#129 mail-changes-envelope-and-mail-people-emit-parseable-address completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/130 - Branch: feat/svd-dev-mail-mind-mcp-129-mail-changes-envelope-and-mail-c29c2a3f - Commit: 2c58e39581e99ae611b032f706f0b12bdc43ab03 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check forgejo-commit-statuses: absent - Checks: PR #130 at 2c58e39: no Forgejo commit statuses (no CI configured, absent). Local make check green (ruff, mypy, 813 passed, pip-audit clean). - Warning: No remote CI exists for dev/mail-mind-mcp; local make check is the only gate. - Warning: Open risk 2 (post-deploy dev/people-mind-mcp#39 probe) remains an operator check after release. - Warning: no CI for forgejo-commit-statuses: No commit statuses on PR head 2c58e39 and the repo has no CI config (CLAUDE.md: CI files are added by the architect); no run in history. — reported as absent, not blocking (gh#633) - Decision: review the PR and merge? (`codex-svd ship --run-id 20261102T052155Z-c29c2a3f --confirm-merge`)
svc-svd-writer 2026-11-02 05:28:42 +00:00
  • closed this issue
  • removed the
    svd:go
    label
Sign in to join this conversation.
No milestone
No project
No assignees
3 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#129
No description provided.