Skip to content

[build-utils] Extend finalizeLambda with pluggable ZIP strategy and pre-digest validation hook#15856

Merged
healeycodes merged 2 commits into
mainfrom
finalize-func-idea
Apr 7, 2026
Merged

[build-utils] Extend finalizeLambda with pluggable ZIP strategy and pre-digest validation hook#15856
healeycodes merged 2 commits into
mainfrom
finalize-func-idea

Conversation

@healeycodes

Copy link
Copy Markdown
Member

Callers that handle large functions (multi-GiB) need to stream zips to disk instead of holding them in memory. The current finalizeLambda always creates an in-memory Buffer, forcing callers to duplicate the entire finalization pipeline (encrypted env, environment setup, streaming detection) just to swap out the zip step.

Additionally, callers need to validate zip size before sha256 runs so the size check must come first.

How

  • Add optional createZip callback to FinalizeLambdaParams. Callers can provide a custom ZIP strategy (e.g. streaming to disk) and the shared function handles everything else
  • Add optional validateZip hook that runs after zip creation but before digest computation
  • Add size and zipPath to FinalizeLambdaResult` so callers don't need to re-derive them
  • Extend TraceFn with optional tags param so callers can attach tracing metadata
  • Widen getLambdaEnvironment / getLambdaPreloadScripts buffer param from Buffer to { byteLength: number } (this is what was actually used, removes the need for as Buffer casts when the zip is on disk.
  • Export new types: CreateZipResult, CreateZipFn

Notes

  • No behavioral change for callers that don't use the new params
  • All new params are optional with backward-compatible defaults

@healeycodes healeycodes requested a review from ofhouse April 7, 2026 13:29
@healeycodes healeycodes requested a review from a team as a code owner April 7, 2026 13:29
@changeset-bot

changeset-bot Bot commented Apr 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d8db542

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

This PR includes changesets to release 16 packages
Name Type
@vercel/build-utils Minor
@vercel/backends Patch
vercel Patch
@vercel/client Patch
@vercel/elysia Patch
@vercel/express Patch
@vercel/fastify Patch
@vercel/fs-detectors Patch
@vercel/gatsby-plugin-vercel-builder Patch
@vercel/h3 Patch
@vercel/hono Patch
@vercel/koa Patch
@vercel/nestjs Patch
@vercel/node Patch
@vercel/static-build Patch
@vercel/cervel 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

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

📦 CLI Tarball Ready

The Vercel CLI tarball for this PR is now available!

Quick Test

You can test this PR's CLI directly by running:

npx https://vercel-1r8gknvd3.vercel.sh/tarballs/vercel.tgz --help

Use in vercel.json

To use this CLI version in your project builds, add to your vercel.json:

{
  "build": {
    "env": {
      "VERCEL_CLI_VERSION": "vercel@https://vercel-1r8gknvd3.vercel.sh/tarballs/vercel.tgz"
    }
  }
}

Python Runtime Wheel

A vercel-runtime wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_RUNTIME_PYTHON="vercel-runtime @ https://vercel-1r8gknvd3.vercel.sh/tarballs/vercel_runtime-0.13.0.dev1775568703+d8db542-py3-none-any.whl"

Python Workers Wheel

A vercel-workers wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_WORKERS_PYTHON="vercel-workers @ https://vercel-1r8gknvd3.vercel.sh/tarballs/vercel_workers-0.1.0.dev1775568703+d8db542-py3-none-any.whl"

@healeycodes healeycodes enabled auto-merge (squash) April 7, 2026 13:30
@vercel

vercel Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Low Risk — Additive API extension with optional params and backward-compatible defaults.

  • finalize-lambda.ts: added optional createZip callback and validateZip hook params
  • finalize-lambda.ts: extended FinalizeLambdaResult with size and zipPath fields
  • get-lambda-environment.ts, get-lambda-preload-scripts.ts: widened buffer param type from Buffer to { byteLength: number }

Assessed at d8db542.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🧪 Unit Test Strategy

Comparing: 280d949d8db542 (view diff)

Strategy: Code changed outside of a package - running all unit tests

⚠️ All unit tests will run because global code changes could impact all packages.

Affected packages - 40 (100%)
  1. @vercel-internals/get-package-json
  2. @vercel/backends
  3. @vercel/build-utils
  4. @vercel/cervel
  5. @vercel/cli-auth
  6. @vercel/client
  7. @vercel/config
  8. @vercel/detect-agent
  9. @vercel/edge
  10. @vercel/elysia
  11. @vercel/error-utils
  12. @vercel/express
  13. @vercel/fastify
  14. @vercel/firewall
  15. @vercel/frameworks
  16. @vercel/fs-detectors
  17. @vercel/functions
  18. @vercel/gatsby-plugin-vercel-builder
  19. @vercel/go
  20. @vercel/h3
  21. @vercel/hono
  22. @vercel/hydrogen
  23. @vercel/koa
  24. @vercel/nestjs
  25. @vercel/next
  26. @vercel/node
  27. @vercel/oidc
  28. @vercel/oidc-aws-credentials-provider
  29. @vercel/python
  30. @vercel/python-analysis
  31. @vercel/redwood
  32. @vercel/related-projects
  33. @vercel/remix-builder
  34. @vercel/routing-utils
  35. @vercel/ruby
  36. @vercel/rust
  37. @vercel/static-build
  38. @vercel/static-config
  39. examples
  40. vercel

Results

  • Unit tests: All affected packages will run unit tests
  • E2E tests: Running in parallel via E2E Tests workflow
  • Type checks: All affected packages will run type checks

This comment is automatically generated based on the affected testing strategy

@healeycodes healeycodes merged commit a80217a into main Apr 7, 2026
338 of 340 checks passed
@healeycodes healeycodes deleted the finalize-func-idea branch April 7, 2026 14:19
healeycodes pushed a commit that referenced this pull request Apr 7, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/build-utils@13.13.0

### Minor Changes

- Extend `finalizeLambda` with pluggable ZIP strategy (`createZip`),
pre-digest validation hook (`validateZip`), and optional trace tags.
Widen `getLambdaEnvironment` buffer param to `{ byteLength: number }`.
([#15856](#15856))

## vercel@50.41.0

### Minor Changes

- Add `vercel edge-config` with `list`, `add`, `get`, `update`,
`remove`, `items`, and `tokens` subcommands for Edge Config dashboard
API parity. ([#15822](#15822))

- Add `vercel project checks` to list a project's deployment checks
configuration (parity with dashboard), including `--format json` and
non-interactive error payloads.
([#15816](#15816))

### Patch Changes

- Improve `vercel teams request` in non-interactive mode: validation,
missing team scope, and API errors emit structured JSON on stdout with
stable `reason` values and `next[]` commands that preserve global flags
(for example `--cwd` and `--non-interactive`).
([#15815](#15815))

- Hide `--search` flag from `vc logs --help` output while continuing to
accept it, and update the `--query` flag description to indicate
advanced querying with filter syntax support.
([#15854](#15854))

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0
    -   @vercel/backends@0.0.56
    -   @vercel/elysia@0.1.59
    -   @vercel/express@0.1.69
    -   @vercel/fastify@0.1.62
    -   @vercel/go@3.4.7
    -   @vercel/h3@0.1.68
    -   @vercel/hono@0.2.62
    -   @vercel/hydrogen@1.3.6
    -   @vercel/koa@0.1.42
    -   @vercel/nestjs@0.2.63
    -   @vercel/next@4.16.5
    -   @vercel/node@5.7.1
    -   @vercel/python@6.29.0
    -   @vercel/redwood@2.4.12
    -   @vercel/remix-builder@5.7.2
    -   @vercel/ruby@2.3.2
    -   @vercel/rust@1.0.6
    -   @vercel/static-build@2.9.9

## @vercel/backends@0.0.56

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/cervel@0.0.43

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/backends@0.0.56

## @vercel/client@17.2.68

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/elysia@0.1.59

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/express@0.1.69

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1
    -   @vercel/cervel@0.0.43

## @vercel/fastify@0.1.62

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/fs-detectors@5.14.3

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/gatsby-plugin-vercel-builder@2.1.9

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/h3@0.1.68

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/hono@0.2.62

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/koa@0.1.42

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/nestjs@0.2.63

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/node@5.7.1

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/static-build@2.9.9

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@2.1.9

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
blurrah pushed a commit that referenced this pull request Apr 8, 2026
…re-digest validation hook (#15856)

Callers that handle large functions (multi-GiB) need to stream zips to
disk instead of holding them in memory. The current `finalizeLambda`
always creates an in-memory `Buffer`, forcing callers to duplicate the
entire finalization pipeline (encrypted env, environment setup,
streaming detection) just to swap out the zip step.

Additionally, callers need to validate zip size before `sha256` runs so
the size check must come first.

### How

- Add optional `createZip` callback to `FinalizeLambdaParams`. Callers
can provide a custom ZIP strategy (e.g. streaming to disk) and the
shared function handles everything else
- Add optional `validateZip` hook that runs after zip creation but
before digest computation
- Add `size` and `zipPath to `FinalizeLambdaResult` so callers don't
need to re-derive them
- Extend `TraceFn` with optional tags param so callers can attach
tracing metadata
- Widen `getLambdaEnvironment` / `getLambdaPreloadScripts` `buffer`
param from `Buffer` to `{ byteLength: number }` (this is what was
actually used, removes the need for `as Buffer` casts when the zip is on
disk.
- Export new types: `CreateZipResult`, `CreateZipFn`

### Notes

- No behavioral change for callers that don't use the new params
- All new params are optional with backward-compatible defaults
blurrah pushed a commit that referenced this pull request Apr 8, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/build-utils@13.13.0

### Minor Changes

- Extend `finalizeLambda` with pluggable ZIP strategy (`createZip`),
pre-digest validation hook (`validateZip`), and optional trace tags.
Widen `getLambdaEnvironment` buffer param to `{ byteLength: number }`.
([#15856](#15856))

## vercel@50.41.0

### Minor Changes

- Add `vercel edge-config` with `list`, `add`, `get`, `update`,
`remove`, `items`, and `tokens` subcommands for Edge Config dashboard
API parity. ([#15822](#15822))

- Add `vercel project checks` to list a project's deployment checks
configuration (parity with dashboard), including `--format json` and
non-interactive error payloads.
([#15816](#15816))

### Patch Changes

- Improve `vercel teams request` in non-interactive mode: validation,
missing team scope, and API errors emit structured JSON on stdout with
stable `reason` values and `next[]` commands that preserve global flags
(for example `--cwd` and `--non-interactive`).
([#15815](#15815))

- Hide `--search` flag from `vc logs --help` output while continuing to
accept it, and update the `--query` flag description to indicate
advanced querying with filter syntax support.
([#15854](#15854))

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0
    -   @vercel/backends@0.0.56
    -   @vercel/elysia@0.1.59
    -   @vercel/express@0.1.69
    -   @vercel/fastify@0.1.62
    -   @vercel/go@3.4.7
    -   @vercel/h3@0.1.68
    -   @vercel/hono@0.2.62
    -   @vercel/hydrogen@1.3.6
    -   @vercel/koa@0.1.42
    -   @vercel/nestjs@0.2.63
    -   @vercel/next@4.16.5
    -   @vercel/node@5.7.1
    -   @vercel/python@6.29.0
    -   @vercel/redwood@2.4.12
    -   @vercel/remix-builder@5.7.2
    -   @vercel/ruby@2.3.2
    -   @vercel/rust@1.0.6
    -   @vercel/static-build@2.9.9

## @vercel/backends@0.0.56

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/cervel@0.0.43

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/backends@0.0.56

## @vercel/client@17.2.68

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/elysia@0.1.59

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/express@0.1.69

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1
    -   @vercel/cervel@0.0.43

## @vercel/fastify@0.1.62

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/fs-detectors@5.14.3

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/gatsby-plugin-vercel-builder@2.1.9

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/h3@0.1.68

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/hono@0.2.62

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/koa@0.1.42

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/nestjs@0.2.63

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.7.1

## @vercel/node@5.7.1

### Patch Changes

- Updated dependencies
\[[`a80217a9ed60d7b7f3e98537b0468cc5488078c1`](a80217a)]:
    -   @vercel/build-utils@13.13.0

## @vercel/static-build@2.9.9

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@2.1.9

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
healeycodes added a commit that referenced this pull request Apr 10, 2026
Follow up to: 
- #15856

After using the exported functions for existing callers, I realized we
didn't get the `zipPath` type correct.

As the goal is to avoid any semantic changes for existing callers, we
have to fix it here.
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