Skip to content

[Improve] Derive the AgentMail inbox from an inbox-scoped API key - #2486

Merged
mrubens merged 3 commits into
developfrom
fix/agentmail-scoped-key-diagnostics
Sep 10, 2026
Merged

[Improve] Derive the AgentMail inbox from an inbox-scoped API key#2486
mrubens merged 3 commits into
developfrom
fix/agentmail-scoped-key-diagnostics

Conversation

@mrubens

@mrubens mrubens commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Saving the Email (AgentMail) settings with an inbox-scoped API key failed with a 403 on the organization-level /v0/webhooks endpoints, even with every permission enabled. Rather than detect key scopes, this PR makes the inbox-scoped key the intended shape and simplifies setup around it.

  • The inbox comes from the key. On save, Roomote lists the inboxes the key can see and requires exactly one (or the one pinned by R_AGENTMAIL_INBOX_ID, which the key must be able to see). A key that sees none or several is refused with copy that names the inboxes and explains how to create an inbox-scoped key. Setup is now: paste key, save.
  • Webhooks are managed on the inbox (/v0/inboxes/{inbox_id}/webhooks), which both inbox-scoped and organization-level keys can reach. Event types converge in place; a drifted URL or a missing secret recreates the registration.
  • Removed: the inbox chooser and free-text inbox field, the listAgentMailInboxes procedure, the inbox provisioning path, the Pod ID field and pod plumbing, and the key-scope detection this PR briefly introduced. R_AGENTMAIL_POD_ID is dropped from the env schema (it never shipped in a release) and cleaned up on disconnect.
  • Errors name the refused request (method, path, and AgentMail's response) instead of only listing permissions.
  • Mock AgentMail server gains the inbox-scoped webhook routes; docs, onboarding copy, and the mock-testing skill updated.

Test plan

  • pnpm check-types, pnpm lint, pnpm knip, docs link check
  • communication: inbox-scoped webhook paths and bodies; mock inbox-scoped routes
  • web: one-inbox resolution, zero/several-inbox refusals, env-pinned inbox, message_read probe, webhook recreate/converge/untouched, host-hash isolation, status, clear
  • Manual: save an inbox-scoped key in Settings > Communications > Email on a preview deployment

An inbox-scoped key passes every inbox check and is then refused on the
organization-level webhook endpoints, which read as a permissions problem
even for a full-access key. The save now falls back to the inbox's own
webhook endpoints on that refusal, records the detected scope so status and
disconnect address the same endpoints, and the error names the exact
request AgentMail refused when the fallback does not apply.

Also fixes the doubled "(optional)" on the Pod ID field and teaches the mock
AgentMail server the inbox-scoped webhook routes.
@roomote-community

roomote-community Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

  • Replacing an inbox-scoped key can retain its scope and orphan the old inbox webhook (apps/web/src/trpc/commands/comms/index.ts:1268).

Reviewed bf0556c

Comment thread apps/web/src/trpc/commands/comms/index.ts Outdated
A Roomote deployment owns exactly one inbox, so the intended AgentMail key
is one created from inside that inbox. The save now resolves the inbox from
the key (it must see exactly one, or the one pinned by R_AGENTMAIL_INBOX_ID)
and manages the webhook through the inbox's own endpoints, which is all an
inbox-scoped key can reach. That removes the inbox chooser and free-text
field, the inbox provisioning path, the pod id field and pod plumbing, and
the key-scope detection this PR briefly introduced. Permission errors name
the exact refused request.
@mrubens mrubens changed the title [Fix] Support inbox-scoped AgentMail API keys [Improve] Derive the AgentMail inbox from an inbox-scoped API key Sep 10, 2026
@mrubens
mrubens merged commit a6e6197 into develop Sep 10, 2026
19 checks passed
@mrubens
mrubens deleted the fix/agentmail-scoped-key-diagnostics branch September 10, 2026 21:17
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.

1 participant