Skip to content

Lasm 0.6.1

Choose a tag to compare

@github-actions github-actions released this 10 Nov 02:06
· 1194 commits to main since this release
841926a

Lasm 0.6.1

A minor release with one small breaking change. Upgrade with npm install -D @lasm/cli@0.6.1; ^0.5.0 does not pick it up.

0.6.0 was never published: its release checks failed on CI problems (fixed here), so 0.6.1 is the first 0.6 release, and it carries every change listed for 0.6.0 as well as those made since.

The breaking change: Lasm.JS.Wire.encode now returns Except String ByteArray, so only code that calls the wire codec directly needs a change; programs that use Lasm.JS through call, get, bindings and Function.ofFn build as before.

What changes: import Lasm.JS.Web gives bindings of the standard web APIs that every target shares (#172); Value.get and Value.set take Symbol and number keys (#170); back-to-back Lasm.JS calls on Node cost about 5 µs instead of 22–24 µs (#171); Async loops of any length run on Bun, Deno, Workers and browsers (#90); on the edge targets a C-stack overflow traps at once instead of overwriting memory, which fixes a hang on Bun (#126), and with JSPI work queued by a synchronous callback no longer waits for an unrelated event (#162); a string that begins with U+FEFF keeps it; and mutation testing found nine smaller fixes. From 0.6.0: a value with a length of 2³² or more fails with a clear error instead of being misread (#154), a stalled tool download reconnects (#152), the function-platform shims no longer forward a forged Host header or answer 502 to unusual paths, queries and header names, and lasm dev is fixed in four places.

New

  • Standard web APIs from Lean: Lasm.JS.Web. import Lasm.JS.Web gives
    bindings of the WinterTC Minimum Common Web API, the web APIs that Node 24 and
    26, Bun, Deno, Cloudflare Workers, the Vercel, Netlify and Supabase edge
    functions and browsers all have: fetch, Request, Response, Headers,
    FormData, URL, URLSearchParams, URLPattern, crypto and
    crypto.subtle, TextEncoder and TextDecoder, Blob and File, readable,
    writable and transform streams, compression streams, AbortController,
    EventTarget and the events, MessageChannel, timers, queueMicrotask,
    structuredClone, atob and btoa, performance, console and
    WebAssembly. They are generated from the specifications' WebIDL, so names
    and shapes are the standards' own, with Lean types: Promise results are
    Async, nullable values Options, dictionaries structures, enums inductive
    types, and JavaScript callbacks are made from Lean functions
    (EventListener.ofSyncFn, UnderlyingSourcePullCallback.ofFn, …). Each spec
    area is its own module (import Lasm.JS.Web.Fetch). Guide and mapping rules:
    docs/JS_BINDINGS.md, "Standard bindings". A conformance suite (WPT's URL data,
    Web Crypto test vectors, round trips) runs them on Node, Bun, Deno, Workers and
    Chromium in CI. Lasm.Web is unchanged.

Improvements

  • Lasm.JS reads and writes Symbol-keyed properties. Value.get and Value.set take a key of any type with ToJS, as JavaScript's o[key] does: a String (unchanged), a number (o.get (3 : Nat)), or a Symbol Value (Symbol.iterator, Symbol.for "k"). An array key is its string, as in JavaScript; getFields still takes strings. Source compatible: existing calls compile unchanged. The signatures are get [ToJS κ] (o : Value) (key : κ) … and set [ToJS κ] [ToJS α] (o : Value) (key : κ) (x : α), previously (key : String). See docs/JS_BINDINGS.md, "Property keys".

Faster

  • Lasm.JS calls on Node cost about 5 µs when a Lean thread makes them one after another (#171). They cost 22–24 µs before. Neither thread now goes to sleep between consecutive calls. Calls that pass a 20-field object each way are about twice as fast on Node, and a third faster on the edge hosts (measured on Deno). A lone call, or calls while an HTTP server is under load, cost what they did, and HTTP throughput is unchanged. No API changed (BENCHMARKS.md).

Fixes

  • Edge targets and browsers with JSPI: Lean work started by a synchronous JavaScript callback no longer waits for an unrelated event (#162). A Lean callback that JavaScript calls synchronously (every Lasm.Web event listener, timer, animation frame and queueMicrotask callback, and Function.ofSyncFn) may resolve a promise that other Lean code awaits. When the callback ran after a Lean entry had returned but before its JSPI promise settled (a microtask queued while Lean ran, or an event in between), or while Lean was suspended, the work it queued ran only when some later event arrived, so an app could stop making progress: in CI, about one WebKit run in three hung for the 5-minute per-app limit in the platform-jspi suite. That work now runs when the entry completes, and a suspended Lean is woken for it. Builds without JSPI (Firefox, Safari without JSPI, the default browser build) were not affected. No API change.

  • Bun, Deno, Workers and browsers: Async loops of any length (#90). A loop in Async (a recursion, for, List.mapM) of steps that complete at once (synchronous host calls such as callMethod, bun:sqlite or D1's prepare(…).bind(…), IO actions, pure) failed after about 2,000 steps on Deno and Workers and 8,000 on Bun with RangeError: Maximum call stack size exceeded. Such loops now run at any length on every target; CI runs 1,000,000 steps on Node, Deno, Bun, workerd and in Chromium, Firefox and WebKit. Lasm's link bounds how deeply Async's binds nest (library/c/lasm_async.c): every 128 nested steps, the rest of the loop continues as a queued Lean task. Results, effects and errors are unchanged, and no code changes are needed; the Std.Async.sleep 0 workaround can be removed. No API change (EDGE.md).

  • Edge targets: a C-stack overflow traps at once instead of overwriting static data (#126). The edge link (every --target built on the edge runtime: Workers, Deno, Bun, Vercel and Netlify Edge, Supabase, the browser) placed Lean's 1 MiB C stack above the program's static data, with nothing between them. A recursion that used up the C stack before the engine's own stack ran out (unoptimized code, or large frames) kept writing below the stack, over that data, and what happened next depended on what it overwrote: usually a trap, sometimes a wrong call_indirect, and on Bun a loop that never ended (the edge-O0-bun hang in CI). The stack now comes first in linear memory (--stack-first, as the WASI target already does), so an overflow runs below address 0 and traps on its first access, and the instance stops with Stack overflow: the program used all of its 1 MiB C stack (deep recursion?). The Node link driver's edge recordings (both the JSPI and the Asyncify link) were updated to match emcc's link byte for byte.

  • A failing SDK archive decoder is reported as itself. (mutation testing) When the managed Python's decoder for .tar.xz and .zip compiler SDK archives failed, could not start, or was killed, the tar parser's TAR_BAD_ARCHIVE: Unrecognized archive format for the empty stream it left was reported instead of the decoder's exit status and messages. The decoder's own error (SDK archive decoder failed (<code or signal>): <its last messages>, or the spawn error) is reported now.

  • A browser app loads when its server sends application/wasm with parameters. (mutation testing) The loader took WebAssembly's streaming compilation for any Content-Type that began with application/wasm, but WebAssembly.compileStreaming accepts exactly application/wasm, so a server that sent, for example, application/wasm; charset=binary made the app fail to start instead of using the buffered path meant for unusual types. Only an exact application/wasm (any case) streams now.

  • app.send, a port's send and messages queued before Lean's handler reject instead of throwing. (mutation testing) A Lasm.Web.App message or port handler that threw synchronously threw out of send at the JavaScript caller (and, for messages sent before Lean registered its handler, out of Lean's onMessage, leaving the queued messages' promises unsettled). The caller's promise now rejects with the handler's error, and every queued message is delivered.

  • A failing async Lean event handler is reported once. (mutation testing) lasm:web's listeners report a handler's rejected promise to the app; the promise was also handed back to the event target, and Node's EventTarget (edge and server targets) turns a listener's rejected promise into an uncaught exception. The listener now hands back a promise that does not reject.

  • Lasm.Web.Canvas.draw rejects every unknown command. (mutation testing) A command named like an Object method (constructor, toString) was run as one instead of failing with "unknown drawing command".

  • A browser build into public/ leaves nothing behind. (mutation testing) lasm build --target browser --output public/dist was refused, as it should be, but only after its staging directory had been created inside public/, where the next build then found it.

  • lasm build --target workers no longer keeps a generated workers/wrangler.toml once the project has its own. (mutation testing) A project that added wrangler.toml, wrangler.json or wrangler.jsonc at its root after an earlier build still had the earlier generated workers/wrangler.toml when the program had not changed (an unchanged rebuild keeps the output directory as it was). It is now removed, as a build from scratch leaves none.

  • macOS network interfaces report the right hardware (MAC) address. (mutation testing) The Node host read the link-layer address of Std.Net.interfaceAddresses at the wrong offset of macOS's sockaddr_dl (after sdl_alen bytes of the name instead of sdl_nlen), so an interface such as en0 reported bytes of its name and address mixed. It now follows libuv's LLADDR.

  • lasm package says why it refuses more than 65,535 files. (mutation testing) A function package with more entries than a ZIP's 16-bit count holds failed with Node's RangeError about an out-of-range value instead of "Function package has more than 65535 files"; the check now comes before any record is written.

  • Lasm.JS: a string that begins with U+FEFF keeps it. On every target the
    host decoded the strings Lean sends with TextDecoder's default, which drops
    a leading byte order mark, so "\uFEFFtest" reached JavaScript as "test"
    (and Lasm.UI text nodes that began with one lost it). Found by the
    Lasm.JS.Web conformance run (WPT's urlencoded-parser case \uFEFFtest=\uFEFF).

  • Lasm.JS: a value with a length of 2³² or more fails loudly instead of being misread (#154). Every value that crosses between Lean and JavaScript carries its lengths (of strings, byte arrays, arrays, objects) as 32-bit numbers, and neither side checked: Lean (wasm64 on Node, so a 4 GiB ByteArray can exist) and the edge host wrapped the length silently, so the reader took the wrong number of bytes and misread what followed, and Node's host threw a bare RangeError [ERR_OUT_OF_RANGE]. Now each side refuses it with an error naming the value (Lasm.JS: cannot pass a ByteArray of 4294967299 bytes to JavaScript (lengths cross as 32-bit numbers, so at most 4294967295)): an IO.userError for a Lean call, a rejected promise for a Lean callback's result, an error thrown to Lean for a JavaScript result.

  • Lasm.RPC.parseJson (and so every Lasm.RPC request and answer) writes a parsed zero as 0. Lean prints a zero with more than ten decimal places (0e-11, which -0.0e-51 parses to) as 0.e-42, which is not JSON, so an RPC answer that echoed such a number could not be decoded (#135). Other numbers print as before.

  • lasm dev --target browser sees every save. It watched with Node's recursive watcher, which on Linux stops reporting a file once an editor saves it by renaming a new file over it (Vim, JetBrains' safe write, many formatters), so later saves of that file were ignored; it also rebuilt and reloaded the page when a file was only touched. It now watches as lasm dev does for every other target: per directory, rebuilding only when a watched file's content changes, and also for lakefile.toml, lean-toolchain and package.json.

  • lasm dev --target browser exits when it cannot serve. A first build that failed, or a port already in use, printed the error and then never exited. A port in use, a port it may not open and an address the machine does not have now say so and name --port or --host (also for lasm dev --target node,browser).

  • lasm dev no longer crashes while an edge build writes its output. The edge and browser writers stage their output in a *.lasm-staging directory beside it; when lasm dev's watcher saw that directory appear and it was gone before the watch started, Node's ENOENT … watch error ended lasm dev with a stack trace (seen with --target workers). Staging directories are no longer watched, and a directory that vanishes before it is watched is skipped.

  • A stalled tool download reconnects (#152). When a connection stopped carrying data but stayed open (a dropped Wi-Fi link, a half-open proxy tunnel), the idle timer ended the attempt, but on Node 26, whose fetch speaks HTTP/2 to GitHub's release CDN, every retry was sent on the same stalled connection (through an HTTPS proxy: no new tunnel), so the install failed with LASM_CONNECT_TIMEOUT after all its attempts. Each download attempt now has a connection pool of its own, closed when the attempt ends, so a retry always opens a fresh connection and resumes where the last one stopped. The fault-injection suite now requires a build to recover from two stalled connections.

  • lasm dev names a missing per-output source at once. With --target node=Server.lean,browser=Client.lean and no Client.lean, it started, failed to build and kept watching; it now stops with Client.lean not found in …, as for the main source.

  • Function platforms: a decoded path or an unencoded query no longer fails the request. API Gateway REST hands the Lambda handler the path decoded (/a b for /a%20b, /a?b for /a%3Fb), and an ALB the query as the client sent it: a space, a non-ASCII character or # made Node's http.request throw (a 502), and a ? in a decoded path moved part of it into the query. What a request target cannot carry is now percent-encoded as UTF-8 (requestTarget in lasm-server.mjs); a target that is already valid, with its escapes, :// in the path and malformed escapes in the query, is forwarded unchanged.

  • Function platforms: a forged Host no longer reaches the server. The shims forwarded the event's Host to the program's server, and a server that builds the request URL from it (Hono's Node adapter does) could be made to see another path (Host: x/admin# turned GET /public into /admin in Lasm.Fetch before 0.5.1). Every shim now sends exactly one Host: the first that is a plain host[:port], else the loopback address. Empty Cookie fields are no longer forwarded.

  • Lambda and Lambda@Edge: a text body that is not UTF-8 arrives intact. A response with a textual type (text/html; charset=iso-8859-1) whose body is not valid UTF-8 was sent as text, with U+FFFD in place of its accented letters; it now travels as base64, byte for byte.

  • Lambda and Lambda@Edge: a response field named __proto__ or constructor is a field like any other. It was dropped (payload 2.0) or threw a TypeError (API Gateway REST, ALB, CloudFront: a 502).

Changes

  • src/browser/browser-dev.mjs no longer exports parseDevArguments and devUsage, a second parser for lasm dev --target browser that the CLI never used (src/dev.mjs parses lasm dev's arguments). No change in behavior.

  • Lasm.JS: the value codec's reader is total and its round trip is proved. Lasm.JS.Wire.encode now returns Except String ByteArray (a value with a length that does not fit is an error, #154), and the reader is Wire.decodeWith, a total function over any monad that Wire.decode runs in IO (it replaces the partial Wire.read). Programs that use Lasm.JS through its API (call, get, bindings, Function.ofFn, …) are unaffected; the same bytes cross, and a native measurement of the codec shows encoding unchanged and decoding about 25% faster.

  • Lasm.KV.memory names the operations on its table (Lasm.KV.Table.read, write, remove), so its proofs are about the code it runs. No change in behavior.

Documentation

  • What is proved about Lasm's library. library/PROOFS.md lists 53 proved propositions in plain English: Lasm.UI's diff (the DOM always shows the view, over any sequence of frames), its patch encoding (the browser reads every frame back as exactly the patch Lean encoded) and commands, Lasm.RPC's validation, serving, dispatch and client (a handler only ever sees valid requests; an invalid request is never sent), Lasm.KV's memory store, Lasm.Fetch's request paths, Lasm.JS's value codec (every value Lean encodes is read back exactly; lengths never wrap) and a model of the function-platform shims (src/serverless/). Each library's Spec.lean states them, its Theorems.lean proves them, and the page lists the guarantees not yet proved.
  • A public test-evidence page, generated by CI. content/learn/test-evidence.md, published on the Millillion website under Learn (Testing), shows in one place the platform levels, the latest result of each CI tier, the nightly mutation scores against their thresholds, the proof counts of the library and each example app, the fuzz targets and their latest campaign, the DST seeds per night, differential cases and divergences, target equivalence on every platform and the latest benchmarks. Every CI fact carries its date and run link, and is kept apart from the hand-written descriptions. evidence-page.yml regenerates it Monday to Saturday (scripts/evidence/page.mjs), with a machine-readable copy in docs/evidence/test-evidence.json.

Repository

  • Unused code and dependencies removed (no behaviour change). The repository no longer depends on binaryen, @yarnpkg/cli-dist, pnpm or miniflare (about 400 MB less node_modules per checkout and CI job), and the Lean 4.32 lean/ (Lasm.IO) and the unused runtime/host.cpp, core.cpp, stack.cpp and tasks.inc.cpp are deleted. The published @lasm/cli is unchanged.

Testing (no change to how programs build or run)

  • Mutation testing covers every JavaScript module under src/ (TESTING.md, "Mutation testing"); the fixes its new tests found are marked (mutation testing) under Fixes.
  • The browser CI's lasm dev rebuild budget no longer fails on slower GitHub runners (CI only, no change to Lasm). The enforced budget is 2.5 s (was 2 s), the median of seven warm edits (was three), and the evidence names the runner's CPU: AMD EPYC 7763 runners rebuild in 1.8–2.3 s, others in 1.2–1.6 s. See docs/BROWSER.md#budgets-measured-in-ci-recorded-per-release.
  • Folio on every platform it was planned for. The site generator example now runs at the edge: ServerEdge.lean builds the site from the platform's key-value store on every request (Lasm.KV.open), on Fastly (Viceroy with a local KV Store), Cloudflare Workers (wrangler dev with local Workers KV) and Deno Deploy's build (the Deno CLI with Deno KV). Every page served must be byte for byte what folio build writes for the same files, before and after the site in the store changes. The CommonMark specification's 652 examples now run on every target, not only Node: the WASI build on wasmtime, wasmer and node:wasi, the browser build in headless Chromium, Firefox and WebKit, and each edge server over HTTP (folio-platforms.yml, local tooling only).
  • Dependable tooling: lasm dev, more faults, and every CLI error accounted for (TESTING.md). The metamorphic tests drive a lasm dev session per target and profile as an editor would (an edit, a touch, a renamed module, a revert and a second edit saved by rename) and compare each step with clean builds; dev builds whose bytes differ are run and compared on every target, the browser in headless Chromium. Fault injection runs for the node, WASI, Workers and browser targets, and adds stalled downloads, npm install through cut connections and onto a full disk, and lasm dev killed mid-rebuild. The error corpus has about 120 cases, and an inventory of the 148 error messages in the CLI's modules fails CI when a message is neither printed by a case nor explained. Found the three lasm dev fixes above and #152 (a stalled download never reconnects).
  • The UI patch encoding is proved. The browser's reading of Lasm.UI's binary patch frames is written in Lean as a reference decoder, function for function the reading half of lasm:ui-dom (library/Lasm/UI/Proofs/Decode.lean), and Lasm.UI.Spec.frames_decode proves that over any session it reads every frame back as exactly the patch that was encoded, with the interned names, values and event decoder shapes never out of step. The JavaScript applier, the shipped library and the prebuilt library are unchanged; the candidates for moving more JavaScript into Lean are ranked in docs/proposals/JS_TO_LEAN.md.
  • The Lasm.JS value codec is proved. Lasm.JS.Spec.decode_encode: whatever plain value Wire.encode accepts, the reader Wire.decode runs reads back exactly (numbers bit for bit); Lasm.JS.Spec.encode_ok_iff_fits: encode fails exactly when a length does not fit its u32 (library/Lasm/JS/Proofs/Wire.lean). The two JavaScript copies of the codec (Node and edge) stay separate: sharing one module would add a file to every application, edge and toolchain host directory and change the browser bundle (JS_TO_LEAN.md).
  • The function-platform mapping is specified in Lean and the fuzzer checks the shim against it. library/Lasm/Serverless/Proofs/Model.lean is the request and response mapping of src/serverless/ (Lambda's five event kinds, the fields every shim forwards, Azure's and Netlify's replies), function for function; Lasm/Serverless/Spec.lean states 20 propositions about it, all proved (the path a server sees is the event's and no header changes it; exactly one Host, a plain one, which cannot move the path; what URLSearchParams writes decodes to the same pairs; at most one Cookie field, and a payload 2.0 event's cookies once; the body byte for byte; every reply field in each response shape; every cookie object Azure gets arrives unchanged). The serverless-http fuzz target runs the model on every input (lean --run, required in CI) and fails when the JavaScript differs; it found the four function-platform fixes above (JS_TO_LEAN.md). library/PROOFS.md lists 53 propositions.
  • The library's proofs are checked on every library change. node scripts/library-proofs.mjs (CI: library-proofs.yml) checks that every proposition has its theorem of exactly that type, that every theorem in the library uses only Lean's standard axioms, and that library/PROOFS.md is current.
  • CI in four tiers (CI.md): PR, nightly, weekly and release. Pull requests run Linux-first checks filtered by path, and use macOS only when macOS-specific code changes, so they wait less for scarce macOS runners. The unit suite now runs on every pull request. The release suites (browser, edge and Bun/Deno, WASI and Fastly, Lasm.UI, fullstack, the dev loop and the Lasm.JS stress test), which used to run only for a release, now run on main every night. A weekly tier adds 100-minute differential campaigns and a 200-run Lasm.JS soak. The release checks themselves are unchanged.

Example apps

  • Porter keeps the reply of a commit that landed but reported an error (#138). A token request whose commit succeeded and then threw (a lost reply from D1, a timeout after COMMIT) used to run again, find its own code used or its refresh token rotated, answer invalid_grant and revoke the tokens it had just issued: one transient database error signed a user out. Each commit now also inserts a commit receipt (commits (id, at), the id a SHA-256 of the request's random values, the same on a rerun); after a failed commit the server looks it up, and if it is there the first reply stands. If the receipt cannot be read, the version decides as before, but the rerun's commit fails on the receipt's key, so nothing is revoked. Receipts older than a day are deleted in each commit. The table is created on start on SQLite and D1 alike. New proposition Spec.landed_commit_stands (28 propositions, 197 theorems); the deterministic simulation now fails on such a refusal instead of counting it.
  • The example apps build with 0.5.1 and parse untrusted JSON with Lasm.RPC.parseJson (#135). Ledger, Porter, Tandem, Conduit and Folio pin @lasm/cli 0.5.1. Lean's Json.parse computes 10 ^ exponent, so a 90-byte request body hung a server; the apps now use Lasm.RPC.parseJson, which refuses numbers whose exponent has more than four digits: Conduit's request bodies (422), its JWT header (read before the signature is checked; 401), its KV and PostgREST reads and its browser app's answers; Ledger's batches (400), its journal auditor and its page. Each app's test/api.mjs posts the body from #135 and requires an answer within 10 s, on every platform it runs on. Porter reads JSON only from its operator's configuration and keys, Tandem and Folio read none. The pure cores (Conduit/, Ledger/) now import Lasm.RPC.Core, so they are checked with Lasm's Lean (npm run proofs), as their proofs already were.