Skip to content

Collapse runtime init into varlock/init and varlock/auto-init - #1239

Merged
theoephraim merged 4 commits into
mainfrom
collapsed-runtime-init
Oct 29, 2026
Merged

theoephraim merged 4 commits into
mainfrom
collapsed-runtime-init

Conversation

@theoephraim

@theoephraim theoephraim commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

What

One edge-safe init sequence, initVarlockRuntime() from varlock/init, that every init path runs:

  • varlock/auto-init: new side-effect-on-import ESM entry for apps whose env is already resolved (varlock run, frozen payloads, sandboxes) and have no CLI to call. Documented next to auto-load.
  • varlock/init-bundle: the same sequence as one self-contained CJS file. The Next.js integration injects it into both server and edge runtimes; varlock/init-server and varlock/init-edge stay as aliases of it so older integration versions keep resolving.
  • The vite integration's virtual SSR init module, the vite plugin's own in-process init, and @varlock/cloudflare-integration/init all call initVarlockRuntime() instead of assembling env init + four patches by hand.

varlock/patch-server-response now loads node:http / node:zlib lazily and is a no-op without node:http, which removes the vite plugin's ssrEdgeRuntime branch (the option is kept as a deprecated no-op; cloudflare, sveltekit and astro callers no longer pass it).

Why the vite module calls a function instead of importing varlock/auto-init

ESM hoists static imports above the module body, and rollup hoists external imports to the top of a chunk, so a side-effect import would run before the resolved-env blob or the Cloudflare bindings loader the generated module sets up first. Top-level await import() would fix a single chunk but siblings of an async module evaluate without waiting, so multi-chunk SSR builds could read ENV before init finished. The same hoisting is why app entry files should use auto-init: an earlier static import is the only thing that runs before sibling imports.

Gotcha found by the framework tests

Next's dev edge sandbox process shim throws when a node API is read off it, rather than leaving it undefined. The old edge bundle never touched those; the unified one does, so process.getBuiltinModule and process.stdout reads are now guarded. A new test evaluates the built dist entries in a node:vm context with no node builtins, and the init bundle under edge-light and Next-dev-sandbox style process shims.

New framework suite: OpenNext

framework-tests/frameworks/opennext builds the Next.js smoke app with @opennextjs/cloudflare and serves it from local workerd (wrangler dev). It asserts the OpenNext build is detected and the env frozen encrypted into the server and middleware handlers, then that the worker decrypts it from the _VARLOCK_ENV_KEY binding and the app page, pages-router SSR, middleware, request-time leak detection and runtime log redaction all behave as on Node. Registered in the changed-integration detector under the Next.js integration.

Verified

varlock, vite, cloudflare, nuxt and nextjs unit suites; docs build; framework tests for vite v7, cloudflare vite7, nuxt v4, Next.js 16 (webpack + turbopack), tanstack-start vite7 and the new OpenNext suite; the real Vercel deployment suite (16/16, plaintext and encrypted frozen env, middleware on the real Edge runtime).

Deferred to the next major (removing the old patch-* / init-server / init-edge subpaths and deleting ssrEdgeRuntime), since every published integration imports them.

@pullfrog

pullfrog Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Pullfrog stalled

The agent stopped emitting events for 125s and was killed by the activity-timeout watchdog. The model produced no output at all before the stall — the request was sent but nothing came back. This is usually transient; re-running often succeeds.

Recent agent stderr
timestamp=2026-10-19T07:28:26.227Z level=ERROR run=18c86390 message="stream error" providerID=azure modelID=gpt-6.1-sol session.id=ses_eacf3f0bbffe3atL16tbuML6E0 small=false agent=build mode=primary error.error="AI_APICallError: The model was unable to complete inference due to an internal error."
timestamp=2026-10-19T07:31:32.656Z level=ERROR run=18c86390 message="stream error" providerID=azure modelID=gpt-6.1-sol session.id=ses_eacf3f0bbffe3atL16tbuML6E0 small=false agent=build mode=primary error.error="AI_APICallError: The model was unable to complete inference due to an internal error."
timestamp=2026-10-19T07:35:07.457Z level=ERROR run=18c86390 message="stream error" providerID=azure modelID=gpt-6.1-sol session.id=ses_eacf3f0bbffe3atL16tbuML6E0 small=false agent=build mode=primary error.error="AI_APICallError: The model was unable to complete inference due to an internal error."
timestamp=2026-10-19T07:39:02.669Z level=ERROR run=18c86390 message="stream error" providerID=azure modelID=gpt-6.1-sol session.id=ses_eacf3f0bbffe3atL16tbuML6E0 small=false agent=build mode=primary error.error="AI_APICallError: The model was unable to complete inference due to an internal error."
timestamp=2026-10-19T07:41:54.524Z level=ERROR run=18c86390 message="stream error" providerID=azure modelID=gpt-6.1-sol session.id=ses_eacf3f0bbffe3atL16tbuML6E0 small=false agent=build mode=primary error.error="AI_APICallError: The model was unable to complete inference due to an internal error."

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using gpt-6.1-sol | 𝕏

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

bumpy-frog

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

minor Minor releases

  • @varlock/native-helper-darwin 1.23.0 → 1.24.0
  • @varlock/native-helper-linux-arm64 1.23.0 → 1.24.0
  • @varlock/native-helper-linux-x64 1.23.0 → 1.24.0
  • @varlock/native-helper-win32-x64 1.23.0 → 1.24.0
  • varlock 1.23.0 → 1.24.0

patch Patch releases

  • @varlock/astro-integration 1.4.4 → 1.4.5
  • @varlock/cloudflare-integration 1.6.2 → 1.6.3
  • @varlock/nextjs-integration 1.2.5 → 1.2.6
  • @varlock/nuxt-integration 0.1.4 → 0.1.5 (cascade)
  • @varlock/vite-integration 1.5.4 → 1.5.5

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle size

✅ shrinks the bundle by 7.7 KB (−0.1%)

Metric main This PR Δ
Total dist 5180.8 KB 5173.1 KB −7.7 KB (−0.1%)
JS 2001.0 KB 1975.4 KB −25.6 KB (−1.3%)
Sourcemaps 3042.8 KB 3060.5 KB +17.7 KB (+0.6%)
Type defs 137.0 KB 137.1 KB +0.1 KB (+0.1%)
Other 0.0 KB 0.0 KB —

dist/ only; native binaries are versioned separately and not counted here.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website fddb0da Commit Preview URL

Branch Preview URL
Oct 29 2026, 06:49 AM

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1239

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@1239

@varlock/cloudflare-integration

npm i https://pkg.pr.new/@varlock/cloudflare-integration@1239

@varlock/nextjs-integration

npm i https://pkg.pr.new/@varlock/nextjs-integration@1239

@varlock/nuxt-integration

npm i https://pkg.pr.new/@varlock/nuxt-integration@1239

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@1239

@varlock/native-helper-darwin

npm i https://pkg.pr.new/@varlock/native-helper-darwin@1239

@varlock/native-helper-linux-arm64

npm i https://pkg.pr.new/@varlock/native-helper-linux-arm64@1239

@varlock/native-helper-linux-x64

npm i https://pkg.pr.new/@varlock/native-helper-linux-x64@1239

@varlock/native-helper-win32-x64

npm i https://pkg.pr.new/@varlock/native-helper-win32-x64@1239

@varlock/1password-plugin

npm i https://pkg.pr.new/@varlock/1password-plugin@1239

commit: fddb0da

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

✅ No new issues found.

Reviewed changes
Reviewed the supplied incremental delta from 3bfb388b to c334341f, with the full PR diff as context. No previous GitHub reviews or open review threads were present.

  • Added OpenNext coverage for encrypted frozen env initialization, app/pages-router rendering, middleware, request-time leak blocking, log redaction, and continued serving in local workerd.
  • Registered Framework test execution through the test:opennext script and Next.js integration change detection.

Traced the new suite against the shared harness and Next.js fixtures. The OpenNext CI job passed; I did not rerun the suite locally.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

Adds a single edge-safe init sequence, initVarlockRuntime() from varlock/init
(no import side effects), that every init path runs: the new varlock/auto-init
entry that calls it on import, the single varlock/init-bundle CJS file the
Next.js integration injects into both server and edge runtimes (init-server and
init-edge remain as aliases of it), the vite integration's virtual SSR init
module, and the Cloudflare init entry.

patch-server-response loads node:http and node:zlib lazily and is a no-op where
node:http does not exist, so the vite integration no longer needs the
ssrEdgeRuntime branch (the option is kept as a deprecated no-op). Node API reads
off process are guarded because Next's dev edge sandbox throws on them rather
than leaving them undefined. Generated init modules call initVarlockRuntime()
rather than importing varlock/auto-init because ESM and bundlers hoist imports
above the resolved-env / entry code they have to run after; app entry files use
varlock/auto-init for the same reason.

A new test evaluates the built dist entries in a node:vm context with no node
builtins, and the init bundle under edge-light and Next-dev-sandbox style
process shims.
… the tanstack once-only check

On the Cloudflare target varlock is bundled into the worker, so the output
also contains the initVarlockRuntime() function declaration (unlike the old
initVarlockEnv(opts?) one). Match the call form with its semicolon.
Next.js built with @opennextjs/cloudflare and served from local workerd:
the build is detected as OpenNext and the env frozen encrypted into the
server and middleware handlers, the worker decrypts it from the
_VARLOCK_ENV_KEY binding, and the shared Next.js fixtures assert env
values on the app page, pages-router SSR and middleware, request-time
leak detection, and runtime log redaction on that target.
…Response guard

An already-resolved globalThis.__varlockLoadedEnv now wins over an encrypted
process.env.__VARLOCK_ENV in initVarlockRuntime, matching initVarlockEnv's
precedence, so a blob that would never be read is not decrypted (and a key
that is not in process.env is not required). patchGlobalServerResponse skips
a ServerResponse whose prototype has no write/end. Docs note that an
encrypted blob on a runtime without node:crypto initializes asynchronously.
@theoephraim
theoephraim force-pushed the collapsed-runtime-init branch from c334341 to fddb0da Compare October 29, 2026 06:46

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

✅ No new issues found.

Reviewed changes
Reviewed the incremental delta from c334341f to fddb0da9, with the affected initialization paths as context.

  • Preserved Resolved-env precedence so an already-loaded graph bypasses decryption of an ignored process-env blob, and added a built-output regression test without a decryption key.
  • Guarded Partial HTTP polyfills so ServerResponse patching skips prototypes missing callable write or end methods.
  • Documented Async edge readiness and the need to await globalThis.__varlockEnvReady outside Next.js when Node crypto is unavailable.

The runtime build and 59 focused tests passed. A separate probe confirmed incomplete HTTP polyfills remain unpatched. Framework and deployment suites were not rerun.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@theoephraim
theoephraim merged commit 0ccee65 into main Oct 29, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant