JMAP draft From: fall back to the session username #211

Closed
opened 2026-11-13 21:39:10 +00:00 by svc-agent-writer · 4 comments

A JMAP account without from_address cannot write drafts. mail_draft, mail_draft_edit and forward drafts fail with config_error ("the account has no from_address"). An IMAP account falls back to its username when that is an address; a JMAP account has no fallback (JmapAccountConfig.sender). Grok hit this on mailmind-piers (starbase/iac#371 sets the address there as a workaround).

What to build

  1. The sync worker reads the JMAP session username (RFC 8620 §2) when it reads the session. It already reads the session for primaryAccounts. When the username is an address (the existing _is_address rule), the worker records it in the existing meta table under one key per account. No schema change. The worker updates the key when the username changes, and removes it when the username is no longer an address.
  2. One sender rule for every caller, in this order: the config from_address; for IMAP, the username when it is an address; for JMAP, the recorded session username. server.py's early refusal in mail_draft and mail_draft_edit and the worker's _compose in jmap.py both use it. The api process reads the recorded value from the store; it never calls the mail server (ADR 0006 §3).
  3. Before the worker has recorded a session username, a JMAP account without from_address still answers config_error. The message says that the first sync pass has not run or that the session username is not an address, and names from_address as the fix.
  4. mailmind check prints each account's sender and its origin: config, username or session. Never print the address in logs: logs carry the origin only.
  5. Docs: README [[accounts]] table, config.example.toml comment on the JMAP from_address, and the mail_draft docstring if it names the rule.

Do not use Identity/get. It needs the submission capability, which the JMAP token must not carry (ADR 0006 §10). Never derive From from mail content, such as Sent mail: mail content is untrusted.

ADR

ADR 0006 §1 lists the JMAP keys. It needs one sentence: "A JMAP account without from_address uses the session username when it is an address." ADR 0004 §6 needs a pointer to it. The architect lands both in a separate PR before dispatch, because the runner refuses to merge a PR that touches docs/adr/.

Acceptance criteria

  • A JMAP account without from_address whose session username is an address writes a draft, a forward and an edit with that From.
  • from_address in config overrides the session username.
  • A session username that is not an address leaves the account without a sender, and mail_draft answers config_error before queueing.
  • The api reads the sender from the store, and tests/test_source.py's no-source-import check still passes.
  • No log record carries the address.
  • Unit tests with a fake session cover all three cases. The Stalwart integration test covers the case its session gives.
  • make check passes.

Out of scope

Masked Email or alias creation. Choosing among several identities. Any send path.

A JMAP account without `from_address` cannot write drafts. `mail_draft`, `mail_draft_edit` and forward drafts fail with `config_error` ("the account has no from_address"). An IMAP account falls back to its `username` when that is an address; a JMAP account has no fallback (`JmapAccountConfig.sender`). Grok hit this on mailmind-piers (starbase/iac#371 sets the address there as a workaround). ## What to build 1. The sync worker reads the JMAP session `username` (RFC 8620 §2) when it reads the session. It already reads the session for `primaryAccounts`. When the username is an address (the existing `_is_address` rule), the worker records it in the existing `meta` table under one key per account. No schema change. The worker updates the key when the username changes, and removes it when the username is no longer an address. 2. One sender rule for every caller, in this order: the config `from_address`; for IMAP, the `username` when it is an address; for JMAP, the recorded session username. `server.py`'s early refusal in `mail_draft` and `mail_draft_edit` and the worker's `_compose` in `jmap.py` both use it. The `api` process reads the recorded value from the store; it never calls the mail server (ADR 0006 §3). 3. Before the worker has recorded a session username, a JMAP account without `from_address` still answers `config_error`. The message says that the first sync pass has not run or that the session username is not an address, and names `from_address` as the fix. 4. `mailmind check` prints each account's sender and its origin: `config`, `username` or `session`. Never print the address in logs: logs carry the origin only. 5. Docs: README `[[accounts]]` table, `config.example.toml` comment on the JMAP `from_address`, and the `mail_draft` docstring if it names the rule. Do not use `Identity/get`. It needs the submission capability, which the JMAP token must not carry (ADR 0006 §10). Never derive From from mail content, such as Sent mail: mail content is untrusted. ## ADR ADR 0006 §1 lists the JMAP keys. It needs one sentence: "A JMAP account without `from_address` uses the session username when it is an address." ADR 0004 §6 needs a pointer to it. The architect lands both in a separate PR before dispatch, because the runner refuses to merge a PR that touches `docs/adr/`. ## Acceptance criteria - [ ] A JMAP account without `from_address` whose session username is an address writes a draft, a forward and an edit with that From. - [ ] `from_address` in config overrides the session username. - [ ] A session username that is not an address leaves the account without a sender, and `mail_draft` answers `config_error` before queueing. - [ ] The api reads the sender from the store, and `tests/test_source.py`'s no-source-import check still passes. - [ ] No log record carries the address. - [ ] Unit tests with a fake session cover all three cases. The Stalwart integration test covers the case its session gives. - [ ] `make check` passes. ## Out of scope Masked Email or alias creation. Choosing among several identities. Any send path.
Collaborator

⏸ SVD architect gate: dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username

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

Run: 20261113T221200Z-89078db9

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

Open risks:

  1. Should a recorded JMAP session username join own_addresses, so that mail_people and mail_evidence with include_self=false leave it out, the way the IMAP login does through .sender? The lean says no: .sender stays config-only for JMAP, the issue scopes the rule to draft callers, and Sent/Drafts From addresses are already excluded through the data-derived from_owner/_SELF_SENDERS path. If yes, it becomes a follow-up issue. [decision]
  2. Should every pass force a fresh session read so a username change is noticed sooner? JmapClient caches the session until close(), which runs after a failed pass or on shutdown, so a change on a healthy long-lived connection is recorded only at the next reconnect. _compose uses the live cached session, but the api may act on the older record until then. The lean follows the issue literally ('when it reads the session') and adds no extra GET per pass. [decision]
  3. scripts/stalwart_setup.py creates the user 'bot' in example.test, and whether Stalwart's session username is 'bot' or 'bot@example.test' is unknown at spec time. The new integration test branches on the observed value. Check: run make test-stalwart on the host and state in the PR which branch ran (session origin or config_error). [verification]
  4. make check (lint, mypy strict, unit tests, pip-audit with network) was not run in Half-A. Check: run make check on the host at the PR head and confirm exit 0, and confirm the fast-filter failure set matches the pristine-base measurement taken before the first edit. [verification]

Change: One sender rule in config.py: add draft_sender(session_username) -> (address, origin) | None on MirrorScope (config only). Override it on MirrorAccountConfig (IMAP username fallback, same behaviour as config.py:340-344) and on JmapAccountConfig (session username fallback). The .sender property delegates to the rule, so own_addresses stays config-only for JMAP. Make _is_address public as is_address, and add the NO_SENDER and NO_SESSION_SENDER messages. store.py: add session_sender(account), which works on a reader, and record_session_sender(account, address|None), which only the writer may call. Both use a meta key 'session_username:', mirroring get_state/set_state at store.py:2046-2059, the meta upsert at :1009 and the writer guard at :1020. jmap.py: add a username field to Session (parsed at :215-236). JmapSource._session_sender() records the value and logs the origin only. run_pass calls it as the first statement in the try at :439, and _compose (:976-979) uses account.draft_sender(self._session_sender()). server.py: add a _draft_sender(account) helper that reads store.session_sender and never imports jmap. It replaces the refusals at :1575-1577 and :1622-1630, before _queue. cli.py: add 'origin' to the log allowlist at :42-64. cmd_check prints a 'sender: account= origin= address=' line, never starting with 'account=' because of test_greenmail.py:123. Docs: README.md:236 and config.example.toml:127 and :134.

Files: src/mail_mind_mcp/config.py · src/mail_mind_mcp/store.py · src/mail_mind_mcp/jmap.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/cli.py · README.md · config.example.toml · tests/test_config.py · tests/test_store.py · tests/test_jmap.py · tests/test_write_tools.py · tests/integration/test_stalwart.py

Decision: 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):

  • 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-13-jmap-draft-from-fall-back-to-the-session-username.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-13-jmap-draft-from-fall-back-to-the-session-username.md

### ⏸ SVD architect gate: dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username **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 effort `high` **Run:** `20261113T221200Z-89078db9` **Held because:** CLEAN but 4 open risk(s) (2 verification · 2 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Should a recorded JMAP session username join own_addresses, so that mail_people and mail_evidence with include_self=false leave it out, the way the IMAP login does through .sender? The lean says no: .sender stays config-only for JMAP, the issue scopes the rule to draft callers, and Sent/Drafts From addresses are already excluded through the data-derived from_owner/_SELF_SENDERS path. If yes, it becomes a follow-up issue. [decision] 2. Should every pass force a fresh session read so a username change is noticed sooner? JmapClient caches the session until close(), which runs after a failed pass or on shutdown, so a change on a healthy long-lived connection is recorded only at the next reconnect. _compose uses the live cached session, but the api may act on the older record until then. The lean follows the issue literally ('when it reads the session') and adds no extra GET per pass. [decision] 3. scripts/stalwart_setup.py creates the user 'bot' in example.test, and whether Stalwart's session username is 'bot' or 'bot@example.test' is unknown at spec time. The new integration test branches on the observed value. Check: run `make test-stalwart` on the host and state in the PR which branch ran (session origin or config_error). [verification] 4. `make check` (lint, mypy strict, unit tests, pip-audit with network) was not run in Half-A. Check: run `make check` on the host at the PR head and confirm exit 0, and confirm the fast-filter failure set matches the pristine-base measurement taken before the first edit. [verification] **Change:** One sender rule in config.py: add draft_sender(session_username) -> (address, origin) | None on MirrorScope (config only). Override it on MirrorAccountConfig (IMAP username fallback, same behaviour as config.py:340-344) and on JmapAccountConfig (session username fallback). The .sender property delegates to the rule, so own_addresses stays config-only for JMAP. Make _is_address public as is_address, and add the NO_SENDER and NO_SESSION_SENDER messages. store.py: add session_sender(account), which works on a reader, and record_session_sender(account, address|None), which only the writer may call. Both use a meta key 'session_username:<account>', mirroring get_state/set_state at store.py:2046-2059, the meta upsert at :1009 and the writer guard at :1020. jmap.py: add a username field to Session (parsed at :215-236). JmapSource._session_sender() records the value and logs the origin only. run_pass calls it as the first statement in the try at :439, and _compose (:976-979) uses account.draft_sender(self._session_sender()). server.py: add a _draft_sender(account) helper that reads store.session_sender and never imports jmap. It replaces the refusals at :1575-1577 and :1622-1630, before _queue. cli.py: add 'origin' to the log allowlist at :42-64. cmd_check prints a 'sender: account=<id> origin=<o> address=<a>' line, never starting with 'account=' because of test_greenmail.py:123. Docs: README.md:236 and config.example.toml:127 and :134. **Files:** `src/mail_mind_mcp/config.py` · `src/mail_mind_mcp/store.py` · `src/mail_mind_mcp/jmap.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/cli.py` · `README.md` · `config.example.toml` · `tests/test_config.py` · `tests/test_store.py` · `tests/test_jmap.py` · `tests/test_write_tools.py` · `tests/integration/test_stalwart.py` **Decision:** 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`): - 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-13-jmap-draft-from-fall-back-to-the-session-username.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-13-jmap-draft-from-fall-back-to-the-session-username.md`</sub>
Collaborator

✅ SVD architect gate: dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username

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: 20261113T221200Z-89078db9

Files: src/mail_mind_mcp/config.py · src/mail_mind_mcp/store.py · src/mail_mind_mcp/jmap.py · src/mail_mind_mcp/server.py · src/mail_mind_mcp/cli.py · README.md · config.example.toml · tests/test_config.py · tests/test_store.py · tests/test_jmap.py · tests/test_write_tools.py · tests/integration/test_stalwart.py

Write-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):

  • 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-13-jmap-draft-from-fall-back-to-the-session-username.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-13-jmap-draft-from-fall-back-to-the-session-username.md

### ✅ SVD architect gate: dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username **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:** `20261113T221200Z-89078db9` **Files:** `src/mail_mind_mcp/config.py` · `src/mail_mind_mcp/store.py` · `src/mail_mind_mcp/jmap.py` · `src/mail_mind_mcp/server.py` · `src/mail_mind_mcp/cli.py` · `README.md` · `config.example.toml` · `tests/test_config.py` · `tests/test_store.py` · `tests/test_jmap.py` · `tests/test_write_tools.py` · `tests/integration/test_stalwart.py` **Write-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`): - 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-13-jmap-draft-from-fall-back-to-the-session-username.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-13-jmap-draft-from-fall-back-to-the-session-username.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username completed integration verify.

  • PR: #216
  • Branch: feat/svd-dev-mail-mind-mcp-211-jmap-draft-from-fall-back-to-t-ab6fd722
  • Commit: (unknown)
  • Build: deferred
  • Test: deferred
  • Reader audit clean: False
  • Spec fidelity: False
  • Ready for merge: False
  • Checks: head-mismatch: worktree HEAD 26d4c79cae does not match forge PR head c10c46e36f
  • Forbidden-mutation check: unmeasured (no diff base recorded)
  • Blocker: head-mismatch: worktree HEAD 26d4c79cae does not match forge PR head c10c46e36f
  • Blocker cause: infra for head-mismatch: worktree HEAD 26d4c79cae does not match forge PR head c10c46e36f; no denial signature; evidence: raised by the runner before any test ran
  • Rework: 0 round(s), outcome head-mismatch
  • Escalation: head-mismatch: worktree HEAD 26d4c79cae does not match forge PR head c10c46e36f
  • Decision: resolve the blockers above and rerun integrate, or park this PR for a human?
spec-verify-dispatch Half B for dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/216 - Branch: feat/svd-dev-mail-mind-mcp-211-jmap-draft-from-fall-back-to-t-ab6fd722 - Commit: (unknown) - Build: deferred - Test: deferred - Reader audit clean: False - Spec fidelity: False - Ready for merge: False - Checks: head-mismatch: worktree HEAD 26d4c79cae003889477ba13281c362a0ec675173 does not match forge PR head c10c46e36f80e288864e8f381d3ff965313511d9 - Forbidden-mutation check: unmeasured (no diff base recorded) - Blocker: head-mismatch: worktree HEAD 26d4c79cae003889477ba13281c362a0ec675173 does not match forge PR head c10c46e36f80e288864e8f381d3ff965313511d9 - Blocker cause: infra for head-mismatch: worktree HEAD 26d4c79cae003889477ba13281c362a0ec675173 does not match forge PR head c10c46e36f80e288864e8f381d3ff965313511d9; no denial signature; evidence: raised by the runner before any test ran - Rework: 0 round(s), outcome head-mismatch - Escalation: head-mismatch: worktree HEAD 26d4c79cae003889477ba13281c362a0ec675173 does not match forge PR head c10c46e36f80e288864e8f381d3ff965313511d9 - Decision: resolve the blockers above and rerun integrate, or park this PR for a human?
Collaborator

spec-verify-dispatch Half B for dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username completed integration verify.

  • PR: #216
  • Branch: feat/svd-dev-mail-mind-mcp-211-jmap-draft-from-fall-back-to-t-ab6fd722
  • Commit: c10c46e36f
  • 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/112/1
  • Checks: PR #216 head c10c46e: ci/woodpecker/pr/validation green (combined status success). Local make check green: 1624 passed, 8 skipped, lint, mypy and pip-audit clean.
  • Warning: Live Stalwart test (tests/integration/test_stalwart.py::test_a_draft_without_from_address_uses_the_session_username) was not run: it needs podman/docker. Run make test-stalwart on a host with a container daemon.
  • Warning: The spec sets own_addresses and mail_people include_self=false as config-only for JMAP. A recorded session username is not treated as an owner address. The spec's open-risk decision records this, and ADR 0014 (#212) owns the follow-up.
  • Warning: Woodpecker history on the PR head lists earlier pending rows for ci/woodpecker/pr/validation. The combined status is success.
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261113T222723Z-ab6fd722 --confirm-merge)
spec-verify-dispatch Half B for dev/mail-mind-mcp#211 jmap-draft-from-fall-back-to-the-session-username completed integration verify. - PR: https://git.groupthink.asia/dev/mail-mind-mcp/pulls/216 - Branch: feat/svd-dev-mail-mind-mcp-211-jmap-draft-from-fall-back-to-t-ab6fd722 - Commit: c10c46e36f80e288864e8f381d3ff965313511d9 - 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/112/1 - Checks: PR #216 head c10c46e: ci/woodpecker/pr/validation green (combined status success). Local make check green: 1624 passed, 8 skipped, lint, mypy and pip-audit clean. - Warning: Live Stalwart test (tests/integration/test_stalwart.py::test_a_draft_without_from_address_uses_the_session_username) was not run: it needs podman/docker. Run make test-stalwart on a host with a container daemon. - Warning: The spec sets own_addresses and mail_people include_self=false as config-only for JMAP. A recorded session username is not treated as an owner address. The spec's open-risk decision records this, and ADR 0014 (#212) owns the follow-up. - Warning: Woodpecker history on the PR head lists earlier pending rows for ci/woodpecker/pr/validation. The combined status is success. - Decision: review the PR and merge? (`codex-svd ship --run-id 20261113T222723Z-ab6fd722 --confirm-merge`)
svc-agent-writer 2026-11-13 23:13:15 +00:00
piers referenced this issue from a commit 2026-11-14 00:10:21 +00:00
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#211
No description provided.