Repository navigation
Description
Tracking issue for a customer bug report received as a voice note on 2026-08-06. One customer session surfaced several compounding failures: monthly report emails that stopped arriving for ~9 months, a report computed against a social handle the artist had since changed, and a visible error in the app when she went in to fix it.
Status: reproduced and root-caused on 2026-08-06. Two of the four findings are systemic, not specific to this account. Reporting account is referenced by UUID only (b1d40ce4-…); identity intentionally omitted since this repo is public.
Goal
- A scheduled report either delivers or fails loudly. Never silently stops delivering while the task keeps running and the UI reports it as healthy.
POST /api/emailsstops rejecting the majority of its traffic at validation.- When a connected social handle stops resolving, the system detects it rather than shipping a report full of empty numbers.
- A cold page load does not show the user "An error occurred, please try again!" for a failure that is internal, expected, and recoverable.
PRs (updated 2026-08-07)
Ordered by fix priority. The two page-load errors lead: they fire on every cold load of / for every account, they are the only findings a customer actually sees in the product, and they are what made this customer stop trying and reach for her phone.
| PR | Item | State |
|---|---|---|
| chat#1950 | F4a: page-load error toast — stream resume fires before auth + chat exist (401/404) | ✅ merged 2026-08-07 — see Done |
| api#TBD | F2a: record the rejection reason in email_send_log (diagnostic unblocker) |
⏳ not started |
| api#TBD | F2b: fix the dominant POST /api/emails rejection cause once visible |
⏳ not started |
| chat#TBD | F6: stop presenting advice as analysis when the data source is unavailable | ⏳ not started |
| chat#TBD | F5: create the schedule when a request specifies a cadence | ⏳ not started |
| api#TBD | F1: maintain scheduled_actions.last_run / next_run on every run |
⏳ not started |
| api#TBD | F3: never overwrite a good social record with an empty scrape result | ⏳ not started |
| api#TBD | F7: mirror scraped images to blob storage instead of storing expiring CDN URLs | ⏳ not started |
Decision 2026-08-07 (Sweets) — F4b is closed, not fixed. chat#1951 was closed unmerged and its row removed from the matrix above. chat#1950 removed F4b's only trigger:
refetchCreditshas exactly one caller (useVercelChat.ts, insideonFinish) and nothing invalidates thecreditsquery key, so with no cold-load resume there is no finish and no refetch. Measured on one account and browser — production pre-#1950 issued/api/accounts/undefined/credits1–2 times on every cold load; the #1950-only preview issued it 0 times across 6 loads. Blast radius did not justify carrying a fix:creditshas one consumer (CreditsUsage.tsx, inside the profile dropdown); every gate readsisSubscribedfromuseProStatus, a different query, so a credits failure cannot cause a false paywall or upgrade prompt; sending is enforced server-side invalidateChatRequest.ts:102; and the query key["credits", account_id]means a failure lands under a different cache entry than the real one and self-heals when the account resolves. Worst case was a number in a closed dropdown being briefly wrong. Accepted regression:userData?.account_id as stringstays inuseCredits; if a secondrefetchCreditscaller or aninvalidateQueries(['credits'])is ever added, the silent 400 returns — bounded to the dropdown. Reopen #1951 if that happens. Root cause, confirmed against@tanstack/query-core@5.90.12and recorded so it is not re-derived:enabledgates automatic fetching only and is consulted nowhere on therefetch()path.
Merge sequencing (updated 2026-08-07). F4a shipped in chat#1950; F4b is closed (see the decision note above), so F4 is complete and nothing here is blocked on it. F2 is now the top item by consequence — it is why the customer received no emails for twelve months — and is independent of the rest. F2a (record the rejection reason) is the diagnostic unblocker and should lead, since F2b cannot be scoped until the dominant rejection cause is visible.
Done
- F4a — chat#1950: gate stream resume on auth and an existing chat.
✅ Shipped 2026-08-07 (squash-merged tomainas5c4dc8cb).
useVercelChatpassedresume: truetouseChatunconditionally, so every mount issuedGET /api/chat/{chatId}/stream?startIndex=0— beating Privy's session resolution (401) or targeting the client-generated placeholder UUID thatNewChatBootstrapmounts before the api has minted anything (404). Either landed inonError, which raisedtoast.error("An error occurred, please try again!"). Resume is now gated behind a newlib/chat/shouldResumeStream.tson an authenticated visit to a chat opened from the canonical/sessions/[sessionId]/chats/[chatId]route — the only situation a resume is for.useChatre-runs its resume effect when the flag flips, so this delays the resume rather than skipping it.
Verified end-to-end on the preview for77b2c9ab, cross-checked against production on the same account and browser (full results): preview produced 0 stream requests, 0 4xx and 0 toasts across 4 cold loads (3 authenticated + 1 signed-out, each with an 8–12s settle window); production on the same account reproduced 3× 4xx on a single load (/stream404 plus/accounts/undefined/credits400 twice) and the toast on 5/5 loads, confirmed in the a11y tree. Regression check: an existing chat on the canonical route still resumes and renders its messages.
A regression was caught by that preview run and fixed before merge. The first attempt also accepted the bootstrap-minted chat id, which maderesumeflipfalse → trueonce provisioning resolved;WorkflowChatTransport'swhile (!gotFinish)loop then reissued the resume GET 118 times against a brand-new chat answering204, where prod issues 1. Every response was a 204, so a literal "zero 4xx" check would have passed while the change was worse than the bug. The bootstrap id was dropped from the decision entirely —useMessageLoaderalready draws the same line, since a bootstrap chat has nothing to load.
Findings
F1 — The task fires, but last_run / next_run are stale (misleading, not the delivery bug)
Her task (c8245e49-…, cron 0 9 1 * *, enabled = true) was created 2025-07-22 19:07, ~54 minutes after signup — the onboarding "interview" she refers to.
The columns claim it is dead: last_run = 2025-10-01 09:00, next_run = 2025-11-01 09:00 — over 9 months in the past.
But the task is actually running. Her chats table has Scheduled generation rows at 09:00 on 2026-02-01, 2026-03-01, 2026-07-01 and 2026-08-01. So the runner executes and never writes back last_run/next_run.
Systemic: 49 of 98 enabled scheduled_actions have a next_run more than 90 days in the past (oldest 2025-10-20). Any dashboard, audit, or alert built on these columns is reading fiction.
- Why: the run path does not update the row after firing.
- Fix: write
last_run/next_runon every execution; backfill the 49 stale rows from actual run history. - Done when: for an account with a live schedule,
next_runis always in the future whileenabled = true, and the 49-row backlog is zero.
F2 — 59% of all outbound email is rejected at validation (this is the delivery bug)
In the last 7 days: 335 rejected vs 236 sent. Every single rejected row has account_id IS NULL.
rejected is set at lib/emails/sendEmailHandler.ts:59 — the else branch when validateSendEmailBody fails. The request never reaches Resend, and account_id is null precisely because validation failed before it could be read.
Her own report shows the pattern exactly: rejected at 2026-08-06 23:57:56, then sent at 2026-08-06 23:58:01 — a retry 5 seconds later succeeded. When the retry does not happen, the customer simply never receives the email and nothing surfaces the failure.
Her specific rejection was malformed JSON. The agent hand-writes the JSON body into a curl -d '…' inside bash. Her text payload contained ("Círculo Privado Sol Siete") with an unescaped double quote, so JSON.parse threw, readRawBody fell back to {}, and the .refine() rejected it as "a non-empty html or text body is required". The retry 5 seconds later succeeded only because the HTML rewrite happened to contain no inner double quotes. Both calls also sent a malformed Content-Type: charset=utf-8.
But that is not the systemic cause. Only 4 of 335 rejected bodies (1.2%) are invalid JSON. Of the 331 that parse cleanly, 329 have both a subject and a non-empty body — they are well-formed. 96 carry to, and the other 233 omit it, which is legal (it defaults to the account's own email).
So the bulk of rejections are failing at auth or recipient resolution, not schema. This cannot be narrowed further from the log, because email_send_log records only raw_body and status — never the rejection reason. That gap is why a 59% failure rate ran unnoticed for months. Prime suspect is the sandbox's ${RECOUP_API_KEY:-$RECOUP_ACCESS_TOKEN} being absent or expired on longer runs.
- Fix: (1) log the rejection reason and status code in
email_send_log— do this first, it is the diagnostic unblocker; (2) re-measure and fix the dominant cause once visible; (3) stop agents hand-building JSON in bash — give the send path a typed tool instead ofcurl -d. - Done when: every
rejectedrow carries a machine-readable reason, and the rejection rate is under 5% over a 7-day window.
F5 — She asked for a monthly report and no schedule was created
Her message opens "puedes enviarme un reporte mensualmente a mi email". The agent sent a single one-off email and created no scheduled_actions row — her only task remains the one from 2025-07-22. She has no recurring report and no way to know that.
- Why: the agent treated a recurring request as a one-shot send.
- Fix: when a request specifies a cadence, create the schedule and confirm it back to the user.
- Done when: a "send me X monthly" request results in a
scheduled_actionsrow, and the reply states the cadence and next run time.
F6 — The delivered report was ungrounded and silently substituted advice for data
She asked for three things: re-analyse her Instagram posts, cross-match her Twitter followers onto Instagram, and build new fan groups to find 200-300 buyers. The delivered report did none of them:
- Instagram posts: not analysed. The agent noted the connector "no está conectado" — consistent with F3's dead handle — then proceeded anyway.
- Twitter→Instagram matching: not performed. It told her to go use third-party tools (TweetScout, Alpha Growth) to do it herself.
- Fan groups: not created. It suggested she start a Telegram/Discord group.
What shipped was generic arithmetic ($10-20 × 50-100 buyers) around one real number (6,215 X followers). The reply then closed with "El reporte completo… ha sido enviado exitosamente" — presenting a strategy memo as a fulfilled data request. This is the "análisis desactualizado" she describes, and it is the finding most likely to lose the customer.
- Fix: when the underlying data is unavailable, say so plainly and do not present advice as analysis; never refer the customer to a competing tool for the job the product is supposed to do.
- Done when: a request whose data source is unavailable returns an explicit "I could not get X, here is why" instead of a substituted narrative.
F3 — Instagram social record is an empty shell after a handle change
Both of her socials are stored as solsiete_web3:
| Platform | profile_url | followerCount | bio | updated_at |
|---|---|---|---|---|
| X | x.com/solsiete_web3 |
6215 | present | 2026-08-01 |
instagram.com/solsiete_web3 |
null | absent | 2026-07-27 |
Correction 2026-08-07 — the handle was never wrong. The stored handle
solsiete_web3is confirmed correct by the account owner. The Instagram scrape was simply failing and persisting an empty record. A manual rescrape viaPOST /api/socials/{id}/scrapeon 2026-08-07 00:45 populated it immediately:followerCountnull → 6,163,followingCountnull → 6,225,bionull → populated, avatar 403 → 200. Nothing about the handle changed. Read her "changed my handle" remark as a user's guess at the cause, not the cause.
- Why: a scrape returning no profile data is persisted as a successful-but-empty record, indistinguishable from a genuinely empty profile. It then silently feeds reports.
- Fix: treat "scrape returned no profile data" as a distinct failure state — do not overwrite a good record with an empty one, and surface the failure.
- Done when: a failed scrape never lands as an empty-but-valid row, and a social stuck with null metrics is visibly flagged rather than silently reported on.
F7 — Every stored Instagram image URL expires (87.4% are already dead)
Instagram/fbcdn URLs are signed and carry an oe= expiry. We persist them raw, so they rot on a timer.
177,237 of 202,758 stored Instagram avatars (87.4%) are already expired. Verified against her account: account_info.image expired 2025-07-22 (the day she signed up) and returns 403; her Instagram socials.avatar expired 2026-07-31 and returned 403. The fresh URL from the 2026-08-07 rescrape expires 2026-08-11 — 4.5 days later. Only her X avatar (pbs.twimg.com, unsigned) survives, and we store its 48×48 _normal variant.
- Why: we store a signed third-party URL instead of the image.
- Fix: mirror the image to our own storage on scrape and persist that URL; prefer full-size variants over
_normal. - Done when: artist and social avatars still render 30+ days after the scrape that produced them, and the expired backlog is re-fetched.
F4 — Cold-load error toast: "An error occurred, please try again!"
Reproduced 2/2 on https://chat.recoupable.dev/ with Chrome DevTools, on a different account than hers — so this is global, not account-specific. Two independent failures on first paint:
F4a — stream resume fires before it can succeed. GET api.recoupable.dev/api/chat/{chatId}/stream?startIndex=0
- Load 1 → 401
{"status":"error","error":"Exactly one of x-api-key or Authorization must be provided"}— the request carries noAuthorizationheader at all; it beats the Privy session (privy.recoupable.dev/api/v1/sessionsresolves after it). - Load 2 → 404
{"status":"error","error":"Chat not found"}— auth present, but the chat being resumed does not exist.
F4b — undefined interpolated into a URL. GET api.recoupable.dev/api/accounts/undefined/credits → 400 {"error":"id must be a valid UUID"}. Reproduced on both loads. This request does carry a valid bearer token, so it is a separate race: auth had resolved, accountId had not.
Both are swallowed — the browser console shows nothing but font-preload warnings. The only user-visible signal is the toast, which is almost certainly the "error" she describes. It is transient and the app recovers, but to a non-technical user it reads as "the product is broken."
- Fix: gate the stream-resume request on both a resolved auth token and a known-existing chat; gate the credits fetch on a defined
accountId; do not raise a user-facing toast for an expected cold-start miss. - Done when: a cold load of
/produces zero 4xx responses and no error toast.
Ruled out (checked, not causes)
- Credits. A chat send requires 1 credit (
lib/chat/validateChatRequest.ts:102); the account had 48 remaining. Not a blocker. - A retired model. Her chats used
google/gemini-3.5-flash-liteandmoonshotai/kimi-k3; both are still live inGET /api/ai/models, and the gemini chat is the one that succeeded (assistant replied 23:58:07). - Chat send being broken. Her sends worked:
"hi"at 23:52 (reply 23:53:03) and the report request at 23:56 (reply 23:58:07). Re-reading the Spanish, "no me manda los mensajes" means "it doesn't send me the messages" — the emails — which points at F2, not the composer.- Her session also contains five
New chatrows with 0 messages, which look like failed sends but are not. A control run on a different account produced three 0-message rows in two minutes of page loads alone, with no message ever sent — the app creates achatsrow per load. Do not read empty chat rows as send failures. (Separately: this meanschatsaccumulates junk rows from idle browsing, worth its own cleanup issue.)
- Her session also contains five
- Sandbox hang.
POST /api/sandboxappearspendingon first paint but resolves 200.
Out of scope
Customer communication and account remediation (re-running her report, replying to the voice note). This issue covers code fixes only.
Source references
- Reporter voice note, 2026-08-06, transcribed via
POST /api/content/transcribe. Audio and transcript retained locally, not attached. - Reproduction: Chrome DevTools against
https://chat.recoupable.dev/, 2026-08-07 00:23–00:25 UTC. - Evidence queries run against the production Supabase project.
Activity
[-]Chat send error blocks self-serve fix for a stale social handle; scheduled report fired ~1 year late[/-][+]Report emails silently rejected at validation (59% of sends); stale run columns, dead IG handle, cold-load error toast[/+]sidneyswift commentedon Nov 6, 2026
F4 is done (#1950). F1 no longer applies because the stale next_run/last_run columns were dropped in recoupable/database#63.
F7 is partly done: Instagram artist avatars are now mirrored when scraped (recoupable/api#866); other images still store expiring URLs.
F2 is still open: rejected sends are logged with no reason, so the rejection rate can't be diagnosed.
F3, F5 and F6 are not started.
sidneyswift commentedon Nov 8, 2026
Status: F2 is done, and missed reports now raise an alert (both live).
POST /api/emailsattempt records why inemail_send_log.reason(Record why an email send was rejected or failed database#132, Record why an email send was rejected or failed api#1235). Codes:invalid_body: …,auth_failed: 401,no_account_email,recipient_not_allowed: …,resend_error: …. Rejections after auth also record the account./api/internal/missed-report-check, at :17). It finds scheduled runs from 2–3 hours earlier that asked for an email but sent none, and classifies each as plan blocked, email rejected (with the reason above) or no email (with the run status). It posts one Telegram alert. Customer notices are built but off untilMISSED_REPORT_CUSTOMER_NOTICES=true.Next:
select split_part(reason, ':', 1) as code, count(*) from email_send_log where status = 'rejected' and created_at > now() - interval '7 days' group by 1 order by 2 desc;resend_erroronly says Resend failed, not why, becauseprocessAndSendEmailreturns a generic error. A follow-up should pass a bounded provider code through.