fix(email): gate draft attempt rotation
CI and Deploy / test (pull_request) Successful in 4m23s
CI and Deploy / deploy (pull_request) Has been skipped

Rotate persisted delivery identity only after the matching owner attempt is definitively failed. Keep stale, foreign, pending, sent, and uncertain drafts non-retryable.
This commit is contained in:
cesnimda
2026-08-10 10:21:37 +02:00
parent 114e3b66ba
commit 29de2632f6
4 changed files with 123 additions and 3 deletions
@@ -388,8 +388,23 @@ export default function CorrespondenceInboxPage() {
}
};
const prepareNewAttempt = () => {
setDraft((current) => current ? { ...current, clientRequestId: globalThis.crypto.randomUUID() } : null);
const prepareNewAttempt = async () => {
if (!draft || sendResult?.status !== "failed") return;
setDraftError(null);
if (draft.id && draft.revision) {
try {
const response = await api.post<StoredEmailDraft>(`/email/drafts/${draft.id}/new-attempt`, { revision: draft.revision });
setDraft((current) => current ? { ...current, ...response.data } : null);
await loadStoredDrafts();
} catch (error: any) {
setDraftError(error?.response?.status === 409
? "A new attempt is allowed only after the latest saved draft has a definitive failed delivery. Reload the draft before continuing."
: getApiErrorMessage(error, "Failed to prepare a new delivery attempt."));
return;
}
} else {
setDraft((current) => current ? { ...current, clientRequestId: globalThis.crypto.randomUUID() } : null);
}
setSendResult(null);
setSendError(null);
};
@@ -524,7 +539,7 @@ export default function CorrespondenceInboxPage() {
<Alert severity="warning" sx={{ mt: 1.5 }}>Delivery status is uncertain. Do not retry this draft. Check the provider Sent folder before taking any further action.</Alert>
) : null}
{sendResult?.status === "failed" ? (
<Alert severity="error" sx={{ mt: 1.5 }} action={<Button color="inherit" size="small" onClick={prepareNewAttempt}>Prepare new attempt</Button>}>
<Alert severity="error" sx={{ mt: 1.5 }} action={<Button color="inherit" size="small" onClick={() => void prepareNewAttempt()}>Prepare new attempt</Button>}>
The provider confirmed that this attempt did not complete. Review the connection and draft before creating a new attempt.
</Alert>
) : null}