Add schema v2 with the actions table and a read-only reader #11

Closed
opened 2026-10-31 03:45:42 +00:00 by svc-agent-writer · 0 comments

Epic: #7

Schema v2 for the outbox (ADR 0004 §2, §7).

What to build

  • Add an actions table to store.py. Columns: id, kind (draft, flag, move, undo), params (JSON, messages by account/mailbox/uidvalidity/uid only), role (token role), state (queued, applied, failed, refused), result_code, inverse (JSON), undo_of, requested_at, applied_at. Rows are append-only apart from the state transition.
  • Bump SCHEMA_VERSION to 2. Write schema_version only when the stored value is lower. 0.1.x writes the version unconditionally (store.py Store.__init__); after this change no process lowers it.
  • Split Store opening into two modes: the writer (sync worker) runs the DDL; the reader (api) opens with file:...?mode=ro for every mirror read and runs no DDL. The api process needs one write path, enqueue_action, which touches actions only. Pick the smallest shape that keeps that boundary visible in code, for example a second connection used only by enqueue_action.
  • On api start before the schema exists, wait and retry with a bounded timeout. Then fail with config_error.
  • Store methods: enqueue_action, next_actions(limit), finish_action, list_actions(since, limit), count_actions_today(kind).

Acceptance

  • Unit tests: a v1 file opens and becomes v2 without data loss; a v2 file opened by code that writes v1 does not lower the version (simulate); the reader connection refuses a write; enqueue_action from the reader process succeeds.
  • make check green.

Blocked by

  • ADR 0004 accepted (PR #6, status in PR #24)
Epic: #7 Schema v2 for the outbox (ADR 0004 §2, §7). ## What to build - Add an `actions` table to `store.py`. Columns: `id`, `kind` (`draft`, `flag`, `move`, `undo`), `params` (JSON, messages by account/mailbox/uidvalidity/uid only), `role` (token role), `state` (`queued`, `applied`, `failed`, `refused`), `result_code`, `inverse` (JSON), `undo_of`, `requested_at`, `applied_at`. Rows are append-only apart from the state transition. - Bump `SCHEMA_VERSION` to 2. Write `schema_version` only when the stored value is lower. 0.1.x writes the version unconditionally (`store.py` `Store.__init__`); after this change no process lowers it. - Split `Store` opening into two modes: the writer (sync worker) runs the DDL; the reader (`api`) opens with `file:...?mode=ro` for every mirror read and runs no DDL. The `api` process needs one write path, `enqueue_action`, which touches `actions` only. Pick the smallest shape that keeps that boundary visible in code, for example a second connection used only by `enqueue_action`. - On `api` start before the schema exists, wait and retry with a bounded timeout. Then fail with `config_error`. - Store methods: `enqueue_action`, `next_actions(limit)`, `finish_action`, `list_actions(since, limit)`, `count_actions_today(kind)`. ## Acceptance - Unit tests: a v1 file opens and becomes v2 without data loss; a v2 file opened by code that writes v1 does not lower the version (simulate); the reader connection refuses a write; `enqueue_action` from the reader process succeeds. - `make check` green. ## Blocked by - [x] ADR 0004 accepted (PR #6, status in PR #24)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#11
No description provided.