Skip to content

feat(cli): inject function slug into served functions - #6345

Merged
raulb merged 12 commits into
developfrom
raulb/inject-function-slug-env-var
Sep 1, 2026
Merged

feat(cli): inject function slug into served functions#6345
raulb merged 12 commits into
developfrom
raulb/inject-function-slug-env-var

Conversation

@raulb

@raulb raulb commented Aug 26, 2026

Copy link
Copy Markdown
Member

Summary

Adds SUPABASE_FUNCTION_SLUG to every locally served Edge Function.

The value always matches the requested function name. This works in both the legacy and next stacks.

Context

Shared function folders

  • Edge Runtime reuses workers by their service path.
  • Two functions can share one source folder. They must not share one worker environment.
  • The CLI now gives each shared function a stable and unique worker path.
  • The CLI still passes the real source file as the entrypoint. Imports and file access remain unchanged.
  • Functions in separate folders keep their current service path.
  • The change does not use queues, owner maps, or forceCreate.

Linked issue

Fixes AI-1129

  • The linked issue is open and carries the open-for-contribution label, or I am a Supabase maintainer.

Checklist

  • The PR title follows Conventional Commits.
  • Tests were added or updated for the change.
  • From the repository root, pnpm check:all passes, and all required workspace checks pass.

@raulb
raulb requested a review from a team as a code owner August 26, 2026 16:53
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from e264980 to 2989c69 Compare August 26, 2026 16:56
@raulb raulb self-assigned this Aug 26, 2026
@raulb
raulb requested a review from kallebysantos August 26, 2026 16:56

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e264980dc6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@6bfa5868b31884a0788ed3c95603e3ba654228c9

Preview package for commit 6bfa586.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 961e6ac204

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from 961e6ac to c1103de Compare August 27, 2026 09:53

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1103de0cf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from c1103de to 954c972 Compare August 27, 2026 10:01

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c24a039af9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread apps/cli/src/shared/functions/serve.main.ts
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from bddf73e to cbc9aec Compare August 27, 2026 10:41
Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread packages/stack/src/services/edge-runtime-main.ts Outdated
raulb added a commit to supabase/supabase that referenced this pull request Aug 28, 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?

Feature (self-hosted Edge Functions)

## What is the current behavior?

The self-hosted Edge Functions router
(`docker/volumes/functions/main/index.ts`) doesn't tell a function which
slug a request resolved to. As a result, `@supabase/server`'s
`withOAuthProtectedResource` can't derive its canonical resource URL and
falls back to reconstructing it from the request path against the
internal `api-gw` origin, so the advertised OAuth Protected Resource is
/wrong for self-hosted deployments.

## What is the new behavior?

`main/index.ts` now injects `SUPABASE_FUNCTION_SLUG: service_name` per
request (after the `Deno.env.toObject()` snapshot, so nothing in the
container env can shadow it).

Combined with the operator's `SUPABASE_PUBLIC_URL`, the advertised
resource is the correct external
`{SUPABASE_PUBLIC_URL}/functions/v1/{slug}`, not the internal
`http://api-gw:8000`.

Verified on the docker stack: the slug is injected per-function, the
resource origin resolves to `SUPABASE_PUBLIC_URL`, and the `401`
`www-authenticate` carries the right `resource_metadata`.

## Additional context

Fixes AI-1128

Companion to `@supabase/server` [PR
#117](supabase/server#117) and the [CLI slug
injection](supabase/cli#6345)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Edge workers now receive the correct function slug in their runtime
environment, improving per-function request handling.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from 43b08e3 to 91f7dfe Compare August 28, 2026 11:54
@raulb
raulb requested a review from jgoux August 28, 2026 11:55

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91f7dfed2c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch 2 times, most recently from 91e1cd3 to abc0a94 Compare August 28, 2026 12:30

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abc0a94e32

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread packages/stack/src/services/edge-runtime-main.ts Outdated
Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread packages/stack/src/services/edge-runtime-main.ts Outdated
Comment thread packages/stack/src/services/edge-runtime-main.ts Outdated
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from abc0a94 to fa6ffc9 Compare August 31, 2026 14:40
@raulb
raulb requested a review from jgoux August 31, 2026 14:40
@raulb
raulb force-pushed the raulb/inject-function-slug-env-var branch from fa6ffc9 to 10eb8ec Compare August 31, 2026 14:44

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10eb8ec2ea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve.main.ts Outdated
Comment thread apps/cli/src/shared/functions/serve-main-offline.e2e.test.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4694df4090

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/cli/src/shared/functions/serve-main-offline.e2e.test.ts Outdated
Comment thread packages/stack/tests/createStack.e2e.test.ts Outdated
Comment thread apps/cli/src/shared/functions/serve-main-offline.e2e.test.ts Outdated
@raulb raulb changed the title feat(cli): inject function slug into served fns feat(cli): inject function slug into served functions Sep 1, 2026
@raulb
raulb enabled auto-merge September 1, 2026 13:54
@raulb
raulb added this pull request to the merge queue Sep 1, 2026
Merged via the queue into develop with commit 713129c Sep 1, 2026
21 checks passed
@raulb
raulb deleted the raulb/inject-function-slug-env-var branch September 1, 2026 14:14
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.

2 participants