Incoming text MMS image failure #106
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From dev-sync:
From database log:
Hi-diddly-ho neighborino! After tracing through the code, here is the root cause analysis:
The Bug: In
platform/text/text.go,HandleTextMessageensures the source number (VoIP.msfromfield, i.e. the customer's number) is in thephonetable viaensurePhoneInDB, but it never ensures the destination number (VoIP.mstofield, i.e. our DID+14806162310) is present in thephonetable. Sincetext_loghas a foreign key constrainttext_log_destination_fkey→phone(e164), the insert fails when our DID is not yet registered.Code Flow:
api/voipms.go:voipmsTextPostcallstext.HandleTextMessage(ctx, from, to, body)—from=+18016984649,to=+14806162310platform/text/text.go:HandleTextMessagedoesensurePhoneInDB(ctx, txn, src)for the source (+18016984649) — ✅text_log{source: s.E164 (+18016984649), destination: dst.PhoneString() (+14806162310), origin: Customer}— ❌ destination is not inphoneThe Fix: In
HandleTextMessage, we also need to callensurePhoneInDBfor the destination number before inserting the text_log. SinceensurePhoneInDBcallsPhoneInsertIfNotExists, it is safe to call even if the record already exists. This would look something like:Or alternatively, the system could use
StoreSources()(which runs at startup) to pre-register all known DIDs. If+14806162310was added to config and stored at startup, this insert would not fail. But the explicit ensure is more defensive.I will happily create a PR with the fix.
Fixed adding the configured VoipMS address, then got:
The
text_log_source_fkeyfailure has the same root cause as the originaltext_log_destination_fkey— a foreign key onphone(e164)being violated — but on the outgoing path rather than the incoming one.What was happening:
HandleTextMessage, which callsensurePhoneInDBfor both source (customer) and destination (our DID). That path already had the destination fix.sendTextDirect, which setsSource: config.PhoneNumberReportStr(our outbound number) but never ensured it existed in thephonetable. Same for the destination.StoreSources()startup function is supposed to pre-register this, but if it hasn't run (e.g. after a DB reset, or because it errored out on a misconfigured VoipMS number), the FK constraint fires.Fix: Added
ensurePhoneInDBcalls for both source and destination insidesendTextDirectitself, so every outbound text path is covered regardless of call site. This is the same pattern used byHandleTextMessagefor incoming texts.Already pushed to the same PR: #107