0321.
Full Capability Trace Record & Deterministic Replay
(--record-caps / --replay-caps)
- Status: Accepted (2026-11-28)
- Date: 2026-11-28
- Plan: M29.2 (builds on ADR-0296)
Context
Tenon's capability-gated CLI runtime (Cli,
Fs, Env, Clock,
Process, Net, Stdin)
already supports in-memory virtualization via
VirtualCaps (ADR-0296) for deterministic
unit testing. However, debugging real-world production or CI
failures in effectful CLI programs still requires reproducing the
exact external environment — command-line arguments, environment
variables, monotonic clock readings, stdin bytes, filesystem
snapshots, subprocess outputs, and network responses.
Developers and AI agents need a built-in, zero-dependency
record-and-replay workflow in tenon interp so any
failing or interesting execution can be captured into a single
deterministic JSON artifact
(--record-caps <file>) and replayed anywhere
offline with zero host OS syscalls
(--replay-caps <file>).
Decision
Deterministic Capability Trace Format (
tenon-cap-trace-1,crates/tenon-compiler/src/interp/cap_trace.rs):- Zero-dependency deterministic JSON serializer
(
CapTrace::to_json) and strict fail-closed parser (CapTrace::from_json). - Schema identifier
"schema": "tenon-cap-trace-1". Unknown top-level or entry fields, duplicate keys, malformed hex, unsupported schemas, or trailing tokens fail closed. - All arbitrary byte buffers (
args,envkeys/values,stdin_hex, filedata_hex, processstdout_hex/stderr_hex, networkresponse_hex) are encoded as lowercase hexadecimal so arbitrary non-UTF-8 bytes, NUL bytes, quotes, and control characters round-trip 100% losslessly and deterministically. - Captures:
args: Vec<Vec<u8>>env: BTreeMap<Vec<u8>, Option<Vec<u8>>>(distinguishing present vs absent lookups)clock_ms: Vec<i64>(ordered sequence of observedclock.now_ms()readings)stdin: Vec<u8>(exact bytes read from stdin)fs_reads: BTreeMap<String, RecordedFsEntry>(file,dir,symlink, orerrorerrno snapshots)proc_runs: Vec<RecordedProcRun>(cmd,args,status,stdout,stderr,os_error)net_connects: Vec<RecordedNetConnect>(addr,response,err_code)
- Zero-dependency deterministic JSON serializer
(
Interpreter Recording & Replay Hooks (
crates/tenon-compiler/src/interp/&driver/interp_run.rs):pub enum CapTraceMode { Off, Record(PathBuf), Replay(PathBuf) }.- Record mode
(
--record-caps <file>): Runs normally against live OS capabilities, records every observedargs,env,clock.now_ms(),stdin,fs(restrict/open/stat/exists/list),process(run/run_input/stream), andnet(connect+read) interaction intoCapTrace, and atomically writes the JSON file (temp file + rename) on exit — including non-zero exits and traps so failing runs remain replayable. - Replay mode
(
--replay-caps <file>): Parses<file>fail-closed (E1255on missing/unreadable/malformed trace), hydratesVirtualCapswithactive = true,capture_stdio = false(so program stdout/stderr still flow to host output), andreplay_strict = true, seeds reader slot 0 with recordedstdin, and executesmainwith zero host OS syscalls. - Clock readings pop chronologically from
clock_queue; exceeding the recorded clock sequence in strict replay mode fails closed withE1256. - Process runs and network connects replay chronologically from
proc_replay_queueandnet_replay_queueso repeated calls to the same command or address with differing outputs reproduce identically.
CLI Interface (
crates/tenon/src/cli/compile.rs):tenon interp [--dev] [--fuel N] [--record-caps <file> | --replay-caps <file>] [path]- Combining
--record-capsand--replay-capsin the same invocation is rejected immediately with diagnosticE1255.
Fail-Closed Diagnostics (
E1255–E1256):E1255: Capability trace I/O, schema, syntax, or flag conflict error (--record-caps/--replay-caps).E1256: Strict capability trace replay overflow (e.g.clock.now_ms()invoked more times than recorded).
Consequences
- Any
tenon interprun can be recorded to a single deterministic JSON file and replayed offline on any machine without touching host files, environment variables, clocks, subprocesses, or network sockets. - Existing
test_capsvirtualization (ADR-0296) remains 100% backward compatible (capture_stdio = true,replay_strict = false). - Zero external crate dependencies and zero runtime overhead
when
CapTraceMode::Off.