Repository navigation
feat(server): emailed run reports, and the recipient question er-server cannot answer - #306
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
POST /v1/emailhas existed since #203, andAppState.mailhad exactly one caller: theoperator_onlysend 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
envunderER_RUN_REPORT_TO— the channel the dispatcher already reads nineER_*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_oncefrom env and passed intodispatch_once_with, mirroring exactly howProfile::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
run_all_full,run_all_incremental,correct,trainlake_maintainprovisionMailing 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:
housekeeping_kinds_are_not_reportedabsence_is_the_opt_out, because configured-but-blank must send nothing rather than mail an empty addressA 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'sDisplay.The two
dispatch_once_withtest call sites passMailer::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 checkgreen (165 suites)pg_provision+pg_entity_eventsgreen against the test Postgres — whichmake checkself-skips, so running them explicitly is the only way to knowVerifiable without V0:
ER_MAIL_BACKEND=logrenders to the server log, so only real delivery waits on an SES identity.🤖 Generated with Claude Code