Snapshot activation scans every staged row per Mail interaction and locks the store #81
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/people-mind-mcp#81
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?
Problem
Snapshot activation (ADR 0010 rule 6, step 3) takes time proportional to Mail interactions times staged rows. During that time the writer holds the store lock, so every other write fails with
store-unavailable.Observed live on 2026-11-04 (People
0.1.0-rc.8, Mail Mind0.13.0):mail-people/1.1and started the planned rebuild (#68). Staging completed with 259,873 rows; 83,377 Mailmessage:interactions existed.store-unavailable. Reads kept working.Cause
src/people_mind_mcp/sync.py:321-327(main98ad738) deletes interactions with this subquery:The
mail_stagedprimary key is(source, snapshot_id, entity_id, address, direction). The subquery does not bindsnapshot_id, so SQLite can use only thesourceprefix:SEARCH s USING INDEX sqlite_autoindex_mail_staged_1 (source=?). Each interaction scans every staged row of the Source.Measured on a copy with the live staged count (259,873 rows) and 8,338 interactions, which is 1/10 of the live interactions:
s.snapshot_id=?bound: 0.014 s.The query landed with #51 (
24c0c17). It became visible now because the first live activation ran on a store with few Mail interactions.Fix
s.snapshot_id = ?, thepage.snapshot_idthat activates), so the lookup uses the primary key prefix(source, snapshot_id, entity_id).mail_stagedstatements on the activation path for the same pattern, and bindsnapshot_idwhere the snapshot is known:sync.py:309-311(the per-address delete of disallowed addresses) andsync.py:315(the affected-address union).snapshot_id. If one cannot, add the narrowest index and record it as a schema step.Acceptance criteria
EXPLAIN QUERY PLANof the activation retraction searchesmail_stagedwithsnapshot_id=?in its index constraint, and does not search onsource=?alone.make checkpasses.Out of scope
COUNT(*)ofmail_stagedandmail_staged_fences(sync.py:286-287) also grows with the staged set. It is linear per page, not per interaction; leave it unless the fix makes it the bottleneck.graph.py:30DELETE_MAIL_STAGED(Forget) scans by address. Forget is rare; leave it.Context
max_staged_records. This defect makes that transaction quadratic, which the ADR did not accept.Filed under: operator word "accept" sha256:c125d0397b60 (#10 gate)
⏸ SVD architect gate: dev/people-mind-mcp#81 snapshot-activation-scans-every-staged-row-per-mail-interact
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:
20261104T122137Z-e7753f8fHeld because: CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
Change: In src/people_mind_mcp/sync.py _mail_snapshot_page, move the activation retraction (sync.py:320-327) into a module constant RETRACT_UNSTAGED, placed directly below RETRACT_UNSUPPORTED (sync.py:27-32) and shaped the same way (triple-quoted, numbered params). It binds
s.snapshot_id = ?2, and the call becomes conn.execute(RETRACT_UNSTAGED, (name, page.snapshot_id)). I probed this at spec time: the subquery plan goes from(source=?)to the full key(source=? AND snapshot_id=? AND entity_id=? AND address=? AND direction=?). Also bind page.snapshot_id in the other activation reads: the DISTINCT address select and per-address DELETE (309, 311), the affected-address union (315), and the mail_support and mail_fences copies from staging (334-342). Leave the COUNTs (286-287), the clean-up deletes (360-361), _mail_reset_snapshot, graph.py and the schema untouched. Binding keeps behaviour the same because every staged row of the Source carries page.snapshot_id at activation (invariant I1).Files:
src/people_mind_mcp/sync.py·tests/test_mailpeer.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-04-snapshot-activation-scans-every-staged-row-per-mail-interact.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-04-snapshot-activation-scans-every-staged-row-per-mail-interact.mdspec-verify-dispatch Half B for dev/people-mind-mcp#81 snapshot-activation-scans-every-staged-row-per-mail-interact completed integration verify.
df2a06a92ddf2a06a. No other required checks.python3 -m pytestfails at conftest import; collection and tests were run throughuv runinstead, which worked.codex-svd ship --run-id 20261104T123646Z-0ae89b3b --confirm-merge)