feat(docs): add resumable WebSockets + Edge Functions troubleshooting guides#46178
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds 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. ChangesEdge Function WebSocket Resilience Documentation
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsapps/docs/content/guides/functions/examples/resumable-websockets.mdxapps/docs/content/guides/functions/websockets.mdxapps/docs/content/troubleshooting/edge-functions-worker-timeouts-and-websocket-drops.mdx
|
|
||
| if (msg.event_id) { | ||
| lastEventId = Math.max(lastEventId, msg.event_id) | ||
| localStorage.setItem('last_event_id', String(lastEventId)) |
There was a problem hiding this comment.
is it better to store this in sessionStorage?
…ts-and-websocket-drops.mdx Co-authored-by: Lakshan Perera <lakshan@supabase.io>
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 2 file(s) based on 2 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 2 file(s) based on 2 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
apps/docs/content/guides/functions/examples/resumable-websockets.mdx Member |
Braintrust eval reportEvals in progress... ⌛ |
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?
sessionIdandlastEventIdinsessionStorage(instead oflocalStorage).Additional context
origin/master.Summary by CodeRabbit