fix: scope visitor lookup by teamId to prevent cross-team mismatches#8904
fix: scope visitor lookup by teamId to prevent cross-team mismatches#8904
Conversation
findFirst queries in validateBlockEvent and getByUserIdAndJourneyId were finding visitors by userId alone, which could return a visitor from the wrong team (e.g. jfp-team) when the user had visitors across multiple teams. This caused duplicate JourneyVisitor records and incorrect event attribution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughVisitor lookup logic has been updated to scope queries by team ID. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 36ec134
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit 36ec134 ☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit 36ec134
☁️ Nx Cloud last updated this comment at |
|
I see you added the "on stage" label, I'll get this merged to the stage branch! |
|
Merge conflict attempting to merge this into stage. Please fix manually. |
Summary
validateBlockEventandgetByUserIdAndJourneyIdinapi-journeys-modernwere querying visitors byuserIdalone (findFirst({ where: { userId } })), without filtering byteamIdjfp-teaminstead of the journey's actual team)JourneyVisitorrecords linking the wrong visitor to a journey, and incorrect event attributionteamId: journey.teamIdto bothfindFirstqueries so visitors are always scoped to the correct teamContext
Riah reported duplicate visitor records appearing mid-session. Investigation showed the same journey (
e3cffd88-...) had two JourneyVisitor records pointing to visitors on different teams — one on the correct team (d0a8d4bb-...) and one onjfp-team. The root cause was the unscopedfindFirstreturning whichever visitor Postgres found first, regardless of team.Test plan
validateBlockEventtests to assertteamIdis included in visitor querygetByUserIdAndJourneyIdtests to mock journey lookup and assert team-scoped querygetByUserIdAndJourneyIdreturning null when journey doesn't exist🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests