ADR-0312:
Stateful Time-Travel App & TUI Workbench
(tenon session)
- Status: Accepted
- Date: 2026-11-28
- Wave / Idea: Wave 4 | Rank 15 | Idea #42
- Related: ADR-0280
(
script-serve), ADR-0301 (tui.a11y), ADR-0302 (tui_lint), ADR-0304 (derive AppSurface), ADR-0305 (app_host), ADR-0306 (app_bus/tenon app)
Context
Agents iterating on interactive Tenon App /
ActionApp programs previously paid a full
compile-and-restart cycle on every UI or reducer tweak: editing
view() or apply() forced a fresh process
launch and manual re-navigation back to the deep state
(rev #5+) under inspection. Meanwhile,
tenon_compiler::interp already executes lowered pure
Core IR in sub-millisecond trap-isolated domains
(script_serve::serve_program) with deterministic JSON
<-> Value marshaling.
Decision
Introduce tenon session [<pkg_or_file>]
(crates/tenon/src/session/) as a persistent JSONL
stdio workbench host over tenon_compiler::interp,
plus six first-class MCP operations (session.start,
session.step, session.render,
session.rewind, session.fork,
session.reload) in tenon-dev-mcp.
1. In-Memory Revision Checkpoints & Branching
- Each branch (default
"main") maintains a bounded ring ofrev 0..Ncheckpoints in RAM (MAX_CHECKPOINTS = 256), an active cursorcursor_rev, and the exact recorded timeline ofEvent/ActionCallsteps fromrev 0. step: executes anEvent(key,paste,resize, or raw event) viaApp.update/stepor anActionCall(action,args_json) viaActionApp.apply/applyin< 1 ms, computes a deterministicBTreeMap-orderedstate_delta, rendersscreen_text,a11y, and deterministiclint_warnings, and appends checkpointrev K+1.render: renders the active cursor (or any retainedrev #K) without advancing state.rewind: movescursor_revto any retainedrev #KinO(1)from RAM checkpoints.fork: clones checkpointrev #Kand its history prefix (0..=K) into a named branchfork_idfor independent speculative exploration.
2. Layout-Hash-Aware Hot Reload
- On load and
reload,compute_layout_hash(program, state_ty)hashes the canonical structural shape of the app's state type (record/union/vec/map structure, field names, and recursively expanded field types — independent of numericLayoutIds) with SHA-256. - Unchanged layout hash
(
mode: "hot_swap"): swaps the compiledir::Programand bindings in memory while keeping all live branch checkpoints (rev 0..N) untouched in RAM, then immediately re-rendersrev #Kthrough the newview()in< 10 mswith zero state loss. - Changed layout hash
(
mode: "replay"): swaps the compiledir::Programand automatically replays each branch's recorded event/action log fromrev 0against the newinit(),step(), andapply()functions.
3. Diagnostics & Sandbox Guarantees
- Pure in-memory execution via
script_serve::serve_programenforcesTrapsdomain isolation (fuel, deadline, heap) and rejects FFI/extern targets fail-closed. - Reserved diagnostic codes:
E1185: session load/compile/FFI refusal error.E1186: invalid JSONL session command or arguments.E1187: invalid branch or revision out of checkpoint range.E1188: interpreter execution or replay failure.E1189: app trapped inside isolated trap domain (prior checkpoint preserved).
4. MCP Surface
(tenon-dev-mcp)
Expose session.start, session.step,
session.render, session.rewind,
session.fork, and session.reload in
ops/session.tn, core/registry.tn, and
core/router.tn following the ops/app.tn
pattern (with strict argument validation, redaction, and effect
gating).
Consequences
- Agents can step, inspect
screen_text+a11y+lint_warnings, rewind in O(1), branch speculatively, and hot-swapview()/apply()edits at deep states without losing state or restarting the app. - Zero changes to
crates/tenon-compiler; zero new Cargo dependencies; 100% deterministicBTreeMapJSON output.