fix(provider-microsoft): return structured failure when reply createReplyAll fails (#50)#54
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
stevenobiajulu
added a commit
that referenced
this pull request
Apr 28, 2026
Update the Draft-Then-Send via createReplyAll requirement to reflect that replyToMessage now returns a structured REPLY_FAILED instead of silently falling back to sendMail. Replace the stale "Fallback to sendMail on 404" scenario with one that captures the new contract. Spotted by Gemini and Codex during peer review of #54.
…eplyAll fails
When createReplyAll threw inside replyToMessage (e.g., the original message
was deleted and Graph returned 404), the catch fell through to a manual
sendMessage that used opts?.cc as `to:` and a literal `'Re: '` as subject.
The result was success: true with the email going to the wrong recipients
(or no one) and no thread context — silent mis-send.
Replace the silent fallback with a structured failure that mirrors
createReplyDraft:
{ success: false, error: { code: 'REPLY_FAILED', message, recoverable: false } }
A sendMail-based "fallback reply" is not actually a reply: it lacks
In-Reply-To / References headers so recipients' clients won't thread it,
and no amount of hydrating to/subject fixes that. Loud failure is correct;
the caller decides whether to send a fresh email.
Tests:
- Replace the broken-fallback scenario that asserted success: true.
- Add four failure-path tests covering createReplyAll throw, opts.cc
regression guard, /send failure after a successful PATCH, and PATCH
failure inside prepareReplyDraft.
Closes #50
stevenobiajulu
added a commit
that referenced
this pull request
Apr 28, 2026
Update the Draft-Then-Send via createReplyAll requirement to reflect that replyToMessage now returns a structured REPLY_FAILED instead of silently falling back to sendMail. Replace the stale "Fallback to sendMail on 404" scenario with one that captures the new contract. Spotted by Gemini and Codex during peer review of #54.
4188031 to
d901989
Compare
Update the Draft-Then-Send via createReplyAll requirement to reflect that replyToMessage now returns a structured REPLY_FAILED instead of silently falling back to sendMail. Replace the stale "Fallback to sendMail on 404" scenario with one that captures the new contract. Spotted by Gemini and Codex during peer review of #54.
d901989 to
444e9cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GraphEmailProvider.replyToMessage. WhencreateReplyAll(or any subsequent step inprepareReplyDraft//send) throws, return a structured{ success: false, error: { code: 'REPLY_FAILED', recoverable: false } }instead of a fresh email toopts?.cc.createReplyDraft.Why not "hydrate then sendMail"?
A sendMail-based reply has no
In-Reply-To/Referencesheaders, so even with the originalto/subject/cccorrectly hydrated, recipients' clients won't thread it. Faking a reply via sendMail is structurally inferior to a loud failure — the caller is in a better position to decide whether to send a fresh email.Scope note
This is a provider-layer fix.
replyToEmailActionalready prefetches the original message viactx.provider.getMessage(input.message_id)(packages/email-core/src/actions/reply.ts:102), so the issue's literal repro (delete the message, then callreply_to_email) currently surfaces asPROVIDER_UNAVAILABLEfrom the lazy server wrapper, not fromreplyToMessage. The provider bug is real and worth fixing for any other failure mode (auth, transient errors, malformed IDs that passgetMessagebut failcreateReplyAll); aligning the action layer to translateMESSAGE_NOT_FOUNDintoREPLY_FAILEDis a separate concern.Test plan
npm run -w @usejunior/provider-microsoft test:run— 114/114 (4 new tests added).npm run test:run— all suites green (525 tests across 4 packages).npm run build— clean.npm run lint— clean.Closes #50