mailmind Source: bound the size of the pending checkpoint written on a failed pass #36

Closed
opened 2026-11-02 02:37:56 +00:00 by piers · 4 comments
Owner

Decision record (grill, 2026-11-02 06:50Z, operator accepted)

The #35 architect gate ruled D1 as in-pass resume only and filed this issue for the cross-pass checkpoint. PR #38 shipped the checkpoint anyway in c27d5f6 "Checkpoint mailmind pages across failed sync passes": MailmindSource.resumable = True, the guarded failure-path UPSERT_STATE in sync.run_pass (fetched_ok local, getattr(source, "resumable", False), state differs from loaded), and the resume and rollback tests. It has run live since rc.3 and resumed the rc.4 pass at cursor 150200 without refetching 1,502 pages.

Decisions:

  1. Ratified. The shipped checkpoint is the decision. The gate-ruling breach is recorded in the SVD lesson ledger, not here.
  2. One row. The pending set stays in the source_state row with the cursor. The only reader is run_pass. A single-statement write is what keeps the invariant "a saved cursor never runs ahead of durable or pending interactions" trivially true. No source_checkpoint table.
  3. Size bound: compress, never cap. Live measurement on the piers mailbox: 14,054,642 bytes JSON for 5,505 Handles and 152,331 events (92 bytes per event), 74% of a 19 MB store. zlib level 6 gives 2,178,197 bytes. A compact encoding without compression gives 10,995,810 bytes and is not worth a format change. A hard cap is rejected: it turns a slow pass into one that can never complete.
  4. The Evidence phase stays unprotected for now. The checkpoint covers the page phase, which takes minutes. The Evidence phase takes about 3 hours on this mailbox (dev/mail-mind-mcp#136) and holds its results in memory. Accepted because a cold pass is a one-time cost per mailbox and incremental passes are small. Trigger: if the current cold pass (started 2026-11-02 05:35Z) fails before completion, file a new issue to save Evidence results per Handle into the checkpoint.

Scope

Compress the source_state value when the state carries a pending key. Leave every other state as plain JSON text.

  • src/people_mind_mcp/sync.py: one encoder and one decoder around UPSERT_STATE and LOAD_STATE. Encode: json.dumps(state, sort_keys=True); if "pending" in state, store zlib.compress(text.encode(), 6) as bytes, else store the text. Decode: bytes means json.loads(zlib.decompress(value)), str means json.loads(value). The state TEXT NOT NULL column is unchanged; SQLite stores bytes in it as a BLOB. No schema version bump.
  • tests/test_mailmind.py: extend the resume test so the stored failure row is bytes and shorter than its JSON, and the resumed pass reads it back; add a test that a plain-text pending row written by rc.4 still loads and resumes; keep the success-path assertion that the stored value is the text {"cursor": "N"}.

Out of scope: CardDAV state (never carries pending), the Evidence phase, any mailmind change, any new error code.

Acceptance

  • A failed pass on the fake with page_size = 1 stores a bytes value that decompresses to the same JSON the current code stores.
  • A plain-text pending row inserted directly by the test loads and resumes at its cursor.
  • Success-path source_state is unchanged: the text {"cursor": "N"}.
  • make check green. Run pytest with --basetemp "$(mktemp -d "${TMPDIR:-/var/tmp}/svd.XXXXXX")/x".

Blocked by

None. #35 is closed.

## Decision record (grill, 2026-11-02 06:50Z, operator accepted) The #35 architect gate ruled D1 as in-pass resume only and filed this issue for the cross-pass checkpoint. PR #38 shipped the checkpoint anyway in c27d5f6 "Checkpoint mailmind pages across failed sync passes": `MailmindSource.resumable = True`, the guarded failure-path `UPSERT_STATE` in `sync.run_pass` (`fetched_ok` local, `getattr(source, "resumable", False)`, state differs from loaded), and the resume and rollback tests. It has run live since rc.3 and resumed the rc.4 pass at cursor 150200 without refetching 1,502 pages. Decisions: 1. **Ratified.** The shipped checkpoint is the decision. The gate-ruling breach is recorded in the SVD lesson ledger, not here. 2. **One row.** The pending set stays in the `source_state` row with the cursor. The only reader is `run_pass`. A single-statement write is what keeps the invariant "a saved cursor never runs ahead of durable or pending interactions" trivially true. No `source_checkpoint` table. 3. **Size bound: compress, never cap.** Live measurement on the piers mailbox: 14,054,642 bytes JSON for 5,505 Handles and 152,331 events (92 bytes per event), 74% of a 19 MB store. zlib level 6 gives 2,178,197 bytes. A compact encoding without compression gives 10,995,810 bytes and is not worth a format change. A hard cap is rejected: it turns a slow pass into one that can never complete. 4. **The Evidence phase stays unprotected for now.** The checkpoint covers the page phase, which takes minutes. The Evidence phase takes about 3 hours on this mailbox (dev/mail-mind-mcp#136) and holds its results in memory. Accepted because a cold pass is a one-time cost per mailbox and incremental passes are small. **Trigger:** if the current cold pass (started 2026-11-02 05:35Z) fails before completion, file a new issue to save Evidence results per Handle into the checkpoint. ## Scope Compress the `source_state` value when the state carries a `pending` key. Leave every other state as plain JSON text. - `src/people_mind_mcp/sync.py`: one encoder and one decoder around `UPSERT_STATE` and `LOAD_STATE`. Encode: `json.dumps(state, sort_keys=True)`; if `"pending" in state`, store `zlib.compress(text.encode(), 6)` as bytes, else store the text. Decode: `bytes` means `json.loads(zlib.decompress(value))`, `str` means `json.loads(value)`. The `state TEXT NOT NULL` column is unchanged; SQLite stores bytes in it as a BLOB. No schema version bump. - `tests/test_mailmind.py`: extend the resume test so the stored failure row is `bytes` and shorter than its JSON, and the resumed pass reads it back; add a test that a plain-text `pending` row written by rc.4 still loads and resumes; keep the success-path assertion that the stored value is the text `{"cursor": "N"}`. Out of scope: CardDAV state (never carries `pending`), the Evidence phase, any mailmind change, any new error code. ## Acceptance - A failed pass on the fake with `page_size = 1` stores a `bytes` value that decompresses to the same JSON the current code stores. - A plain-text `pending` row inserted directly by the test loads and resumes at its cursor. - Success-path `source_state` is unchanged: the text `{"cursor": "N"}`. - `make check` green. Run pytest with `--basetemp "$(mktemp -d "${TMPDIR:-/var/tmp}/svd.XXXXXX")/x"`. ## Blocked by None. #35 is closed.
Author
Owner

Scope narrowed 2026-11-02

PR #38 (merged 5e0a500) shipped the cross-pass checkpoint from the #35 spec's section 4: MailmindSource.resumable = True, per-page self.state holding cursor, pending and full, and a failure-path UPSERT_STATE in sync.run_pass guarded by fetched_ok (only fetch failures checkpoint; an ingest rollback keeps the loaded state). Tests cover resume at both cursors, rollback, and malformed-page replay. Items 1 and 2 above are therefore decided by code.

What stays open here is item 3: a size bound or trimming rule for pending. A first pass over a large mailbox accumulates one tuple per interaction until every page and evidence call succeeds; on failure the whole set is written to source_state. Measure SELECT length(state) FROM source_state WHERE source='mail' after a failed first pass on the gate instance, then decide whether a bound is needed and where (drop the oldest interactions per address, cap the address count, or accept the size).

## Scope narrowed 2026-11-02 PR #38 (merged 5e0a500) shipped the cross-pass checkpoint from the #35 spec's section 4: `MailmindSource.resumable = True`, per-page `self.state` holding `cursor`, `pending` and `full`, and a failure-path `UPSERT_STATE` in `sync.run_pass` guarded by `fetched_ok` (only fetch failures checkpoint; an ingest rollback keeps the loaded state). Tests cover resume at both cursors, rollback, and malformed-page replay. Items 1 and 2 above are therefore decided by code. What stays open here is item 3: a size bound or trimming rule for `pending`. A first pass over a large mailbox accumulates one tuple per interaction until every page and evidence call succeeds; on failure the whole set is written to `source_state`. Measure `SELECT length(state) FROM source_state WHERE source='mail'` after a failed first pass on the gate instance, then decide whether a bound is needed and where (drop the oldest interactions per address, cap the address count, or accept the size).
piers changed title from mailmind Source: cross-pass checkpoint of cursor plus pending interactions on a failed pass to mailmind Source: bound the size of the pending checkpoint written on a failed pass 2026-11-02 04:19:53 +00:00
Author
Owner

Measured on the gate instance 2026-11-02 (rc.3, 5e0a500)

After the first mailmind pass failed at cursor 150200 (see #39), SELECT length(state) FROM source_state WHERE source='mail' reads 14,054,642 bytes: 5,505 pending addresses, 152,331 pending events, full=1. That checkpoint is parsed and re-serialised on every later pass and rewritten on every failure.

The resume itself works (the pass restarts at page 1,503, not page 1). The size does not: 14 MB of JSON in one SQLite row for a mailbox of 150k changes, growing with the mailbox, is the case item 3 anticipated.

Architect lean: the pending set should not live in source_state at all. Ingest interactions per accepted page inside the pass (a per-page transaction, with the cursor), and keep only cursor and the list of addresses still owed an evidence call in the checkpoint. That is a change to the run_pass contract (fetch and ingest interleaved for this Source), so it needs a grill, not a direct spec. Ready for ready-for-human.

## Measured on the gate instance 2026-11-02 (rc.3, 5e0a500) After the first mailmind pass failed at cursor 150200 (see #39), `SELECT length(state) FROM source_state WHERE source='mail'` reads **14,054,642 bytes**: 5,505 pending addresses, 152,331 pending events, `full=1`. That checkpoint is parsed and re-serialised on every later pass and rewritten on every failure. The resume itself works (the pass restarts at page 1,503, not page 1). The size does not: 14 MB of JSON in one SQLite row for a mailbox of 150k changes, growing with the mailbox, is the case item 3 anticipated. Architect lean: the pending set should not live in `source_state` at all. Ingest interactions per accepted page inside the pass (a per-page transaction, with the cursor), and keep only `cursor` and the list of addresses still owed an evidence call in the checkpoint. That is a change to the run_pass contract (fetch and ingest interleaved for this Source), so it needs a grill, not a direct spec. Ready for `ready-for-human`.
Collaborator

⏸ SVD architect gate: dev/people-mind-mcp#36 mailmind-source-bound-the-size-of-the-pending-checkpoint-wri

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: 20261102T080051Z-209c8788

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

Open risks:

  1. D1: Rolling back to an image at or before 902eed7 while a compressed 'mail' checkpoint row exists makes every mailmind pass fail sync-failed, because old code calls json.loads on the BLOB. The issue's decision record accepts no schema version bump. Question: accept this and put the one-line recovery DELETE FROM source_state WHERE source = 'mail' in the PR body (replay is idempotent via interactions_once, at the cost of refetching pages), or require a pre-image rollback gate? Recommended lean: accept with a PR-body note. [decision]
  2. V1: The live size reduction can only be observed after a real failed pass on the gate instance; a failure cannot be forced in CI. Check: after the next failed mailmind pass on the deployed image, SELECT typeof(state), length(state) FROM source_state WHERE source = 'mail' should return blob and roughly 2.2 MB (decision record: 2,178,197 at zlib 6 for the 14,054,642-byte checkpoint), and the following pass should resume at the stored cursor rather than calling mail_changes from 0. [verification]

Change: In sync.py, add import zlib and two module-level functions next to the LOAD_STATE/UPSERT_STATE constants (sync.py:15-23 style). encode_state(state) -> str | bytes runs json.dumps(sort_keys=True) and returns zlib.compress(text.encode(), 6) only when "pending" is in state. decode_state(value) -> dict[str, Any] decompresses bytes, passes str through, then json.loads, using a typed local so mypy strict does not reject returning Any. Route the three state I/O sites through them: the load at sync.py:35, the success write at :53 and the failure checkpoint at :75. Leave the guard, the transactions, the SQL and store.py unchanged; SQLite TEXT affinity keeps bytes as a BLOB, verified this session. In tests/test_mailmind.py: extend test_failed_pass_checkpoints_and_resumes_without_refetch (:443 and :459) to assert a bytes row that decompresses to today's JSON, is shorter than that JSON, and leaves an exact text {"cursor": N} row after success. Add test_plain_text_pending_checkpoint_from_rc4_resumes. Switch the CONV-23 readers at :219, :482 and :903 from json.loads to sync.decode_state.

Files: src/people_mind_mcp/sync.py · tests/test_mailmind.py

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-mailmind-source-bound-the-size-of-the-pending-checkpoint-wri.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mailmind-source-bound-the-size-of-the-pending-checkpoint-wri.md

### ⏸ SVD architect gate: dev/people-mind-mcp#36 mailmind-source-bound-the-size-of-the-pending-checkpoint-wri **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:** `20261102T080051Z-209c8788` **Held because:** CLEAN but 2 open risk(s) (1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. D1: Rolling back to an image at or before 902eed7 while a compressed 'mail' checkpoint row exists makes every mailmind pass fail sync-failed, because old code calls json.loads on the BLOB. The issue's decision record accepts no schema version bump. Question: accept this and put the one-line recovery `DELETE FROM source_state WHERE source = 'mail'` in the PR body (replay is idempotent via interactions_once, at the cost of refetching pages), or require a pre-image rollback gate? Recommended lean: accept with a PR-body note. [decision] 2. V1: The live size reduction can only be observed after a real failed pass on the gate instance; a failure cannot be forced in CI. Check: after the next failed mailmind pass on the deployed image, `SELECT typeof(state), length(state) FROM source_state WHERE source = 'mail'` should return blob and roughly 2.2 MB (decision record: 2,178,197 at zlib 6 for the 14,054,642-byte checkpoint), and the following pass should resume at the stored cursor rather than calling mail_changes from 0. [verification] **Change:** In sync.py, add `import zlib` and two module-level functions next to the LOAD_STATE/UPSERT_STATE constants (sync.py:15-23 style). `encode_state(state) -> str | bytes` runs json.dumps(sort_keys=True) and returns zlib.compress(text.encode(), 6) only when "pending" is in state. `decode_state(value) -> dict[str, Any]` decompresses bytes, passes str through, then json.loads, using a typed local so mypy strict does not reject returning Any. Route the three state I/O sites through them: the load at sync.py:35, the success write at :53 and the failure checkpoint at :75. Leave the guard, the transactions, the SQL and store.py unchanged; SQLite TEXT affinity keeps bytes as a BLOB, verified this session. In tests/test_mailmind.py: extend test_failed_pass_checkpoints_and_resumes_without_refetch (:443 and :459) to assert a bytes row that decompresses to today's JSON, is shorter than that JSON, and leaves an exact text {"cursor": N} row after success. Add test_plain_text_pending_checkpoint_from_rc4_resumes. Switch the CONV-23 readers at :219, :482 and :903 from json.loads to sync.decode_state. **Files:** `src/people_mind_mcp/sync.py` · `tests/test_mailmind.py` **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-mailmind-source-bound-the-size-of-the-pending-checkpoint-wri.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-mailmind-source-bound-the-size-of-the-pending-checkpoint-wri.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/people-mind-mcp#36 mailmind-source-bound-the-size-of-the-pending-checkpoint-wri completed integration verify.

  • PR: #42
  • Branch: feat/svd-dev-people-mind-mcp-36-mailmind-source-bound-the-siz-95a2fade
  • Commit: b16e313837
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Checks: PR #42 head b16e313: no commit statuses on Forgejo (no CI configured). Local filtered tests (11) and make check (296 passed, 5 skipped, 4 deselected) are green.
  • Warning: No CI is configured for dev/people-mind-mcp: the commit statuses on b16e313 are an empty list, so there are no remote checks to read.
  • Warning: Post-merge check V1 from the spec is still open: after a real failed mailmind pass, run SELECT typeof(state), length(state) FROM source_state WHERE source = 'mail' and expect blob at about 2.2 MB.
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261102T082047Z-95a2fade --confirm-merge)
spec-verify-dispatch Half B for dev/people-mind-mcp#36 mailmind-source-bound-the-size-of-the-pending-checkpoint-wri completed integration verify. - PR: https://git.groupthink.asia/dev/people-mind-mcp/pulls/42 - Branch: feat/svd-dev-people-mind-mcp-36-mailmind-source-bound-the-siz-95a2fade - Commit: b16e313837484c3df06e02850196b6980ee7c261 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Checks: PR #42 head b16e313: no commit statuses on Forgejo (no CI configured). Local filtered tests (11) and make check (296 passed, 5 skipped, 4 deselected) are green. - Warning: No CI is configured for dev/people-mind-mcp: the commit statuses on b16e313 are an empty list, so there are no remote checks to read. - Warning: Post-merge check V1 from the spec is still open: after a real failed mailmind pass, run SELECT typeof(state), length(state) FROM source_state WHERE source = 'mail' and expect blob at about 2.2 MB. - Decision: review the PR and merge? (`codex-svd ship --run-id 20261102T082047Z-95a2fade --confirm-merge`)
svc-svd-writer 2026-11-02 09:02:52 +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/people-mind-mcp#36
No description provided.