Repository navigation
Replace SSE live-status stream with WebSocket (AFD does not relay SSE) - #1942
Merged
David Pine (IEvangelist) merged 2 commits intoOct 23, 2026
Merged
Conversation
Azure Front Door does not relay Server-Sent Events (documented), so the live badge went stale in production. Serve live state over /api/live/ws (JSON frames, 15 s heartbeat, jittered max lifetime), reuse the existing broadcaster, enable WebSockets on the App Service, and have the client fall back to polling /api/live/ the whole time the socket is not open. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 90ef1a20-cd65-43f3-97cd-6fa484d8b0a4
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The Front Door-to-App Service transport remains unverified, browser integration tests were not run, and a fallback-refresh issue remains unresolved.
1 open issue
What changed in this PR
Replaces the live-status SSE transport with WebSockets so updates can pass through Azure Front Door, while preserving the existing Redis-backed broadcaster and snapshot API.
Changes:
- Adds WebSocket streaming with heartbeats, bounded connection lifetimes, and shutdown handling.
- Updates the browser client with reconnects, fallback polling, and a stale-socket watchdog.
- Enables App Service and development-proxy WebSocket support and updates tests and documentation.
| File | Description |
|---|---|
| tests/StaticHost.Tests/Live/LiveWebSocketTests.cs | Adds WebSocket lifecycle and message tests. |
| tests/StaticHost.Tests/Live/LiveStreamTests.cs | Removes obsolete SSE tests. |
| tests/StaticHost.Tests/Live/LiveStatusBroadcasterTests.cs | Checks the JSON message envelope. |
| tests/StaticHost.Tests/Live/LiveEndpointsTests.cs | Adapts the test server for WebSockets. |
| src/statichost/StaticHost/Program.cs | Enables WebSocket middleware. |
| src/statichost/StaticHost/Live/README.md | Documents transport behavior and deployment requirements. |
| src/statichost/StaticHost/Live/LiveStatusServiceCollectionExtensions.cs | Updates transport terminology in comments. |
| src/statichost/StaticHost/Live/LiveStatusOptions.cs | Updates connection-lifetime documentation. |
| src/statichost/StaticHost/Live/LiveStatusBroadcaster.cs | Serializes shared WebSocket state messages. |
| src/statichost/StaticHost/Live/LiveStatus.cs | Updates subscriber terminology in comments. |
| src/statichost/StaticHost/Live/LiveEndpoints.cs | Replaces SSE with the WebSocket endpoint. |
| src/statichost/StaticHost/Extensions.cs | Excludes WebSocket requests from tracing. |
| src/frontend/tests/unit/live-status.vitest.test.ts | Tests reconnects, polling, and heartbeat detection. |
| src/frontend/tests/unit/astro-vite-config.vitest.test.ts | Checks WebSocket proxy configuration. |
| src/frontend/tests/e2e/live-status.spec.ts | Migrates live-status browser mocks to WebSockets. |
| src/frontend/tests/e2e/live-pip.spec.ts | Updates picture-in-picture transport mocking. |
| src/frontend/tests/e2e/live-embeds.spec.ts | Updates embedded-player transport mocking. |
| src/frontend/tests/e2e/live-accessibility.spec.ts | Updates accessibility-test transport mocking. |
| src/frontend/src/components/live-status.ts | Implements WebSocket updates and recovery behavior. |
| src/frontend/astro.config.mjs | Enables WebSocket forwarding in development. |
| src/apphost/Aspire.Dev.AppHost/LiveExtensions.cs | Updates the dashboard endpoint link. |
| src/apphost/Aspire.Dev.AppHost/AppHost.cs | Enables App Service WebSockets. |
Review effort: Balanced
Contributor
Frontend HTML artifact readyThe latest frontend build uploaded the This comment updates automatically when a new frontend build artifact is uploaded. |
Call seed function when document is visible after socket loss Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Sébastien Ros (sebastienros)
approved these changes
Oct 23, 2026
David Pine (IEvangelist)
deleted the
ievangelist-live-status-websocket
branch
October 23, 2026 18:17
Sébastien Ros (sebastienros)
added a commit
that referenced
this pull request
Nov 11, 2026
- TypeScript API parameter descriptions (#2009) - No locale prefix or hreflang alternates for English-only pages: the footer language picker (#1988), hreflang (#1987) and the sidebar Glossary link (#1989) - Footer link to the Aspire MIT license - Homepage: environment fade (#1993), stale AppHost animations (#1950), the dashboard carousel keeps the selected slide on activation - Search: first-result highlight with out-of-order renders (#2007), hover cursor flicker (#1977) - Live status over WebSocket (#1942) and twoslash hover, merged into the copies of the frontend scripts - Icon data 5.40.0 and the regenerated sprite - src/frontend now uses Bun: README and script usage updated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Replaces the Server-Sent Events (SSE) live-status stream with a WebSocket stream, because Azure Front Door (AFD) does not relay SSE.
Problem
The first-party doc says it outright: "Front Door doesn't support Server-Sent Events (SSE)" (https://learn.microsoft.com/en-us/azure/frontdoor/standard-premium/websocket). We confirmed it empirically for
GET /api/live/stream/:text/event-stream,event: stateat 0.6 s,:hbcomment every 15 s,Cache-Control: no-store,X-Accel-Buffering: nohttps://aspire.dev)new EventSource('/api/live/stream/')never firesopenThe client seeded once from
GET /api/live/and then relied only onEventSource, so the live badge went stale in production.What changed
src/statichost/StaticHost)GET /api/live/wsendpoint (app.UseWebSockets(), KeepAliveInterval 30 s). It reuses the existingLiveStatusBroadcaster/ Redis fan-out; only the transport changed.{"type":"state","data":{...}}(same data as the oldstateevent) and{"type":"hb"}every 15 s.StreamMaxLifetimeSeconds(default 600 s, key name unchanged) with 1000, and with 1001 on shutdown. Client disconnects and cancellation are handled./api/live/wsget 400./api/live/streamis removed (now 404)./api/livesnapshot is unchanged. Telemetry exclusion and the AppHost dashboard URL now point at/api/live/ws.live-status.ts)EventSourcereplaced byWebSocket(ws:/wss:fromlocation, path/api/live/ws, no trailing slash)./api/live/; exponential backoff with jitter; visibility/online handling kept; DOM/CSS unchanged./api/live/is polled every 30 s whenever the socket is not open (and the tab is visible), so the badge cannot go stale if the socket is blocked. A 45 s stale-socket watchdog closes and reconnects a socket that goes silent./api/livegetsws: true.website.SiteConfig.IsWebSocketsEnabled = true. It was NOT set in the public AppHost, and WebSockets are off by default on App Service, so this is required for the endpoint to work. Please review this setting.LiveWebSocketTests; vitest and Playwright specs updated;Live/README.mdupdated.AFD constraints considered
Deploy note
The internal Azure DevOps
deploybranch pulls from publicmain, so it needs to be synced for this to ship (including the App Service WebSockets setting).Third-party links and affiliations
None. The only new link is the first-party Microsoft Learn AFD WebSocket doc.
Validation
dotnet build tests\StaticHost.Tests\StaticHost.Tests.csproj- passed (0 errors; only the existing NU1902 MessagePack warning)dotnet test tests\StaticHost.Tests\StaticHost.Tests.csproj --no-build --filter "FullyQualifiedName!~Live.Redis"- passed, 337/337 (includes new WebSocket tests: initial state, updates, heartbeat, non-WS 400, max-lifetime close, shutdown close, client close/abort)pnpm exec vitest run --config vitest.config.ts tests/unit/live-status.vitest.test.ts tests/unit/astro-vite-config.vitest.test.ts(insrc/frontend) - passed, 22/22http://127.0.0.1:5099against a throwaway Redis container; a Nodewsclient received{"type":"state",...}at 0.2 s and{"type":"hb"}at 15.2 s and 30.2 s, then a clean 1000 close; plainGET /api/live/wsreturned 400 and/api/live/streamreturned 404.Not verified
Live.Redis*integration tests (need Aspire + Docker containers) were not run.Post-deploy checklist
webSocketsEnabledis true after deploywss://aspire.dev/api/live/wsand showsstate+hbmessages for 60+ s, including past 220 s (and ideally past 5 min)https://aspire.devwith the network tab showing a 101 upgrade