Skip to content

Add the portal WebSocket with heartbeats (W4-03) - #108

Merged
calebyhan merged 3 commits into
mainfrom
91/portal-websocket
Nov 4, 2026
Merged

calebyhan merged 3 commits into
mainfrom
91/portal-websocket

Conversation

@ckkunc

@ckkunc ckkunc commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The portal updates live. New conversations, new messages, and the end of a shift all arrive over one WebSocket per tab (TDD 4.6.4). The same socket carries the portal's heartbeat every 30 seconds, which is what tells the site a responder is really there (#48). This ticket adds /ws/portal, which listens on the account's event bus topic (#74) and forwards events to the browser.

Changes:

  • Add /ws/portal with cookie authentication, an exact Origin check against the new app_origin setting, and account-topic JSON event forwarding. Off-shift staff can connect.
  • Handle heartbeats by revalidating the session and updating an open shift. Session checks on the socket preserve last_seen_at, so heartbeats and reconnects cannot extend the idle timeout.
  • Publish session.revoked after committed single/bulk revocations, forward that event, and close the socket with 4001. Heartbeats also detect revocation, expiry, or deactivation without an event.
  • Unsubscribe and cancel/reap pending tasks on disconnect, revocation, malformed frames, or cancellation. Run synchronous database work in the thread pool and release the connection after each check.
  • Document APP_ORIGIN in the environment example and extend Uvicorn's WebSocket log filter to cover trace messages containing client addresses.
  • Add 29 WebSocket test cases plus session-event and logging regression tests.

Validation:

  • make check passed: lint/format, backend/frontend type checks, 376 backend tests, 152 frontend tests, and the production frontend build.
  • PostgreSQL 18: alembic upgrade head and alembic check passed; no schema changes are needed.

Closes #91

@ckkunc
ckkunc requested a review from calebyhan November 4, 2026 03:20
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Backend Test Results

395 tests  +39   395 ✅ +39   11s ⏱️ -1s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit cea2688. ± Comparison against base commit 898d320.

♻️ This comment has been updated with latest results.

session.revoked is published to the account topic, so revoking one
device's session closed every socket on the account. Re-check this
socket's session before forwarding the event and closing with 4001.

@calebyhan calebyhan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@calebyhan
calebyhan merged commit ea228b0 into main Nov 4, 2026
4 checks passed
@calebyhan
calebyhan deleted the 91/portal-websocket branch November 4, 2026 22:45
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.

Add the portal WebSocket with heartbeats (W4-03)

2 participants