# Lua + SQLite Cursor Machine Lab

The Machine Lab is the shortest end-to-end proof that the browser body is doing real work. Open **Cursor Apps → Lua + SQLite Machine Lab**, or use `/cursor-machine-proof.html` when diagnosing the lab independently of the Open MCT shell.

Press **Run Proof Flight**. A passing flight reports the SQLite version and the number of leased assertions and outbox intents read back from the database.

## What the flight actually proves

1. The UI creates a dedicated module Worker; the UI thread never owns the writable connection.
2. The Worker loads the official `@sqlite.org/sqlite-wasm` engine and opens the selected local backend.
3. The stored `watch-party-presence/v0` Lua profile is parsed and validated into a content-addressed program graph.
4. The graph contains a renewable Linda assertion, a structural interest, and an explicit checkpoint reference.
5. The body commits the assertion and its `dataspace.assert` outbox intent in one allowlisted SQLite transaction.
6. The cockpit reads both rows back through SQLite's bounded, read-only authorizer path.

The default memory backend makes the public demonstration repeatable and leaves no false persistence claim. OPFS and the SyncAccessHandle pool are exercised by the browser test suite when the browser exposes their prerequisites.

## Read the four panels

- **Restricted Lua source** is the durable, reviewable source artifact. Editing it does not grant authority.
- **SQLite Wasm body** reports the engine version, selected backend, attached local databases, and single-Worker ownership rule.
- **Portable continuation graph** shows the source ID, compiler ID, program ID, lease operators, and checkpoint.
- **Transactional readback** shows the committed statement count, leased assertion, and pending outbox effect.

The outbox row is not evidence that a network effect happened. An effect executor must claim it with a lease, perform the bounded effect, and commit a stable receipt before dependent work wakes.

## Truth boundary

This is a real restricted-Lua compiler and a real SQLite Wasm transaction. It is **not** a general embedded Lua VM. The current profile accepts only allowlisted calls with JSON-compatible values; it cannot load modules, access the DOM or database, invoke FFI, or manufacture capabilities. Durable resumption uses explicit serializable continuation state, never a Lua heap, C stack, or VM snapshot.

Nelua is a separate portable-core path. The pinned Nelua compiler emits C, Emscripten emits scalar and SIMD Wasm, and both artifacts must pass the same JS fixtures and scheduler-task packets. That acceleration does not change the Lua source boundary or acquire authority.

## If the flight fails

- **Worker or Wasm load failure:** confirm the production build contains `sqlite-body-worker` and `sqlite3.wasm`, and that static responses preserve the required cross-origin isolation headers.
- **Compilation failure:** restore the declared profile, one assertion, one interest, declared `dataspace.assert`/`dataspace.interest` capabilities, and bounded leases.
- **Transaction/query failure:** inspect the displayed error; do not replace the authorizer or allowlisted operation compiler with raw SQL.
- **Open MCT shell failure:** open `/cursor-machine-proof.html`. A passing standalone flight isolates the body from shell/navigation startup; it does not conceal the shell fault.

Run the corresponding checks with `npm test`, `npm run test:browser`, `npm run build`, `npm run benchmark:cursor-machine -- 2000 64 1`, and `npm run build:nelua-core` when the pinned Docker toolchain is available.

Continue with [SQLite + Lua Cursor Machine](sqlite-lua-cursor-machine.md), [SQLite Body and Lua Programs](sqlite-body-and-lua-programs.md), and [Nelua → C → Wasm portable core](nelua-wasm-core.md).
