Skip to content

refactor(core): simplify hardened serialization and close the bound-getter reporting hole - #3288

Merged
NathanColosimo merged 1 commit into
mainfrom
nathanc/hardened-serialization-simplify
Aug 3, 2026
Merged

refactor(core): simplify hardened serialization and close the bound-getter reporting hole#3288
NathanColosimo merged 1 commit into
mainfrom
nathanc/hardened-serialization-simplify

Conversation

@NathanColosimo

Copy link
Copy Markdown
Contributor

Summary

Simplification + one correctness fix for the hardened serialization layer from #3257, extracted from the retained-VM stack (#3046) so it can be reviewed and land independently — it has no dependency on retention.

  • Optional-capture state deleted. Every intrinsic the module captures exists on all supported engines (Node 18+), so the intrinsicGetter-returns-undefined layer, canReadUrl/canReadUrlSearchParams/canReadHeaders, and the per-use ?./as fallbacks are replaced by captures that throw at import if absent. A missing intrinsic on a supported engine is a bug in the capture table, and failing at boot beats serializing through a live (patchable) lookup later.
  • URLSearchParams.prototype.size is not needed — it was the one genuinely missing member on Node 18, and the emptiness probe it powered falls out of the captured toString() result the reducer already computes. Node 18 now serializes URLSearchParams natively instead of degrading to devalue's default handling.
  • The call/get tables and their re-export aliases flatten into direct typed exports; readProxyAware and the viewInfo getter-indirection unroll into plain two-branch functions.
  • Bound-getter reporting hole closed (the module's own documented limitation): fn.bind() stringifies as [native code], so workflow code could run a side-effectful getter with an empty guest-code report. The toString text is identical to real native getters; the one passive distinguisher V8 exposes is the bound -prefixed name own property, which is now checked (test added). Also drops the WeakMap memo and the defensive try/catch (descriptor getters are always callable).

hardened.ts: 763 → 625 lines. Wire output unchanged — parity verified for DataView and typed-array subviews on top of the existing suite.

Validation

Full packages/core serialization suite: 548 passed (including the 800-line hardened.test.ts unchanged except the new bound-getter test). Full unit suite green on the retained-VM branch this was developed on.

Extracted from #3046 (originally commit 6084f8f0e); #3046 and #3047 no longer carry it.

…onal-capture states, close the bound-getter reporting hole

- Every captured intrinsic exists on all supported engines (Node 18+), so
  the optional-capture layer (intrinsicGetter-returns-undefined, canReadUrl/
  canReadUrlSearchParams/canReadHeaders, per-use fallbacks) is replaced by
  captures that throw at import if absent.
- URLSearchParams.prototype.size (the one genuinely missing member on Node
  18) is not needed: emptiness falls out of the captured toString() result,
  which the reducer already computes. Node 18 now serializes URLSearchParams
  natively instead of falling back to devalue's default handling.
- The call/get tables and their re-export aliases flatten into direct typed
  exports; readProxyAware and the viewInfo getter-indirection unroll into
  two-branch functions.
- isEngineAccessor: drop the WeakMap memo and try/catch (descriptor getters
  are always callable); exclude bound functions, which stringify as native
  code but run their target — previously workflow code could launder a
  side-effectful getter past the report with fn.bind() (test added).
- 763 -> 625 lines, byte output unchanged (parity checked for DataView and
  typed-array subviews on top of the existing test suite).
@NathanColosimo
NathanColosimo requested review from a team and ijjk as code owners August 2, 2026 23:19
@changeset-bot

changeset-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d710362

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

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

@vercel

vercel Bot commented Aug 2, 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 Aug 2, 2026 11:23pm
example-nextjs-workflow-webpack Ready Ready Preview Aug 2, 2026 11:23pm
example-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-astro-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-express-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-fastify-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-hono-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-nestjs-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-nitro-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-nuxt-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-sveltekit-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-tanstack-start-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workbench-vite-workflow Ready Ready Preview Aug 2, 2026 11:23pm
workflow-docs Ready Ready Preview, v0 Aug 2, 2026 11:23pm
workflow-swc-playground Ready Ready Preview Aug 2, 2026 11:23pm
workflow-tarballs Ready Ready Preview Aug 2, 2026 11:23pm
workflow-web Ready Ready Preview Aug 2, 2026 11:23pm

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

E2E Test Summary

Summary
Passed Failed Skipped Total
✅ ▲ Vercel Production 1466 0 239 1705
✅ 💻 Local Development 1633 0 227 1860
✅ 📦 Local Production 1633 0 227 1860
✅ 🐘 Local Postgres 1633 0 227 1860
✅ 🪟 Windows 155 0 0 155
✅ 📋 Other 1028 0 212 1240
✅ vercel-multi-region 27 0 0 27
Total 7575 0 1132 8707
Details by Category

✅ ▲ Vercel Production

App Passed Failed Skipped
✅ astro 127 0 28
✅ example 127 0 28
✅ express 127 0 28
✅ fastify 127 0 28
✅ hono 127 0 28
✅ nextjs-turbopack 152 0 3
✅ nextjs-webpack 152 0 3
✅ nitro 127 0 28
✅ nuxt 127 0 28
✅ sveltekit 146 0 9
✅ vite 127 0 28

✅ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nextjs-webpack-stable 155 0 0
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nextjs-webpack-stable 155 0 0
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable 129 0 26
✅ express-stable 129 0 26
✅ fastify-stable 129 0 26
✅ hono-stable 129 0 26
✅ nextjs-turbopack-canary 136 0 19
✅ nextjs-turbopack-stable 155 0 0
✅ nextjs-webpack-canary 136 0 19
✅ nextjs-webpack-stable 155 0 0
✅ nitro-stable 129 0 26
✅ nuxt-stable 129 0 26
✅ sveltekit-stable 148 0 7
✅ vite-stable 129 0 26

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack 155 0 0

✅ 📋 Other

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

✅ vercel-multi-region

App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit d710362 · Sun, 02 Aug 2026 23:41:36 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1238 (+57%) 🔻 1307 🔴 (+19%) 🔻 1328 🔴 (+16%) 🔻 1345 🔴 (-12%) 30
TTFS stream 1250 (+425%) 🔻 1295 🔴 (+20%) 🔻 1304 🔴 (+18%) 🔻 1355 🔴 (+16%) 🔻 30
TTFS hook + stream 731 (-42%) 💚 1550 🔴 (+13%) 1585 🔴 (+10%) 1766 🔴 (-4.0%) 30
STSO 1020 steps (inline) 168 (-2.9%) 466 (-10%) 524 (-10%) 696 (-21%) 💚 1016
STSO 1020 steps (queue-hop) 2354 (+19%) 🔻 3329 (+0.7%) 3329 (+0.7%) 3329 (+0.7%) 3
WO 1020 steps 396809 (-11%) 396809 (-11%) 396809 (-11%) 396809 (-11%) 1
SL stream latency 96 (+4.3%) 144 🔴 (-20%) 💚 166 🔴 (-31%) 💚 777 🔴 (+79%) 🔻 30
SO stream overhead (text) 100 (-26%) 💚 143 (-34%) 💚 168 (-38%) 💚 300 (-20%) 💚 30
SO stream overhead (structured) 99 (-16%) 💚 168 (-30%) 💚 183 (-43%) 💚 232 (-48%) 💚 30
📈 STSO distribution vs main (inline / queue-hop histograms)

1020 steps (inline)

Cumulative STSO time: main 437759ms → this run 386891ms (Δ -50868ms, -12%)

  150-200 ms  ██░░░┃                    main  10  this  40   +30
  200-250 ms  ██████████████░░░┃        main  86  this 113   +27
  250-300 ms  █████████████████░░░░░░┃  main 104  this 149   +45
  300-350 ms  ████████████████░░░░░┃    main  98  this 137   +39
  350-400 ms  ██████████████████████┃   main 136  this 143    +7
  400-450 ms  █████████████████████┃    main 132  this 135    +3
  450-500 ms  ███████████████████████┃  main 140  this 147    +7
  500-550 ms  ██████████████┃███████    main 135  this  96   -39
  550-600 ms  ███┃███████████           main  93  this  26   -67
  600-650 ms  █┃████                    main  38  this  12   -26
  650-700 ms  ┃██                       main  18  this   8   -10
  700-750 ms  ┃                         main   8  this   4    -4
  750-800 ms  ┃                         main   3  this   1    -2
  800-850 ms  ┃                         main   2  this   0    -2
  850-900 ms  ┃                         main   3  this   0    -3
  900-950 ms  ┃                         main   5  this   2    -3
 950-1000 ms  ┃                         main   0  this   1    +1
1050-1100 ms  ┃                         main   1  this   1    +0
1200-1250 ms  ┃                         main   2  this   0    -2
1250-1300 ms  ┃                         main   1  this   0    -1
1300-1350 ms  ┃                         main   1  this   0    -1
2550-2600 ms  ┃                         main   0  this   1    +1

1020 steps (queue-hop)

Cumulative STSO time: main 8262ms → this run 8658ms (Δ +396ms, +5%)

1500-2000 ms  ┃███████████████████████  main 1  this 0  -1
2000-2500 ms  ░░░░░░░░░░░░░░░░░░░░░░░┃  main 0  this 1  +1
2500-3000 ms  ███████████████████████┃  main 1  this 1  +0
3000-3500 ms  ███████████████████████┃  main 1  this 1  +0
ℹ️ Metric definitions & methodology

The collapsed STSO distribution section above buckets every step gap of the sequential-steps run (not a sampled window), split by whether the step ending the gap ran inline — in the same warm process as the step before it, so the gap is pure framework overhead — or after a queue-hop — the first step of a fresh process, which pays queue dispatch, client reinit and event-log replay. Bars overlay the two runs: is main, marks where this run lands, bridges the gap when this run has more samples in a bucket.

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

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.

@TooTallNate TooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the capture-table change, the bound-getter fix, and the wire-parity claims — each against the failure modes a hardening layer can introduce. Approving.

Import-throw is safe in every context this module loads. The concern with assert-at-import is a consumer that used to limp along now crashing at boot — so I checked the import graph: hardened.ts is reached only from core's serialization modules (host/Node contexts where it already ran), and the browser surface (web-shared hydration) imports only the serialization-format revivers subpath, never this module. The node:util dependency predates this PR. And the claim that every remaining capture exists on Node 18+ holds: ES intrinsics plus Headers/URL/URLSearchParams (global since 18.0) — the one genuine gap in the old table, URLSearchParams.prototype.size (18.16+), is eliminated by design rather than papered over, which also upgrades Node 18.0–18.15 from degraded output to native URLSearchParams serialization. Root engines still includes ^18.0.0, so that's a real fix, not dead reasoning.

The emptiness-probe replacement is exactly wire-equivalent. size === 0 ⟺ toString() === '' holds with no edge cases — any entry renders at least =, zero entries always render '' — so the . sentinel contract is byte-identical on engines that took the old path, and the change is observable only where the old path didn't exist (Node <18.16, in the correctness direction, with a tag every reader already understands).

The bound-getter fix is right, and honestly scoped. Screen ordering is correct (proxy → bound -name → native-toString / host-proto), the false-positive direction is the safe one (a re-bound genuine native getter gets reported, never silently trusted), and the evasion I went looking for — name is configurable on bound functions, so guest code can rename to re-launder — is explicitly documented as costing "a missing report entry, like the other impersonation caveats," which is consistent with the module's stated non-adversarial threat model from the sandbox-hardening work. The rewritten isEngineAccessor doc now coherently enumerates all three impersonation paths in one place. The new test is the full contract in one assertion set: the getter ran (once), the value serialized, and the report captured it — closing the reporting hole without changing behavior, which is precisely the PR's claim.

The deletions I checked rather than assumed:

  • Dropping the defensive try/catch is sound: descriptor .get is callable-or-undefined by both defineProperty validation and proxy invariants, proxies are screened before functionToString, and toString on a callable non-proxy never throws.
  • The cross-realm getPrototypeOf(getter) === Function.prototype branch that survives the flatten looked alarming out of context (any ordinary function matches!) — but it's host-realm provenance: VM-guest functions carry the sandbox's Function.prototype, so only host-realm accessors match. Pre-existing, correct, and worth having re-verified since the refactor moved it.
  • The WeakMap memo removal trades a cache for a cheap toString per accessor read — noise, and it removes a cache whose key was guest-reachable.

Verified locally: serialization suite 548/548, full core 1787 (+3 pre-existing expected-fails). CI is 102/102 with zero failures. Changeset patch is right — no API surface changes, and the Node 18 delta is bug-fix-shaped.

Nice extraction, too — landing this independently of the retained-VM stack keeps #3046's review surface honest.

@NathanColosimo
NathanColosimo merged commit 679dfa9 into main Aug 3, 2026
177 of 179 checks passed
@NathanColosimo
NathanColosimo deleted the nathanc/hardened-serialization-simplify branch August 3, 2026 18:26
@github-actions github-actions Bot mentioned this pull request Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

No backport to stable for 679dfa9 (AI decision).

This is primarily a refactor/simplification of the hardened serialization layer, and that layer does not exist on stable at all — git ls-tree origin/stable -- packages/core/src/serialization/ is empty (stable still has the flat packages/core/src/serialization.ts), so hardened.ts, reducers/common.ts, and the intrinsic-capture machinery are all main-only code introduced by #3257. The one genuine fix (excluding bound functions from isEngineAccessor so a fn.bind() getter is reported as guest code) affects only the guest-code telemetry report, never serialized output, and has nothing to attach to on stable.

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

679dfa9c15e68e841d8c326c716bc14b5997c6c3

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