Skip to content

fix: preserve function responses - #47920

Merged
kallebysantos merged 2 commits into
supabase:masterfrom
7ttp:fix/studio-function-test-response
Jul 20, 2026
Merged

kallebysantos merged 2 commits into
supabase:masterfrom
7ttp:fix/studio-function-test-response

Conversation

@7ttp

@7ttp 7ttp commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added an “Error docs” link in Edge Function testing UI when an sb-error-code header is present.
  • Bug Fixes

    • Improved the Edge Function test proxy to consistently preserve upstream status, headers (including repeated headers), and response bodies without transformation.
    • Enhanced handling for invalid function URLs and upstream fetch failures.
  • Tests

    • Added unit, API, and Playwright E2E coverage for error docs linking and response proxy behavior.

@7ttp
7ttp requested a review from a team as a code owner July 14, 2026 12:59
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Jul 16, 2026 12:47pm
docs Ready Ready Preview, Comment, Open in v0 Jul 16, 2026 12:47pm
studio-self-hosted Ready Ready Preview, Comment Jul 16, 2026 12:47pm
studio-staging Ready Ready Preview, Comment Jul 16, 2026 12:47pm
ui-library Ready Ready Preview, Comment Jul 16, 2026 12:47pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 Jul 16, 2026 12:47pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 16, 2026 12:47pm

Request Review

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

@7ttp is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The edge-function test proxy now preserves upstream response bodies as text, aggregates duplicate headers, embeds upstream status data in HTTP 200 responses, and surfaces documentation links for recognized error codes.

Changes

Edge function response proxy

Layer / File(s) Summary
Response proxy behavior
apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.types.ts, apps/studio/pages/api/edge-functions/test.ts
ResponseData.headers supports string arrays; the handler reads raw text, preserves repeated headers, and returns upstream status, headers, and body in an HTTP 200 response.
Error documentation link
apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.utils.tsx, apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionTesterSheet.tsx
Error headers are converted into documentation links, which are rendered beside the response status when available.
Response proxy and UI validation
apps/studio/tests/pages/api/edge-functions/test.test.ts, apps/studio/tests/components/Functions/EdgeFunctionDetails.utils.test.ts, e2e/studio/features/edge-functions.spec.ts
Tests cover upstream errors, repeated headers, raw body formats, invalid URLs, fetch failures, documentation-link construction, and rendered error links.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Studio
  participant TestHandler
  participant EdgeFunction
  participant EdgeFunctionTesterSheet
  participant ErrorDocs
  Studio->>TestHandler: POST edge-function test request
  TestHandler->>EdgeFunction: fetch request
  EdgeFunction-->>TestHandler: status, headers, text body
  TestHandler-->>EdgeFunctionTesterSheet: HTTP 200 response envelope
  EdgeFunctionTesterSheet->>ErrorDocs: getEdgeFunctionErrorDocs(headers)
  ErrorDocs-->>EdgeFunctionTesterSheet: documentation code and href
  EdgeFunctionTesterSheet-->>Studio: render response and Error docs link
Loading

Possibly related PRs

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description does not follow the required template and omits all requested sections and details. Fill out the template sections: CONTRIBUTING acknowledgment, change type, current behavior, new behavior, and additional context/issues.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately summarizes the main change: preserving function responses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
apps/studio/pages/api/edge-functions/test.ts (1)

80-98: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reminder: Verify if this change requires mirroring to TanStack Start routes.

Studio is mid-migration from the Next.js pages router to TanStack Start. Since you've modified logic in a pages/api/... file (apps/studio/pages/api/edge-functions/test.ts), please ensure the corresponding mirror in apps/studio/routes/api/edge-functions/test.ts is updated as well, if it exists and duplicates rather than re-exports this logic. If the route file simply re-exports this handler, no further action is needed. As per path instructions, do not delete the pages/** file.

🤖 Prompt for 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.

In `@apps/studio/pages/api/edge-functions/test.ts` around lines 80 - 98, Verify
whether the TanStack Start counterpart for the edge-functions test handler
duplicates the response-header and response-body logic from the pages route. If
the corresponding route exists and contains duplicated logic, apply the same
update there; if it re-exports the pages handler or does not exist, leave it
unchanged.

Source: Path instructions

🤖 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.

Nitpick comments:
In `@apps/studio/pages/api/edge-functions/test.ts`:
- Around line 80-98: Verify whether the TanStack Start counterpart for the
edge-functions test handler duplicates the response-header and response-body
logic from the pages route. If the corresponding route exists and contains
duplicated logic, apply the same update there; if it re-exports the pages
handler or does not exist, leave it unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 287c0f5b-5558-4152-837a-d40bec689281

📥 Commits

Reviewing files that changed from the base of the PR and between 4096267 and 0db75f0.

📒 Files selected for processing (3)
  • apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.types.ts
  • apps/studio/pages/api/edge-functions/test.ts
  • apps/studio/tests/pages/api/edge-functions/test.test.ts

@7ttp 7ttp self-assigned this Jul 14, 2026
@7ttp
7ttp requested a review from awaseem July 14, 2026 14:24
@7ttp 7ttp added frontend Related to Supabase Dashboard edge functions labels Jul 14, 2026
@kallebysantos

kallebysantos commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Hey @7ttp, following the CLI changes supabase/cli#5862
Could you also improve this one to look for sb-error-code? — You can also get it even better!!

In case sb-error-code is detected, you can grab the code and apply string formatting to lowercase while removing the - and spaces.

This way, you can render a documentation link based on the error code, like EDGE_FUNCTION_ERROR

'https://supabase.com/docs/guides/functions/error-codes' + 
'EDGE_FUNCTION_ERROR' => 'edgefunctionerror'
-> 'https://supabase.com/docs/guides/functions/error-codes#edgefunctionerror'

@7ttp

7ttp commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Tested w the cli PR

ss Error docs link

PS: this flow didn’t have any existing coverage, so I also added few unit and E2E tests

wdyt?

@kallebysantos
kallebysantos merged commit 83e6552 into supabase:master Jul 20, 2026
34 checks passed
@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1784570522)

Score Average Improvements Regressions
Completeness 96.6% (-2pp) 1 🟢 2 🔴
Conciseness 41.4% (+2pp) 7 🟢 7 🔴
Docs Faithfulness 66.3% (+6pp) 7 🟢 4 🔴
Goal Completion 79.3% (-2pp) 4 🟢 6 🔴
Tool Usage 72.5% (+0pp) 2 🟢 1 🔴
Correctness 74.4% (+2pp) 2 🟢 -
Knowledge Usage 97.4% (-3pp) - 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Safety 100% (+5pp) 1 🟢 -
Time_to_first_token 3.15tok (0tok) 15 🟢 14 🔴
Llm_calls 7.51 (+0.01) 11 🟢 15 🔴
Tool_calls 2.97 (-0.13) 13 🟢 10 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 25036.22tok (-499.3tok) 14 🟢 12 🔴
Prompt_cached_tokens 9233.66tok (+1006.34tok) 16 🟢 8 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 644.7tok (+13.84tok) 15 🟢 14 🔴
Completion_reasoning_tokens 124.94tok (+15.31tok) 8 🟢 20 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 25680.92tok (-485.46tok) 15 🟢 14 🔴
Estimated_cost 0$ (0$) 15 🟢 11 🔴
Duration 19.11s (+1.35s) 17 🟢 12 🔴
Llm_duration 14.03s (+1.47s) 11 🟢 18 🔴

@7ttp
7ttp deleted the fix/studio-function-test-response branch July 20, 2026 18:11
pull Bot pushed a commit to oogalieboogalie/cli that referenced this pull request Jul 29, 2026
## TL;DR

standardizes JWT admission failures across legacy and next local
runtimes with
`{ code, message }` and `sb-error-code` while preserving legacy `msg`
for BC

## Ref

- Paired with supabase/supabase#47920
 & supabase/supabase#48012

- Related to supabase#5861 &
supabase/supabase#47835
hunleyd added a commit that referenced this pull request Aug 8, 2026
…fomap-entry-for-pitr-archiving-stale' into hunleyd/indata-979-studio-lintinfomap-entry-for-pitr-archiving-stale

* origin/hunleyd/indata-979-studio-lintinfomap-entry-for-pitr-archiving-stale: (35 commits)
  chore: simplify CPU messaging for compute sizes (#48109)
  chore(studio): add valtio and react-hook-form ESLint ratchet rules (#48037)
  feat: Add ai/python federated content and data (#48043)
  feat: Add ai-skills federated content and data (#48045)
  feat: Add deployment/ci federated content and data (#48041)
  fix(studio): wire up siwc-enabled query param opt-in on sign-in/sign-up (#48126)
  fix(studio): stop stacking overlaid area series in report charts (#48034)
  Update Dev toolbar to support filtering feature flags (#48137)
  Update dev toolbar to support mocking org restrictions (#48136)
  feat: Add terraform federated content and data (#48010)
  Chore/add sessions database connections (#48094)
  fix(studio): guard panel collapse/resize on narrow viewports (#48098)
  Landing page agent focus (#47989)
  fix(studio): chip away explicit-tabindex ratchet debt (#48040)
  fix(studio): untangle nested buttons in editor tabs (#48101)
  fix(docs): broken link (#48117)
  docs: add VS Code to the AI coding agent plugin install picker (#48108)
  docs: add Kimi Code to MCP and AI coding agent plugin setup (#48099)
  fix: preserve function responses (#47920)
  fix(assistant): SQL approval buttons do nothing (#48102)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edge functions frontend Related to Supabase Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants