mail_draft_edit on JMAP: guard, order and undo #196

Closed
opened 2026-11-12 05:52:20 +00:00 by svc-agent-writer · 3 comments

Part of epic #187. Implements ADR 0013 item 8 for JMAP.

Read docs/adr/0013-trash-forward-and-draft-edits.md and 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 apply interface. 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 source apply interface with the fake IMAP session or the fake JMAP server, and the GreenMail and Stalwart integration targets.

What to build

  1. Replace the unsupported refusal from the IMAP edit issue.
  2. Guard. The old draft must still carry $draft and its recorded blob id.
  3. Order. Import the new draft into Drafts first, then remove the old Email. JMAP Emails are immutable, so the edit gives a new Email id and a new draft id, returned in the result. Nothing is submitted.
  4. Undo. Check the same guard on the edited draft, import the previous content, then remove the edited draft. A crash between the two leaves two drafts, never none (ADR 0013 item 8 as amended; the IMAP source in #195 uses the same order). The restored draft is not a valid target for a further edit or undo.

Notes from the IMAP issue (#195, PR #205)

  • The tool mail_draft_edit, the target rule, the shared draft cap, the refusal of a replaced target in mail_undo and the worker's target check already exist. Change none of them unless a JMAP case needs it.
  • The IMAP runner refuses an edit whose target draft was not written on IMAP. Mirror that: refuse an edit whose target inverse is not JMAP-shaped with invalid_argument.
  • The edit keeps the reply_to or forward reference of the action it replaces. The undo rebuilds the previous content from the replaced action's stored params.
  • The undo of an edit returns the restored draft's location as the undo action's inverse, and the tool reports it as the draft id. Return the same shape.
  • A test pins that the JMAP source refuses edit with unsupported. Replace it.
  • An edit of a forward must keep the forward block on JMAP too. Add that case.

Acceptance criteria

  • Fake JMAP server: the import comes before the removal; the result names the new stable id; no submission call is made.
  • A draft the owner changed is left in place, with the outcome of the existing changed-draft test.
  • Undo restores the previous content under a new id.
  • An edit of a reply keeps its threading headers.
  • Stalwart: draft, edit, undo against the real server.
  • make check passes.

Out of scope

Any change to the tool, the target rule or the cap.

Blocked by

  • #188 (ADR 0013 merged and accepted)
  • #195
Part of epic #187. Implements ADR 0013 item 8 for JMAP. Read `docs/adr/0013-trash-forward-and-draft-edits.md` and 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 `apply` interface. 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 source `apply` interface with the fake IMAP session or the fake JMAP server, and the GreenMail and Stalwart integration targets. ## What to build 1. Replace the `unsupported` refusal from the IMAP edit issue. 2. **Guard.** The old draft must still carry `$draft` and its recorded blob id. 3. **Order.** Import the new draft into Drafts first, then remove the old Email. JMAP Emails are immutable, so the edit gives a new Email id and a new draft id, returned in the result. Nothing is submitted. 4. **Undo.** Check the same guard on the edited draft, import the previous content, then remove the edited draft. A crash between the two leaves two drafts, never none (ADR 0013 item 8 as amended; the IMAP source in #195 uses the same order). The restored draft is not a valid target for a further edit or undo. ## Notes from the IMAP issue (#195, PR #205) - The tool `mail_draft_edit`, the target rule, the shared draft cap, the refusal of a replaced target in `mail_undo` and the worker's target check already exist. Change none of them unless a JMAP case needs it. - The IMAP runner refuses an edit whose target draft was not written on IMAP. Mirror that: refuse an edit whose target inverse is not JMAP-shaped with `invalid_argument`. - The edit keeps the `reply_to` or `forward` reference of the action it replaces. The undo rebuilds the previous content from the replaced action's stored params. - The undo of an edit returns the restored draft's location as the undo action's inverse, and the tool reports it as the draft id. Return the same shape. - A test pins that the JMAP source refuses `edit` with `unsupported`. Replace it. - An edit of a forward must keep the forward block on JMAP too. Add that case. ## Acceptance criteria - [ ] Fake JMAP server: the import comes before the removal; the result names the new stable id; no submission call is made. - [ ] A draft the owner changed is left in place, with the outcome of the existing changed-draft test. - [ ] Undo restores the previous content under a new id. - [ ] An edit of a reply keeps its threading headers. - [ ] Stalwart: draft, edit, undo against the real server. - [ ] `make check` passes. ## Out of scope Any change to the tool, the target rule or the cap. ## Blocked by - #188 (ADR 0013 merged and accepted) - #195
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo

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: 20261112T213532Z-a14a09f0

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

Open risks:

  1. Should ADR 0006 §10 (docs/adr/0006-pluggable-mail-sources.md:56-61) gain a bullet for JMAP draft edits in this PR, or be left to epic #187's docs follow-up? The spec updates only the jmap.py docstrings, because the issue says not to change rulings here and ADR 0013 Consequences lists the ADR 0006 re-read as a separate follow-up. [decision]
  2. The Stalwart case is excluded from make check/CI. After merge, or in the dispatch worktree if the container is available, run make test-stalwart. It passes when tests/integration/test_stalwart.py::test_draft_edit_and_undo passes and test_writes_and_their_undo still passes. This also confirms that Stalwart's Email/get blobId equals the Email/import created blobId, which the guard depends on. [verification]

Change: Mirror #205's IMAP split in actions.py (_compose/_append_draft/_edit/_undo_edit/_check_draft/_expunge_draft) on JmapSource. Split _draft (jmap.py:970-1003) into _compose(action_id, params) -> raw and _import_draft(raw) -> (location, drafts_id, wanted), with no mirroring. Split _undo_draft (jmap.py:1005-1012) into _check_draft(inverse) -> state ($draft + blob_id guard via _current) and _destroy_draft(state, inverse) (Email/set destroy with ifInState, then delete_sources). Add _replace(inverse, raw): guard -> import -> re-guard and RE-READ state (the import advances the Email state) -> destroy -> _add the new id if Drafts is wanted. _edit uses edit_target, refuses a non-JMAP inverse (no source_id/blob_id) with invalid_argument, composes from action.params and returns the new {mailbox, source_id, blob_id}. _undo_edit composes from the replaced action's params and returns the restored location. In apply (jmap.py:489-522), remove the two unsupported refusals and route edit and undo-of-edit to the new helpers. Update the module and apply docstrings. Leave server.py, source.py and store.py untouched.

Files: src/mail_mind_mcp/jmap.py · tests/test_jmap.py · tests/integration/test_stalwart.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-12-mail-draft-edit-on-jmap-guard-order-and-undo.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-draft-edit-on-jmap-guard-order-and-undo.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo **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:** `20261112T213532Z-a14a09f0` **Held because:** CLEAN but 2 open risk(s) (1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Should ADR 0006 §10 (docs/adr/0006-pluggable-mail-sources.md:56-61) gain a bullet for JMAP draft edits in this PR, or be left to epic #187's docs follow-up? The spec updates only the jmap.py docstrings, because the issue says not to change rulings here and ADR 0013 Consequences lists the ADR 0006 re-read as a separate follow-up. [decision] 2. The Stalwart case is excluded from make check/CI. After merge, or in the dispatch worktree if the container is available, run `make test-stalwart`. It passes when tests/integration/test_stalwart.py::test_draft_edit_and_undo passes and test_writes_and_their_undo still passes. This also confirms that Stalwart's Email/get blobId equals the Email/import created blobId, which the guard depends on. [verification] **Change:** Mirror #205's IMAP split in actions.py (_compose/_append_draft/_edit/_undo_edit/_check_draft/_expunge_draft) on JmapSource. Split _draft (jmap.py:970-1003) into _compose(action_id, params) -> raw and _import_draft(raw) -> (location, drafts_id, wanted), with no mirroring. Split _undo_draft (jmap.py:1005-1012) into _check_draft(inverse) -> state ($draft + blob_id guard via _current) and _destroy_draft(state, inverse) (Email/set destroy with ifInState, then delete_sources). Add _replace(inverse, raw): guard -> import -> re-guard and RE-READ state (the import advances the Email state) -> destroy -> _add the new id if Drafts is wanted. _edit uses edit_target, refuses a non-JMAP inverse (no source_id/blob_id) with invalid_argument, composes from action.params and returns the new {mailbox, source_id, blob_id}. _undo_edit composes from the replaced action's params and returns the restored location. In apply (jmap.py:489-522), remove the two unsupported refusals and route edit and undo-of-edit to the new helpers. Update the module and apply docstrings. Leave server.py, source.py and store.py untouched. **Files:** `src/mail_mind_mcp/jmap.py` · `tests/test_jmap.py` · `tests/integration/test_stalwart.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-12-mail-draft-edit-on-jmap-guard-order-and-undo.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-draft-edit-on-jmap-guard-order-and-undo.md`</sub>
Collaborator

✅ SVD architect gate: dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo

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 effort unclassified

Run: 20261112T213532Z-a14a09f0

Files: src/mail_mind_mcp/jmap.py · tests/test_jmap.py · tests/integration/test_stalwart.py

Write-set divergence: present table wins. 0 sourceHashes vs 15-row table.

Decision: dispatch this spec (svd:go)?

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-12-mail-draft-edit-on-jmap-guard-order-and-undo.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-draft-edit-on-jmap-guard-order-and-undo.md

### ✅ SVD architect gate: dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo **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 effort `unclassified` **Run:** `20261112T213532Z-a14a09f0` **Files:** `src/mail_mind_mcp/jmap.py` · `tests/test_jmap.py` · `tests/integration/test_stalwart.py` **Write-set divergence:** present table wins. 0 sourceHashes vs 15-row table. **Decision:** dispatch this spec (`svd:go`)? **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-12-mail-draft-edit-on-jmap-guard-order-and-undo.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-12-mail-draft-edit-on-jmap-guard-order-and-undo.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo completed integration verify.

  • PR: #206
  • Branch: feat/svd-dev-mail-mind-mcp-196-mail-draft-edit-on-jmap-guard-88adb39b
  • Commit: 5fc41e0c3d
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/91/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: Spec names test_the_restored_draft_is_not_a_target; the PR renamed it test_the_restored_draft_of_an_edit_is_not_a_target so the spec's -k "edit or stable_ids" filter collects it. The original name would be filtered out. The spec has no scenario-trace table, so this is not a blocker.
  • Warning: Stalwart integration test test_draft_edit_and_undo exists but was not run: no container daemon was reachable for the subagent. It was not run here either.
  • Warning: The spec filter -k "edit or stable_ids" collects 15 tests, so it is not empty. Every other named spec test collects.
  • Warning: Full non-integration suite: 1613 passed, 8 skipped. ruff check passed. Audit not re-run here.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Rework: 1 round(s), outcome converged
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261112T222737Z-88adb39b --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#196 mail-draft-edit-on-jmap-guard-order-and-undo completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/206 - Branch: feat/svd-dev-mail-mind-mcp-196-mail-draft-edit-on-jmap-guard-88adb39b - Commit: 5fc41e0c3d30deefcb71d21011f3c4a6efc2d8c7 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/72/pipeline/91/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: Spec names test_the_restored_draft_is_not_a_target; the PR renamed it test_the_restored_draft_of_an_edit_is_not_a_target so the spec's `-k "edit or stable_ids"` filter collects it. The original name would be filtered out. The spec has no scenario-trace table, so this is not a blocker. - Warning: Stalwart integration test test_draft_edit_and_undo exists but was not run: no container daemon was reachable for the subagent. It was not run here either. - Warning: The spec filter `-k "edit or stable_ids"` collects 15 tests, so it is not empty. Every other named spec test collects. - Warning: Full non-integration suite: 1613 passed, 8 skipped. ruff check passed. Audit not re-run here. - CI wait: ci/woodpecker/pr/validation -> pass - Rework: 1 round(s), outcome converged - Decision: review the PR and merge? (`codex-svd ship --run-id 20261112T222737Z-88adb39b --confirm-merge`)
svc-svd-writer 2026-11-12 22:50:46 +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/mail-mind-mcp#196
No description provided.