Lasm 0.6.1
A minor release with one small breaking change. Upgrade with npm install -D @lasm/[email protected]; ^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.Webgives 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,cryptoandcrypto.subtle,TextEncoderandTextDecoder,BlobandFile, readable, writable and transform streams, compression streams,AbortController,EventTargetand the events,MessageChannel, timers,queueMicrotask,structuredClone,atobandbtoa,performance,consoleandWebAssembly. They are generated from the specifications' WebIDL, so names and shapes are the standards' own, with Lean types:Promiseresults areAsync, nullable valuesOptions, 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.Webis unchanged.
Improvements
- Lasm.JS reads and writes Symbol-keyed properties.
Value.getandValue.settake a key of any type withToJS, as JavaScript'so[key]does: aString(unchanged), a number (o.get (3 : Nat)), or a SymbolValue(Symbol.iterator,Symbol.for "k"). An array key is its string, as in JavaScript;getFieldsstill takes strings. Source compatible: existing calls compile unchanged. The signatures areget [ToJS κ] (o : Value) (key : κ) …andset [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.Webevent listener, timer, animation frame andqueueMicrotaskcallback, andFunction.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 theplatform-jspisuite. 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:
Asyncloops of any length (#90). A loop inAsync(a recursion,for,List.mapM) of steps that complete at once (synchronous host calls such ascallMethod,bun:sqliteor D1'sprepare(…).bind(…),IOactions,pure) failed after about 2,000 steps on Deno and Workers and 8,000 on Bun withRangeError: 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 deeplyAsync'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; theStd.Async.sleep 0workaround 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
--targetbuilt 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 wrongcall_indirect, and on Bun a loop that never ended (theedge-O0-bunhang 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 withStack 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.xzand.zipcompiler SDK archives failed, could not start, or was killed, the tar parser'sTAR_BAD_ARCHIVE: Unrecognized archive formatfor 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/wasmwith parameters. (mutation testing) The loader took WebAssembly's streaming compilation for anyContent-Typethat began withapplication/wasm, butWebAssembly.compileStreamingaccepts exactlyapplication/wasm, so a server that sent, for example,application/wasm; charset=binarymade the app fail to start instead of using the buffered path meant for unusual types. Only an exactapplication/wasm(any case) streams now.app.send, a port'ssendand messages queued before Lean's handler reject instead of throwing. (mutation testing) ALasm.Web.Appmessage or port handler that threw synchronously threw out ofsendat the JavaScript caller (and, for messages sent before Lean registered its handler, out of Lean'sonMessage, 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'sEventTarget(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.drawrejects every unknown command. (mutation testing) A command named like anObjectmethod (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/distwas refused, as it should be, but only after its staging directory had been created insidepublic/, where the next build then found it.lasm build --target workersno longer keeps a generatedworkers/wrangler.tomlonce the project has its own. (mutation testing) A project that addedwrangler.toml,wrangler.jsonorwrangler.jsoncat its root after an earlier build still had the earlier generatedworkers/wrangler.tomlwhen 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.interfaceAddressesat the wrong offset of macOS'ssockaddr_dl(aftersdl_alenbytes of the name instead ofsdl_nlen), so an interface such asen0reported bytes of its name and address mixed. It now follows libuv'sLLADDR.lasm packagesays 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'sRangeErrorabout 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
ByteArraycan 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 bareRangeError [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)): anIO.userErrorfor 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 everyLasm.RPCrequest and answer) writes a parsed zero as0. Lean prints a zero with more than ten decimal places (0e-11, which-0.0e-51parses to) as0.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 browsersees 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 aslasm devdoes for every other target: per directory, rebuilding only when a watched file's content changes, and also forlakefile.toml,lean-toolchainandpackage.json.lasm dev --target browserexits 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--portor--host(also forlasm dev --target node,browser).lasm devno longer crashes while an edge build writes its output. The edge and browser writers stage their output in a*.lasm-stagingdirectory beside it; when lasm dev's watcher saw that directory appear and it was gone before the watch started, Node'sENOENT … watcherror 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
fetchspeaks 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 withLASM_CONNECT_TIMEOUTafter 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 devnames a missing per-output source at once. With--target node=Server.lean,browser=Client.leanand noClient.lean, it started, failed to build and kept watching; it now stops withClient.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 bfor/a%20b,/a?bfor/a%3Fb), and an ALB the query as the client sent it: a space, a non-ASCII character or#made Node'shttp.requestthrow (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 (requestTargetinlasm-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#turnedGET /publicinto/adminin Lasm.Fetch before 0.5.1). Every shim now sends exactly one Host: the first that is a plainhost[: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__orconstructoris a field like any other. It was dropped (payload 2.0) or threw aTypeError(API Gateway REST, ALB, CloudFront: a 502).
Changes
src/browser/browser-dev.mjsno longer exportsparseDevArgumentsanddevUsage, a second parser forlasm dev --target browserthat the CLI never used (src/dev.mjsparseslasm 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.encodenow returnsExcept String ByteArray(a value with a length that does not fit is an error, #154), and the reader isWire.decodeWith, a total function over any monad thatWire.decoderuns inIO(it replaces thepartialWire.read). Programs that useLasm.JSthrough 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.memorynames 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.leanstates them, itsTheorems.leanproves 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.ymlregenerates it Monday to Saturday (scripts/evidence/page.mjs), with a machine-readable copy indocs/evidence/test-evidence.json.
Repository
- Unused code and dependencies removed (no behaviour change). The repository no longer depends on
binaryen,@yarnpkg/cli-dist,pnpmorminiflare(about 400 MB lessnode_modulesper checkout and CI job), and the Lean 4.32lean/(Lasm.IO) and the unusedruntime/host.cpp,core.cpp,stack.cppandtasks.inc.cppare deleted. The published@lasm/cliis 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 devrebuild 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.leanbuilds 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 whatfolio buildwrites 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 andnode: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 alasm devsession 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 installthrough cut connections and onto a full disk, andlasm devkilled 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 threelasm devfixes 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), andLasm.UI.Spec.frames_decodeproves 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 valueWire.encodeaccepts, the readerWire.decoderuns reads back exactly (numbers bit for bit);Lasm.JS.Spec.encode_ok_iff_fits:encodefails 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; whatURLSearchParamswrites 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
mainevery 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, answerinvalid_grantand 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 propositionSpec.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/cli0.5.1. Lean'sJson.parsecomputes10 ^ exponent, so a 90-byte request body hung a server; the apps now useLasm.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'stest/api.mjsposts 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 importLasm.RPC.Core, so they are checked with Lasm's Lean (npm run proofs), as their proofs already were.