Skip to content

worker_threads: use the intrinsic MessagePort and MessageChannel, not the mutable globals - #40271

Merged
dylan-conway merged 1 commit into
mainfrom
farm/174af703/worker-threads-intrinsic-messageport
Aug 24, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
farm/174af703/worker-threads-intrinsic-messageport

Conversation

@robobun

@robobun robobun commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • new Worker() from node:worker_threads throws TypeError: port.on is not a function (in registerMainThreadPort, internal:worker/messaging) on 1.4.0 when user code replaced globalThis.MessagePort before the module loads. happy-dom's global registrator does this, so every suite that preloads it and constructs a worker (pino transports through thread-stream) broke. Worked on 1.3.14.
  • The cause: src/js/node/worker_threads.ts captured globalThis.MessagePort (line 284) and globalThis.MessageChannel at module load, and src/js/internal/worker/messaging.ts:162 called new globalThis.MessageChannel(). With a replaced global, the node-style emitter methods land on the replacement's prototype and the native MessagePort.prototype never gets .on. The 1.4.0 postMessageToThread hub made new Worker call .on on a native port, which exposed the latent bug.

Fix

  • createNodeWorkerThreadsBinding (src/jsc/bindings/webcore/Worker.cpp) now appends the intrinsic MessagePort, MessageChannel, BroadcastChannel, and Worker constructors (via JS*::getConstructor, which returns the cached per-global constructor) to the binding array.
  • worker_threads.ts takes all four from the binding instead of globalThis, and passes the intrinsic MessageChannel into messaging.ts through initThreadInfo.
  • Correct because the module now behaves like Node's: its internals and exports never depend on the mutable globals, and a replaced global cannot reach them.
  • Verified: test/regression/issue/40268.test.ts (fails on stock bun, passes with the fix). Also test/js/node/worker_threads/ (137 pass), the worker transfer/dispose/TLA suites, and the node parallel message-port tests.

Background

  • node:worker_threads wraps the web Worker/MessagePort. At module load it grafts Node's EventEmitter-style methods (on, off, once, ...) onto MessagePort.prototype (injectFakeEmitter).
  • postMessageToThread (Node 22+) makes the main thread a message hub: new Worker creates a control MessageChannel and registers the hub-side port with port.on("message", ...). That registration is the call that threw.
  • getConstructor returns the same constructor object the global property was initialized with, so instanceof and prototype identity are unchanged for untouched globals.
Notes
  • Repro (no dependencies): replace globalThis.MessagePort with a class extending EventTarget, then new Worker("", { eval: true }). Prints ok on 1.3.14 and with this fix, throws on 1.4.0.
  • test/js/web/workers/worker.test.ts has two failures on a debug build ("message flood" and "preload with an un-awaited import()"). Both fail identically on main without this diff (verified with the diff stashed) and pass on the release build, so they are pre-existing debug-build timing failures.
  • The fix also covers BroadcastChannel and Worker: the same mutable-global read, so worker_threads.BroadcastChannel no longer becomes the replacement class, and a replaced globalThis.Worker cannot hijack new Worker internals.

[review] gate passed · iteration 0 · 4 files touched

fails on main (without fix)
ASAN without fix: 1 FAILED
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" "test/regression/issue/40268.test.ts"
bun test v1.4.1 (4448a2e21)

test/regression/issue/40268.test.ts:
40 |     ],
41 |     env: bunEnv,
42 |     stderr: "pipe",
43 |   });
44 |   const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
45 |   expect(stderr).toBe("");
                      ^
error: expect(received).toBe(expected)

- ""
+ " 8 |       globalThis.Worker = FakeWorker;
+  9 | 
+ 10 |       const wt = await import("node:worker_threads");
+ 11 | 
+ 12 |       // The module exports are the intrinsics, not the replaced globals.
+ 13 |       if (wt.MessagePort === FakePort) throw new Error("MessagePort export is the replaced global");
+                                                       ^
+ error: MessagePort export is the replaced global
+       at /workspace/bun/[eval]:13:50
+ 
+ Bun v1.4.1-debug+4448a2e21 (Linux x64)
+ "

- Expected  - 1
+ Received  + 12

      at <anonymous> (/workspace/bun/test/regression/issue/40268.test.ts:45:18)
(fail) new Worker works after user co
... (truncated)

release without fix: 1 FAILED
bun test v1.4.0-canary.1 (4448a2e21)

test/regression/issue/40268.test.ts:
40 |     ],
41 |     env: bunEnv,
42 |     stderr: "pipe",
43 |   });
44 |   const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
45 |   expect(stderr).toBe("");
                      ^
error: expect(received).toBe(expected)

- ""
+ " 8 |       globalThis.Worker = FakeWorker;
+  9 | 
+ 10 |       const wt = await import("node:worker_threads");
+ 11 | 
+ 12 |       // The module exports are the intrinsics, not the replaced globals.
+ 13 |       if (wt.MessagePort === FakePort) throw new Error("MessagePort export is the replaced global");
+                                                       ^
+ error: MessagePort export is the replaced global
+       at /workspace/bun/[eval]:13:50
+ 
+ Bun v1.4.0-canary.1+4448a2e21 (Linux x64)
+ "

- Expected  - 1
+ Received  + 12

      at <anonymous> (/workspace/bun/test/regression/issue/40268.test.ts:45:18)
(fail) new Worker works after user code replaces the web globals [14.53ms]

 0 pass
 1 fail
 1 expect() calls
Ran 1 test across 1 file. [162.00ms]
__F:1:S:0
passes on PR (with fix)
ASAN with fix: all passed
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" "test/regression/issue/40268.test.ts"
bun test v1.4.1 (4448a2e21)

test/regression/issue/40268.test.ts:
(pass) new Worker works after user code replaces the web globals [1149.09ms]

 1 pass
 0 fail
 3 expect() calls
Ran 1 test across 1 file. [3.19s]
__F:0:S:0

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 636ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/24] gen generated_host_exports.rs
generated_host_exports.rs: 120 exports (host=5, lazy=10, generic=105, rust=0); 244 extern-C blocks audited
[2/24] gen cpp.rs (cppbind)
[3/24] gen JS modules (bundle-modules)
Preprocess modules (7401ms)
Bundle modules (69ms)
Postprocesss modules (35ms)
Bundle Functions (530ms)
Generate Code (21ms)

[8.07s] Bundled "src/js" for production
  2594 kb
  197 internal modules
  13 native modules
  50 internal functions across 16 files
[3/8] cargo bun_runtime → libbun_runtime.a (--target x86_64-unknown-linux-gnu)

  nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19)

�[1m�[92m   Compiling�[0m bun_sys v0.0.0 (/workspace/bun/src/sys)
�[1m�[92m   Compiling�[0m bun_perf v0.0.0 (/workspace/bun/src/perf)
�[1m�[92m   Compiling�[0m bun_threading v0.0.0 (/workspace/bun/src/threading)
�[1m�[92m   Compiling�[0m bun_which v0.0.0 (/workspace/bun/src/which)
�[1m�[92m   Compiling�[0m bun_spawn_sys v0.0.0 (/workspace/bun/src/spawn_sys)
�[1m�[9
... (truncated)
diff hotspot
src/js/internal/worker/messaging.ts |  8 +++++--
 src/js/node/worker_threads.ts       | 27 +++++++++++----------
 src/jsc/bindings/webcore/Worker.cpp | 10 +++++++-
 test/regression/issue/40268.test.ts | 48 +++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 15 deletions(-)

gate history · 1 passed · 0 rejected · iteration 0

evidence per changed file
file                                 reads  edits  tests
src/js/internal/worker/messaging.ts      1      3      0
src/js/node/worker_threads.ts            4      5      0
src/jsc/bindings/webcore/Worker.cpp      2      4      0
test/regression/issue/40268.test.ts      0      1      0

root cause · written by the author bot

The node:worker_threads module read MessagePort and MessageChannel from the mutable global object, so when user code such as happy-dom's registrator replaced globalThis.MessagePort before the module loaded, Bun's internal messaging code received a DOM-shaped port without emitter methods and threw "port.on is not a function" during Worker construction. The fix has the native worker_threads binding supply the intrinsic MessagePort, MessageChannel, BroadcastChannel, and Worker constructors directly, and the module's internals now use those instead of the globals. As a result, Worker constructi…

…ding the globals

new Worker() read MessagePort, MessageChannel, BroadcastChannel, and Worker
from the mutable globals when node:worker_threads loaded. Code that replaces
them before the module loads (happy-dom's global registrator) made Worker
construction throw "port.on is not a function" from registerMainThreadPort.

The native binding now hands the module the intrinsic constructors, so a
replaced global cannot reach worker_threads internals or its exports.

Fixes #40268
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

On-demand reviews are free for the next 28 days. After that, they cost $0.25 per reviewed file.

Or wait 23 seconds for your next included review.

View limit details

Limit details: You’ve used all 5 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 009e4e9f-7c7d-44d3-8abe-44672193d3dd

📥 Commits

Reviewing files that changed from the base of the PR and between 9dd7374 and 53c89b5.

📒 Files selected for processing (4)
  • src/js/internal/worker/messaging.ts
  • src/js/node/worker_threads.ts
  • src/jsc/bindings/webcore/Worker.cpp
  • test/regression/issue/40268.test.ts

Comment @coderabbitai help to get the list of available commands.

@claude claude 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.

LGTM — targeted regression fix that swaps mutable-global reads for the intrinsic constructors from the native binding.

What was reviewed:

  • Verified JS{MessagePort,MessageChannel,BroadcastChannel,Worker}::getConstructor all exist and return the cached per-global constructor; new includes added for the two not already present.
  • Confirmed initThreadInfo runs at module load before any createMessagingChannel call, so the module-local MessageChannel in messaging.ts is always set before use.
  • Checked no other globalThis.{MessagePort,MessageChannel,Worker,BroadcastChannel} reads remain in the touched builtins.
  • Test follows harness conventions (spawned subprocess, concurrent pipe drain, stderr/stdout asserted before exitCode).
Extended reasoning...

Overview

Fixes #40268: new Worker() from node:worker_threads threw port.on is not a function when user code (e.g. happy-dom) replaced globalThis.MessagePort before the module loaded. The fix moves the four web constructors (MessagePort, MessageChannel, BroadcastChannel, Worker) from globalThis reads to the native createNodeWorkerThreadsBinding array (indices 13-16), and threads the intrinsic MessageChannel into internal/worker/messaging.ts via the existing initThreadInfo call. Four files touched: two builtin TS modules, one C++ binding function, one new regression test.

Security risks

None. This removes a userland-tampering vector (replacing globals could previously hijack worker_threads internals). getConstructor returns the JSC-cached per-global constructor, not anything user-controllable.

Level of scrutiny

Low-to-moderate. The change is mechanical: extend an existing binding array by 4 entries using the standard generated getConstructor pattern, and destructure them on the TS side in place of globalThis reads. No control-flow changes, no new state, no lifecycle changes. The C++ additions follow the exact local convention (no RETURN_IF_EXCEPTION between putDirectIndex calls, matching the 13 preceding entries). I verified all four getConstructor methods exist on the generated wrapper classes and that the two new headers are properly included.

Other factors

  • The fix covers the whole class (all four constructors), not just the one that triggered the reported symptom — matches the repo's "fix the bug class" guidance.
  • initThreadInfo is called at worker_threads.ts module-load time, strictly before any Worker constructor runs, so createMessagingChannel's module-local MessageChannel is always initialized before use.
  • Regression test is hermetic (subprocess with -e, no network/fs), drains stdout/stderr/exited concurrently, and asserts output before exit code per harness conventions. It exercises all four replaced globals plus the actual new Worker path that regressed.
  • PR description confirms the existing test/js/node/worker_threads/ suite (137 tests) still passes.
  • No CODEOWNERS coverage for these paths.

@robobun

robobun commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 5:31 PM PT - Aug 23rd, 2026

✅ @robobun, your commit 53c89b535b55830fb6831914614dc975973a5878 passed in Build #104455! 🎉


🧪   To try this PR locally:

bunx bun-pr 40271

That installs a local version of the PR into your bun-40271 executable, so you can run:

bun-40271 --bun

@dylan-conway
dylan-conway merged commit b746c07 into main Aug 24, 2026
8 of 9 checks passed
@dylan-conway
dylan-conway deleted the farm/174af703/worker-threads-intrinsic-messageport branch August 24, 2026 18:05
robobun added a commit that referenced this pull request Aug 24, 2026
The node-flavoured BroadcastChannel subclass now extends the intrinsic the
native binding hands over (#40271) instead of the mutable global, and is
declared after that binding.
alejoamiras added a commit to alejoamiras/presto that referenced this pull request Oct 15, 2026
* build(bun): pin Bun 1.4.2

Bun 1.4.2's `crypto.verify` hashes EC keys with SHA-256 when no digest is named, as Node and
OpenSSL do; 1.4.0 throws NO_DEFAULT_DIGEST. sigstore-js and tuf-js verify that way, so the npm
provenance verifier needs it. `ec-verify-without-digest.test.ts` pins the property and fails on
1.4.0.

Workers Builds selects Bun only through its `BUN_VERSION` build variable, one list per trigger
(production and preview), and `scripts/workers-build.ts` refuses a mismatch with `.bun-version`.
The deployment doc gives the cutover order, and a test keeps its `BUN_VERSION` equal to the pin.

Bun 1.4.2's plain `bun install` corrects sdk-noir's stale workspace version in `bun.lock`;
`--frozen-lockfile` accepts the committed lock unchanged on both versions. The lock is left as is
because that entry is in presto-noir's release slice; follow-ups.md tracks folding it into the next
noir release.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(follow-ups): carry the JEST_WORKER_ID preloads with the Bun pin

Their removal condition is a Bun carrying oven-sh/bun#40271, which 1.4.2 is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
alejoamiras added a commit to alejoamiras/presto that referenced this pull request Oct 15, 2026
…111)

* docs(plan): open presto-verifier-identity

The verifier binds a provenance statement to its signing identity before
any claim in it is trusted. The plan is at the approval gate because it
adds a verification policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): approve presto-verifier-identity with decision A

The publish job stays dependency-free beside its OIDC identity; identity binding lives in every
consumer and in the reusable workflow's verify job. The consumer list and the dependency table now
match the implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(deps): add the sigstore verification packages

Exact root devDependencies, each past the 7-day release-age gate: @sigstore/verify 4.1.2,
@sigstore/tuf 5.0.0 and @sigstore/bundle 5.0.0 for verification, and @sigstore/mock 0.13.0 with
@sigstore/protobuf-specs 0.5.2 (the version the others already resolve) for tests. The lock adds
only their subtree: 43 packages added, none removed or changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(release): bind provenance statements to their signing identity

The verifier binds a provenance statement to its signing identity. Before any claim is used, the
Sigstore bundle npm verified is verified again with @sigstore/verify against an explicit policy:
the GitHub Actions issuer, the signing workflow (the SAN, anchored and escaped, and its build signer
extension), release-sdk.yml as the build config, the repository URI and its immutable repository
and owner IDs, refs/heads/main, a GitHub-hosted runner, and the source commit in both the repository
digest and build config digest extensions. The statement's repository, workflow, ref and commit
must then equal the certificate's, and an expected commit must equal both.

Only rollback accepts the reusable workflow's earlier name as signer. Trust is Sigstore's
public-good root through TUF.

The OIDC publish job runs no dependency code: its registry checks move to the dependency-free
registry-consistency.ts, and the reusable workflow's verify job, after a frozen install with
--ignore-scripts, runs the identity-bound verifier, whose failure fails the workflow. Release
planning, promotion and the production playground build take the bound verifier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): prove the signing identity binding

A mock Sigstore world (CA with CT log, transparency log, trusted root) signs the release's own
statement, and the release identity verifies through both entry points; each certificate field
changed alone is refused for that field. The real presto 6.0.0-rc.3 bundle verifies at its release
commit and no other; presto 5.2.0 verifies only on the rollback path. A live test against the
registry and TUF runs with PRESTO_LIVE_PROVENANCE set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(ci): say what the packaged-e2e SDK swap does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(release): verify with freshly installed, locked bytes only

The reusable workflow's verify job installs from the registry against bun.lock with no restored
package cache, so the identity-bound verifier never runs files a job that ran dependency code
could have saved. The registry-consistency helper reads the installed version from the package's
manifest instead of spawning node.

The isolation contract now also requires that Bun runs only repository script files in the
credentialed job, and refuses `require`, computed imports and spawned interpreters or package
runners anywhere in their import graph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): prove tampered bundles fail cryptographically

A changed payload, another signer's certificate, a second envelope signature, a log entry with
another integrated time and another signature's log entry are each refused by the cryptographic
checks, never as an identity mismatch, with the release and the rollback signers alike. presto 5.2.0
runs through the report path too, and a complete presto-core 1.2.1 bundle verifies offline at its
release commit; the trimmed presto-core 1.0.0 report is labelled as claim extraction only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): record presto-verifier-identity's final boundary and gates

The plan states the exact certificate fields pinned and why the others are not, the verify job's
cache-free install and the final contract assertions; the lessons log the gates and consults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): guard every code path beside the publish credentials

The credentialed job's commands may run Bun only on repository scripts, inline Node only without
loading code, and npm only to publish or read. Every module those scripts reach is refused
`require`, non-literal imports and any subprocess other than npm reading the registry or
installing without scripts, whether spawned from a literal array or through a helper whose calls
all pass one. Each refused form is a test row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): state the credentialed-job guard and keep lessons technical

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): allow only exact npm reads beside the publish credentials

npm runs only `view` with positional values, `audit signatures`, or `install` with an exact flag set
that includes `--ignore-scripts`, so no override, spread or other audit mode passes. Spawn calls are
matched regardless of spacing, a spawn whose command is not a literal array or the reviewed helper
is refused, and Node in the job runs only quoted inline code that loads nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): close presto-verifier-identity

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(release): give EC signature checks a digest on Bun 1.4.0

Bun 1.4.0, the pinned runtime, has no default digest for EC keys: `crypto.verify(null, ...)` throws
ERR_OSSL_EVP_NO_DEFAULT_DIGEST where Node, OpenSSL and Bun 1.4.2 use SHA-256. sigstore-js checks
inclusion promises and tuf-js checks root metadata that way and read the throw as a bad signature,
so every verification failed closed. On such a runtime only, ec-default-digest.ts makes a null
digest with an EC key, bare or wrapped as `{ key }`, SHA-256; the identity module loads it first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(release): state when the EC digest shim retires

The shim's comment names what it wraps and its removal condition, `.bun-version` at 1.4.2 or newer;
follow-ups.md carries that Bun bump, the tag-after-verification decision and the reuse-pin
hardening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(bun): pin Bun 1.4.2

Bun 1.4.2 verifies EC signatures with SHA-256 when no digest is named, as Node and OpenSSL do;
sigstore-js and tuf-js verify that way. Every setup-bun step reads `.bun-version`. Workers Builds
refuses a Bun other than `.bun-version`, so its `BUN_VERSION` build variable moves with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(release): verify EC signatures on the pinned runtime, without a crypto shim

On Bun 1.4.2 `crypto.verify` with no digest hashes EC keys with SHA-256, so the wrapper that
supplied it on Bun 1.4.0 goes, with its import and its path-filter entry. The runtime property
stays under test in its own file, for a bare key and `{ key }`, a null and an undefined digest:
tuf-js reaches it only in the live provenance test, so a Bun bump that loses it fails here first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): record Bun 1.4.2 as the verifier's runtime

The presto-verifier-identity record ships Bun 1.4.2 instead of a crypto wrapper, with the live gate
re-run under it (80 checks), and drops the bump from the open items. follow-ups.md trades it for the
`JEST_WORKER_ID` preloads, whose stated removal condition Bun 1.4.2 meets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(bun): pin Bun 1.4.2

Bun 1.4.2's `crypto.verify` hashes EC keys with SHA-256 when no digest is named, as Node and
OpenSSL do; 1.4.0 throws NO_DEFAULT_DIGEST. sigstore-js and tuf-js verify that way, so the npm
provenance verifier needs it. `ec-verify-without-digest.test.ts` pins the property and fails on
1.4.0.

Workers Builds selects Bun only through its `BUN_VERSION` build variable, one list per trigger
(production and preview), and `scripts/workers-build.ts` refuses a mismatch with `.bun-version`.
The deployment doc gives the cutover order, and a test keeps its `BUN_VERSION` equal to the pin.

Bun 1.4.2's plain `bun install` corrects sdk-noir's stale workspace version in `bun.lock`;
`--frozen-lockfile` accepts the committed lock unchanged on both versions. The lock is left as is
because that entry is in presto-noir's release slice; follow-ups.md tracks folding it into the next
noir release.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(follow-ups): carry the JEST_WORKER_ID preloads with the Bun pin

Their removal condition is a Bun carrying oven-sh/bun#40271, which 1.4.2 is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): name why a published release does not verify

Release planning read any failed check of a published version as "does not verify; bump the
version", including a Sigstore TUF mirror, npm registry or GitHub API it could not reach. A
transient outage therefore advised a needless version bump. The refusal still fails closed, and
now carries the reason: a missing tag or GitHub release, a commit mismatch, or the error of the
check that could not run, and says to rerun when the check could not reach a service.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(deps): leave presto-noir's lockfile entry as its release has it

Installing the sigstore packages also rewrote `packages/sdk-noir`'s workspace version in `bun.lock`
from 2.0.0-rc.1 to 2.0.0-rc.2, which a plain Bun 1.4.2 install does. That entry is in noir's
release slice, and the `@alejoamiras/presto-noir@2.0.0-rc.2` tag commit has rc.1, so release
planning refused to reuse the published 2.0.0-rc.2 ("build inputs changed since its release
tag"). With the line restored, `bun install --frozen-lockfile` leaves the lock unchanged and a
dry-run plan of all packages reuses core, noir and banners again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): give up on an npm call that never answers

A registry, or a proxy, that accepts the connection and never answers held
`npm install` with no deadline: a provenance check through one was still
waiting after 25 minutes, so the release job would sit until its own timeout.
Each npm call now fails after 180 s, naming the command; a cold install and
audit of the largest package take about 30 s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): name the cause behind a wrapped verification error

`@sigstore/tuf` wraps every metadata refresh failure as `error refreshing TUF
metadata`, keeping the code and the underlying error as separate properties,
so a refused reuse showed the wrapper and hid whether TUF was unreachable or
its metadata invalid. The refusal now carries each error's code and its
cause chain.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
alejoamiras added a commit to alejoamiras/presto that referenced this pull request Oct 15, 2026
…erifies (#121)

* docs(plan): open presto-verifier-identity

The verifier binds a provenance statement to its signing identity before
any claim in it is trusted. The plan is at the approval gate because it
adds a verification policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): approve presto-verifier-identity with decision A

The publish job stays dependency-free beside its OIDC identity; identity binding lives in every
consumer and in the reusable workflow's verify job. The consumer list and the dependency table now
match the implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(deps): add the sigstore verification packages

Exact root devDependencies, each past the 7-day release-age gate: @sigstore/verify 4.1.2,
@sigstore/tuf 5.0.0 and @sigstore/bundle 5.0.0 for verification, and @sigstore/mock 0.13.0 with
@sigstore/protobuf-specs 0.5.2 (the version the others already resolve) for tests. The lock adds
only their subtree: 43 packages added, none removed or changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(release): bind provenance statements to their signing identity

The verifier binds a provenance statement to its signing identity. Before any claim is used, the
Sigstore bundle npm verified is verified again with @sigstore/verify against an explicit policy:
the GitHub Actions issuer, the signing workflow (the SAN, anchored and escaped, and its build signer
extension), release-sdk.yml as the build config, the repository URI and its immutable repository
and owner IDs, refs/heads/main, a GitHub-hosted runner, and the source commit in both the repository
digest and build config digest extensions. The statement's repository, workflow, ref and commit
must then equal the certificate's, and an expected commit must equal both.

Only rollback accepts the reusable workflow's earlier name as signer. Trust is Sigstore's
public-good root through TUF.

The OIDC publish job runs no dependency code: its registry checks move to the dependency-free
registry-consistency.ts, and the reusable workflow's verify job, after a frozen install with
--ignore-scripts, runs the identity-bound verifier, whose failure fails the workflow. Release
planning, promotion and the production playground build take the bound verifier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): prove the signing identity binding

A mock Sigstore world (CA with CT log, transparency log, trusted root) signs the release's own
statement, and the release identity verifies through both entry points; each certificate field
changed alone is refused for that field. The real presto 6.0.0-rc.3 bundle verifies at its release
commit and no other; presto 5.2.0 verifies only on the rollback path. A live test against the
registry and TUF runs with PRESTO_LIVE_PROVENANCE set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(ci): say what the packaged-e2e SDK swap does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(release): verify with freshly installed, locked bytes only

The reusable workflow's verify job installs from the registry against bun.lock with no restored
package cache, so the identity-bound verifier never runs files a job that ran dependency code
could have saved. The registry-consistency helper reads the installed version from the package's
manifest instead of spawning node.

The isolation contract now also requires that Bun runs only repository script files in the
credentialed job, and refuses `require`, computed imports and spawned interpreters or package
runners anywhere in their import graph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): prove tampered bundles fail cryptographically

A changed payload, another signer's certificate, a second envelope signature, a log entry with
another integrated time and another signature's log entry are each refused by the cryptographic
checks, never as an identity mismatch, with the release and the rollback signers alike. presto 5.2.0
runs through the report path too, and a complete presto-core 1.2.1 bundle verifies offline at its
release commit; the trimmed presto-core 1.0.0 report is labelled as claim extraction only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): record presto-verifier-identity's final boundary and gates

The plan states the exact certificate fields pinned and why the others are not, the verify job's
cache-free install and the final contract assertions; the lessons log the gates and consults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): guard every code path beside the publish credentials

The credentialed job's commands may run Bun only on repository scripts, inline Node only without
loading code, and npm only to publish or read. Every module those scripts reach is refused
`require`, non-literal imports and any subprocess other than npm reading the registry or
installing without scripts, whether spawned from a literal array or through a helper whose calls
all pass one. Each refused form is a test row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): state the credentialed-job guard and keep lessons technical

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(release): allow only exact npm reads beside the publish credentials

npm runs only `view` with positional values, `audit signatures`, or `install` with an exact flag set
that includes `--ignore-scripts`, so no override, spread or other audit mode passes. Spawn calls are
matched regardless of spacing, a spawn whose command is not a literal array or the reviewed helper
is refused, and Node in the job runs only quoted inline code that loads nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): close presto-verifier-identity

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(release): give EC signature checks a digest on Bun 1.4.0

Bun 1.4.0, the pinned runtime, has no default digest for EC keys: `crypto.verify(null, ...)` throws
ERR_OSSL_EVP_NO_DEFAULT_DIGEST where Node, OpenSSL and Bun 1.4.2 use SHA-256. sigstore-js checks
inclusion promises and tuf-js checks root metadata that way and read the throw as a bad signature,
so every verification failed closed. On such a runtime only, ec-default-digest.ts makes a null
digest with an EC key, bare or wrapped as `{ key }`, SHA-256; the identity module loads it first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(release): state when the EC digest shim retires

The shim's comment names what it wraps and its removal condition, `.bun-version` at 1.4.2 or newer;
follow-ups.md carries that Bun bump, the tag-after-verification decision and the reuse-pin
hardening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(bun): pin Bun 1.4.2

Bun 1.4.2 verifies EC signatures with SHA-256 when no digest is named, as Node and OpenSSL do;
sigstore-js and tuf-js verify that way. Every setup-bun step reads `.bun-version`. Workers Builds
refuses a Bun other than `.bun-version`, so its `BUN_VERSION` build variable moves with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(release): verify EC signatures on the pinned runtime, without a crypto shim

On Bun 1.4.2 `crypto.verify` with no digest hashes EC keys with SHA-256, so the wrapper that
supplied it on Bun 1.4.0 goes, with its import and its path-filter entry. The runtime property
stays under test in its own file, for a bare key and `{ key }`, a null and an undefined digest:
tuf-js reaches it only in the live provenance test, so a Bun bump that loses it fails here first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(plan): record Bun 1.4.2 as the verifier's runtime

The presto-verifier-identity record ships Bun 1.4.2 instead of a crypto wrapper, with the live gate
re-run under it (80 checks), and drops the bump from the open items. follow-ups.md trades it for the
`JEST_WORKER_ID` preloads, whose stated removal condition Bun 1.4.2 meets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build(bun): pin Bun 1.4.2

Bun 1.4.2's `crypto.verify` hashes EC keys with SHA-256 when no digest is named, as Node and
OpenSSL do; 1.4.0 throws NO_DEFAULT_DIGEST. sigstore-js and tuf-js verify that way, so the npm
provenance verifier needs it. `ec-verify-without-digest.test.ts` pins the property and fails on
1.4.0.

Workers Builds selects Bun only through its `BUN_VERSION` build variable, one list per trigger
(production and preview), and `scripts/workers-build.ts` refuses a mismatch with `.bun-version`.
The deployment doc gives the cutover order, and a test keeps its `BUN_VERSION` equal to the pin.

Bun 1.4.2's plain `bun install` corrects sdk-noir's stale workspace version in `bun.lock`;
`--frozen-lockfile` accepts the committed lock unchanged on both versions. The lock is left as is
because that entry is in presto-noir's release slice; follow-ups.md tracks folding it into the next
noir release.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(follow-ups): carry the JEST_WORKER_ID preloads with the Bun pin

Their removal condition is a Bun carrying oven-sh/bun#40271, which 1.4.2 is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): name why a published release does not verify

Release planning read any failed check of a published version as "does not verify; bump the
version", including a Sigstore TUF mirror, npm registry or GitHub API it could not reach. A
transient outage therefore advised a needless version bump. The refusal still fails closed, and
now carries the reason: a missing tag or GitHub release, a commit mismatch, or the error of the
check that could not run, and says to rerun when the check could not reach a service.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(deps): leave presto-noir's lockfile entry as its release has it

Installing the sigstore packages also rewrote `packages/sdk-noir`'s workspace version in `bun.lock`
from 2.0.0-rc.1 to 2.0.0-rc.2, which a plain Bun 1.4.2 install does. That entry is in noir's
release slice, and the `@alejoamiras/presto-noir@2.0.0-rc.2` tag commit has rc.1, so release
planning refused to reuse the published 2.0.0-rc.2 ("build inputs changed since its release
tag"). With the line restored, `bun install --frozen-lockfile` leaves the lock unchanged and a
dry-run plan of all packages reuses core, noir and banners again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(release): record a publication only after its signing identity verifies

The publish job holding npm's OIDC identity drops `contents: write`, and its checkout keeps no
credential. A new `release-records` job, `contents: write` with no OIDC identity and no install,
creates the git tag and GitHub release after `verify` has bound the provenance to the release
signing identity, then reads both back. No job holds both credentials.

A publication whose verification fails stays on npm under `testnet` without records. Release
planning refuses to reuse it and names the missing record, promotion refuses it before touching npm,
and dependants and the playground pin wait on the whole reusable workflow. "Re-run failed jobs"
completes a run whose verification failed transiently: `publish` does not run again, a tag already
at the run's commit is a no-op push, and an existing release is kept. The runbook gives the owner
the commands that check both records, and the path for an identity that does not verify.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): give up on an npm call that never answers

A registry, or a proxy, that accepts the connection and never answers held
`npm install` with no deadline: a provenance check through one was still
waiting after 25 minutes, so the release job would sit until its own timeout.
Each npm call now fails after 180 s, naming the command; a cold install and
audit of the largest package take about 30 s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): name the cause behind a wrapped verification error

`@sigstore/tuf` wraps every metadata refresh failure as `error refreshing TUF
metadata`, keeping the code and the underlying error as separate properties,
so a refused reuse showed the wrapper and hid whether TUF was unreachable or
its metadata invalid. The refusal now carries each error's code and its
cause chain.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): finish a draft release that an interrupted record left

`gh release create` uploads assets to a draft and publishes it last, so a
`Record <package>` attempt interrupted mid-upload leaves a draft that `gh
release view` still finds. A rerun took that for a finished release, and the
read-back checked only its tag. A rerun now uploads the asset and publishes
the draft, and the read-back requires a published release with its asset.
Both steps are tested by running them with git and gh stubbed.

The runbook now starts from the job that failed. A failed `Publish` must not
be re-run, since npm refuses the existing version; the hand repair keeps a
tag already at the verified commit and creates only the missing release.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): accept only a published release as a record

`gh release view` also finds drafts. Release planning and promotion took a
draft that an interrupted `Record` left for a finished record, so a version
whose release was never published could be reused or promoted. Both now
require a published release; a draft still counts as an existing record
when planning checks that a new version is free.

`Record` now finishes only a draft it could have left: authored by
github-actions[bot], titled with the tag, holding no asset but its own.
It stops on any other draft, and the read-back requires exactly the
expected asset.

The runbook re-runs one job at a time, since "Re-run failed jobs" would
also re-run a failed `Publish`. The hand repair attaches the migration
guide as it was at the verified commit, not from the operator's checkout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(release): keep a tag already at the run's commit, annotated or not

A hand repair creates a signed annotated tag, and pushing a lightweight tag
of the same name cannot update it, so a rerun of Record failed before it
reached the release. Resolve the remote tag first: absent, create and push;
at this commit, keep it; anywhere else, stop. The step tests drive all four
cases, and the read-back accepts an annotated tag.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants