feat(frontend): AMA real time updates - #298
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR adds Redis-backed realtime invalidation. API and AMA bot mutations publish channel events. WebSocket clients identify browser tabs, filter origin events, reconnect, and refresh AMA question queries. ChangesAMA realtime invalidation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant BrowserTab
participant API
participant Redis
participant WebSocketServer
participant AMAQueries
BrowserTab->>API: Send mutation with client ID header
API->>Redis: Publish invalidation with origin client ID
Redis->>WebSocketServer: Deliver invalidation message
WebSocketServer->>BrowserTab: Send to subscribed non-origin tabs
BrowserTab->>AMAQueries: Invalidate AMA questions queries
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
services/api/src/core/server.ts (1)
142-151: 🗄️ Data Integrity & Integration | 🔵 TrivialExercise the full Redis and WebSocket path before merge.
The test changes in
services/api/src/core/__tests__/server.test.tsverify thepublishRealtimeInvalidatecall only. They do not verify Redis delivery, cross-process fan-out, origin filtering, or the AMA bot publishers. Run the API and AMA bot services with Redis. Use two subscribed browser tabs. Exercise an API mutation, guest skip, moderator deny, and question submission. Confirm that API mutations skip only the originating tab. Confirm that bot-originated mutations reach all subscribed tabs.As per coding guidelines, changes with a runtime surface must be exercised by running the affected service; typechecking and unit tests alone are insufficient.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@services/api/src/core/server.ts` around lines 142 - 151, Exercise the runtime change by running the API and AMA bot services with Redis, then validate the full Redis/WebSocket flow using two subscribed browser tabs. Cover API mutations, guest skip, moderator deny, and question submission; verify API mutations exclude only the originating tab while bot-originated mutations reach both tabs, including origin filtering and cross-process delivery.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/website/src/api/ws.ts`:
- Around line 56-61: Update the WebSocket lifecycle around subscribe(), the
unsubscribe cleanup callback, and scheduleReconnect(): clear any pending
reconnectTimer before opening an immediate socket; have the reconnect timer
callback return when no channels remain, a socket already exists, or a
connection is in progress; and stop or close the socket when the final channel
subscription is removed.
In
`@apps/website/src/app/dashboard/`[id]/ama/amas/[amaId]/_components/AMADetails.tsx:
- Around line 198-200: Update the realtime invalidation flow around
useRealtimeInvalidate and invalidateAMAQuestions so it also invalidates the
useAMA query identified by queryKeys.ama.byId(guildId, amaId). Prefer extending
invalidateAMAQuestions to invalidate that AMA-by-ID query while preserving its
existing question-list and stats invalidations.
In `@services/ama-bot/src/components/submitQuestion.ts`:
- Around line 137-141: The initial publishRealtimeInvalidate in submitQuestion
must not occur before queue message IDs are persisted. Move or supplement
invalidation so amaQuestionsChannel is published after each successful update of
mod_queue_message_id, guest_queue_message_id, or answers_message_id, while
preserving invalidation for questions without queue posts.
In `@services/api/src/ws/server.ts`:
- Around line 94-102: Validate the parsed payload in the realtime subscriber
before delivery: reject null and non-object values, require valid string fields
for type and channel, and validate optional originClientId when present. Update
the parsing flow around RealtimeInvalidateMessage and only call hub.deliverLocal
after these checks; malformed payloads should be logged and discarded without
throwing.
---
Nitpick comments:
In `@services/api/src/core/server.ts`:
- Around line 142-151: Exercise the runtime change by running the API and AMA
bot services with Redis, then validate the full Redis/WebSocket flow using two
subscribed browser tabs. Cover API mutations, guest skip, moderator deny, and
question submission; verify API mutations exclude only the originating tab while
bot-originated mutations reach both tabs, including origin filtering and
cross-process delivery.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c963705e-071f-4359-a01e-da4b218983ad
📒 Files selected for processing (25)
apps/website/src/api/fetch.tsapps/website/src/api/realtimeClientId.tsapps/website/src/api/routes/ama.tsapps/website/src/api/ws.tsapps/website/src/app/dashboard/[id]/ama/amas/[amaId]/_components/AMADetails.tsxapps/website/src/app/dashboard/[id]/ama/amas/[amaId]/questions/_components/QuestionsList.tsxapps/website/src/hooks/useRealtimeInvalidate.tspackages/private/backend-core/src/index.tspackages/private/backend-core/src/lib/realtimeBroadcast.tspackages/private/core/src/lib/constants.tsservices/ama-bot/src/components/guestAddAnswer.tsservices/ama-bot/src/components/guestApprove.tsservices/ama-bot/src/components/guestSkip.tsservices/ama-bot/src/components/markDuplicateSelect.tsservices/ama-bot/src/components/modApprove.tsservices/ama-bot/src/components/modDeny.tsservices/ama-bot/src/components/modFlag.tsservices/ama-bot/src/components/sendQuestion.tsservices/ama-bot/src/components/submitQuestion.tsservices/api/src/app.tsservices/api/src/core/__tests__/server.test.tsservices/api/src/core/server.tsservices/api/src/index.tsservices/api/src/ws/hub.tsservices/api/src/ws/server.ts
No description provided.