llw-livive-net

Don’t Take No

A planning document for lowering traditionally “impossible” browser and host behavior into a deterministic no_std Rust core.

Premise

The usual answers are:

no_std can't do network
no_std can't do time
no_std can't do JSON
no_std can't do files
no_std can't do a browser

Those are not useful answers. The useful question is:

Where is the seam?

Every one of those has a boundary that can be moved. The goal is not to pretend the platform does not exist. The goal is to make the platform a small, explicit, inspectable input to a deterministic state machine.

Working principles

  1. Time is data, not a syscall.
  2. Events are ordered inputs, not callbacks.
  3. Memory is a fixed budget, not a hidden heap.
  4. Parsing is a bounded transition, not an ambient service.
  5. I/O is a host adapter, not a state-machine dependency.
  6. Every input that affects output is recordable.
  7. Every replay produces the same state and bytes.
  8. “Platform-specific” means “host-owned,” not “outside the model.”

The seams

Traditionally “impossible” Seam What the no_std side owns What the host owns
Wall clock start_time + logical_tick Relative time, elapsed time, scheduling Initial anchor or tick source
Timers Tick-driven event queue Event ordering, due-event dispatch Advancing the clock
Network Transport adapter Request/response state, retries, deadlines Sockets, DNS, TLS
TLS Host termination or virtual device Trust decisions exposed as state Certificates, handshake, entropy
JSON Host reduction or bounded parser Typed scenario/model Raw bytes or reduced fixture
Files Byte buffer or host mount Content state Opened files, paths, mounts
Allocation Fixed buffers or arena Layout, capacity, overflow policy Arena backing memory
DOM Semantic text/event model View state and text projection DOM, CSS, layout, paint
Screenshots/PDF Host projection Snapshot descriptors and state Browser/PDF engine
Browser lifecycle JS hypervisor Guest ABI and state Module loading, memory, events

Time is the first serious test

Timing is an ideal “impossible” claim to attack. A no_std state machine can own time completely if time is represented as:

initial anchor
+ logical timebase
+ tick count
+ ordered events

No Instant, no SystemTime, no hidden clock reads.

Timebase

The clock rate must be configurable. The scenario may use:

1000 Hz  1 ms resolution
  60 Hz  frame-aligned
  10 Hz  coarse scenario steps
   1 Hz  slow state progression

The timebase is part of the scenario input and part of replay metadata.

pub struct Timebase {
    pub ticks_per_second: u32,
}

pub struct Clock {
    pub tick: u64,
}

Use integer arithmetic only:

elapsed_ms = tick * 1000 / ticks_per_second
elapsed_us = tick * 1_000_000 / ticks_per_second

Use u128 intermediates when multiplying. Never accumulate per-tick milliseconds; always derive elapsed from the total tick count.

Events at specific clock cycles

Events are scheduled in logical ticks:

pub struct ScheduledEvent {
    pub at_tick: u64,
    pub sequence: u32,
    pub event: Event,
}

Ordering is always (at_tick, sequence). Events at the same tick are deterministic.

advance_to(target_tick):
    while next_event.at_tick <= target_tick:
        clock.tick = next_event.at_tick
        apply(next_event)
    clock.tick = target_tick

That gives:

Rate choice and quantization

The same canonical event time maps differently across rates:

Event time 1000 Hz 60 Hz 10 Hz 1 Hz
0 ms 0 0 0 0
500 ms 500 30 5 0 or 1
1000 ms 1000 60 10 1
1500 ms 1500 90 15 1 or 2

At coarse rates, not every event time is representable. The scenario must choose and document one policy:

floor  — event happens at or before the requested time
ceil   — event happens at or after the requested time
round  — nearest representable tick

For “no earlier than intended,” use ceil.

tick = ceil(ms * ticks_per_second / 1000)

At 1 Hz:

500 ms  -> tick 1 -> displayed elapsed 1000 ms
1500 ms -> tick 2 -> displayed elapsed 2000 ms

That is not an error; it is an inspectable quantization decision.

Fixed vs changing timebase

Two valid models:

Fixed timebase per scenario

scenario declares 60 Hz
events are authored in ticks
replay is exact

Timebase changes during a run

Use epochs or a canonical elapsed-time accumulator:

epoch 0: 1000 Hz
epoch 1:   60 Hz
epoch 2:   10 Hz

or:

elapsed_us += tick_in_epoch * 1_000_000 / current_hz
current_hz = new_hz
tick_in_epoch = 0

Changing the rate without preserving elapsed time is the only real hazard. Preserve it explicitly.

Timing invariants

Replay envelope

initial_start_time
timebase
rate changes
event schedule
target tick
state hash

A replay is:

clock.tick = initial_tick
for event in schedule where event.at_tick <= target:
    clock.tick = event.at_tick
    apply(event)
clock.tick = target
render(clock, state)

Branching is just replaying a prefix and applying a different suffix.

Browser demo update

The browser demo is the first proving ground.

Current split:

JS hypervisor: load Wasm, read memory, paint screen, drive DevTools
Rust no_std: scenario loop, view rendering, golden comparison, report

Implemented update:

  1. Add configurable timebase: 1000, 60, 10, 1.
  2. Schedule the six views at canonical millisecond offsets.
  3. Convert canonical offsets to view ticks with ceil.
  4. Run all views at the selected timebase.
  5. Report per view:
    • scheduled milliseconds
    • logical tick
    • elapsed milliseconds
  6. Include timebase and duration in the Rust-generated report.
  7. Keep the same golden text output independent of clock rate.

The text snapshots must remain identical across clock rates. Only timing metadata changes.

Acceptance criteria

Status

The first implementation is in the browser demo.

Implemented:

Measured results:

Rate Last tick Last elapsed Text result
1000 Hz 4500 4500 ms 6/6 exact
60 Hz 270 4500 ms 6/6 exact
10 Hz 45 4500 ms 6/6 exact
1 Hz 5 5000 ms 6/6 exact

At 1 Hz, the 4500 ms final view quantizes to tick 5, so elapsed time is 5000 ms. That is the intended ceiling behavior.

The six rendered text snapshots are identical across all four rates. Only the timing metadata changes.

The JS hypervisor now only selects the rate, calls Rust, and reads back the results. Timing, quantization, event placement, and report generation are all in the no_std Rust side.

TTY screen layer

The next layer is implemented as a fixed character-cell screen.

This moves the remaining JS presentation decisions into Rust without introducing DOM, CSS, fonts, pixels, screenshots, or PDF.

The screen state is inspectable through:

selected view
scroll offset
timebase
clock tick
elapsed time
match status
screen text

UI manifest layer

The last application-specific JS constants have moved into Rust.

Rust emits a line-oriented manifest containing:

JS now:

JS no longer contains action IDs, rate values, labels, key bindings, or download filenames.

This leaves the JS side as a platform adapter:

Wasm loading
manifest parsing
DOM control creation
event capture
linear-memory reads
text painting
DevTools buffer rendering

Self-describing contract

The browser demo now queries a Rust-owned machine contract.

lodalite-web-rs/src/contract.rs declares:

The same declarations drive:

The Wasm adapter no longer hand-writes a manifest. It serializes the contract.

The action dispatch also uses the same Action enum that populates the contract, so numeric action IDs are not maintained in two places.

Execution policy and manual

The contract now announces the execution model as well:

The machine also emits a full instruction manual from the same contract. The manual documents:

The browser ingests the manifest and can read manual.txt through the ABI. No external document or host-side contract is required to discover the machine’s shape.

The no_std policy module includes concrete primitives:

Provenance and help

The machine now announces its build and source identity:

build.rs captures these at compile time. The contract fingerprint hashes only the declared machine shape, excluding volatile build data, so a new compiler does not look like a new interface.

The machine also emits two instruction surfaces:

help.txt    short description and usage
manual.txt  full contract, policy, provenance, and replay rules

Both are generated from the same Rust contract. A host can expose --help without maintaining its own copy of the action list or usage text.

Browser startup mode

The default screen is now a text browser shell, not the help path.

The startup shell renders its own borders, title bar, logo, address, action hints, and footer at every screen render.

Current ABI: 16.