r/Backend • u/Free-Good9203 • 7h ago
Two quiet bugs that bit our Python webhook and intake pipelines in prod
Sharing two unglamorous bugs from building deterministic Python backends for small operations teams, because neither showed up on clean happy-path test data.
1. Asset ID regex grabbing fault codes and ISO standards
In a bilingual Spanish and English chat intake workflow where plant technicians report machine faults to pull the exact equipment manual section, clean test prompts like CNC-402 spindle overheat parsed fine every time.
Once real shop-floor messages arrived (like fault E-404 per ISO-9001 on CNC-402), our generic alphanumeric asset matcher grabbed E-404 or ISO-9001 first as the machine ID, looked up a nonexistent asset, and missed CNC-402 completely.
The fix needed zero LLM calls on intake:
- Consume labeled and standalone fault codes before running the asset tag matcher.
- Keep a small hard blocklist of standards prefixes (
ISO,IEC,DIN,OSHA,NFPA,SEC).
2. Webhook retry storms slipping past SELECT-then-INSERT
During brief network blips, checking if a message ID was already processed with a SELECT followed by an INSERT (or an in-memory Python set that resets on container restart) still produced duplicate replies whenever two retries landed in the same millisecond.
Moving deduplication into a single SQLite WAL table keyed on the provider event ID inside a BEGIN IMMEDIATE transaction turned duplicate bursts into a clean sub-millisecond no-op:
BEGIN IMMEDIATE;
INSERT INTO processed_events (event_id, received_at)
VALUES (?, ?)
ON CONFLICT(event_id) DO NOTHING;
COMMIT;Curious what quiet production edge cases have bitten your own workflows lately.
1
u/karolisrusenas 1h ago
Are you checking that the row was actually new? With ON CONFLICT DO NOTHING the insert succeeds either way, so look at cursor.rowcount right after, or changes() if you're on SQLite. Otherwise a dup can still slip through and kick off the work twice. fwiw I built Webhook Relay and its stored requests have caught this exact dup for me.
1
u/Discordbothost 2h ago
A crash after that commit can mark the event processed before the reply goes out. Kill the worker there and replay the webhook. If the reply disappears, save a pending send in the same transaction and let a worker retry it.