Skip to content

Pass the webhook request through without buffering its body - #3166

Merged
pranaygp merged 2 commits into
mainfrom
naterajlich/webhook-token-before-body-read
Jul 28, 2026
Merged

Pass the webhook request through without buffering its body#3166
pranaygp merged 2 commits into
mainfrom
naterajlich/webhook-token-before-body-read

Conversation

@TooTallNate

@TooTallNate TooTallNate commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem

The Astro and SvelteKit webhook wrappers copied the incoming request via normalizeRequest() — which reads the whole body with arrayBuffer() — before calling the handler. That read happened before the handler had a chance to look at the token, so requests carrying an unknown token did unnecessary work before being rejected.

Fix

The copy turns out to be unnecessary. Both frameworks already hand the route a standard Request, so the wrappers now pass it straight through:

const createHandler = (method) => async ({ request, params, platform }) => {
  const response = await handler(request, params.token);
  return response;
};

The body is left untouched until resumeWebhook() has accepted the token. This deletes code rather than adding a second normalizer — an earlier revision of this PR added a streaming variant of normalizeRequest, but with the body read removed that wrapper was just an identity copy of the request, so it's gone.

The flow route keeps normalizeRequest(): it authenticates via the queue trigger rather than a URL token, so the ordering doesn't matter there. Whether the shim is needed there at all is a separate question — see below.

On the origin of the shim

Per prior discussion, normalizeRequest was introduced to get an e2e test passing before a launch, and the specific failure is no longer remembered. For the webhook route I can confirm it is not needed: with it removed, the full e2e.test.ts passes on both frameworks, including the webhook cases that assert exact received bodies across the default, static and manual respondWith paths.

I have not tested removing it from the flow route. That's a larger change and unrelated to this one, so it's left for a follow-up rather than folded in.

Verification

Astro SvelteKit
full e2e.test.ts 128 passed, 7 skipped 128 passed, 7 skipped
unknown-token request rejected without the body being read rejected without the body being read

Notes for reviewers

Astro dev server. It reads request bodies upstream of the route handler — a route that never touches the body behaves the same way — so the change is only observable in built output (node adapter / Vercel), which is what gets deployed.

No automated regression guard. The property "the webhook wrapper must not read the body" is currently enforced only by the comment in each builder. Making it testable would mean extracting the wrapper template into an exported constant so a unit test could assert it; happy to add that if reviewers want it.

Copilot AI review requested due to automatic review settings July 28, 2026 20:06
@TooTallNate
TooTallNate requested review from a team and ijjk as code owners July 28, 2026 20:06
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Jul 28, 2026 9:45pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment Jul 28, 2026 9:45pm
example-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-astro-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-express-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-fastify-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-hono-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-nestjs-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-nitro-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-nuxt-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-sveltekit-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workbench-vite-workflow Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workflow-docs Ready Ready Preview, Comment, Open in v0 Jul 28, 2026 9:45pm
workflow-swc-playground Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workflow-tarballs Ready Ready Preview, Comment Jul 28, 2026 9:45pm
workflow-web Ready Ready Preview, Comment Jul 28, 2026 9:45pm

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ff9026

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@workflow/astro Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/world-testing Patch
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
@workflow/nest Patch
@workflow/nuxt Patch
@workflow/rollup Patch
@workflow/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 8ff9026 · Tue, 28 Jul 2026 22:06:10 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1213 (+72%) 🔻 1271 🔴 (+26%) 🔻 1290 🔴 (+27%) 🔻 1383 🔴 (-8.3%) 30
TTFS stream 1201 (+26%) 🔻 1246 🔴 (+26%) 🔻 1262 🔴 (+25%) 🔻 1467 🔴 (+40%) 🔻 30
TTFS hook + stream 492 (-59%) 💚 1521 🔴 (+18%) 🔻 1536 🔴 (+15%) 1605 🔴 (±0%) 30
STSO 1020 steps (1-20) 168 (+5.0%) 262 🔴 (+1.9%) 311 🔴 (+2.6%) 321 🔴 (-24%) 💚 19
STSO 1020 steps (101-120) 162 (-12%) 253 🔴 (+3.3%) 327 🔴 (+16%) 🔻 533 🔴 (-24%) 💚 19
STSO 1020 steps (1001-1020) 456 (-2.4%) 510 🔴 (-9.7%) 522 🔴 (-14%) 576 🔴 (-16%) 💚 19
WO 1020 steps 582923 (+51%) 🔻 582923 (+51%) 🔻 582923 (+51%) 🔻 582923 (+51%) 🔻 1
SL stream latency 80 (-1.2%) 136 🔴 (+3.0%) 141 🔴 (+0.7%) 367 🔴 (+105%) 🔻 30
SO stream overhead (text) 94 (-6.9%) 152 (-16%) 💚 187 (-7.4%) 285 (+14%) 30
SO stream overhead (structured) 100 (+1.0%) 140 (-14%) 147 (-25%) 💚 174 (-20%) 💚 30
📜 Previous results (2)

acf61a3

Tue, 28 Jul 2026 21:20:47 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1264 (+79%) 🔻 1339 🔴 (+33%) 🔻 1397 🔴 (+38%) 🔻 1495 🔴 (-0.9%) 30
TTFS stream 392 (-59%) 💚 1319 🔴 (+34%) 🔻 1331 🔴 (+32%) 🔻 1393 🔴 (+33%) 🔻 30
TTFS hook + stream 515 (-58%) 💚 1565 🔴 (+21%) 🔻 1581 🔴 (+18%) 🔻 1664 🔴 (+3.4%) 30
STSO 1020 steps (1-20) 182 (+14%) 310 🔴 (+21%) 🔻 387 🔴 (+28%) 🔻 635 🔴 (+50%) 🔻 19
STSO 1020 steps (101-120) 188 (+1.6%) 262 🔴 (+6.9%) 327 🔴 (+16%) 🔻 356 🔴 (-49%) 💚 19
STSO 1020 steps (1001-1020) 491 (+5.1%) 547 🔴 (-3.2%) 593 🔴 (-2.8%) 665 🔴 (-3.1%) 19
WO 1020 steps 405492 (+5.1%) 405492 (+5.1%) 405492 (+5.1%) 405492 (+5.1%) 1
SL stream latency 128 (+58%) 🔻 229 🔴 (+73%) 🔻 302 🔴 (+116%) 🔻 468 🔴 (+161%) 🔻 30
SO stream overhead (text) 173 (+71%) 🔻 264 🔴 (+47%) 🔻 286 (+42%) 🔻 521 (+108%) 🔻 30
SO stream overhead (structured) 147 (+48%) 🔻 242 (+49%) 🔻 264 (+35%) 🔻 291 (+34%) 🔻 30

d8a70f9

Tue, 28 Jul 2026 20:28:48 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 291 (-59%) 💚 1431 🔴 (+42%) 🔻 1459 🔴 (+44%) 🔻 1912 🔴 (+27%) 🔻 30
TTFS stream 216 (-77%) 💚 1448 🔴 (+47%) 🔻 1524 🔴 (+51%) 🔻 1555 🔴 (+48%) 🔻 30
TTFS hook + stream 392 (-68%) 💚 1597 🔴 (+24%) 🔻 1654 🔴 (+24%) 🔻 1706 🔴 (+6.0%) 30
STSO 1020 steps (1-20) 180 (+13%) 293 🔴 (+14%) 372 🔴 (+23%) 🔻 383 🔴 (-9.7%) 19
STSO 1020 steps (101-120) 196 (+5.9%) 300 🔴 (+22%) 🔻 419 🔴 (+49%) 🔻 442 🔴 (-37%) 💚 19
STSO 1020 steps (1001-1020) 575 (+23%) 🔻 655 🔴 (+16%) 🔻 675 🔴 (+11%) 923 🔴 (+35%) 🔻 19
WO 1020 steps 439125 (+14%) 439125 (+14%) 439125 (+14%) 439125 (+14%) 1
SL stream latency 99 (+22%) 🔻 181 🔴 (+37%) 🔻 192 🔴 (+37%) 🔻 215 🔴 (+20%) 🔻 30
SO stream overhead (text) 127 (+26%) 🔻 248 (+38%) 🔻 307 (+52%) 🔻 467 (+87%) 🔻 30
SO stream overhead (structured) 120 (+21%) 🔻 215 (+33%) 🔻 282 (+45%) 🔻 559 (+158%) 🔻 30
ℹ️ Metric definitions & methodology

Best/P75/P90/P99 deltas compare against the most recent benchmark run on main at the time of this run. 🔻 flags a delta worse than +15%, 💚 one better than −15%.

Metrics — TTFS: time to first step body (in-deployment start() → first step body, deployment clocks) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored) · SL: stream latency (in-deployment write → read propagation, readAt - writtenAt) · SO: stream overhead (end-to-end write+consume time beyond the modelled generation window)

Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · stream latency: parallel reader/writer steps on a dedicated stream; SL is the in-deployment write->read propagation (readAt - writtenAt) · stream overhead (text): writer streams 300 variable-length text token deltas paced at 100/s for 3s (a haiku-size LLM's token throughput) while a parallel reader drains the whole stream; SO is the end-to-end write+consume time beyond the 3s generation window (overhead/backpressure) · stream overhead (structured): same workload as stream overhead (text), but each delta is an AI-SDK-style structured object ({ type: 'text-delta', id, text }) instead of a raw string, so the SO gap vs the text scenario is the added serialization cost

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · SO 250/500/1000 · STSO (1-20) 20/30/60 · STSO (101-120) 30/45/90 · STSO (1001-1020) 40/60/120

All metrics are measured from deployment-side timestamps only. Runs are triggered by an in-deployment route that stamps the anchor (clientStart) right before start(), so the CI runner’s request and its path through api.vercel.com sit outside every measured window. TTFS = in-deployment start() → first step body (turbo uses the in-process fast path, non-turbo the dispatch path), and includes the VQS dispatch hop plus any /flow cold start. STSO/WO are measured between step bodies on the deployment. SL is measured inside the workflow (parallel reader/writer steps), so it no longer includes the api.vercel.com read path.

Cold starts are kept in the numbers on purpose — they are part of real bursty-workload latency. The workbench deployment cold-starts the /flow invocation for a large fraction of runs, inflating P75+; the Best column shows the fastest (warm-start) sample for comparison.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

❌ Failed E2E Tests

▲ Vercel Production (1 failed)

fastify (1 failed):

💻 Local Development (1 failed)

nuxt-stable (1 failed):

  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_41KYNBBR7H0GXN812PT9G0VFCW

E2E Test Summary

Summary
Passed Failed Skipped Total
❌ ▲ Vercel Production 1454 1 239 1694
❌ 💻 Local Development 1485 1 208 1694
✅ 📦 Local Production 1621 0 227 1848
✅ 🐘 Local Postgres 1621 0 227 1848
✅ 🪟 Windows 154 0 0 154
✅ 📋 Other 1020 0 212 1232
✅ vercel-multi-region 27 0 0 27
Total 7382 2 1113 8497
Details by Category

❌ ▲ Vercel Production

App Passed Failed Skipped
✅ astro 126 0 28
✅ example 126 0 28
✅ express 126 0 28
❌ fastify 125 1 28
✅ hono 126 0 28
✅ nextjs-turbopack 151 0 3
✅ nextjs-webpack 151 0 3
✅ nitro 126 0 28
✅ nuxt 126 0 28
✅ sveltekit 145 0 9
✅ vite 126 0 28

❌ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
❌ nuxt-stable 127 1 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

✅ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack 154 0 0

✅ 📋 Other

App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 128 0 26
✅ e2e-local-dev-tanstack-start- 128 0 26
✅ e2e-local-postgres-nest-stable 128 0 26
✅ e2e-local-postgres-tanstack-start- 128 0 26
✅ e2e-local-prod-nest-stable 128 0 26
✅ e2e-local-prod-tanstack-start- 128 0 26
✅ e2e-vercel-prod-nest 126 0 28
✅ e2e-vercel-prod-tanstack-start 126 0 28

✅ vercel-multi-region

App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

@TooTallNate TooTallNate mentioned this pull request Jul 28, 2026
@TooTallNate
TooTallNate force-pushed the naterajlich/webhook-token-before-body-read branch from d8a70f9 to ef2f142 Compare July 28, 2026 20:38
@TooTallNate TooTallNate changed the title Validate webhook token before reading the request body Pass the webhook request through without buffering its body Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No backport to stable for 0d6ec43 (AI decision).

This removes an unnecessary normalizeRequest() copy from the generated Astro/SvelteKit webhook routes so the body isn't buffered before the token is validated — an efficiency/cleanup change, not a fix for a user-visible defect. The existing behavior works correctly on stable (the PR confirms e2e passes both with and without the copy); the only difference is that unknown-token requests did some wasted work before rejection, which doesn't rise to a stability problem like an unbounded allocation or crash. Both packages/astro/src/builder.ts and packages/sveltekit/src/builder.ts do exist on stable, so the change would apply, but per the maintenance-branch criteria performance/refactor work stays on main.

To override, re-run the Backport to stable workflow manually via workflow_dispatch and paste this commit SHA into the ref input:

0d6ec438770f42cb3c512e97c27ec551c957de32

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #3174. (backport job run)

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.

3 participants