Skip to content

Prototype browser/WASM validation in isolated workers - #538

Draft
robgruen wants to merge 8 commits into
mainfrom
agents/since-you-ve-looked-into-it-th-emost
Draft

robgruen wants to merge 8 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

Summary

Draft investigation for #536, under #534. This is an opt-in prototype for design review, not a supported browser release or a request to merge an experimental compiler into main.

  • 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 #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

Windows, Node.js 24.22.1, after integrating approved main at f0e71c0:

  • typescript: npm run build-all and npm test with TYPECHAT_LIVE_TESTS=0 -- 492 ordinary tests passed; the live API suite remained disabled.
  • Experimental checks were rerun together with TYPECHAT_STABILITY_BROWSERS=1: 36 passed, 0 failed, 0 skipped. The two formerly failing Unicode assertions are unchanged and now pass in both backends. The expanded 88-outcome corpus covers independent Unicode semantics, scoped/merged/member enums, default schema-first and explicit legacy prompts, history roles, and repair behavior; same-version native/WASM diagnostics also match.
  • The combined run includes 3 passing browser-matrix suites, 3 passing hosted-page CSP/cache suites, 3 passing worker-recovery suites, and 4 HTTP hosting-contract tests. Browser coverage is Chromium 149.0.7827.55, Firefox 151.0, and Playwright WebKit 26.5.
  • Each engine ran the 88-case corpus, the example UI, ten worker lifecycle/error checks, cancellation after a partial network response, concurrent job isolation, termination during validation, and all-worker cleanup.
  • A 500-property schema was validated 250 times in a worker while the main-thread heartbeat continued.
  • Compiler-version mismatch, HTTP/network/abort/size/integrity errors, and explicit disposal were tested.
  • git diff --check passed.

All model responses were synthetic. No live model calls or credentials were used. Tests manage and close their own browsers, workers, and loopback servers.

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.

Important limits / not ready for main

  • 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 KB raw / 95 KB 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.
  • Sampled instrumented Playwright browser-process-tree working-set sums reached approximately 0.86-1.10 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.

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 2 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>
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