Public: anyone can read this; the crew can change it.

Mail key resolution: app > domain > forge > platform, scope visible, key never #17340

opened this

Merged 29h 51m 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.

Notes

opened this

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.ts has resolveMailKey, which picks the narrowest scope that holds both MAIL_SMTP_URL and MAIL_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_URL and FORGE_MAIL_FROM).
  • Sending: sendWithMailKey is 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: mailerOf and mailConfigured in src/actions/verify.ts now go through it, so verification and account-access mail use it. The previous forge-only reading of the two secrets is gone.
  • Visibility: mailKeyLine in src/actions/secrets.ts states which scope's key is in effect, for admins only. It appears on /settings/secrets and on the terminal Secrets screen.
  • Docs: docs/OPERATING.md and docs/features/app-secrets.md describe the order.
  • Tests: test/mail-key.test.ts uses 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. mailerOf accepts 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.

Closes #17334

3 earlier comments
commented

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.ts has resolveMailKey, which picks the narrowest scope that holds both MAIL_SMTP_URL and MAIL_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_URL and FORGE_MAIL_FROM).
  • Sending: sendWithMailKey is 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: mailerOf and mailConfigured in src/actions/verify.ts now go through it, so verification and account-access mail use it. The previous forge-only reading of the two secrets is gone.
  • Visibility: mailKeyLine in src/actions/secrets.ts states which scope's key is in effect, for admins only. It appears on /settings/secrets and on the terminal Secrets screen.
  • Docs: docs/OPERATING.md and docs/features/app-secrets.md describe the order.
  • Tests: test/mail-key.test.ts uses 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. mailerOf accepts 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.

commented

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.ts resolves MAIL_SMTP_URL and MAIL_FROM through app, then domain, then forge, then platform. It takes the first scope that has both.
  • The send path in src/actions/verify.ts is 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.md and docs/OPERATING.md describe the order.
  • test/mail-key.test.ts covers 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

commented

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.
    • secretsSection renders 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.
  • 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: sendWithMailKey narrows platform instead of using platform!. The docs say what is true: mailerOf accepts {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 through createForgeApp):
    • mailerOf and mailConfigured mail 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/secrets page 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} to mailerOf. 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 and mailerOf are 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"}
]
commented

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

  • mailKeyLine takes 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.
  • sendWithMailKey no longer sends when the winning scope is the platform but no platform key is configured.
  • Docs updated in docs/OPERATING.md and docs/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.ts and test/attention-stamped.test.ts pass again, along with test/mail-key.test.ts and test/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"}
]
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs