feat(emails): verify-the-send building block — hasDeliveredEmail (DRAFT, needs design call)#732
feat(emails): verify-the-send building block — hasDeliveredEmail (DRAFT, needs design call)#732sweetmantech wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…-day observability) When an empty/footer-only email went out we could not recover what the API received: safeParseJson discards malformed bodies, the route logged nothing, and the sandbox that built the request is ephemeral. This records every attempt — sent, send_failed, and rejected (empty/malformed) — so a send is debuggable days later. - lib/supabase/email_send_log/insertEmailSendLog.ts: typed insert. - lib/emails/logEmailAttempt.ts: builds the row (computes body_parsed, truncates raw_body to 10k); best-effort — never throws, so logging can't break a send. - sendEmailHandler: capture the raw body via request.clone() and log on every outcome (rejected attempts keep the raw body, so a malformed send is visible). - types/database.types.ts: email_send_log added so the typed insert compiles. The migration lives in the recoupable/database repo (mono/database) — applied via its CI — not here. Tests: logEmailAttempt unit (parsed/malformed/truncation/swallow-errors) + handler asserts the sent/rejected/send_failed log calls. Full lib/emails: 150. Ref: recoupable/chat#1829 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d guarantee Reads email_send_log to answer "did this run actually deliver a non-empty email?" — the check a report task needs so it can fail/flag instead of reporting a silent success when the agent never sent (the observed 30% no-send case). Best-effort (returns false on error). Stacked on the email_send_log PR. This PR intentionally ships ONLY the verifiable building block + tests; the enforcement point (where/whether to fail vs warn, and how to detect that a task was "supposed to email") is the open design question — see PR body. Ref: recoupable/chat#1829 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bf4fafa to
5ac5c57
Compare
|
Closing — superseded + deferred. The observability half of this draft ( The only net-new content is the verify-the-send building block ( Tracked under recoupable/chat#1829 (verify-the-send deferred). |
What
hasDeliveredEmail(chatId)(andcountDeliveredEmails) — readsemail_send_logto answer "did this run actually deliver a non-empty email?" That's the check needed for the issue's verify-the-send item: a report task that finishes without delivering should be flagged, not reported as a silent success.Why
The baseline showed ~30% of report-task runs made zero
/api/emailsattempts (e.g. Fat Beats weeklies: 13/15 runs sent nothing) yet the runs completed "successfully." Nothing checks delivery.What's here (safe, tested)
lib/supabase/email_send_log/countDeliveredEmails.ts— countsstatus='sent'rows for a chat (best-effort; 0 on error).lib/emails/hasDeliveredEmail.ts—count > 0.Open design decision (why this is a draft)
The building block is safe; where and how to enforce is not obvious and shouldn't be guessed:
no_email_delivered) emitted after a natural finish inrunAgentWorkflowwhen the run was email-mandated andhasDeliveredEmail(chatId)is false; escalate to a run failure only once the signal proves clean.runAgentWorkflowpost-finish step vs. a post-run sweep overemail_send_log.I've deliberately not wired a hard guarantee into
runAgentWorkflowyet — that's the call to make on review.Depends on
email_send_logtable + types) — this PR reads that table. Merge feat(emails): log every POST /api/emails attempt (email_send_log, 7-day observability) #731 first.Part of recoupable/chat#1829 (last item in the PR matrix). Base
test.🤖 Generated with Claude Code
Summary by cubic
Adds a durable
email_send_logand logs every/api/emailsattempt, plushasDeliveredEmail(chatId)to verify that a run actually delivered an email. This supports the verify-the-send requirement in recoupable/chat#1829; enforcement wiring will follow.New Features
public.email_send_log(types added) with a typed insert helper.sendEmailHandlerrecords all outcomes (sent,send_failed,rejected) vialogEmailAttempt, capturing the raw body (viarequest.clone()), parse flag, truncatedraw_body(10k), lengths, andresend_id. Best-effort; never throws.countDeliveredEmails(chatId)andhasDeliveredEmail(chatId)to answer “did this run deliver at least one email?”Migration
email_send_logtable is migrated in the recoupable/database repo (mono/database). Ensure that migration is deployed there before relying on this.Written for commit 5ac5c57. Summary will update on new commits.