# Browser demo

Start with the [1 MW guided experiment](https://khanlab.co.technology/), open the [50 MW generator-failure preset](https://khanlab.co.technology/?preset=ai_cluster_generator_failure) in the advanced workspace, or follow [the twelve continuity lessons](../tutorials/power-systems-course.md). The first result uses the local JavaScript continuity engine. **Verify against Python** explicitly loads the reference Python engine when you want a second calculation.

The JavaScript port uses exact rational arithmetic for dispatch and accounting, then matches Python's 100-digit decimal formatting, canonical inputs and result hashes. It handles the bounded topology contract, including max-flow, charging, generator delay, shared failures and event boundaries. It does not use a preset lookup table of precomputed results. Reports, sensitivity and the separate PUE exercise also calculate locally.

Both engines run in Web Workers. The optional Python check uses pinned Pyodide 314.0.8 (CPython 3.14.2). The Python source archive has an explicit per-file manifest and a checked SHA-256 digest. Equality checks compare the complete result: normalized inputs, hashes, interval ledger, warnings and event times. A mismatch is an error; it cannot produce a successful verification badge. A failed optional download leaves the completed JavaScript result available and offers retry.

The browser compares the downloaded archive with its manifest's archive digest. Per-file hashes are audit metadata, not separate browser checks; they describe archived text after CRLF-to-LF normalization. Compare normalized source bytes when auditing on Windows. These hashes detect mismatched files and do not replace trust in the host serving both archive and manifest.

## First experiment

The home page opens the 1 MW predict-run-explain guide. Predict the battery's duration after the outage, then explicitly run the experiment. Charging is disabled: 100 kWh gives **307.8 s of ride-through** and depletion at **607.8 s elapsed**; 50 kWh gives **153.9 s of ride-through** and depletion at **453.9 s elapsed**. Both use 0.90 battery discharge efficiency and 0.95 distribution efficiency. The [canonical case](../canonical-case.md) includes the inputs and equations.

## Advanced 50 MW comparison

The explicit AI-cluster generator-failure preset loses utility and generator availability at 300 s and restores utility at 900 s. With 5,000 kWh initial battery energy in the 50 MW case, depletion occurs at 607.8 s. Change **Initial battery** to **2,500 kWh** and run again. Depletion moves to **478.2675 s**, displayed as 478.3 s: this preset allows charging during the first 300 s while utility is available. Its outage-opening balance is `2500 + 5000 × 0.95 × 300/3600 = 2895.833333... kWh`; ride-through is that balance times `0.90 × 0.95 × 3600/50000`, giving `178.2675 s`. This charging-enabled advanced comparison differs from the charging-disabled guide above.

Use the event buttons to inspect failure and recovery, export JSON, download a Markdown/HTML report, or compare empty/half/full initial reserves. Reports use the last completed scenario; unapplied edits are labeled. For a simpler hand calculation with charging disabled, use the [reproducibility capsule](../validation/reproducibility-capsule.md).

## Historical first-result measurement

The [12 September local observation](../validation/browser-entry-measurement.json) recorded **322,816 decoded response bytes** for the first 50 MW result, including a **42,262-byte JavaScript worker**, and **605 ms** from navigation to the displayed result. This predates the guided landing page and custom domain. It was one fresh Chromium context against loopback Vite on Windows, with no network or CPU throttling. It is not a current hosted-site measurement, a compressed transfer size or a promise of visitor latency. The test confirmed no Pyodide, Python archive, catalog or cover request on that path.

## Privacy and limits

The first result does not request Pyodide, the Python source archive or the cover image. The optional verifier downloads about 14 MB the first time; browser cache can reduce later transfers. The browser test writes a timestamped `first-result-measurement.json` listing observed decoded response sizes and local time to result. Its 600,000-byte regression budget covers the explicit advanced 50 MW journey; local timing is not a claim about every visitor or network. All runtime assets come from the same site.

The application code sends no scenario inputs, exports, completion events, cookies, or analytics identifiers to a server. Cloudflare serves the primary site; see [Cloudflare's privacy policy](https://www.cloudflare.com/privacypolicy/) for its processing of service requests. Legacy GitHub Pages redirects and GitHub source/download requests involve [GitHub's privacy statement](https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement). Provider-injected analytics are a separate hosting setting, not a measurement of lesson completion. Browser extensions and local filtering software may make their own requests; they are outside the application.

There is no automatic collection of demo completion or repeat use. Those metrics remain unknown unless someone voluntarily reports a reproducible journey. Browser execution uses the same bounded scenario contract (including a 4 MiB request limit and bounded simulation size), plus a 90-second worker deadline. A deadline terminates the worker and reports an actionable error. Closing/reloading the page discards workspace state. Downloads happen only when requested. There is no service worker or offline-install guarantee.

Results remain synthetic and uncalibrated. This does not establish facility safety, cooling or workload performance, AC transients, protection coordination, certified uptime, or live controls. No login or sensitive inputs are required.

## Rebuild and verify

Complete the [contributor setup](../../CONTRIBUTING.md#before-opening-a-pull-request) first. It creates an isolated Python environment, installs the locked API and frontend dependencies, and sets `TWIN_PYTHON` to that environment. Continue in the same terminal from the repository root so the native calculations and browser checks use the same Python packages.

Windows / PowerShell:

```powershell
& $env:TWIN_PYTHON -m pip install -r requirements-studies.lock
& $env:TWIN_PYTHON scripts/fetch_study_runtime.py
& $env:TWIN_PYTHON scripts/prepare_browser_demo.py
npm.cmd --prefix apps/web run test:engine
npm.cmd --prefix apps/web run build:demo
npm.cmd --prefix apps/web exec playwright install chromium
npm.cmd --prefix apps/web run test:demo
```

macOS / Linux:

```sh
"$TWIN_PYTHON" -m pip install -r requirements-studies.lock
"$TWIN_PYTHON" scripts/fetch_study_runtime.py
"$TWIN_PYTHON" scripts/prepare_browser_demo.py
npm --prefix apps/web run test:engine
npm --prefix apps/web run build:demo
npm --prefix apps/web exec playwright install chromium
npm --prefix apps/web run test:demo
```

The build lives in `.local/browser-demo-site` and uses relative asset paths so the same files work at a domain root or a repository subpath. From `apps/web`, run `npx vite preview --mode demo --host 127.0.0.1 --port 4174 --base /datacenter-twin-lab/` and open `http://127.0.0.1:4174/datacenter-twin-lab/`. Stop that preview before running `test:demo`, which starts its own server on the same port. The default suite covers that repository path; set `TWIN_DEMO_BASE=/` to exercise a root deployment. CI checks the guide's two reserves, complete native/Python equality and the evidence hub at the root using the same built artifact. See [custom-domain deployment](custom-domain.md) for DNS and HTTPS requirements.

The HTML entry includes a readable example and Python/documentation links before scripts load. The [24 readable lesson pages](https://khanlab.co.technology/learn/) also work without JavaScript; the interactive simulations require it. All eighteen presets and all twelve continuity default/challenge lesson pairs are checked against native Python. Infrastructure screens have their separate equation checks and export protocol. Phone-width and JavaScript-disabled journeys, optional Python verification, corruption/retry and initial network requests are checked as well. The [recorded walkthrough](../examples/demo-walkthrough.md) provides a small visual preview and a text transcript.

`npm run build` in `apps/web` still produces the small loopback dashboard for the Python wheel. It does not include the browser Python runtime. See [third-party notices](../third-party/README.md) and the pinned dependency lockfile. The static deployment workflow requires native tests, JavaScript/native differential checks and browser journeys before uploading an artifact. These are maintainer software checks, not an independent external technical review.
