Skip to content

feat(docs): add resumable WebSockets + Edge Functions troubleshooting guides#46178

Merged
mansueli merged 6 commits into
masterfrom
feat-websockets-example-&-troubleshooting-guide
May 27, 2026
Merged

feat(docs): add resumable WebSockets + Edge Functions troubleshooting guides#46178
mansueli merged 6 commits into
masterfrom
feat-websockets-example-&-troubleshooting-guide

Conversation

@mansueli
Copy link
Copy Markdown
Member

@mansueli mansueli commented May 20, 2026

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Docs update (new guides + follow-up documentation fix from review feedback).

What is the current behavior?

There was no consolidated docs example for resumable WebSockets with Edge Functions, and no dedicated troubleshooting guide for worker timeouts / WebSocket drops.

What is the new behavior?

  • Adds a resumable WebSockets guide for Edge Functions, including:
    • session persistence
    • event replay
    • idempotency pattern and schema examples
    • client/server example flow
  • Adds an Edge Functions troubleshooting guide for worker timeouts and WebSocket drops.
  • Updates docs navigation to surface the new guides.
  • Follow-up fix from review feedback: the browser client example now stores sessionId and lastEventId in sessionStorage (instead of localStorage).

Additional context

  • Branch has been updated with latest origin/master.
  • This PR remains documentation-focused; no production runtime code changes were introduced.

Summary by CodeRabbit

  • Documentation
    • Added a Resumable WebSockets guide covering reconnect-safe patterns, session persistence, event replay, idempotency, SQL schema examples, server proxy and client snippets, guarantees, and next steps.
    • Added a Troubleshooting guide on Edge Functions worker timeouts and WebSocket drops with scenarios, symptoms, root causes, and workarounds.
    • Clarified WebSocket best practices with a production note on keeping runtime promises open to avoid premature worker shutdowns.
  • Navigation
    • Updated docs navigation to surface the new guides.

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment, Open in v0 May 27, 2026 6:30pm
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 27, 2026 6:30pm
design-system Skipped Skipped May 27, 2026 6:30pm
studio-self-hosted Skipped Skipped May 27, 2026 6:30pm
studio-staging Skipped Skipped May 27, 2026 6:30pm
ui-library Skipped Skipped May 27, 2026 6:30pm
zone-www-dot-com Skipped Skipped May 27, 2026 6:30pm

Request Review

@supabase
Copy link
Copy Markdown

supabase Bot commented May 20, 2026

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 20, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6d17af00-f32e-454d-844a-d40d10431cae

📥 Commits

Reviewing files that changed from the base of the PR and between 7d54663 and 1943444.

📒 Files selected for processing (1)
  • apps/docs/content/guides/functions/examples/resumable-websockets.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/docs/content/guides/functions/examples/resumable-websockets.mdx

📝 Walkthrough

Walkthrough

Adds documentation: a troubleshooting guide on Edge Function worker timeouts/WebSocket drops, a detailed resumable WebSocket example with session persistence and replay, and links plus navigation entries integrating these guides into existing WebSocket docs.

Changes

Edge Function WebSocket Resilience Documentation

Layer / File(s) Summary
Worker timeout and WebSocket drop troubleshooting guide
apps/docs/content/troubleshooting/edge-functions-worker-timeouts-and-websocket-drops.mdx
New guide covering runtime limits, early retirement behavior, five scenarios causing worker timeouts/WebSocket/SSE drops, and specific symptoms/root causes/workarounds.
Resumable WebSocket pattern with session persistence
apps/docs/content/guides/functions/examples/resumable-websockets.mdx
New example documenting architecture, MDX frontmatter and overview, reconnection/resume flow, SQL schema for session/event/idempotency storage, an Edge Function WebSocket proxy with JWT auth, idempotent event persistence and replay via lastEventId, preemptive restart handling, and a browser client snippet using sessionStorage.
Documentation cross-linking and navigation updates
apps/docs/content/guides/functions/websockets.mdx, apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
Adds a reference from the existing WebSocket guide to the resumable example, a runtime lifecycle caution about holding EdgeRuntime.waitUntil() until socket.onclose, and navigation menu entries exposing the new troubleshooting and example pages.

Sequence Diagram(s)

sequenceDiagram
  participant BrowserClient
  participant EdgeFunction as EdgeFunction (WebSocket proxy)
  participant Database as Database (ws_sessions / ws_events / ws_idempotency_keys)
  BrowserClient->>EdgeFunction: Open WebSocket (sessionId?, jwt, lastEventId)
  EdgeFunction->>EdgeFunction: verifyCredentials(jwt) / Deno.upgradeWebSocket(req)
  EdgeFunction->>Database: create/resume session (sessionId)
  BrowserClient->>EdgeFunction: user_message (idempotency_key, payload)
  EdgeFunction->>Database: insert idempotency_key, insert ws_events row
  EdgeFunction->>BrowserClient: echo stored event (event_id)
  EdgeFunction->>Database: query ws_events where id > lastEventId (replay)
  EdgeFunction->>BrowserClient: send replayed events (replay: true)
  EdgeFunction->>EdgeFunction: schedule preemptive restart -> send server_restarting, close socket
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • laktek
  • ChrisChinchilla
  • jeremenichelli

Poem

🐰 Hopping logs and webs that mend,
I guard each session to the end,
Replay the past where gaps begin,
Keep workers waiting, hold them in,
Reconnect, resume — let messages win.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding resumable WebSockets guide and Edge Functions troubleshooting guides to documentation.
Description check ✅ Passed The description follows the template structure, clearly states the PR is a docs update, explains current/new behavior, and includes relevant context about changes and follow-up fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-websockets-example-&-troubleshooting-guide

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts`:
- Around line 1659-1662: The nav entry for "Worker timeouts and WebSocket drops"
currently sets url to
"/docs/troubleshooting/edge-functions-worker-timeouts-and-websocket-drops" which
includes the unwanted "/docs" prefix; update that url property on the nav item
with name "Worker timeouts and WebSocket drops" to the site-relative route
format used elsewhere (remove the "/docs" prefix) — e.g. set url to
"/troubleshooting/edge-functions-worker-timeouts-and-websocket-drops" as
`/${string}` so the navigation links resolve correctly.

In `@apps/docs/content/guides/functions/examples/resumable-websockets.mdx`:
- Around line 115-128: The current insert into ws_idempotency_keys via
admin.from('ws_idempotency_keys').insert(...) will  raise a PK/conflict on
retries and drop messages; change the flow to be conflict-aware: when inserting
the idempotency row (ws_idempotency_keys) use an upsert/ON CONFLICT style
operation or catch the unique-constraint error and in that case read the
already-stored user event from ws_events (e.g., query ws_events by session_id
and idempotency_key) and return that instead of failing; ensure the subsequent
admin.from('ws_events').insert(...) only runs when the idempotency insert
created a new key (or run both in a transaction that upserts idempotency and
returns the existing/created ws_events row so retries return the persisted
userEvent).
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6e019cbc-4431-47dd-9e92-75c0f7886110

📥 Commits

Reviewing files that changed from the base of the PR and between 44462c4 and 26da31e.

📒 Files selected for processing (4)
  • apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
  • apps/docs/content/guides/functions/examples/resumable-websockets.mdx
  • apps/docs/content/guides/functions/websockets.mdx
  • apps/docs/content/troubleshooting/edge-functions-worker-timeouts-and-websocket-drops.mdx

Comment thread apps/docs/content/guides/functions/examples/resumable-websockets.mdx Outdated

if (msg.event_id) {
lastEventId = Math.max(lastEventId, msg.event_id)
localStorage.setItem('last_event_id', String(lastEventId))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it better to store this in sessionStorage?

…ts-and-websocket-drops.mdx

Co-authored-by: Lakshan Perera <lakshan@supabase.io>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 2 unresolved review comments.

Files modified:

  • apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
  • apps/docs/content/guides/functions/examples/resumable-websockets.mdx

Commit: 4c0a419df66201110bf050b28b37008fdc765226

The changes have been pushed to the feat-websockets-example-&-troubleshooting-guide branch.

Time taken: 4m 36s

Fixed 2 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@mansueli
Copy link
Copy Markdown
Member Author

@copilot

  • fix the prettier things;
  • update the branch;
  • Also address this comment:

apps/docs/content/guides/functions/examples/resumable-websockets.mdx

if (msg.event_id) {
  lastEventId = Math.max(lastEventId, msg.event_id)
  localStorage.setItem('last_event_id', String(lastEventId))

Member
@laktek
laktek
last week
is it better to store this in sessionStorage?

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

@copilot

  • fix the prettier things;
    ...

Addressed in 7d54663: updated the resumable WebSocket browser client example to use sessionStorage for sessionId/lastEventId.

Also updated the branch with latest origin/master in merge commit 611fa55.

Copilot AI changed the title feat: add websockets with server example & troubleshooting guide for edge functions feat(docs): add resumable WebSockets + Edge Functions troubleshooting guides May 27, 2026
@mansueli mansueli enabled auto-merge (squash) May 27, 2026 18:27
@mansueli mansueli merged commit 894cb53 into master May 27, 2026
32 of 33 checks passed
@mansueli mansueli deleted the feat-websockets-example-&-troubleshooting-guide branch May 27, 2026 18:34
@github-actions
Copy link
Copy Markdown
Contributor

Braintrust eval report

Evals in progress... ⌛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants