mailmind Source: bound the size of the pending checkpoint written on a failed pass #36
Labels
No labels
bug
enhancement
epic
needs-info
needs-triage
ready-for-agent
ready-for-human
svd:fire
svd:go
svd:hold
svd:respec
svd:skip
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/people-mind-mcp#36
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?
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-pathUPSERT_STATEinsync.run_pass(fetched_oklocal,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:
source_staterow with the cursor. The only reader isrun_pass. A single-statement write is what keeps the invariant "a saved cursor never runs ahead of durable or pending interactions" trivially true. Nosource_checkpointtable.Scope
Compress the
source_statevalue when the state carries apendingkey. Leave every other state as plain JSON text.src/people_mind_mcp/sync.py: one encoder and one decoder aroundUPSERT_STATEandLOAD_STATE. Encode:json.dumps(state, sort_keys=True); if"pending" in state, storezlib.compress(text.encode(), 6)as bytes, else store the text. Decode:bytesmeansjson.loads(zlib.decompress(value)),strmeansjson.loads(value). Thestate TEXT NOT NULLcolumn 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 isbytesand shorter than its JSON, and the resumed pass reads it back; add a test that a plain-textpendingrow 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
page_size = 1stores abytesvalue that decompresses to the same JSON the current code stores.pendingrow inserted directly by the test loads and resumes at its cursor.source_stateis unchanged: the text{"cursor": "N"}.make checkgreen. Run pytest with--basetemp "$(mktemp -d "${TMPDIR:-/var/tmp}/svd.XXXXXX")/x".Blocked by
None. #35 is closed.
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-pageself.stateholdingcursor,pendingandfull, and a failure-pathUPSERT_STATEinsync.run_passguarded byfetched_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 tosource_state. MeasureSELECT 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).mailmind Source: cross-pass checkpoint of cursor plus pending interactions on a failed passto mailmind Source: bound the size of the pending checkpoint written on a failed passMeasured 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_stateat all. Ingest interactions per accepted page inside the pass (a per-page transaction, with the cursor), and keep onlycursorand 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 forready-for-human.⏸ 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 effortmediumRun:
20261102T080051Z-209c8788Held because: CLEAN but 2 open risk(s) (1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
902eed7while 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 recoveryDELETE 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]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 zliband two module-level functions next to the LOAD_STATE/UPSERT_STATE constants (sync.py:15-23 style).encode_state(state) -> str | bytesruns 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.pyDecision: 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):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-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.mdspec-verify-dispatch Half B for dev/people-mind-mcp#36 mailmind-source-bound-the-size-of-the-pending-checkpoint-wri completed integration verify.
b16e313837b16e313: no commit statuses on Forgejo (no CI configured). Local filtered tests (11) and make check (296 passed, 5 skipped, 4 deselected) are green.b16e313are an empty list, so there are no remote checks to read.codex-svd ship --run-id 20261102T082047Z-95a2fade --confirm-merge)