Skip to content

[Experimental] Prototype browser/WASM validation in isolated workers - #538

Merged
robgruen merged 10 commits into
mainfrom
agents/since-you-ve-looked-into-it-th-emost
Nov 30, 2026
Merged

robgruen merged 10 commits into
mainfrom
agents/since-you-ve-looked-into-it-th-emost

Conversation

@robgruen

@robgruen robgruen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

EXPERIMENTAL - SOURCE-ONLY, OPT-IN PROTOTYPE.
Not production-supported or published as a browser package. Build/link from source;
the private experiment stays outside normal workspaces and does not replace the
default native Node backend. APIs and upstream compiler support may change.
An experimental repository merge is distinct from a supported release; human
review and any approval, ready-status change, or merge remain owner decisions.

Summary

Draft investigation for #536, under #534. This is an opt-in prototype for design review, not a supported browser release or a replacement for the default native Node compiler.

  • Add a separate, private experimental browser package outside the normal npm workspaces. It now follows main's approved TypeScript 0.3 schema-first behavior, with explicit legacy layout support. The normal Node compiler, manifests, and public entry points match current main; no experimental dependency is added to the normal package.
  • Extract shared schema generation, enum normalization, preflight, and diagnostic logic rather than duplicate or weaken validation. Keep separately typed adapters for the native and experimental compiler APIs.
  • Pin matching compiler/WASM artifacts to 7.1.0-dev.20261030.1; verify version, length, and SHA-256 before compiling. Make loading, cancellation, errors, independent validator ownership, and disposal explicit.
  • Add a runnable application-owned, one-job-per-worker example. Cancellation terminates the owned worker and rejects its promise, including during synchronous validation. There is no public worker-pool API, silent fallback, or hidden retry.
  • Add cross-backend parity and real Chromium/Firefox/WebKit tests, slow-download checks, worker lifecycle coverage, and broader performance/memory measurements.

The branch now integrates main through #535, including #551 and #545, including the approved 0.3 behavior from #540. Compiler-rendered enum literal queries are shared across separately typed native/WASM adapters. Tests preserve lexical scope, member-only namespace filtering, collisions, original-schema restoration, diagnostic precedence, and native CJS/ESM compatibility.

Verification (2026-11-30 refresh)

Refreshed in 65a9e7e by merging approved main 35d9150 without conflicts, extra runtime patches, dependency upgrades, relaxed assertions, or skipped checks. Windows, Node.js 24.22.1:

  • Ordinary typescript: npm run build-all passed for the library and every example; npm test with TYPECHAT_LIVE_TESTS=0 passed 596 tests, 0 failed, 0 skipped, including native CJS/ESM package/declaration checks and the merged temperature/Zod regressions.
  • Private browser package: npm run build passed. One combined serial runner selected all six experimental/browser test files with TYPECHAT_STABILITY_BROWSERS=1: 36 passed, 0 failed, 0 skipped, in about 174 seconds.
  • All 88 corpus outcomes matched the stable native baseline in Chromium 149.0.7827.55, Firefox 151.0, and Playwright WebKit 26.5. Same-version native/WASM diagnostics also matched.
  • The complete run includes three browser-matrix checks, three hosted-page CSP/cache checks, three worker-recovery checks, and four HTTP hosting-contract checks. Seven recovery workers closed per engine, with no remaining abort listeners, page errors, or version-mismatch fetches. The 500-property/250-validation worker workload kept the main-thread heartbeat running and reported zero owned linear memory after close.
  • Library JavaScript: 444,593 bytes raw / 94,922 bytes gzipped. Unchanged WASM: 52,616,552 / 13,359,431 bytes. All existing provisional payload and linear-memory ceilings passed without increases.
  • Normal runtime manifests match main; exact private compiler/WASM pins and integrity metadata are unchanged. The prototype delta passes git diff --check origin/main; incoming Python files are unchanged from approved main.

Fresh instrumented worker observations (one run per engine, not production guarantees):

Engine 500-property / 250 validations Main-thread ticks Maximum worker linear memory Largest process-tree working-set sample
Chromium 1,857 ms 185 34,603,008 bytes 865 MB
Firefox 19,241 ms 1,830 34,603,008 bytes 1,250 MB
WebKit 2,809 ms 178 35,127,296 bytes 798 MB

Process-tree figures are rounded decimal MB, include prior corpus/lifecycle probes, may double-count shared pages, and are not unique physical memory, one-job incremental cost, or precise peaks. Firefox still uses Playwright/Juggler; the historical retail probe below was not rerun. Strict CSP and versioned gzip delivery passed; two-job cache reuse was observed only in Firefox again.

All responses were synthetic. No live model calls or credentials were used. Tests closed their own browsers, workers, and loopback servers. Ordinary repository CI does not run the separately installed experimental suite. Reproducible commands, fresh costs, and historical evidence are in the updated prototype README.

Browser hosting follow-up

  • Follow-up validation addressed the CodeQL header-parser finding with tokenization and bounded syntax checks. Large/malformed header regressions were added, and all seven HTTP/hosted-browser checks passed after the change.

  • The application-owned example now uses a shared, tested static handler; no hosting API was added to the TypeChat core and nothing was deployed externally.

  • HTML/UI scripts/styles are external and no-store. Strict CSP permits same-origin resources and wasm-unsafe-eval, not general JavaScript eval or inline scripts/styles. Both the document and worker receive the policy. Real-page eval blocking and explicit failure without WASM permission pass in all three engines.

  • The compiler asset URL includes its exact version and SHA-256. Startup verifies the bytes before serving it with immutable caching, gzip/identity negotiation, representation-specific ETags, Vary: Accept-Encoding, and correct HEAD/304/error handling.

  • Four protocol tests verify actual bytes, MIME types, cache headers, compression, conditional responses, and encoding/method errors. Existing browser and recovery fixtures use the same hosting handler.

  • Automated two-job checks observed a warm cache hit in Firefox; Chromium and WebKit fetched again. Every network artifact response was gzip (13,359,431 bytes). Cache headers make reuse possible but do not guarantee storage, prevent eviction, or avoid initialization in a new worker.

Hosting remains application-owned and separate from core validation. The later #545 integration clears the Unicode gates without suppressing them; normal manifests match main and the pinned experimental compiler/artifact versions remain unchanged.

Resolved Unicode blocker and follow-up findings

  • Fixed: a retained closed validator previously kept its compiled WASM module alive through the loader context. Moving validator closure construction to a module-level helper removes that strong retaining path. The heap-reference regression fails before the fix and passes afterwards; reactor and linear-memory disposal also pass.
  • Unicode blocker resolved: #541 was fixed on main by #545, and that reviewed algorithm is now used by the browser adapter too. The original declared-value/altered-value assertions pass without changes. The historical pre-fix reproduction on untouched main 0ef51b0 established that the bug predated this refactor; it is no longer an open conformance gate here.
  • Portable TypeChat reproduction records the original microsoft/TypeScript#65458 symptom and now succeeds on the fixed checkout. No separate upstream comment or PR was posted. No decoder patch, dependency upgrade, relaxed validation, skipped conformance assertion, or silent fallback was introduced.
  • Retail Firefox confirmation: official Mozilla Windows x64/en-US 151.0, verified SHA-512 manifest and valid Mozilla signatures, fresh profiles, no Juggler resources or debugger connection. Three dedicated-worker runs used the identical fixed compiler and 500-property x250 workload; valid/invalid/recovery/after-close controls all passed. Retail BuildID 20260516144017 differs from Playwright's 20260611193205. This does not certify WAN/mobile performance, retail memory costs, or a full retail-browser matrix.

Ordinary repository CI does not run this separately installed experimental suite, so it was run explicitly with all browser recovery checks enabled: zero failures or skips. That clears the recorded Unicode gates, not the need for an upstream-support/maintenance decision or production deployment assessment. This remains a draft investigation.

Experimental limitations / not a supported release

  • The upstream WASM API is experimental; publication is not a stability guarantee. See microsoft/TypeScript#64174.
  • The artifact is about 52.6 MB raw / 13.4 MB gzipped, plus about 444,593 bytes raw / 94,922 bytes gzipped library JavaScript in the current build.
  • The original roughly 19.4-second automated Firefox result is not representative of the tested retail build. Official retail Firefox 151.0, with an unobserved dedicated worker and the same workload/library, took 2.141 / 2.180 / 2.161 seconds. The Playwright debugger is a confound; differing BuildIDs and the small one-host sample limit pure-causal/general performance claims.
  • Fresh sampled instrumented Playwright browser-process-tree working-set sums reached approximately 0.80-1.25 GB after the preceding corpus/lifecycle probes. These sums include runtime overhead and may double-count shared pages; they are not one-job incremental memory or precise peaks. Retail Firefox memory was not reprofiled.
  • Playwright WebKit on Windows does not certify Safari. macOS/mobile/low-memory devices, production CSPs, and real edge runtimes remain unverified.
  • This package intentionally omits the Node HTTP/proxy client and program/interactive helpers. It does not silently bypass proxy configuration or make the existing public typechat/ts entry point browser-compatible.

The prototype README documents reproducible commands, measured results, provisional budgets, lifecycle trade-offs, upgrade/rollback, and outstanding merge gates:
Browser prototype README.

Keep #534 and #536 open. Any supported mainline integration still needs explicit upstream-stability/maintenance, API, performance, and compatibility decisions.

Go/no-go recommendation (2026-11-30)

Suitable for isolated experimental evaluation; not ready as a supported browser release. Current-main compatibility, recorded conformance checks, and provisional payload/linear-memory ceilings pass. An isolated experimental repository merge is a separate owner-reviewed decision, including acceptance of the upstream dependency and maintenance risks. It does not publish the private package or promise stable browser support.

Remaining supported-release gates from #536:

  1. A sufficiently stable supported upstream WASM contract, or the owner's explicit experimental-maintenance decision with upgrade/rollback ownership. The merged upstream PR still labels the artifact, package, and host experimental and subject to change without notice.
  2. Separate review of the supported opt-in API, loading/errors, cancellation/disposal, and application-owned assets.
  3. Accepted download/startup/responsiveness/total-memory budgets measured on intended devices, not just provisional localhost ceilings.
  4. Required production CSP/CDN and target-browser/device evidence, including applicable Safari/macOS and mobile/low-memory coverage. Historical retail Firefox timings and Windows Playwright WebKit are not substitutes.
  5. Any supported distribution must preserve Node/CJS/ESM and validation/repair behavior, with explicit ongoing browser/parity/recovery test execution.

This is an experimental investigation, not production support or an automated approval. Approval, ready status, and any merge remain human-owner decisions. Keep #534 and #536 open for the outstanding support and deployment work.

robgruen and others added 5 commits November 23, 2026 16:20
Preserve the opt-in investigation for #536 before reviewing the shared refactor and expanding worker/browser coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add an application-owned worker example, Chromium/Firefox/WebKit coverage, explicit cancellation and cleanup checks, and broader performance and process-memory measurements for #536.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Retain the opt-in live-test work while keeping this browser prototype isolated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Document the 424 passing ordinary tests, disabled live suite, and both browser memory ceilings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Eliminate the closed-validator compiled-module retaining path. Add independent stability and Unicode regressions, confirm the Unicode failure on pristine main, and document the verified retail Firefox dedicated-worker comparison. Keep the two upstream conformance failures explicit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep hosting application-owned. Verify CSP, compressed immutable artifacts, encoding negotiation, conditional requests, and worker loading errors across the browser matrix. Preserve the separate Unicode conformance gates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
robgruen and others added 4 commits November 25, 2026 21:33
Merge approved main through #545 and share scoped compiler-rendered enum queries across native and WASM adapters. Preserve the original schema, error precedence, and schema-first/legacy message behavior. Keep independent Unicode assertions unchanged and expand the browser corpus to 88 outcomes.

Verified build-all and 492 ordinary tests, plus all 36 experimental/browser checks with zero failures and skips. The pinned experimental compiler and WASM artifact are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tokenize coding and quality fields before simple bounded syntax checks. Preserve negotiation behavior and cover large whitespace, malformed qualities, and extra parameters. All seven HTTP and hosted-browser checks pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Merge main at 35d9150 without conflict resolutions or runtime workarounds.
Record 596 passing ordinary tests and 36 passing experimental/browser tests
with zero skips, fresh payload/timing/memory measurements, and explicit
GO for continued isolated evaluation / NO-GO for supported mainline release.
Keep the investigation draft and retain all upstream and deployment gates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a prominent source-only opt-in warning and distinguish an owner-reviewed
experimental repository merge from publishing supported browser functionality.
Keep package isolation, measured limitations, and supported-release gates.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robgruen robgruen added the experimental Opt-in prototype; APIs and upstream support are experimental, not production-supported. label Nov 30, 2026
@robgruen robgruen changed the title Prototype browser/WASM validation in isolated workers [Experimental] Prototype browser/WASM validation in isolated workers Nov 30, 2026
@robgruen
robgruen marked this pull request as ready for review November 30, 2026 18:39
Copilot AI balanced review requested due to automatic review settings November 30, 2026 18:39

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.

🔵 Needs a closer look

The unstable upstream WASM dependency and shared native-validator changes require human owner review of experimental maintenance ownership and browser/runtime limits, especially since the supplied runtime checks were not independently rerun.

No open issues 🎉

1 file not reviewed
  • typescript/experimental/browser/package-lock.json: Generated file
What changed in this PR

Adds a private, source-only browser/WASM prototype for #536, investigating #534 while keeping the native Node backend as the default. This remains an opt-in experiment, not a published or supported browser release.

Changes:

  • Extracts shared validation, enum handling, diagnostics, and model types for separately typed native and WASM adapters.
  • Adds verified WASM loading and an application-owned worker example with cancellation, disposal, and explicit hosting policies.
  • Adds backend parity, browser, lifecycle, and hosting tests, plus documented measurements and supported-release limitations.
File Description
typescript/​test/​compiler.test.ts Tests shared compiler lifecycle and failure handling.
typescript/​src/​typechat.ts Imports browser-safe model protocol types.
typescript/​src/​ts/​validation.ts Extracts compiler-independent validator logic.
typescript/​src/​ts/​validate.ts Adapts the native compiler to shared validation.
typescript/​src/​ts/​compiler.ts Defines shared compiler operations and diagnostics.
typescript/​src/​modelTypes.ts Separates model and prompt type definitions.
typescript/​src/​model.ts Re-exports extracted types without changing HTTP behavior.
typescript/​README.md Links the isolated experiment and clarifies its scope.
typescript/​experimental/​browser/​tsconfig.json Configures prototype compilation and declarations.
typescript/​experimental/​browser/​tests/​types.ts Checks validator and prompt-layout types.
typescript/​experimental/​browser/​tests/​stability.test.mjs Tests recovery, cancellation, isolation, and resource retention.
typescript/​experimental/​browser/​tests/​repro-unicode-enum.mjs Provides a standalone Unicode enum regression probe.
typescript/​experimental/​browser/​tests/​parity.test.mjs Compares native and WASM outcomes and diagnostics.
typescript/​experimental/​browser/​tests/​native-preview.mjs Supplies the matching-version native test adapter.
typescript/​experimental/​browser/​tests/​loader.test.mjs Tests artifact verification and validator ownership.
typescript/​experimental/​browser/​tests/​hosting.test.mjs Tests HTTP caching, compression, and error responses.
typescript/​experimental/​browser/​tests/​corpus.mjs Defines shared validation and translation cases.
typescript/​experimental/​browser/​tests/​browser/​worker-entry.mjs Exercises worker lifecycle and responsiveness.
typescript/​experimental/​browser/​tests/​browser/​version-mismatch.mjs Checks version rejection before fetching WASM.
typescript/​experimental/​browser/​tests/​browser/​process-memory.mjs Samples Windows browser-process memory.
typescript/​experimental/​browser/​tests/​browser/​hosting.test.mjs Checks hosted-page security policy and asset delivery.
typescript/​experimental/​browser/​tests/​browser/​entry.mjs Runs browser validation and initialization probes.
typescript/​experimental/​browser/​tests/​browser/​browser.test.mjs Runs the browser matrix and resource measurements.
typescript/​experimental/​browser/​src/​versions.ts Pins compiler version, artifact length, and hash.
typescript/​experimental/​browser/​src/​project.ts Adapts experimental compiler projects to shared logic.
typescript/​experimental/​browser/​src/​index.ts Exposes the limited experimental browser API.
typescript/​experimental/​browser/​src/​compiler.ts Implements verified loading and disposable validators.
typescript/​experimental/​browser/​README.md Documents setup, design, evidence, and limitations.
typescript/​experimental/​browser/​package.json Defines private dependencies and opt-in commands.
typescript/​experimental/​browser/​package-lock.json Locks the isolated experiment’s dependencies.
typescript/​experimental/​browser/​examples/​worker/​validator.worker.ts Validates one batch and closes owned resources.
typescript/​experimental/​browser/​examples/​worker/​tsconfig.json Type-checks worker code with worker-specific globals.
typescript/​experimental/​browser/​examples/​worker/​style.css Styles the runnable example.
typescript/​experimental/​browser/​examples/​worker/​serve.mjs Serves the example on loopback.
typescript/​experimental/​browser/​examples/​worker/​main.mjs Connects validation, cancellation, and UI status.
typescript/​experimental/​browser/​examples/​worker/​index.html Provides the offline validation interface.
typescript/​experimental/​browser/​examples/​worker/​host.mjs Serves verified assets with security and cache headers.
typescript/​experimental/​browser/​examples/​worker/​client.ts Owns each worker’s promise, cancellation, and cleanup.
typescript/​experimental/​browser/​examples/​worker/​build.mjs Bundles example assets and versions the WASM URL.

Review effort: Balanced

@robgruen
robgruen merged commit 7c5781a into main Nov 30, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Opt-in prototype; APIs and upstream support are experimental, not production-supported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants