Skip to content

feat(frontend): AMA real time updates - #298

Merged
didinele merged 2 commits into
mainfrom
feat/api-gateway-frontend
Aug 7, 2026
Merged

feat(frontend): AMA real time updates#298
didinele merged 2 commits into
mainfrom
feat/api-gateway-frontend

Conversation

@didinele

@didinele didinele commented Aug 7, 2026

Copy link
Copy Markdown
Member

No description provided.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chatsift-website Ready Ready Preview Aug 7, 2026 8:29am

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: db8dfa25-91b1-4f94-9a81-64a06d5bae69

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This 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.

Changes

AMA realtime invalidation

Layer / File(s) Summary
Realtime message and client contracts
packages/private/core/..., packages/private/backend-core/...
Defines the client-ID header, invalidation message shape, Redis channel, and publisher.
API and AMA invalidation publishing
services/api/src/core/..., services/api/src/core/__tests__/*, services/ama-bot/src/components/*
API mutations and AMA bot actions publish invalidations after successful question changes. Tests verify channels, origins, and failure cases.
WebSocket Redis fan-out
services/api/src/ws/*, services/api/src/app.ts, services/api/src/index.ts
The WebSocket server subscribes to Redis, delivers messages locally, filters the originating client, and closes the subscriber during shutdown.
Browser subscription and AMA refresh
apps/website/src/api/*, apps/website/src/hooks/*, apps/website/src/app/dashboard/.../ama/...
The browser creates a tab client ID, sends it with fetch and WebSocket requests, reconnects subscriptions, and invalidates AMA queries on events.

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
Loading

Possibly related PRs

  • ChatSift/chatsift#175: Both changes modify the website API layer and AMA route handling.
  • ChatSift/chatsift#296: Both changes modify AMA dashboard components and AMA question invalidation logic.
  • ChatSift/chatsift#297: This PR extends the WebSocket gateway, hub, route broadcasting, and ticket infrastructure introduced there.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided, so the changeset lacks author-provided context. Add a brief description that explains the AMA real-time update behavior and the main implementation changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the frontend AMA real-time updates, which matches the main changeset objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-gateway-frontend

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@didinele

didinele commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
services/api/src/core/server.ts (1)

142-151: 🗄️ Data Integrity & Integration | 🔵 Trivial

Exercise the full Redis and WebSocket path before merge.

The test changes in services/api/src/core/__tests__/server.test.ts verify the publishRealtimeInvalidate call 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

📥 Commits

Reviewing files that changed from the base of the PR and between 88e84a2 and a9c0151.

📒 Files selected for processing (25)
  • apps/website/src/api/fetch.ts
  • apps/website/src/api/realtimeClientId.ts
  • apps/website/src/api/routes/ama.ts
  • apps/website/src/api/ws.ts
  • apps/website/src/app/dashboard/[id]/ama/amas/[amaId]/_components/AMADetails.tsx
  • apps/website/src/app/dashboard/[id]/ama/amas/[amaId]/questions/_components/QuestionsList.tsx
  • apps/website/src/hooks/useRealtimeInvalidate.ts
  • packages/private/backend-core/src/index.ts
  • packages/private/backend-core/src/lib/realtimeBroadcast.ts
  • packages/private/core/src/lib/constants.ts
  • services/ama-bot/src/components/guestAddAnswer.ts
  • services/ama-bot/src/components/guestApprove.ts
  • services/ama-bot/src/components/guestSkip.ts
  • services/ama-bot/src/components/markDuplicateSelect.ts
  • services/ama-bot/src/components/modApprove.ts
  • services/ama-bot/src/components/modDeny.ts
  • services/ama-bot/src/components/modFlag.ts
  • services/ama-bot/src/components/sendQuestion.ts
  • services/ama-bot/src/components/submitQuestion.ts
  • services/api/src/app.ts
  • services/api/src/core/__tests__/server.test.ts
  • services/api/src/core/server.ts
  • services/api/src/index.ts
  • services/api/src/ws/hub.ts
  • services/api/src/ws/server.ts

Comment thread apps/website/src/api/ws.ts
Comment thread services/ama-bot/src/components/submitQuestion.ts Outdated
Comment thread services/api/src/ws/server.ts Outdated
@didinele
didinele merged commit 1ca9e54 into main Aug 7, 2026
22 checks passed
@didinele
didinele deleted the feat/api-gateway-frontend branch August 7, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant