Repository navigation
fix(self-hosted): emit error key from edge functions worker - #3
Conversation
Align self-hosted edge runtime error JSON with platform shape ({ error })
instead of { msg }. Studio and other tooling expect the error key, so
worker failures previously surfaced only as a generic message.
Closes supabase#47835
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates the self-hosted edge functions worker to emit platform-compatible Sequence diagram for self-hosted edge worker error responsessequenceDiagram
participant Client
participant EdgeWorker
participant FunctionWorker
Client->>EdgeWorker: HTTP request
EdgeWorker->>EdgeWorker: isValidHybridJWT(token)
alt Invalid JWT
EdgeWorker-->>Client: 401 { error: Invalid JWT }
else Missing function name
EdgeWorker-->>Client: 400 { error: missing function name in request }
else Valid request
EdgeWorker->>FunctionWorker: create worker with importMapPath and SUPABASE_FUNCTION_SLUG
FunctionWorker-->>EdgeWorker: worker
EdgeWorker->>FunctionWorker: worker.fetch(req)
alt Worker failure
EdgeWorker-->>Client: 500 { error: exception message }
else Function response
FunctionWorker-->>Client: Function response
end
end
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docker/volumes/functions/main/index.ts" line_range="153" />
<code_context>
- const envVarsObj = Deno.env.toObject()
+ // Using a common Import Map for all functions
+ // to use a scope 'deno.json' it must be dinamically resolved base on the 'service_name'
+ const importMapPath = `/home/deno/functions/deno.jsonc`
+ // SUPABASE_FUNCTION_SLUG is listed after the container env snapshot so
+ // nothing in it can shadow the value, and it is per-request because only this
</code_context>
<issue_to_address>
**issue (bug_risk):** The worker is configured with `/home/deno/functions/deno.jsonc`, but that file is not present in the self-hosted functions volume. `EdgeRuntime.userWorkers.create` therefore fails for every function request that uses the bundled configuration, so no edge function executes.
**Triggers:** When running the standard self-hosted Docker setup without manually creating `/home/deno/functions/deno.jsonc`.
**Suggested fix:** Use the resolved function's existing import map, or provision a shared `deno.jsonc` at this path before passing it to `userWorkers.create`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: docker/volumes/functions/main/index.ts:153
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const envVarsObj = Deno.env.toObject() | ||
| // Using a common Import Map for all functions | ||
| // to use a scope 'deno.json' it must be dinamically resolved base on the 'service_name' | ||
| const importMapPath = `/home/deno/functions/deno.jsonc` |
There was a problem hiding this comment.
issue (bug_risk): The worker is configured with /home/deno/functions/deno.jsonc, but that file is not present in the self-hosted functions volume. EdgeRuntime.userWorkers.create therefore fails for every function request that uses the bundled configuration, so no edge function executes.
Triggers: When running the standard self-hosted Docker setup without manually creating /home/deno/functions/deno.jsonc.
Suggested fix: Use the resolved function's existing import map, or provision a shared deno.jsonc at this path before passing it to userWorkers.create.
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Refactor, plus one bug fix. Groundwork for showing the user a preview of what they are approving when the AI Assistant creates or edits a notebook. No UI in this PR. Towards FE-4143 ## What is the current behavior? `applyNotebookOperations` resolves an ordered list of notebook operations into the resulting cells and nothing else. Rendering a diff for the approval gate needs to know *what happened* to each cell position, not just where things landed, so there is no way to build the preview on top of it. Separately, replacing a cell dropped its id, so `[replace cell-2, insert after cell-2]` failed with a spurious `unknown_cell_id`. ## What is the new behavior? `deriveNotebookDiff` resolves operations into one annotated entry per cell position (`unchanged`, `added`, `removed`, `replaced`, `moved`). `applyNotebookOperations` becomes a thin projection over its result, so there is a single interpreter of notebook operations and the diff a user approves cannot disagree with the cells that get written. The pre-existing tests pass untouched, which is the evidence that the projection is faithful. Notes on the annotations: - `removed` entries stay in the position the cell used to hold so the list reads as a diff. This does not perturb insert-anchor arithmetic: prior inserts still sit contiguously after their anchor. - Moves that cancel out are downgraded to `unchanged`, since two moves can anchor on each other and leave every cell where it started. Badging those as moved would make the preview lie. - `fromIndex` is the cell's position in the original notebook rather than in the shifted working order, so `was #3` means what a reader expects. A replaced cell now stays addressable as an anchor. Anchoring and targeting are separate lookups: a replaced cell can be anchored on, but is never a legitimate target. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Notebook changes now provide a structured view of added, removed, replaced, moved, and unchanged cells. * Replaced cells can be used as insertion anchors, while invalid or duplicate targets are rejected. * No-op moves are handled as unchanged cells. * Notebook edits preserve operation ordering and original cell positions for more predictable results. * **Bug Fixes** * Improved notebook operation handling and error reporting for complex cell edits. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Fixes the self-hosted edge functions worker error JSON shape for supabase#47835.
Worker responses used
{ "msg": "..." }while platform tooling expects{ "error": "..." }, which caused Studio’s Edge Functions Test panel to hide the real failure reason.Changes
In
docker/volumes/functions/main/index.ts, all worker-generated error payloads now useerrorinstead ofmsg:Open against upstream
Please open against supabase/supabase:
https://github.com/supabase/supabase/compare/master...sugata100:supabase:fix/self-hosted-edge-worker-error-key?expand=1
Closes supabase#47835
Summary by Sourcery
Align self-hosted edge function worker responses with the expected error format and function runtime context.
Bug Fixes:
errorJSON field so clients can display the actual reason.Enhancements: