Add the wake queue and the mail_wakes read tools #39

Merged
svc-agent-writer merged 1 commit from feat/wakes into main 2026-10-31 12:21:22 +00:00

Closes #22. Stacked on #38, which is stacked on #37. Merge them in order: #37, #38, then this.

Schema v3

  • wakes(seq AUTOINCREMENT, account, mailbox, uidvalidity, uid, thread_key, class, score, raised_at). AUTOINCREMENT means a seq is never reused, so a stored position never points at a different wake.
  • wake_consumers(consumer, seq, updated_at) holds positions only, never mail data. It is the second table the api writes (ADR 0003 §7).
  • The writer creates both with CREATE IF NOT EXISTS. A v1 or v2 file upgrades in place, and the reader waits for v3, as before.

Raising wakes

  • After each assessed batch, the assessor applies would_wake (from #38) to each answer, and Store.raise_wakes inserts the accepted ones.
  • The thread's and the instance's counts for the UTC day are read in the same transaction as the inserts, so the caps hold.
  • A new key, [wake] max_age_hours (default 24), means only a fresh message can wake. When you first enable triage over a 14-day backlog, it raises nothing.
  • No [wake] section means no wakes. mailmind sync --once prints woken=.

Tools (read scope, registered only when [wake] is set)

  • mail_wakes(consumer | cursor, limit) returns seq | id | class | score | at, then ack_seq=N more=M.
    • A consumer seen for the first time is stored at the current end, so it never misses wakes raised between its first two calls.
    • A wake repeats until it is acked.
    • With a cursor, no consumer row is written.
    • With neither, only the current ack_seq is returned.
    • With both, the call is refused.
  • mail_wakes_ack(consumer, seq) moves the position forward only. A seq past the queue's end is refused with invalid_argument.
  • A consumer name must match [a-z0-9-]{1,32}. The schema refuses any other name before the tool runs.
  • _register_write_tools becomes _register_tools(tools, scope, enabled) and serves both groups.

Docs

  • README: a wake tools section with a sample Grok Automation instruction, and a max_age_hours row.
  • config.example.toml.
  • CLAUDE.md and SECURITY.md now say the api writes two tables.

Tests

tests/test_wakes.py:

  • The tools are absent without [wake].
  • Over HTTP:
    • A new consumer starts at the end.
    • An unacked run repeats.
    • Ack advances and never moves back.
    • An ack past the end is refused.
    • Cursor mode writes no consumer row.
    • A consumer and a cursor together are refused.
    • A bad name is refused.
  • The assessor: the day's cap holds, a backlog raises nothing, and no [wake] means no wakes.

The store tests now upgrade v1 to v3. make check passes (110 tests).

🤖 Generated with Claude Code

Closes #22. Stacked on #38, which is stacked on #37. Merge them in order: #37, #38, then this. ## Schema v3 - `wakes(seq AUTOINCREMENT, account, mailbox, uidvalidity, uid, thread_key, class, score, raised_at)`. AUTOINCREMENT means a seq is never reused, so a stored position never points at a different wake. - `wake_consumers(consumer, seq, updated_at)` holds positions only, never mail data. It is the second table the `api` writes (ADR 0003 §7). - The writer creates both with `CREATE IF NOT EXISTS`. A v1 or v2 file upgrades in place, and the reader waits for v3, as before. ## Raising wakes - After each assessed batch, the assessor applies `would_wake` (from #38) to each answer, and `Store.raise_wakes` inserts the accepted ones. - The thread's and the instance's counts for the UTC day are read in the same transaction as the inserts, so the caps hold. - A new key, `[wake] max_age_hours` (default 24), means only a fresh message can wake. When you first enable triage over a 14-day backlog, it raises nothing. - No `[wake]` section means no wakes. `mailmind sync --once` prints `woken=`. ## Tools (read scope, registered only when `[wake]` is set) - `mail_wakes(consumer | cursor, limit)` returns `seq | id | class | score | at`, then `ack_seq=N more=M`. - A consumer seen for the first time is stored at the current end, so it never misses wakes raised between its first two calls. - A wake repeats until it is acked. - With a cursor, no consumer row is written. - With neither, only the current `ack_seq` is returned. - With both, the call is refused. - `mail_wakes_ack(consumer, seq)` moves the position forward only. A seq past the queue's end is refused with `invalid_argument`. - A consumer name must match `[a-z0-9-]{1,32}`. The schema refuses any other name before the tool runs. - `_register_write_tools` becomes `_register_tools(tools, scope, enabled)` and serves both groups. ## Docs - README: a wake tools section with a sample Grok Automation instruction, and a `max_age_hours` row. - `config.example.toml`. - CLAUDE.md and SECURITY.md now say the `api` writes two tables. ## Tests `tests/test_wakes.py`: - The tools are absent without `[wake]`. - Over HTTP: - A new consumer starts at the end. - An unacked run repeats. - Ack advances and never moves back. - An ack past the end is refused. - Cursor mode writes no consumer row. - A consumer and a cursor together are refused. - A bad name is refused. - The assessor: the day's cap holds, a backlog raises nothing, and no `[wake]` means no wakes. The store tests now upgrade v1 to v3. `make check` passes (110 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mail_search gains a triage filter, search and thread rows end with the class once triage has run, and mail_read shows the class and wake score. Untriaged rows keep the 0.2 shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An optional [wake] section holds the threshold and the per-thread and per-day caps. would_wake is the rule in code; mailmind replay prints, per UTC day received, the count per class and the wakes the rule would raise, plus a score histogram. It prints counts only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Schema v3 adds wakes and wake_consumers. The assessor raises a wake for a fresh message under the [wake] rule, with the caps counted in the same transaction. mail_wakes returns wakes after a consumer's stored position or a cursor, and mail_wakes_ack moves the position forward only. Both tools exist only when [wake] is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.