feat(ama): guest, public realtime + guild list ordering - #336
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:
📝 WalkthroughWalkthroughThe PR adds public AMA WebSocket tickets, channel-level authorization, multi-channel realtime invalidation, and live updates for public answer pages. It also updates AMA publishers, guild sorting, tests, and realtime architecture documentation. ChangesPublic AMA realtime flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PublicAnswers
participant publicAMAWsTicketRoute
participant RealtimeClient
participant AMAQuestionRoute
participant publishRealtimeInvalidate
PublicAnswers->>publicAMAWsTicketRoute: request share-token WebSocket ticket
publicAMAWsTicketRoute-->>RealtimeClient: return channel-restricted ticket
RealtimeClient->>PublicAnswers: subscribe to response realtime channel
AMAQuestionRoute->>publishRealtimeInvalidate: publish question and public answer channels
publishRealtimeInvalidate-->>RealtimeClient: deliver public answer invalidation
RealtimeClient->>PublicAnswers: invalidate answers query
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/website/src/api/ws.ts (1)
87-130: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winPrevent a socket from opening after the final unsubscribe.
If
mintTicket()resolves after the final listener unsubscribes,disconnect()sees no socket to close. Lines 89-130 then create and retain an idle socket with no channels. Public page navigation or unmount during ticket minting triggers this path.Check
this.channels.sizeimmediately after ticket minting. Exit before constructingWebSocketwhen it is zero. Add coverage for an unsubscribe before the ticket promise resolves.Proposed fix
const ticket = await this.mintTicket(); +if (this.channels.size === 0) { + return; +} const url = new URL(wsURL());🤖 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 `@apps/website/src/api/ws.ts` around lines 87 - 130, Update the async connection flow around mintTicket() to check this.channels.size immediately after the ticket resolves and return when it is zero, before constructing or assigning a WebSocket. Preserve normal socket setup when channels remain subscribed, and add coverage for unsubscribing before the ticket promise resolves.
🤖 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/app/ama-answers/`[shareToken]/_components/PublicAnswers.tsx:
- Around line 46-52: Add a confirmed-subscription callback or signal to the
useRealtimeInvalidate flow in PublicAnswers, and invalidate
queryKeys.ama.publicAnswers(shareToken) once the WebSocket subscription is
active, while preserving the existing realtime invalidation callback. Add an
integration test covering an answer mutation during the mint/subscription delay,
and run it against the affected service.
In `@services/api/src/core/__tests__/server.test.ts`:
- Around line 360-389: Add coverage in the server route tests for the string
form of RouteDefinition.realtimeChannel by defining a route whose
realtimeChannel returns one channel string, invoking its final handler with a
realtime client ID, and asserting publishRealtimeInvalidate is called exactly
once for that channel.
---
Outside diff comments:
In `@apps/website/src/api/ws.ts`:
- Around line 87-130: Update the async connection flow around mintTicket() to
check this.channels.size immediately after the ticket resolves and return when
it is zero, before constructing or assigning a WebSocket. Preserve normal socket
setup when channels remain subscribed, and add coverage for unsubscribing before
the ticket promise resolves.
🪄 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: 5fe1b9ef-8df1-45ff-89b1-6a5f94c766e0
📒 Files selected for processing (28)
apps/website/src/api/ws.tsapps/website/src/app/ama-answers/[shareToken]/_components/PublicAnswers.tsxapps/website/src/app/dashboard/_components/GuildList.tsxapps/website/src/hooks/usePublicRealtimeClient.tsapps/website/src/hooks/useRealtimeInvalidate.tsapps/website/src/utils/util.tsdocs/roadmap/01-architecture.mdpackages/private/backend-core/src/lib/__tests__/realtimeBroadcast.test.tspackages/private/backend-core/src/lib/realtimeBroadcast.tspackages/private/backend-core/src/lib/wsTicket.tspackages/private/core/src/lib/realtimeChannels.tsservices/ama-bot/src/components/markDuplicateSelect.tsservices/ama-bot/src/components/modApprove.tsservices/api/src/app.tsservices/api/src/core/__tests__/server.test.tsservices/api/src/core/route.tsservices/api/src/core/server.tsservices/api/src/index.tsservices/api/src/routes/ama/questions/mergeQuestion.tsservices/api/src/routes/ama/questions/mergeQuestionsBulk.tsservices/api/src/routes/ama/questions/publicAnswers.tsservices/api/src/routes/ama/questions/publicWsTicket.tsservices/api/src/routes/ama/questions/sendQuestion.tsservices/api/src/routes/ama/questions/updateQuestion.tsservices/api/src/routes/ws/getTicket.tsservices/api/src/ws/__tests__/authorizeChannel.test.tsservices/api/src/ws/authorizeChannel.tsservices/api/src/ws/server.ts
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Closes #321
Closes #323