Skip to content

feat(server): emailed run reports, and the recipient question er-server cannot answer - #306

Merged
athvin merged 1 commit into
mainfrom
feat/emailed-run-reports
Oct 23, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/emailed-run-reports

Conversation

@athvin

@athvin athvin commented Oct 23, 2026

Copy link
Copy Markdown
Owner

POST /v1/email has existed since #203, and AppState.mail had exactly one caller: the operator_only send route. There was no dispatcher-side mailer at all, so nothing the engine did could ever reach a human by mail.

The plan asked "which org members get a report". There is no answer in this process.

Membership lives in the frontend's database. The process that knows a run finished has no user roster — and inventing a cross-store read for a notification would be a far worse trade than asking an operator for addresses.

So recipients are an explicit list in the org's env under ER_RUN_REPORT_TO — the channel the dispatcher already reads nine ER_* keys from — and its absence is the opt-out. A tenant who never asked for mail does not get any because a run happened to finish.

That's the finding, not a gap papered over.

How it hooks in

The mailer is built by dispatch_once from env and passed into dispatch_once_with, mirroring exactly how Profile::from_env() is injected so tests supply their own rather than depending on the runner's environment.

The report rides the same settle as the job.* webhook and obeys the rule the comment there already states: one per OUTCOME, not per attempt. A job that fails twice then succeeds is one success, and three notifications for one incident is how an integration learns to ignore them.

A send that fails is logged and dropped. Mail is best-effort by design, and reporting an outcome is not part of producing it.

Reported kinds are a decision, not a default

kind reported why
run_all_full, run_all_incremental, correct, train ✅ a steward is waiting on the outcome
lake_maintain ❌ platform housekeeping a tenant cannot act on
provision ❌ the tenant-create UI already polls it with a progress indicator

Mailing either of the last two teaches a recipient to filter the whole thread. Both still emit webhooks and still appear in the runs list.

Verification

The whole decision is one pure function, so every rule is testable without a mailer, a Postgres or a job — each branch is something someone will want to change later.

Observed failing two ways:

  • reporting every kind → fails housekeeping_kinds_are_not_reported
  • dropping the blank-address filter → fails absence_is_the_opt_out, because configured-but-blank must send nothing rather than mail an empty address

A success report carries the O3c entity counts; a failure carries error_detail, already chain-flattened so it reads as a sentence rather than the outermost wrapper's Display.

The two dispatch_once_with test call sites pass Mailer::off() deliberately: their orgs configure no recipients, so a mailer that cannot send turns a stray report into a logged error instead of a silent success.

  • make check green (165 suites)
  • pg_provision + pg_entity_events green against the test Postgres — which make check self-skips, so running them explicitly is the only way to know

Verifiable without V0: ER_MAIL_BACKEND=log renders to the server log, so only real delivery waits on an SES identity.

🤖 Generated with Claude Code

…er cannot answer

`POST /v1/email` has existed since #203 and `AppState.mail` had exactly one
caller: the `operator_only` send route. There was no dispatcher-side mailer at
all, so nothing the engine did could ever reach a human by mail.

The plan asked "which org members get a report". That has no answer in this
process, and the absence is the finding rather than a gap to paper over:
membership lives in the FRONTEND's database, so the process that knows a run
finished has no user roster. Inventing a cross-store read for a notification
would be a far worse trade than asking an operator for addresses.

So recipients are an explicit list in the org's `env` under
`ER_RUN_REPORT_TO` — the channel the dispatcher already reads nine `ER_*` keys
from — and its ABSENCE is the opt-out. A tenant who never asked for mail does
not get any because a run happened to finish.

The mailer is built by `dispatch_once` from env and passed into
`dispatch_once_with`, mirroring exactly how `Profile::from_env()` is injected so
tests supply their own rather than depending on the runner's environment.

The report rides the same settle as the `job.*` webhook and obeys the rule the
comment there already states: one per OUTCOME, not per attempt. A job that fails
twice and then succeeds is one success, and three notifications for one incident
is how an integration learns to ignore them. A send that fails is logged and
dropped — mail is best-effort by design, and reporting an outcome is not part of
producing it.

Reported kinds are a decision, not a default: run_all_full,
run_all_incremental, correct, train — the ones whose outcome a steward waits on.
`lake_maintain` is platform housekeeping a tenant cannot act on, and
`provision` is already polled by the tenant-create UI with a progress
indicator; mailing either teaches a recipient to filter the whole thread. Both
still emit webhooks and still appear in the runs list.

The whole decision is one pure function so every rule is testable without a
mailer, a Postgres or a job — each branch is something someone will want to
change later. Observed failing two ways: reporting every kind fails
`housekeeping_kinds_are_not_reported`, and dropping the blank-address filter
fails `absence_is_the_opt_out`, because configured-but-blank must send nothing
rather than mail an empty address.

A success report carries the O3c entity counts; a failure carries
`error_detail`, which is already chain-flattened so it reads as a sentence
rather than the outermost wrapper's Display.

The two `dispatch_once_with` test call sites pass `Mailer::off()` deliberately:
their orgs configure no recipients, so a mailer that CANNOT send turns a stray
report into a logged error instead of a silent success.

Verifiable without V0 — `ER_MAIL_BACKEND=log` renders to the server log, so only
real delivery waits on an SES identity.

Verified: `make check` green (165 suites), and `pg_provision` + `pg_entity_events`
green against the test Postgres, which `make check` self-skips.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 1d7e3b6 into main Oct 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants