[18.0][FIX] mail_gateway: cache gateway map by state and type #1950
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 263 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.334
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1950"
general
weight: 0.35
etobella
Problem
The webhook controller finds the gateway of each request with
mail.gateway._get_gateway(key, state, gateway_type), which reads the map{webhook_key: gateway data}built by_get_gateway_map(state, gateway_type):_get_gateway_map()is cached with@tools.ormcache()without keys, so its arguments are not part of the cache key: all the calls share one cache entry, and the map computed first is returned for anystateandgateway_typeuntil the cache is cleared.Steps to reproduce
1. Have an integrated WhatsApp gateway.
2. Send a GET to its webhook URL (open it in a browser, or a verification with a wrong token). The lookup of the pending gateways caches an empty map.
3. Receive a WhatsApp message. The lookup of the integrated gateways gets the cached empty map: "Gateway was not found for token ...", and the message is dropped. Meta gets a 200 answer, so it does not send it again.
4. Every following message is dropped too, until the cache is cleared (restart, or a change of a gateway).
The same happens with gateways of several types: with Telegram and WhatsApp, the first one that receives a webhook caches the map of its type and the others are not found.
Change
stateandgateway_typeare now part of the cache key, so each combination has its own cached map (pending WhatsApp, integrated WhatsApp, integrated Telegram...) and every lookup gets the gateways it asked for.Nothing else changes: the maps are still cleared when a gateway is created or its webhook key, state, secret or user changes, and there are only a few combinations, so the cache stays as small and fast as before.
Tests
test_gateway_map_by_state(mail_gateway_whatsapp) looks up the pending gateways first and then the integrated one. It fails without the fix and passes with it.@BinhexTeam