Serve the Mail peer change feed and peer info #160

Closed
opened 2026-11-03 07:27:21 +00:00 by svc-agent-writer · 2 comments

Outcome

Peers can read Mail's v1 change feed directly: mail_peer_info reports identity, the supported profile and the implemented operations, and mail_peer_changes_v1 serves bounded, signed-cursor pages from the unit 1 log. Unit 2 of the epic #152.

Decision substrate

ADR 0012 (rules 9–11, 13, 14), ADR 0010, the contract kit contracts/mind-v1/ (README, schema.json, requests.schema.json, fixtures, recovery.md), and ADR 0008. The grill record is on #152.

Scope and acceptance criteria

  1. mail_peer_info({}) returns the exact profile mail-people/1.0, source_id, epoch, retention_seconds, and the operations it implements: evidence and changes. It never advertises snapshot.
  2. mail_peer_changes_v1 with the exact negotiated request and output schemas, published with their full $defs; evidence scope and the existing rate-limit bucket; a structured error sets isError=true.
  3. scope_id is the salted hash of source, epoch, contract and the account selection (ADR 0012 rule 9). HMAC-SHA256 cursors bound to source, epoch, scope, contract and position; a token from another scope, epoch or key returns invalid_cursor; a position below the floor returns cursor_expired, never an empty success.
  4. Pages: limit 1–100, default 100; a finite high-water mark captured per page as through; strictly increasing sequences at most through; has_more=true only with a nonempty page and a new continuation; an empty page may advance across irrelevant events. An index on peer_events(account, seq) serves single-account scopes. The 1 MiB response cap and per-record caps return record_too_large without advancing the cursor.
  5. ADR 0008 tool-list amendment for both tools without widening payload authority. P08 (legacy text bytes and permissions unchanged; evidence, read and write tokens; no bodies, Bcc or attachment data), P09 (oversize, malformed cursor, wrong contract) and the reader half of P05 (below-floor cursor, quiet or filtered account, no busy loop).
  6. The contract wire suite and fixtures pass against the served tools. I02 feed-page budget from ADR 0012 rule 14 measured and reported. make check passes.

Non-goals

mail_peer_snapshot_v1, advertising snapshot, writer or schema changes beyond the index, People consumer changes, release or deploy.

Blocked by

## Outcome Peers can read Mail's v1 change feed directly: `mail_peer_info` reports identity, the supported profile and the implemented operations, and `mail_peer_changes_v1` serves bounded, signed-cursor pages from the unit 1 log. Unit 2 of the epic #152. ## Decision substrate ADR 0012 (rules 9–11, 13, 14), ADR 0010, the contract kit `contracts/mind-v1/` (README, `schema.json`, `requests.schema.json`, fixtures, `recovery.md`), and ADR 0008. The grill record is on #152. ## Scope and acceptance criteria 1. `mail_peer_info({})` returns the exact profile `mail-people/1.0`, `source_id`, epoch, `retention_seconds`, and the operations it implements: `evidence` and `changes`. It never advertises `snapshot`. 2. `mail_peer_changes_v1` with the exact negotiated request and output schemas, published with their full `$defs`; evidence scope and the existing rate-limit bucket; a structured error sets `isError=true`. 3. `scope_id` is the salted hash of source, epoch, contract and the account selection (ADR 0012 rule 9). HMAC-SHA256 cursors bound to source, epoch, scope, contract and position; a token from another scope, epoch or key returns `invalid_cursor`; a position below the floor returns `cursor_expired`, never an empty success. 4. Pages: `limit` 1–100, default 100; a finite high-water mark captured per page as `through`; strictly increasing sequences at most `through`; `has_more=true` only with a nonempty page and a new continuation; an empty page may advance across irrelevant events. An index on `peer_events(account, seq)` serves single-account scopes. The 1 MiB response cap and per-record caps return `record_too_large` without advancing the cursor. 5. ADR 0008 tool-list amendment for both tools without widening payload authority. P08 (legacy text bytes and permissions unchanged; evidence, read and write tokens; no bodies, Bcc or attachment data), P09 (oversize, malformed cursor, wrong contract) and the reader half of P05 (below-floor cursor, quiet or filtered account, no busy loop). 6. The contract wire suite and fixtures pass against the served tools. I02 feed-page budget from ADR 0012 rule 14 measured and reported. `make check` passes. ## Non-goals `mail_peer_snapshot_v1`, advertising `snapshot`, writer or schema changes beyond the index, People consumer changes, release or deploy. ## Blocked by - dev/mail-mind-mcp#159 — the event log, projection, continuity and retention floor.
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#160 serve-the-mail-peer-change-feed-and-peer-info

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 effort high

Run: 20261103T095651Z-195b53bb

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

Open risks:

  1. Response-cap behaviour. AC4 says 'The 1 MiB response cap and per-record caps return record_too_large without advancing the cursor'. The lean instead shortens a page to fit under 1 MiB (has_more=true). It returns record_too_large only when the first record of a page cannot be served (oversize flag or entity > 2048 chars); peer.result's 1 MiB refusal stays as a backstop. Each record is capped at about 66 KB, so one record always fits in 1 MiB. Erroring on the page total would block a limit=100 consumer for good, and the contract only names 'a single record that cannot fit'. Question: does the architect accept page-shortening over erroring on the page total? [decision]
  2. schema.json requires info.snapshot_ttl_seconds, but unit 2 does not advertise snapshot. The lean fills it with [peer] snapshot_lease_seconds (default 3600; the fixture shows 1800). Question: is the lease the right value, given that unit 3 will make it real? [decision]
  3. mail_peer_evidence_v1 'through' still reads MAX(seq) FROM the legacy changes table (store.py:2657), not the peer_events sequence that this feed uses. A consumer comparing the evidence watermark with the feed 'through' would compare two different counters. The fix is outside this unit's scope (evidence tool, #151 surface), so it is not absorbed. Question: open a follow-up issue to move the evidence watermark to the peer_events high-water mark, before People #47 relies on it? [decision]
  4. The I02 feed-page budget (ADR 0012 rule 14: feed page p99 <= 250 ms, health p99 <= 100 ms with no failures, mail_search p95 <= 125% of idle, RSS growth <= 64 MiB on the 210k store) can only be measured on the host. Check: run uv run python3 scripts/bench_feed.py on the dispatched branch and confirm the PR quotes the I02 JSON line with host and commit against each budget. The snapshot leg of rule 14 is deferred to unit 3 (#161). [verification]
  5. The lean adds the peer_events(account, seq) index to _SCHEMA as CREATE INDEX IF NOT EXISTS without bumping SCHEMA_VERSION from 16. The writer builds it on its next open; a reader that briefly runs first is correct but slower. A bump would be a schema change beyond the index (issue non-goal) and would touch every test that pins version 16. Question: confirm no version bump. [decision]

Change: Copy the #158 mail_peer_evidence_v1 slice.

(1) Turn server.py:1010-1024 PeerEvidenceTool into a base _PeerTool whose schemas are ClassVars. Add PeerInfoTool and PeerChangesTool, registered like server.py:1085-1092: SCOPE_EVIDENCE, READ_ONLY, the shared peer.Jobs pool. Copy the mail_peer_evidence_v1 flow at server.py:1027-1083 line for line: contract mismatch gives unsupported_version, an unknown account gives invalid_arguments, the selection is the sorted configured accounts.

(2) Add Store.peer_changes(cursor, accounts, limit, budget) and Store.peer_identity. Copy the dedicated read-connection discipline of Store.peer_evidence at store.py:2609-2785. In one read txn:

  • read identity, peer_cursor_key and peer_floor_seq from meta;
  • through = sqlite_sequence('peer_events'), the same expression as _marker_payload at store.py:798-806;
  • position = peer.open_cursor(...); position > through gives invalid_cursor, position < floor gives cursor_expired;
  • read events seq in (position, through], filtered by account, LIMIT limit+1.

(3) In peer.py:

  • add literal INFO/CHANGES request and output closures, built like peer.py:26-178;
  • extract scope_id (peer.py:260-262) and freshness (peer.py:239-259) unchanged into helpers;
  • add seal_cursor/open_cursor: base64url(canonical JSON {c,e,k,p,s,sc,v}) + '.' + HMAC-SHA256 with the meta key. Verify the MAC before parsing; any failure gives invalid_cursor;
  • add render_info, which advertises changes and evidence only;
  • add render_changes. Stop before an oversize or over-budget record. If that record is first on the page, return record_too_large. The next position is the last seq if has_more, else through.

(4) Add CREATE INDEX IF NOT EXISTS peer_events_account ON peer_events(account, seq) to _SCHEMA after store.py:239. No version bump.

(5) Amend the ADR 0008 §1 tool list and add §9. Update the tool lists in README, SECURITY, CLAUDE.md and config.example.

(6) Add scripts/bench_feed.py for I02, shaped like bench_search.py:24-60 and test_peer_evidence.py:751-833.

Files: src/mail_mind_mcp/peer.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/store.py · tests/test_peer_changes.py · tests/test_server.py · tests/test_evidence.py · scripts/bench_feed.py · docs/adr/0008-evidence-scope.md · README.md · SECURITY.md · CLAUDE.md · config.example.toml

Decision: 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):

  • 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-03-serve-the-mail-peer-change-feed-and-peer-info.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-03-serve-the-mail-peer-change-feed-and-peer-info.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#160 serve-the-mail-peer-change-feed-and-peer-info **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 effort `high` **Run:** `20261103T095651Z-195b53bb` **Held because:** CLEAN but 5 open risk(s) (1 verification · 4 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Response-cap behaviour. AC4 says 'The 1 MiB response cap and per-record caps return record_too_large without advancing the cursor'. The lean instead shortens a page to fit under 1 MiB (has_more=true). It returns record_too_large only when the first record of a page cannot be served (oversize flag or entity > 2048 chars); peer.result's 1 MiB refusal stays as a backstop. Each record is capped at about 66 KB, so one record always fits in 1 MiB. Erroring on the page total would block a limit=100 consumer for good, and the contract only names 'a single record that cannot fit'. Question: does the architect accept page-shortening over erroring on the page total? [decision] 2. schema.json requires info.snapshot_ttl_seconds, but unit 2 does not advertise snapshot. The lean fills it with [peer] snapshot_lease_seconds (default 3600; the fixture shows 1800). Question: is the lease the right value, given that unit 3 will make it real? [decision] 3. mail_peer_evidence_v1 'through' still reads MAX(seq) FROM the legacy changes table (store.py:2657), not the peer_events sequence that this feed uses. A consumer comparing the evidence watermark with the feed 'through' would compare two different counters. The fix is outside this unit's scope (evidence tool, #151 surface), so it is not absorbed. Question: open a follow-up issue to move the evidence watermark to the peer_events high-water mark, before People #47 relies on it? [decision] 4. The I02 feed-page budget (ADR 0012 rule 14: feed page p99 <= 250 ms, health p99 <= 100 ms with no failures, mail_search p95 <= 125% of idle, RSS growth <= 64 MiB on the 210k store) can only be measured on the host. Check: run `uv run python3 scripts/bench_feed.py` on the dispatched branch and confirm the PR quotes the I02 JSON line with host and commit against each budget. The snapshot leg of rule 14 is deferred to unit 3 (#161). [verification] 5. The lean adds the peer_events(account, seq) index to _SCHEMA as CREATE INDEX IF NOT EXISTS without bumping SCHEMA_VERSION from 16. The writer builds it on its next open; a reader that briefly runs first is correct but slower. A bump would be a schema change beyond the index (issue non-goal) and would touch every test that pins version 16. Question: confirm no version bump. [decision] **Change:** Copy the #158 mail_peer_evidence_v1 slice. (1) Turn server.py:1010-1024 PeerEvidenceTool into a base _PeerTool whose schemas are ClassVars. Add PeerInfoTool and PeerChangesTool, registered like server.py:1085-1092: SCOPE_EVIDENCE, READ_ONLY, the shared peer.Jobs pool. Copy the mail_peer_evidence_v1 flow at server.py:1027-1083 line for line: contract mismatch gives unsupported_version, an unknown account gives invalid_arguments, the selection is the sorted configured accounts. (2) Add Store.peer_changes(cursor, accounts, limit, budget) and Store.peer_identity. Copy the dedicated read-connection discipline of Store.peer_evidence at store.py:2609-2785. In one read txn: - read identity, peer_cursor_key and peer_floor_seq from meta; - through = sqlite_sequence('peer_events'), the same expression as _marker_payload at store.py:798-806; - position = peer.open_cursor(...); position > through gives invalid_cursor, position < floor gives cursor_expired; - read events seq in (position, through], filtered by account, LIMIT limit+1. (3) In peer.py: - add literal INFO/CHANGES request and output closures, built like peer.py:26-178; - extract scope_id (peer.py:260-262) and freshness (peer.py:239-259) unchanged into helpers; - add seal_cursor/open_cursor: base64url(canonical JSON {c,e,k,p,s,sc,v}) + '.' + HMAC-SHA256 with the meta key. Verify the MAC before parsing; any failure gives invalid_cursor; - add render_info, which advertises changes and evidence only; - add render_changes. Stop before an oversize or over-budget record. If that record is first on the page, return record_too_large. The next position is the last seq if has_more, else through. (4) Add CREATE INDEX IF NOT EXISTS peer_events_account ON peer_events(account, seq) to _SCHEMA after store.py:239. No version bump. (5) Amend the ADR 0008 §1 tool list and add §9. Update the tool lists in README, SECURITY, CLAUDE.md and config.example. (6) Add scripts/bench_feed.py for I02, shaped like bench_search.py:24-60 and test_peer_evidence.py:751-833. **Files:** `src/mail_mind_mcp/peer.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/store.py` · `tests/test_peer_changes.py` · `tests/test_server.py` · `tests/test_evidence.py` · `scripts/bench_feed.py` · `docs/adr/0008-evidence-scope.md` · `README.md` · `SECURITY.md` · `CLAUDE.md` · `config.example.toml` **Decision:** 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`): - 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-03-serve-the-mail-peer-change-feed-and-peer-info.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-03-serve-the-mail-peer-change-feed-and-peer-info.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#160 serve-the-mail-peer-change-feed-and-peer-info completed integration verify.

  • PR: #166
  • Branch: feat/svd-dev-mail-mind-mcp-160-serve-the-mail-peer-change-fee-e6461552
  • Commit: 6d9bd7c1bc
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/25/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: I02 search budget missed per the subagent: loaded p95 238.39 ms vs 116.61 ms idle (over 1.25x). Feed, health and RSS passed. Output is recorded in ADR 0008; architect should decide before merge (snapshot load is unit 3).
  • Warning: The mail_status regression test normalizes physical DB/WAL size counters because the new index changes them. Its pre-edit digest is kept.
  • Warning: Spec says to run pytest with the fast-loop -k filter; it collects 232 tests, so it is not vacuous.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261103T102225Z-e6461552 --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#160 serve-the-mail-peer-change-feed-and-peer-info completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/166 - Branch: feat/svd-dev-mail-mind-mcp-160-serve-the-mail-peer-change-fee-e6461552 - Commit: 6d9bd7c1bc4947528233110ce40889939cbe9f97 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/25/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: I02 search budget missed per the subagent: loaded p95 238.39 ms vs 116.61 ms idle (over 1.25x). Feed, health and RSS passed. Output is recorded in ADR 0008; architect should decide before merge (snapshot load is unit 3). - Warning: The mail_status regression test normalizes physical DB/WAL size counters because the new index changes them. Its pre-edit digest is kept. - Warning: Spec says to run pytest with the fast-loop -k filter; it collects 232 tests, so it is not vacuous. - CI wait: ci/woodpecker/pr/validation -> pass - Decision: review the PR and merge? (`codex-svd ship --run-id 20261103T102225Z-e6461552 --confirm-merge`)
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#160
No description provided.