Public: anyone can read this; the crew can change it.
Mail key resolution: app > domain > forge > platform, scope visible, key never #17340
Merged 32h 1m ago, live in production
Mail key resolution is in place and the forge now sends mail through it. The new tests, tsc and the dead-code, doorless and feature-doors tests pass, along with test/verify-email.test.ts. src/main.ts needed no change.
-
Reviews
Changes requested — before the latest pushNo security finding: the key is opened in one place, only the winning scope is read, nothing returns or logs a value, and the line is admin-only. Two things stop this from being whole.
- The app and domain scopes do nothing yet. No caller passes
appordomain(mailerOf,mailConfiguredandmailKeyLineall resolve with{}). A key set under a repository's or organization's secrets is never used and never shown, and the page can only say forge or platform. Butdocs/OPERATING.mdanddocs/features/app-secrets.mdsay an app's own key is used and that the page says which scope is in effect. Either wire one real caller (the mail for a repo's own event passes{app, domain}) and have the page show it, or say in the docs that only forge and platform apply today. I prefer wiring it, since the issue is titled app > domain > forge > platform. - Missing tests. Nothing covers
mailerOformailConfiguredinverify.ts, which replaced the old forge-secret path. Nothing covers the/settings/secretsline, or the terminal line (that it appears and is not cut off). Add one test throughmailerOfthat mails via the winning scope, and one that renders the page as an admin and as a non-admin.
Smaller: the terminal line is appended to the header text and
truncated to the header width, so on a narrow terminal the scope is the part that gets cut. Put it on its own row or ahead of the generic sentence. Also drop theplatform!non-null assertion insendWithMailKeyby narrowing.ApprovedAll three earlier asks are met. (1) The line now resolves for the place in view: a repo passes its app and owning org, an org passes its domain, and the forge passes neither. (2) The tests now cover
mailerOf,mailConfigured, the rendered page (admin sees the line, non-admin does not) and the terminal screen. (3) The terminal draws the line on its own row. No new security findings: the line is admin-only, names only the scope, and onlysendWithMailKeyopens a key, restricted to the winning scope. Non-blocking: the new paragraph in docs/OPERATING.md has uneven line wrapping. - The app and domain scopes do nothing yet. No caller passes
-
Checks
shipped production is serving it deploy a544da9
-
History
- Mail key line sits in the Secrets card's intro, not a block of its own: crew page stays in its first-view budget (#17334) fe88105
- Mail key test: one key helper, no near-duplicate (#17334) 1b0f5d8
- Mail key line follows the place in view (app, domain, forge); tests through mailerOf, the page and the terminal (#17334) 162110b
- Merge main: picks up the revert of the flaky bundle CPU-share test (#17346) f449694
- Revert #17320: the bundle boot's CPU share doesn't separate bundle from source on Linux (#17346) 2e737a7
- A spawn whose first proof answered still settles it, so the new home is asked… (#17331) 8485415
- Full-suite report files every tally echo under the budget note's file (failed… (#17333) 466ceda
- The crew falls back to the capped key when every plan's window is full, and Settings → Crew shows and steers it (#17168) 4cad6ca
- The bundle's boot is held to a share of the source boot's CPU, measured in the same run, not a wall-clock bound (#17320) 252f7b6
- server.ts imports page, studio, render and API modules on the first request to their prefix (#17313) 9f6e1c4
- The test budget is CPU time: a test starved on a loaded box is not red, one that spends its seconds is (#17310) 3814902
- Advisory integrations: notify on a new exploited advisory (#17326) 31c05ee
- A workspace's dev checkout is synced with the forge's own git, never the operator's environment (#17318) 9a612d3
- fork-flows: the test's forks do not follow, so the background fast-forward cannot move them between two reads (#17328) fe88e40
- Direction: mail key resolves app > domain > forge > platform; callers see the scope, only the send opens the key (#17334) 7fe9330
- sweepSoon starts its sweep on the next turn of the loop, so "sweeping a check… (#17327) 1c9fc4c
- Move the accessors out of looks/service.ts (keepLook, lookUrl, memoryPressure) so it leaves the boot's static closure (#17277) 3bdad32
- Shards are packed by the verification's times first: the committed table's stale ones no longer win (#17296) 0d8a7ee
- The scans' budget is their planned wall time over the check's shards, and the scans carry their measured times (#17321) dd898c7
- Sentinel: The guard parked 20 runs in a private repository (01m5th8bwh248hrnezwstf9fff) in a day (#17325) 909a51b
3 earlier comments
Mail key resolution is in place and the forge now sends mail through it. The new tests, tsc and the dead-code, doorless and feature-doors tests pass, along with test/verify-email.test.ts. src/main.ts needed no change.
One thing differs from the issue: docs/MAIL-RELAY.md is not in the repository, so I worked from the issue text and #15872.
What changed
- Resolution:
src/core/mail_key.tshasresolveMailKey, which picks the narrowest scope that holds bothMAIL_SMTP_URLandMAIL_FROM: app, then domain, then forge, then platform. It returns the scope name and opens nothing. A half-set pair counts as no key at that scope. - Scope mapping: "app" is the repository's secrets and "domain" is the organization's. "Platform" is the boot configuration (
FORGE_SMTP_URLandFORGE_MAIL_FROM). - Sending:
sendWithMailKeyis the only place a key is opened. It reads only the winning scope, so the URL and sender never mix across scopes. It hands the pair to the SMTP sender and returns only{scope, sent}. - Wiring:
mailerOfandmailConfiguredinsrc/actions/verify.tsnow go through it, so verification and account-access mail use it. The previous forge-only reading of the two secrets is gone. - Visibility:
mailKeyLineinsrc/actions/secrets.tsstates which scope's key is in effect, for admins only. It appears on/settings/secretsand on the terminal Secrets screen. - Docs:
docs/OPERATING.mdanddocs/features/app-secrets.mddescribe the order. - Tests:
test/mail-key.test.tsuses a loopback SMTP stub that records which key authenticated. It covers:- inheriting the platform key;
- each scope overriding the wider one;
- other apps and domains not seeing a sibling's key;
- removal falling back one scope at a time;
- a half-set pair being ignored;
- no key value in the answer or the audit event;
- the admin-only line.
Not done
- Per-scope rate limits and allowed from-domains, which are other items in #15872.
- No caller passes an app or domain yet.
mailerOfaccepts them, but today's callers still resolve at forge level, so the app and domain scopes are reachable only through the resolver until the app-mail relay step. - No new page or screen; the existing Secrets ones carry the line.
Gate: bun scripts/gate.ts still reports one similarity warning (my test helper key against test/signup-window.test.ts). I left it because they are different things. unused-exports prints a note that two unrelated exports are no longer dead.
How to try it: as an admin, open /settings/secrets on the preview and read the muted line saying which scope's mail key is in effect.
Reused: resolveSecrets with only:, listSecretNames and the kernel sendMail. scripts/similar.ts was not run.
The mail key now resolves app > domain > forge > platform. Callers only see which scope's key is in effect, and only the send opens the key.
Check failure: the failing test, "the bundle reaches /readyz on under 60% of the source boot's CPU", was not caused by this change. The bundle and source boots took about the same CPU on the forge's runner, a share of 1.0 against the 0.6 limit. Main has since reverted that test (#17346), because the CPU share doesn't separate bundle from source on Linux. I merged current main into this branch rather than rebasing, so the push stayed a plain fast-forward, and pushed it.
Checks: after the merge, bun x tsc --noEmit is clean and test/mail-key.test.ts passes (6 tests). bun scripts/gate.ts exits 0; it prints one advisory note that a helper in the mail-key test looks 0.56 similar to one in signup-window.test.ts, which I left alone. I did not re-run the full suite, since the forge runs it on the push.
What changed
src/core/mail_key.tsresolvesMAIL_SMTP_URLandMAIL_FROMthrough app, then domain, then forge, then platform. It takes the first scope that has both.- The send path in
src/actions/verify.tsis the only place that opens the key. - The Secrets page (
src/web/pages/secrets.ts) and its terminal screen (src/tui/screens/secrets.ts) show one muted line naming the scope in effect. docs/features/app-secrets.mdanddocs/OPERATING.mddescribe the order.test/mail-key.test.tscovers each fallback and the display.
Not done: no layout change, no new dependency, and no new page. The existing Secrets page carries the line.
Try it: open /settings/secrets as an admin on the preview and read the line saying which scope's mail key is in effect.
[{"go":"/settings/secrets","look":"the muted line under the mail key fields","expect":"it names the scope (app, domain, forge or platform) whose mail key is in effect, and the page layout does not shift"}]
🤖 Generated with Claude Code
The mail key is now resolved per place, so the app and domain scopes appear on the Secrets card and the terminal screen. No send path passes an app or domain yet, though. The new tests, tsc, design-lint and gate.ts are clean. I did not run the full bun test. The forge runs the full check on the push.
What changed
- App and domain scopes:
mailKeyLine(app, actor, scope, ref)now resolves for the place being viewed.- A repository passes
{app: repo id, domain: owning org id}. An organization passes{domain}. The forge passes neither. secretsSectionrenders the line, so it appears on the forge Secrets page and on a repo's and an org's settings. It is admin-only and names only the scope.
- A repository passes
- Terminal: the Secrets screen draws the line on its own row (the header is two rows now), so a narrow terminal no longer cuts the scope off. It follows the place chosen with
s. - Smaller fixes:
sendWithMailKeynarrowsplatforminstead of usingplatform!. The docs say what is true:mailerOfaccepts{app, domain}, but today's mails (sign-up, orders, recovery) belong to the forge and pass none. - Tests (
test/mail-key.test.ts, which now builds the real session throughcreateForgeApp):mailerOfandmailConfiguredmail through the winning scope and fall back to the forge's key.- The line is checked for a repo and for an org.
- The
/settings/secretspage is rendered as an admin, who sees the line, and as a non-admin, who sees nothing. - The terminal screen is drawn on a 60-column terminal with the line whole.
Not done
- No send path passes
{app, domain}tomailerOf. The mails the forge sends today have no repository behind them. Wiring one needs a feature that mails from a repo's own event, which I did not invent. The resolver andmailerOfare ready for it. - A repository owned by a user has no domain, so its line shows the forge or platform scope when no app key is set. That is intended.
Review
[
{"go": "/settings/secrets as an admin", "look": "the line under the card", "expect": "Mail goes out with the forge's key, or No mail key is set"},
{"go": "a repo's settings, with an app-scope MAIL_SMTP_URL and MAIL_FROM set", "look": "the Secrets card's line", "expect": "the app's key"},
{"go": "the same page as a non-admin", "look": "the Secrets card", "expect": "no card and no line"}
]The mail key line now follows the place in view: an app, its organization, or the forge. It resolves narrowest first (app, then organization, then forge, then the host's boot configuration). The first push made the crew page one block too big for its first-view budget, and that is now fixed.
What changed
mailKeyLinetakes the scope and reference of the Secrets card it is drawn on. For a repository it asks as that app, with the owning organization as its domain. For an organization it asks as that domain, and for the forge it asks as neither.- The line says which scope's key sends mail there. It never shows the key, and only admins see it.
- The terminal's Secrets screen shows the same line on its own row for the place in view.
sendWithMailKeyno longer sends when the winning scope is the platform but no platform key is configured.- Docs updated in
docs/OPERATING.mdanddocs/features/app-secrets.md.
The check failure
- Cause: the new line was an extra
<p>after the card, and it counted as a block on the crew page (90 against a budget of 89). - Fix: the line now goes inside the Secrets card's existing intro paragraph, so it adds no block (
src/web/pages/secrets.ts). - Result:
test/attention.test.tsandtest/attention-stamped.test.tspass again, along withtest/mail-key.test.tsandtest/secrets-card.test.ts.bun x tsc --noEmit, the gate and the design lint are clean. - Not reproduced: the third failure, in the forks screen's sent-offers test, passed when I ran it locally, so I did not change anything for it. I expect it to pass in the check, but I haven't seen it do so.
Not done: today's mails (sign-up, orders, recovery) are the forge's own, so they still pass no app or domain and use the forge's or the platform's key. Passing an app or domain from a mail path is a separate change.
To try: as an admin, open Settings → Secrets, an organization's settings, or a repository's settings. Each Secrets card names the scope whose key sends mail for that place. The terminal's Secrets screen shows the same.
[
{"go": "/settings/secrets", "look": "Intro paragraph of the Secrets card", "expect": "Ends with 'Mail goes out with the <scope>'s key (the key itself is never shown).' and there is no separate muted line under the card for it"},
{"go": "/settings (repository, as admin)", "look": "Secrets card intro", "expect": "Names the scope that wins for this app, such as app, domain, forge or platform"}
]
Mail key resolution is in place and the forge now sends mail through it. The new tests,
tscand the dead-code, doorless and feature-doors tests pass, along withtest/verify-email.test.ts.src/main.tsneeded no change.One thing differs from the issue:
docs/MAIL-RELAY.mdis not in the repository, so I worked from the issue text and #15872.What changed
src/core/mail_key.tshasresolveMailKey, which picks the narrowest scope that holds bothMAIL_SMTP_URLandMAIL_FROM: app, then domain, then forge, then platform. It returns the scope name and opens nothing. A half-set pair counts as no key at that scope.FORGE_SMTP_URLandFORGE_MAIL_FROM).sendWithMailKeyis the only place a key is opened. It reads only the winning scope, so the URL and sender never mix across scopes. It hands the pair to the SMTP sender and returns only{scope, sent}.mailerOfandmailConfiguredinsrc/actions/verify.tsnow go through it, so verification and account-access mail use it. The previous forge-only reading of the two secrets is gone.mailKeyLineinsrc/actions/secrets.tsstates which scope's key is in effect, for admins only. It appears on/settings/secretsand on the terminal Secrets screen.docs/OPERATING.mdanddocs/features/app-secrets.mddescribe the order.test/mail-key.test.tsuses a loopback SMTP stub that records which key authenticated. It covers:Not done
mailerOfaccepts them, but today's callers still resolve at forge level, so the app and domain scopes are reachable only through the resolver until the app-mail relay step.Gate:
bun scripts/gate.tsstill reports one similarity warning (my test helperkeyagainsttest/signup-window.test.ts). I left it because they are different things.unused-exportsprints a note that two unrelated exports are no longer dead.How to try it: as an admin, open
/settings/secretson the preview and read the muted line saying which scope's mail key is in effect.Reused:
resolveSecretswithonly:,listSecretNamesand the kernelsendMail.scripts/similar.tswas not run.Closes #17334