Skip to content

feat(api): websocket gateway - #297

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

feat(api): websocket gateway#297
didinele merged 2 commits into
mainfrom
feat/api-gateway

Conversation

@didinele

@didinele didinele commented Aug 6, 2026

Copy link
Copy Markdown
Member

No description provided.

@vercel

vercel Bot commented Aug 6, 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 6, 2026 8:18pm

@coderabbitai

coderabbitai Bot commented Aug 6, 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: 7163f3f4-ba43-4177-b8e6-5c1966ca13ca

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:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

The PR adds short-lived WebSocket JWT tickets, an authenticated ticket endpoint, WebSocket channel subscriptions, heartbeat handling, and invalidation broadcasts. AMA question and tag routes publish invalidations through guild- and AMA-specific channels.

Changes

Realtime WebSocket support

Layer / File(s) Summary
Ticket and channel contracts
packages/private/backend-core/src/lib/wsTicket.ts, packages/private/core/src/lib/realtimeChannels.ts, packages/private/*/src/index.ts
The packages export WebSocket ticket creation and verification and provide the AMA questions channel builder.
WebSocket server and hub
services/api/src/ws/*, services/api/package.json
The API adds ticket and origin validation, guild authorization, subscriptions, invalidation broadcasts, connection cleanup, and heartbeat handling.
Route invalidation integration
services/api/src/core/route.ts, services/api/src/core/server.ts, services/api/src/routes/ama/**/*, services/api/src/core/__tests__/server.test.ts
Routes can derive realtime channels. Successful handlers broadcast invalidate messages. Tests cover broadcast, skipped channels, and handler failures.
API server wiring and ticket endpoint
services/api/src/app.ts, services/api/src/routes/ws/getTicket.ts
The API creates an explicit HTTP server, attaches the WebSocket hub, mounts /v3/ws/ticket, and issues tickets from authenticated session context.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant API
  participant WebSocketServer
  participant WsHub
  participant AMA route
  Client->>API: GET /v3/ws/ticket
  API-->>Client: WebSocket ticket
  Client->>WebSocketServer: Connect to /v3/ws with ticket
  WebSocketServer->>WsHub: Register channel subscription
  Client->>AMA route: Modify AMA question
  AMA route->>WsHub: Broadcast invalidate message
  WsHub-->>Client: Send channel invalidation
Loading

Possibly related PRs

  • ChatSift/chatsift#170: Extends the route definition and mounting behavior introduced by this PR with realtime-channel callbacks and WebSocket broadcasts.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 its relevance to the changeset cannot be assessed. Add a concise description of the WebSocket gateway, ticket endpoint, authorization, subscriptions, and realtime invalidation broadcasts.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a WebSocket gateway to the API.
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

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.

@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

🤖 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 `@services/api/src/core/server.ts`:
- Around line 123-127: Move the realtimeChannel broadcast in the request
handling flow to execute only after response handling completes, and guard it
with a 2xx res.statusCode check. Preserve the existing channel resolution and
wsHub.broadcast behavior for successful responses, while preventing
invalidations when handlers return 4xx or 5xx statuses.

In `@services/api/src/routes/ws/getTicket.ts`:
- Around line 23-30: Update the getTicket handler to set the response
Cache-Control header to no-store before returning the ticket, ensuring the
bearer credential is not cached while preserving the existing ticket creation
and response behavior.

In `@services/api/src/ws/server.ts`:
- Around line 114-119: Stop passing ticket data through the WebSocket connection
event, whose listener should receive only the WebSocket and request. Introduce a
local setup function that accepts the upgraded WebSocket, request, and ticket,
move the ticket-dependent connection setup from the `wss.on('connection')`
listener into it, and invoke it directly from the `handleUpgrade` callback
instead of emitting a third argument.
- Around line 94-98: Update the upgrade handler around the
httpServer.on('upgrade') callback to destroy the socket whenever url.pathname is
not WS_PATH, ensuring unsupported paths are closed rather than left open. Add an
explicit dispatcher for any other upgrade protocol while preserving the existing
/v3/ws handling.
🪄 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: 4c603402-3eab-4bc4-b4bc-e665c18928dc

📥 Commits

Reviewing files that changed from the base of the PR and between be6d441 and b8ec84e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (17)
  • packages/private/backend-core/src/index.ts
  • packages/private/backend-core/src/lib/wsTicket.ts
  • packages/private/core/src/index.ts
  • packages/private/core/src/lib/realtimeChannels.ts
  • services/api/package.json
  • services/api/src/app.ts
  • services/api/src/core/__tests__/server.test.ts
  • services/api/src/core/route.ts
  • services/api/src/core/server.ts
  • services/api/src/routes/ama/questions/mergeQuestion.ts
  • services/api/src/routes/ama/questions/mergeQuestionsBulk.ts
  • services/api/src/routes/ama/questions/sendQuestion.ts
  • services/api/src/routes/ama/questions/updateQuestion.ts
  • services/api/src/routes/ama/tags/createTag.ts
  • services/api/src/routes/ws/getTicket.ts
  • services/api/src/ws/hub.ts
  • services/api/src/ws/server.ts

Comment thread services/api/src/core/server.ts Outdated
Comment thread services/api/src/routes/ws/getTicket.ts Outdated
Comment thread services/api/src/ws/server.ts Outdated
Comment thread services/api/src/ws/server.ts Outdated
@didinele
didinele merged commit 88e84a2 into main Aug 7, 2026
6 checks passed
@didinele
didinele deleted the feat/api-gateway branch August 7, 2026 07:16
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