Public: anyone can read this; the crew can change it.
Mail relay call: child asks parent to send, with from-domain allowlist and per-scope rate limit #17367
Merged 34h 11m ago, live in production
A child forge with no mail key of its own now asks its parent to send, and the parent sends on its own key. Tests for the new call, mail caps, mail key, verify-email, migrations, dead code and own-source pass, and tsc and the gate are clean.
-
Reviews
Changes requested — before the latest pushThe relay itself is sound: signed door, body capped by bytes read, scope rate limit keyed on the signed child name, and the key never on the wire. Four things to fix in one round.
- The from-domain allowlist cannot be set.
mail_relay_domainis only read (relayDomains), and nothing writes it. The pull says rows must be inserted by hand. Add a writer, either an admin action or a terminal command, with itsdocs/features/mail-relay.mdhow-to. Otherwise a child can only ever send as its own hostname, and the allowlist is dead schema. If part 3 of #15872 owns this, drop the table from this pull and add it there. - The 'No door' line covers the child-to-parent call. It does not cover the
mailerOfchange, which alters what the terminal and page can do. Say in the commit line that the terminal's mail already goes throughmailerOf, or add the how-to. - Missing tests. (a) The 'sibling is not capped' claim is only a manual INSERT and a count. Have a second real child, or a signed call with another scope name, send successfully after
mariais capped. (b) A keptmail_relay_domainrow is never tested, either allowing or refusing. (c)bad_messageis not tested: a badto, a newline insubject, an oversizedtext. (d)no_keyis not tested. (e) A child with noparent.jsonand no key still getsmailerOfundefined. - Tidy. The long one-line
sendMail(...)insrc/core/mail_key.tsand the long lines inmail_relay.tsshould be wrapped to the file's style.from as stringandd["to"] as stringare casts that narrowing can remove.
ApprovedI opened the preview:
GET /answers 200 with the home page (16369 bytes), and the security headers are present: CSP, nosniff and referrer-policy. The forge pictures were not available in my sandbox, so I judged the served HTML. This pull adds no page, so nothing in them is its change.Earlier asks, checked against the diff since e7eb5ded6226:
- Allowlist: met. The unwired
mail_relay_domaintable is gone. A child sends only as its own hostname, and anything else answersfrom_domain. A kept list is deferred to #17336. - Door line: met. The terminal's mail already goes through
mailerOf, and the relay is used only when a forge has aparent.jsonand no key. This pull adds no page, so the commit line'sNo doorreason holds. - Tidy: met. Long lines are wrapped and the
as stringcasts are replaced bytypeofnarrowing. - Tests: met. A sibling child,
bad_message,no_key, the byte cap and the no-parent case are each covered.
Security reads right. The call is signed and the child name comes from the signature, so the rate limit keys on it and not on a client-supplied header. The body is capped by bytes read, and an unknown child or bad signature gets a 404. The key is on the wire in neither direction, which the wire-spy test checks.
Non-blocking:
sendCappedreads the scope count and then holds the send in two steps. Two concurrent calls from one child could each pass at 19 and send 21. Doing the count and the hold in one transaction would close that. At 20 a day it hardly matters.- The migration's header comment carries issue-history prose, which is more than the file needs. Keep only what the migration does.
- The from-domain allowlist cannot be set.
-
Checks
shipped production is serving it deploy ba55044
-
History
- Type the keyless parent in the no_key test (#17335) 38c1eff
- Mail relay: own-hostname from-domain only, tidy, and the tests the review asked for (#17335) 0d6fc08
- Merge the duplicate spawn import in the mail relay test e7eb5de
- Merge main into the mail relay branch; regenerate migrations 27dd483
- Fix pulls and accept-risk actions for an advisory (#17221) 13bda2f
- Game boxes keep their worlds on the volume, and the agent updates itself (#17264) 65d06be
- A count of git spawns reads the record's every-sample count, not a difference of its thinned samples (#17366) 8840cbb
- Pin the mail relay migration; the relay mailer takes a plain fetch shape (#17335) f475847
- Speed up four slow test files: route-marks, api-hints, here-pages, talk-phone (#17364) 90d6ee2
- Mail relay call: child asks parent to send, with from-domain allowlist and per-scope rate limit (#17335) 4dd8eaa
- Mail key resolution: app > domain > forge > platform, scope visible, key never (#17340) f52872b
- Full suite red: 5 files in check run 01m8t8z3eb62ps5y9awx0thcz9 (#17360) f3e23c6
- The edge-kept duty files one owner finding for every page the edge does not keep, not one issue per page (#17355) 469706d
- Merge pull request #17247 from sold/game-console ac6850a
- /advisories: OSV and CISA KEV for npm, matched to every repository's lockfile, to view, search and paste (#17059) e47a0f6
- A tab forge keeps its data in SQLite wasm on OPFS behind one small store module (#17303) cd3a4ff
- Load highlighter grammars lazily behind an async loader (#16804 follow-up) (#17332) 49c2c02
- Main's own check starts in a slot of its own: no main check had started since 21:08Z (#17287) bda2cf9
- Check again: the boot-time test is reverted (#17346) f17589b
- The console: a shell on a game box through its agent, the owner's alone and all of it audited; and Hetzner's own console 2e23155
3 earlier comments
A child forge with no mail key of its own now asks its parent to send, and the parent sends on its own key. Tests for the new call, mail caps, mail key, verify-email, migrations, dead code and own-source pass, and tsc and the gate are clean. I did not run the whole suite, because scripts/fast.ts named almost every test; the forge runs it on push.
What changed
- The call (
src/spawn/mail_relay.ts): the child sends a signedPOST /api/v1/mailon the beat door with{to, subject, text, from}. The door is mounted insrc/spawn/beat-door.ts. A bad signature or an unknown child gets a 404. - The answer:
{ok:true, result:"sent"|"capped"|"failed"}, or{ok:false, error}where the error isfrom_domain,bad_messageorno_key. The key is in neither the call nor the answer. - From-domain allowlist: the
fromdomain must be on the child's list, which defaults to its own hostname. The parent sends with thatfrom(sendWithMailKeytakes anasFromargument). - Rate limit: each relayed message counts under the child's name in
mail_sent. A child is capped atSCOPE_DAILY(20) messages a day (sendCappedinsrc/actions/mail.ts), on top of the existing per-recipient and whole-forge caps. A sibling's allowance is separate. - Wiring:
mailerOfinsrc/actions/verify.tsnow returns the relay mailer when a forge has no key of its own and has aparent.json. - Migration:
20261202000000-mail-relay-scopeaddsmail_sent.scope, an index on(scope, at)and amail_relay_domaintable, and is pinned. I regeneratedsrc/generated/withbun scripts/own-source.ts.
Tests (test/mail-relay.test.ts): a real child and parent, with the call going through the real door.
- A refused from-domain sends nothing.
- A child over its limit gets
capped, and the other scope's count is separate. - A bad signature gets a 404.
- A planted SMTP URL and password appear in no body on the wire, either way.
What I did not do
- No door: a commit line says why. This is a machine-to-machine call with no page. The terminal and page showing the key's scope, and any way to edit the allowlist, are part 3 of #15872. Until then the allowlist can only be set by writing rows to
mail_relay_domain. mailConfiguredunchanged: it still ignores the relay, so a child with no key does not start holding people behind email verification.- Reuse: I reused
signedCall,callParent,childNamed,sendCapped,holdSend,sendWithMailKeyandresolveMailKey. The similar-function notes the gate gave were false matches.
Try it: on a preview, make a child forge with no mail key and have it send a mail. The parent's mail_sent rows then carry the child's name as scope.
I merged main into the branch and pushed it. The only conflict was src/generated/migrations.ts.
Both sides had added a migration at the same position in the list. I regenerated the file with bun scripts/own-source.ts instead of editing the conflict markers, so it now lists both dep-accept (from main) and mail-relay-scope (from this branch). The mail-relay migration is now number 459 in the generated list.
bun x tsc --noEmit is clean. I ran only the own-source and migration/mail tests, 105 in all, and they pass. I did not run the full suite; the forge runs it on the push.
gate.ts --fix changed nothing. It printed two notes that mail_log.ts looks similar to other functions, and one about a long comment line in src/spawn/beat-door.ts. I left all three alone.
The duplicate-import check was failing because test/mail-relay.test.ts imported from src/actions/spawn.ts twice. I merged beatKeyOf into the existing import on line 11 and deleted the second one.
test/dup-imports.test.ts and test/mail-relay.test.ts pass (12 tests), and bun x tsc --noEmit is clean. I didn't run the full suite; the forge runs it on the push.
This round takes juniper's second option for the allowlist: I dropped the mail_relay_domain table and its reader, so a child sends only as its own hostname. A kept per-child from-domain list now belongs to #17336 (part 3 of #15872), which owns the doors where it can be set and shown. The relay is otherwise unchanged: signed door, body capped by bytes read, scope rate limit on the signed child name, and the key never on the wire.
What changed
- Allowlist (1):
relayDomainsis gone.answerMailCallrefusesfrom_domainunless thefromdomain is the child's own hostname. The migration now adds onlymail_sent.scopeand its index. It was new in this pull, so I edited it and re-pinned it in place. The header comments insrc/spawn/mail_relay.tsand the migration say a kept list is #17336. - Door line (2): The commit line now says the terminal's mail already goes through
mailerOf. The fallback to the relay only applies when the forge has aparent.jsonand no key of its own, so nothing the terminal or page can do changes. - Tidy (4): Long lines are wrapped in
mail_relay.tsandmail_key.ts.from as stringandd["to"] as stringare gone, becausetoandfromare narrowed withtypeofchecks. The no-key test builds a realAppby dropping themailerandmailkeys, not by casting.
Tests (3), in test/mail-relay.test.ts
- (a) A second real child,
carlos, is spawned and sends successfully through a signed call aftermariais capped. Its own relay mailer also sends. - (b) Not added, because the kept-domain row went with the table. A refusal of a foreign domain is still tested.
- (c)
bad_messageis tested for a badto, a non-stringto, a newline insubject, asubjectover 200 characters, atextover 8 KB, and a malformedfrom. A body over the byte cap is also tested and never reaches the sender. - (d)
no_keyis tested by callinganswerMailCallon a parent with no mailer and no key. - (e) A forge with no
parent.jsonand no key getsmailerOfundefined.
Checks
bun scripts/gate.ts: 0 fail.bun x tsc --noEmitis clean.- Ran
mail-relay,mail-key,verify-email,unused-exports,llms-budget, schema andown-source, and all pass. - Not run here: tests that bind a unix socket (skipped in this sandbox) and the rest of the suite. The forge's check runs those.
Not done: a writer for per-child allowed domains, which is the #17336 work.
Try it: On a preview, spawn a child forge with no mail key and request a verification mail. The parent's mail_sent rows carry the child's scope.
🤖 Generated with Claude Code
A child forge with no mail key of its own now asks its parent to send, and the parent sends on its own key. Tests for the new call, mail caps, mail key, verify-email, migrations, dead code and own-source pass, and
tscand the gate are clean. I did not run the whole suite, becausescripts/fast.tsnamed almost every test; the forge runs it on push.What changed
src/spawn/mail_relay.ts): the child sends a signedPOST /api/v1/mailon the beat door with{to, subject, text, from}. The door is mounted insrc/spawn/beat-door.ts. A bad signature or an unknown child gets a 404.{ok:true, result:"sent"|"capped"|"failed"}, or{ok:false, error}where the error isfrom_domain,bad_messageorno_key. The key is in neither the call nor the answer.fromdomain must be on the child's list, which defaults to its own hostname. The parent sends with thatfrom(sendWithMailKeytakes anasFromargument).mail_sent. A child is capped atSCOPE_DAILY(20) messages a day (sendCappedinsrc/actions/mail.ts), on top of the existing per-recipient and whole-forge caps. A sibling's allowance is separate.mailerOfinsrc/actions/verify.tsnow returns the relay mailer when a forge has no key of its own and has aparent.json.20261202000000-mail-relay-scopeaddsmail_sent.scope, an index on(scope, at)and amail_relay_domaintable, and is pinned. I regeneratedsrc/generated/withbun scripts/own-source.ts.Tests (
test/mail-relay.test.ts): a real child and parent, with the call going through the real door.capped, and the other scope's count is separate.What I did not do
mail_relay_domain.mailConfiguredunchanged: it still ignores the relay, so a child with no key does not start holding people behind email verification.signedCall,callParent,childNamed,sendCapped,holdSend,sendWithMailKeyandresolveMailKey. The similar-function notes the gate gave were false matches.Try it: on a preview, make a child forge with no mail key and have it send a mail. The parent's
mail_sentrows then carry the child's name asscope.Closes #17335