Pace the mailmind client: 20 pages in 0.58 s trip mailmind's rate limit, read as mailmind-auth #35
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#35
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
On the live gate instance the mailmind Source fails every pass with
code=mailmind-auth, although the evidence token is valid: a hand-madetools/listandmail_changescall with the same token answer 200, and the token file hashes match on both pods.Traced inside the sync container with the app's own
MailmindSource._fetch(statuses only):mail_changespages in 0.58 s (about 34 requests per second), then the next request answered 401 and_fetchraisedmailmind-auth;rate_per_second = 5.0,rate_burst = 20on this instance, which are the defaults); when the bucket is emptyverify_tokenreturnsNone, so FastMCP answers401 invalid_token.A first full pass over a real mailbox needs many
mail_changespages (30:PAGE_LIMIT = 100) and then onemail_evidencecall per distinct correspondent, so without pacing it can never finish. Every pass restarts from the same cursor becauseself.stateis only written after success, so the instance never catches up.Fix
In
MailmindSource._fetch:MailmindSourceConfig(rate_per_second, default 4.0).Retry-Afteron 429; also treat a 401 that follows at least one successful authenticated call in the same session as a rate limit (mailmind today answers 401 for an empty bucket; dev/mail-mind-mcp has the sibling issue to answer 429), retry up to 5 times with exponential backoff from 0.5 s. A 401 on the first call staysmailmind-auth.self.state["cursor"]after each acceptedmail_changespage so a pass that fails midway resumes rather than restarts. Evidence calls remain per address and are retried under the same rules.Acceptance
mailmind-auth.source=mail kind=mailmind status=okwith non-zerofetched(recorded on #10).Primary files
src/people_mind_mcp/sources/mailmind.pysrc/people_mind_mcp/config.py(MailmindSourceConfig.rate_per_second)tests/test_mailmind.pyBlocked by
None. Independent of #34 (different file).
Sibling on the server side: dev/mail-mind-mcp#126 (answer 429 with Retry-After instead of 401 invalid_token). This client fix does not wait for it; the 401-after-success rule covers today's server.
⏸ SVD architect gate: dev/people-mind-mcp#35 pace-the-mailmind-client-20-pages-in-0-58-s-trip-mailmind-s
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 efforthighRun:
20261102T022451Z-fdf8516cHeld because: CLEAN but 5 open risk(s) (3 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
SELECT error FROM sync_log WHERE source='mail' ORDER BY finished DESC LIMIT 1must return NULL. Record it on #10. [verification]SELECT length(state) FROM source_state WHERE source='mail'. If it is tens of MB, trim or batch the pending set. [verification]async with Client(...)as a bare httpx.HTTPStatusError. The live trace supports this, since it produced mailmind-auth rather than mailmind-unavailable. Test 2 on the local serve() stack must prove it. If fastmcp 3.4.11 wraps it in an ExceptionGroup, _retry_delay must unwrap it. [verification]Change: Add MailmindSourceConfig.rate_per_second (Field(default=4.0, gt=0), mirroring ApiConfig.rate_per_second at config.py:83). In mailmind.py, add an async _Pacer token bucket (burst constant RATE_BURST=10) that mirrors the refill math of RateLimiter.allow at auth.py:77-90 but waits instead of refusing, with module-level _clock/_sleep so tests can drive virtual time. Acquire a token before every call_tool and before every Client open. Wrap _fetch's
async with Client(...)in an attempt loop that keeps cursor, pending interactions and finished evidence records across attempts, because a 401 or 429 tears down the MCP session (mcp streamable_http _handle_post_request runs raise_for_status inside a task-group child), so each retry opens a new Client. _retry_delay rules: on a 429, wait for Retry-After as delta-seconds, capped at 60 s, falling back to 0.52^n; treat a 401 after at least one successful _call in this pass as a rate limit with 0.52^n backoff; a first-call 401 or a 403 gives mailmind-auth; allow 5 retries per request, with the counter reset on each success. Cross-pass resume: MailmindSource.resumable=True; after each accepted page, self.state={cursor, pending, full?}; on success, self.state={cursor} only. sync.run_pass's failure transaction (sync.py:59-76) saves source.state only when records() itself raised (fetched_ok guard), the source is resumable, and the state differs from what was loaded, so a rolled-back ingest never saves a cursor that has run ahead of the interactions. Architect decision D1: confirm the sync.py extension, or cut back to in-pass resume.Files:
src/people_mind_mcp/sources/mailmind.py·src/people_mind_mcp/config.py·src/people_mind_mcp/sync.py·tests/test_mailmind.pyDecision: 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):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-pace-the-mailmind-client-20-pages-in-0-58-s-trip-mailmind-s.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-02-pace-the-mailmind-client-20-pages-in-0-58-s-trip-mailmind-s.mdArchitect gate (Half-A CLEAN)
Spec:
specs/2026-11-02-pace-the-mailmind-client-20-pages-in-0-58-s-trip-mailmind-s.md(exhaust worktree, gate adjustments appended).D1 ruled: in-pass resume only.
sync.pyleaves the write set; theresumableattribute, the failure-path state write and the two checkpoint tests are dropped. Within one pass the cursor and pending interactions survive rate-limit retries, so a retried pass never refetches an accepted page. Persisted state shape unchanged. Cross-pass checkpointing is #36 (needs-triage) with the spec's worked design.D2 ruled: no new error code. Exhausted retries keep
mailmind-auth(401) andmailmind-unavailable(429). dev/mail-mind-mcp#126 makes throttling an explicit 429 server-side.Kept from the lean:
rate_per_seconddefault 4.0,RATE_BURST10,MAX_RETRIES5,BACKOFF_BASE0.5,RETRY_AFTER_MAX60, async pacer, attempt loop reopening the client onHTTPStatusError, first-call 401/403 staysmailmind-auth. V3 (ExceptionGroup unwrap on the localserve()stack) is a dispatch obligation.Host baseline at
2224edd: neighbours (test_mailmind test_config_cli test_carddav test_vcard_sync) 143 passed.Riders: basetemp on every pytest command,
python3 -m pytest, no nested.git, no.agents/.codex/.gitpaths written.Operator: paste
svd:goto release Half-B (batched with #34).spec-verify-dispatch Half B for dev/people-mind-mcp#35 pace-the-mailmind-client-20-pages-in-0-58-s-trip-mailmind-s completed integration verify.
c27d5f6bcbc27d5f6: no remote checks reported (absent CI). Local full suite: 288 passed, 9 skipped. No blockers.c27d5f6returns an empty list, so no required checks exist.codex-svd ship --run-id 20261102T035837Z-3cf65163 --confirm-merge)