Skip to content

fix(self-hosted): emit error key from edge functions worker - #3

Merged
sugata100 merged 1 commit into
masterfrom
fix/self-hosted-edge-worker-error-key
Sep 4, 2026
Merged

sugata100 merged 1 commit into
masterfrom
fix/self-hosted-edge-worker-error-key

Conversation

@sugata100

@sugata100 sugata100 commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

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 use error instead of msg:

  • Invalid JWT
  • Auth verification failures
  • Missing function name
  • Worker create/fetch failures

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:

  • Return self-hosted edge function worker failures using the platform-compatible error JSON field so clients can display the actual reason.

Enhancements:

  • Configure shared function import-map resolution and expose the resolved function name to each worker request.

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
@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the self-hosted edge functions worker to emit platform-compatible { error: ... } responses for all worker-generated failures, while also configuring the shared import map and per-request function slug in the worker environment.

Sequence diagram for self-hosted edge worker error responses

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Standardize worker-generated error responses on the platform-compatible error JSON key.
  • Changed invalid JWT, authentication, missing-function, and worker failure payloads from msg to error.
  • Preserved existing HTTP statuses and JSON content-type headers.
docker/volumes/functions/main/index.ts
Configure per-request function execution context for dynamically resolved edge functions.
  • Enabled the shared /home/deno/functions/deno.jsonc import map.
  • Injected the resolved function name through SUPABASE_FUNCTION_SLUG, overriding any container-level value.
docker/volumes/functions/main/index.ts

Assessment against linked issues

Issue Objective Addressed Explanation
supabase#47835 Update the self-hosted Edge Functions worker to emit error responses using the error JSON key expected by Studio, so worker-level failures expose their actual messages instead of falling back to a generic error. ✅
supabase#47835 Apply the response-shape correction consistently across all worker-generated error paths, including invalid JWTs, authentication failures, missing function names, and worker creation or execution failures. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@sugata100
sugata100 merged commit d6f56d9 into master Sep 4, 2026
1 check passed
sugata100 pushed a commit that referenced this pull request Sep 5, 2026
## 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 -->
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.

Edge Functions Test panel always shows generic error for non-platform, hiding the real failure reason

1 participant