mail_trash on IMAP: tool, trash action kind, schema v18, cap, undo and mirror effect #192
Labels
No labels
bug
enhancement
epic
needs-info
needs-triage
ready-for-agent
ready-for-human
svd:go
svd:hold
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dev/mail-mind-mcp#192
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?
Part of epic #187. Implements ADR 0013 items 1 to 6 and the schema part of item 11, for IMAP.
Read
docs/adr/0013-trash-forward-and-draft-edits.mdand ADR 0004 first. ADR 0013 is the contract. If the code shows that a ruling cannot work, stop and report; do not change the ruling here.Standing rules: tools only queue to the outbox and never call a mail server. The sync worker applies each action through the existing source
applyinterface. Logs carry counts, roles and error codes only. Secrets are files. Add no new test seam: use the tools over HTTP with the stand-in worker, the sourceapplyinterface with the fake IMAP session or the fake JMAP server, and the GreenMail and Stalwart integration targets.What to build
actionstable admitstrashandedit. Add no schema change here. Replace the twotest_runner_refusesrows that pintrashasinvalid_argumenton IMAP; keep theeditrow.mail_trash(message_ids). Scopewrite. It is absent without a write token file, like the other write tools. It carriesdestructiveHint=True; every other write tool keeps its hints. The docstring names its untrusted fields in one sentence.trash_per_day. Default 20, in[writes]. It counts messages, not requests, from the deduplicated refs, in the same transaction as the enqueue. A request that would pass the cap is refused whole withrate_limitedand queues nothing. Messages in refused or failed queued trash actions still count. Every other cap still counts requests.unsupported. Use MOVE, or COPY with UID EXPUNGE of the moved UIDs only. Record the source, Trash, the Trash UIDVALIDITY and the new UIDs as the inverse. Without new UIDs the action isunsupported.not_foundand change nothing. The existing move undo stays all-or-nothing.mail_movestill refuses Trash and Junk at the tool and at the source. Junk is never a target of any tool.actions.kind. Update the worker undo dispatch, the per-kind branches ofmail_undoand the action detail, themail_actionsdisplay, the cap lookup and the daily count query.mail_actionsdetail carries counts and mailbox names only.trashaction on a JMAP account is refused withunsupported.Design note from slice 1
Item 6 needs the rows to leave the mirror in the same transaction as the action result. Today the worker applies the action and then settles it in a separate store transaction. Add a settle path in the store that records the result, removes the rows and writes the change and peer deletion events in one transaction. Use it for
trashonly.This is slice 2 of 2. If the work still exceeds the file ceiling, split by source of change: first the tool, cap and readers with the worker refusing
trashasunsupported; then IMAP apply, undo and the mirror effect.Acceptance criteria
mail_trashover HTTP queues onetrashaction and returns the outcome in the shape of the other write tools.mail_trashwith the destructive hint, and no other write tool has it. Update the existing test that asserts every write tool has a false destructive hint.rate_limited. A request of 21 messages at the default cap is refused. Duplicate refs count once.not_found.make checkpasses.Out of scope
JMAP trash. Forward drafts. Draft edits. README, SECURITY and release notes: the docs issue owns them.
Blocked by
⏸ SVD architect gate: dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und
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:
20261112T060957Z-dca1101fHeld because: CLEAN but 5 open risk(s) (2 verification · 3 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
e2327a7, but #188's state was not in the issue-context snapshot. Is ADR 0013 accepted so dispatch may proceed, with the status-line flip left to the docs issue? [decision]mailmind apiagainst it, and call mail_actions. It must list every row, a trash row showingof=None, and mail_flag must still queue. [verification]make checkanduv run python3 -m pytest -qover the 13 listed test files on pristinee2327a7, then assert that after the change only the new tests change state. [verification]Change: Slice 1 of 2 (re-sliced for the scope ceiling: the v18 bump alone breaks hard-coded version assertions in 12 test files, and the full issue needs about 22 files). Steps: (1) Follow the
_SCHEMA = _TABLES.replace("{fts}", ...)placeholder pattern at store.py:388. Lift the actions DDL at store.py:176-204 into_ACTIONS_TABLE, whose kind CHECK gains 'trash' and 'edit', and_ACTIONS_GUARDS, a tuple of three indexes and three triggers. Splice them into_TABLESvia{actions}, and set SCHEMA_VERSION = 18. (2) Add_migrate_actions(conn)beside_migrate_fts(store.py:3687-3702) and call it last in_add_columns(store.py:3677). It runs in the writer only, before the upward-only version upsert. It detects by structure ("'trash'" in sqlite_master.sql), not by version, which keeps the log-silence tests at test_sign_off.py:214 and test_attachments.py:637 green. In one BEGIN IMMEDIATE transaction it runs conn.execute per statement (never executescript): CREATE actions_v18, INSERT with explicit columns, DROP actions, RENAME, recreate the guards, COMMIT, with ROLLBACK on error. It then logs a counts-only "actions table rebuilt for schema v18". This was proven on a scratch DB this session. (3) Bump the 22schema_version() == 17sites and the 5match="schema v17"sites to 18. Add tests to test_store.py: v17→v18 upgrade keeping rows, ids, triggers and indexes; a v18 store opening in a reader with SCHEMA_VERSION patched to 17; a fresh store with no rebuild. Add trash and editinvalid_argumentrows to test_actions.py::test_runner_refuses. No reader of actions.kind changes in this slice; CONV-23 audit is in spec §3.Files:
src/mail_mind_mcp/store.py·tests/test_store.py·tests/test_actions.py·tests/test_attachment_vectors.py·tests/test_attachments.py·tests/test_copy_collapse.py·tests/test_embed_scans.py·tests/test_evidence.py·tests/test_mailbox_search.py·tests/test_peer_changes.py·tests/test_peer_snapshot.py·tests/test_recipients.py·tests/test_sign_off.py·tests/test_utc_dates.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-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und.md✅ SVD architect gate: dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und
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
unclassified· dispatch effortunclassifiedRun:
20261112T060957Z-dca1101fFiles:
src/mail_mind_mcp/store.py·tests/test_store.py·tests/test_actions.py·tests/test_attachment_vectors.py·tests/test_attachments.py·tests/test_copy_collapse.py·tests/test_embed_scans.py·tests/test_evidence.py·tests/test_mailbox_search.py·tests/test_peer_changes.py·tests/test_peer_snapshot.py·tests/test_recipients.py·tests/test_sign_off.py·tests/test_utc_dates.pyWrite-set divergence: present table wins. 0 sourceHashes vs 25-row table.
Decision: dispatch this spec (
svd:go)?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-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und.mdspec-verify-dispatch Half B for dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und completed integration verify.
62702f4858codex-svd ship --run-id 20261112T062733Z-fd23ff36 --confirm-merge)Slice 1 (schema v18) landed in PR #199 as
c01ef13. The issue body now describes slice 2: items 2 to 9.⏸ SVD architect gate: dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und
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:
20261112T064946Z-3980a278Held because: CLEAN but 4 open risk(s) (2 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim:
Open risks:
c01ef13) under the same status, and this slice is the first to put a destructive tool (mail_trash) behind a write token. Question: is ADR 0013 accepted, so this slice may ship with the status flip, CLAUDE.md, GLOSSARY and the README upgrade note left to the epic #187 docs issue, or must the status flip land first? [decision]c01ef13has no .venv, and Half A is read-only. This differs from the prior attempt because the base moved frome2327a7toc01ef13. Check: before the first edit on pristinec01ef13, run make check and uv run python3 -m pytest -q -m "not integration" tests/test_actions.py tests/test_store.py tests/test_write_tools.py tests/test_server.py tests/test_config.py tests/test_jmap.py and record the failure set. After the change, assert that only the new or updated tests changed state. [verification]Change: Slice 2 of #192, on
c01ef13(schema v18 already merged; no schema change). (1) config.py:180-201: add trash_per_day=20 and cap('trash'). (2) store.py:3306-3333 and 3401-3407: one _day_count_sql(kind) helper. For trash it is SUM(json_array_length(params,'$.refs')); otherwise COUNT(*). Enqueue weight is len(refs) for trash and 1 otherwise; refuse when used+weight > cap. (3) store.py:1451-1477: extract the delete_uids body into Store._delete_uid_rows(conn,…), which keeps the DELETE, the changes del row and _emit. Add Store.finish_trash(...), which runs the actions UPDATE plus _delete_uid_rows in ONE _tx and deletes nothing when the action is not queued. Update the peer-writer guard set at test_store.py:840. (4) source.py:136-154: settle routes kind=='trash' with an inverse to _settle_trash. Non-empty uids → applied; empty uids (moved, no new UIDs) → refused/unsupported with the rows still removed in the same transaction. (5) actions.py: split _move_uids (318-344) into _transfer + _map_moved(refresh kwarg). _trash_mailbox resolves exactly one selectable role=='trash' mailbox from session.list_mailboxes(), else unsupported. _trash mirrors _move (291-309), refreshes Trash only when account.wanted() is true, and returns {from, from_uidvalidity, from_uids, to, uidvalidity, uids, message_ids} without deleting rows. _undo_trash examines Trash: a UIDVALIDITY mismatch or no present UIDs → not_found with no change; otherwise _move_uids moves back only the present UIDs. The _undo dispatch (378-386) gets an explicit trash/move/else. (6) server.py: WRITE_DESTRUCTIVE hint; mail_trash following mail_move (1574-1594), refusing a source mailbox with the trash role; _refs dedups by (mailbox, uidvalidity, uid); _outcome adds trashed=N; _action_detail shows counts and mailbox names; mail_undo docstring; WRITE_TOOLS and TOOL_HINTS. (7) jmap.py:487-509: trash → unsupported before any session call, plus an explicit undo fallthrough.Files:
src/mail_mind_mcp/server.py·src/mail_mind_mcp/config.py·src/mail_mind_mcp/store.py·src/mail_mind_mcp/source.py·src/mail_mind_mcp/actions.py·src/mail_mind_mcp/jmap.py·config.example.toml·tests/test_write_tools.py·tests/test_server.py·tests/test_actions.py·tests/test_store.py·tests/test_config.py·tests/test_jmap.py·tests/integration/test_greenmail_writes.pyDecision: accept the 4 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-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und-slice-2.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und-slice-2.md✅ SVD architect gate: dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und
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
unclassified· dispatch effortunclassifiedRun:
20261112T064946Z-3980a278Files:
src/mail_mind_mcp/server.py·src/mail_mind_mcp/config.py·src/mail_mind_mcp/store.py·src/mail_mind_mcp/source.py·src/mail_mind_mcp/actions.py·src/mail_mind_mcp/jmap.py·config.example.toml·tests/test_write_tools.py·tests/test_server.py·tests/test_actions.py·tests/test_store.py·tests/test_config.py·tests/test_jmap.py·tests/integration/test_greenmail_writes.pyWrite-set divergence: present table wins. 0 sourceHashes vs 23-row table.
Decision: dispatch this spec (
svd:go)?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-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und-slice-2.md— next:codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und-slice-2.mdspec-verify-dispatch Half B for dev/mail-mind-mcp#192 mail-trash-on-imap-tool-trash-action-kind-schema-v18-cap-und completed integration verify.
2e6a4bb89fcodex-svd ship --run-id 20261112T071823Z-4b95e9c6 --confirm-merge)