Add the Jev assessor as a thread in the sync process #36

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

Closes #19. Stacked on #35 (ADR 0003): merge #35 first.

What it does

  • Adds an optional [assess] section. When it is absent, nothing leaves the host, and the startup and mailmind check say so.
  • When [assess] is set, SyncWorker starts one more thread, assess, in the sync process. The sync worker stays the one writer of the mirror tables.
  • Each tick, per account:
    1. A row whose Message-ID already has a class takes that class without a call. This covers a moved message.
    2. The assessor sends unassessed inbox-role rows received within backlog_days, batch per call, to POST https://api.typesafe.ai/v1/systemone. It uses stdlib urllib, as in the estate's Python precedent.
    3. Each message gets one Choice over the six classes and one Score over four wake levels. The score is stored scaled to 0..1.
  • Field list. message_state is the one place that builds it. A test pins the keys for each mode.
    • headers: from, name, subject, date, List-Id, system flags (\Seen, \Answered, \Flagged), and attachment names and types.
    • full adds excerpt: the first 500 characters of the quote-trimmed body.
    • Keywords, other recipients and the full body stay on the host.
  • Transport.
    • One retry on 429 or 529, honouring retry-after (capped at 30 s).
    • 401 and 403 map to auth_error. Everything else maps to unavailable.
    • The key is registered with the scrubber and never logged.
  • Failures. A failed call leaves the rows unassessed for the next tick. The error is recorded in the sync log, so mail_status shows it.
  • Answers are advisory. A class outside the six or a score out of range is dropped. A batch where every answer is invalid ends the tick.
  • Status and CLI.
    • mail_status prints assess: fields=… model=… or assess: off, and assessed=N per account.
    • mailmind sync --once also runs one assess tick.
  • Logs. Counts, dropped counts, the model and token counts.

Config defaults

Key Default
fields headers
model jev-1.13.0 (pinned)
batch 10
backlog_days 14
poll_seconds 60
timeout_seconds 25

Deploy

No change to the init script. A Secret key named jev.key lands in the sync runtime directory only, because only .token keys go to api. The base and compose comments say so.

Tests

tests/test_assess.py has 13 tests:

  • the closed keys for each mode, with keywords and other recipients not sent
  • excerpt trimming
  • the payload shape
  • answer validation
  • the 429 retry, 401 and 503 against a fake Jev on 127.0.0.1
  • end to end: window, role, batch and the moved copy, with the key, subjects and addresses absent from the captured logs
  • full mode
  • a failed call followed by a retry on the next tick
  • an absent section
  • a relative key path refused

make check passes (99 tests). The image's SQLite is 3.40.1, so the UPDATE … AS alias in copy_assessments is supported.

🤖 Generated with Claude Code

Closes #19. Stacked on #35 (ADR 0003): merge #35 first. ## What it does - Adds an optional `[assess]` section. When it is absent, nothing leaves the host, and the startup and `mailmind check` say so. - When `[assess]` is set, `SyncWorker` starts one more thread, `assess`, in the `sync` process. The sync worker stays the one writer of the mirror tables. - Each tick, per account: 1. A row whose Message-ID already has a class takes that class without a call. This covers a moved message. 2. The assessor sends unassessed inbox-role rows received within `backlog_days`, `batch` per call, to `POST https://api.typesafe.ai/v1/systemone`. It uses stdlib `urllib`, as in the estate's Python precedent. 3. Each message gets one Choice over the six classes and one Score over four wake levels. The score is stored scaled to 0..1. - **Field list.** `message_state` is the one place that builds it. A test pins the keys for each mode. - `headers`: from, name, subject, date, `List-Id`, system flags (`\Seen`, `\Answered`, `\Flagged`), and attachment names and types. - `full` adds `excerpt`: the first 500 characters of the quote-trimmed body. - Keywords, other recipients and the full body stay on the host. - **Transport.** - One retry on 429 or 529, honouring `retry-after` (capped at 30 s). - 401 and 403 map to `auth_error`. Everything else maps to `unavailable`. - The key is registered with the scrubber and never logged. - **Failures.** A failed call leaves the rows unassessed for the next tick. The error is recorded in the sync log, so `mail_status` shows it. - **Answers are advisory.** A class outside the six or a score out of range is dropped. A batch where every answer is invalid ends the tick. - **Status and CLI.** - `mail_status` prints `assess: fields=… model=…` or `assess: off`, and `assessed=N` per account. - `mailmind sync --once` also runs one assess tick. - **Logs.** Counts, dropped counts, the model and token counts. ## Config defaults | Key | Default | |---|---| | `fields` | `headers` | | `model` | `jev-1.13.0` (pinned) | | `batch` | 10 | | `backlog_days` | 14 | | `poll_seconds` | 60 | | `timeout_seconds` | 25 | ## Deploy No change to the init script. A Secret key named `jev.key` lands in the `sync` runtime directory only, because only `.token` keys go to `api`. The base and compose comments say so. ## Tests `tests/test_assess.py` has 13 tests: - the closed keys for each mode, with keywords and other recipients not sent - excerpt trimming - the payload shape - answer validation - the 429 retry, 401 and 503 against a fake Jev on 127.0.0.1 - end to end: window, role, batch and the moved copy, with the key, subjects and addresses absent from the captured logs - `full` mode - a failed call followed by a retry on the next tick - an absent section - a relative key path refused `make check` passes (99 tests). The image's SQLite is 3.40.1, so the `UPDATE … AS` alias in `copy_assessments` is supported. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An optional [assess] section sends the ADR 0003 field list for recent inbox messages to TypeSafe Jev, one batch per call, and stores a triage class and a wake score per row. A moved message copies its class by Message-ID. The key reaches the sync container only.

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