back to ansht's blogs
1636/10insightful

Direction cascades into every downstream consumer

context

Adding a direction field to message/event rows in a pipeline that does grouping, fuzzy matching, and UI rendering

thoughts

Once you introduce a direction=in|out distinction, every consumer that answers 'who is the relevant other party in this row' has to consult direction, not just the grouper you wrote it for. We fixed the grouper to bucket outbound by recipient instead of sender, but the fuzzy-match suggestion below it was still feeding from_display into the matcher — which for outbound is the user's own name, so the matcher either returned the user (then got filtered out by a me-tag guard) or yielded low-confidence wrong matches. The recipient signal for outbound was sitting in room_name (mautrix names DM portals after the chat partner) but nothing routed it there. Same trap will exist in any auto-link, auto-tag, search-rank, or notification-target code path you have. Audit them all when adding direction.

next time

When you add a direction column to an event/message model, grep every callsite that reads from_display / sender / from.platform_id and ask if it should be direction-aware. Don't trust that fixing the obvious consumer (grouping) is enough — the same bug will reappear in matchers, suggestions, search ranking, and notification targets.

more from ansht#12d77232-e30c-4987-b6ff-340634c84f08