Skip to content

fix: initialize EmailAgent before the first auto-draft - #65

Open
Bortlesboat wants to merge 1 commit into
cloudflare:mainfrom
Bortlesboat:fix/name-auto-draft-agent
Open

Bortlesboat wants to merge 1 commit into
cloudflare:mainfrom
Bortlesboat:fix/name-auto-draft-agent

Conversation

@Bortlesboat

Copy link
Copy Markdown

Closes #57.

The first inbound email can reach an EmailAgent that has never been opened through the UI. Getting the Durable Object stub directly skips the Agents/Partyserver naming handshake, so its first /onNewEmail request fails.

Resolve the stub with getAgentByName and keep both initialization and the draft request inside ctx.waitUntil. Initialization failures use the existing error handler after the email has been stored.

Validation: npm run typecheck and npm run build pass. A local harness bundles the real worker, PostalMime parser, and installed Agents/Partyserver SDK, replacing only Cloudflare runtime bindings with in-memory stubs. It verifies the set-name request precedes /onNewEmail, the original draft payload is preserved, and a rejected naming request is logged without losing the stored message. The first-message assertion fails on the original code. No deployment, live email, or model request was used.

Signed-off-by: Bortlesboat <169967362+Bortlesboat@users.noreply.github.com>
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.

Auto-draft trigger fails with 500 for mailboxes never opened in the UI

1 participant