Files
aji/docs/spec/11-determinism-and-replay.md
T
dev fb4338cea6 spec: accept RFC 0006 and integrate effects and capabilities
- spec 05 §9-§12: flat effects, checking rule, capability model,
  instantiation by parameter name, lifetime, fallible narrowing,
  intrinsic calls, runtime
- spec 07 §8.9, 07a (cap.narrow, intrinsic, run result), 08 stage
  order, 11 not_instantiated outcome
- new reference/effects.md and reference/capabilities.md (kinds,
  scopes, built-in cap_error)
- features effects and capabilities published
- Q-011, Q-012 resolved
2026-10-04 13:36:46 +03:00

3.2 KiB

11. Determinism, Trace and Replay

1. Interpreter

The reference AIR interpreter defines executable semantic behavior for the language model.

2. Trace

Trace mode may record each AIR instruction and selected abstract-state changes.

Example:

#120 region.create -> r3
#121 region.alloc r3 4096 -> p8
#122 borrow.mut p8 -> b4
#123 store.u32 b4 10
#124 borrow.end b4

3. Deterministic mode

Deterministic execution controls or records sources of nondeterminism including:

  • task scheduling choices;
  • timer progression;
  • clock reads;
  • random inputs;
  • I/O completion ordering;
  • channel wake selection;
  • selected filesystem/network inputs.

4. Replay

A recorded execution should be replayable when program, runtime and replay-format compatibility requirements are met.

aji run --record failure.ajr app.aji
aji replay failure.ajr

5. Concurrency exploration

Test mode may systematically or pseudo-randomly vary scheduling at synchronization points.

Candidate scheduling points include:

  • atomic operations;
  • lock/unlock;
  • channel send/receive;
  • task yield/wake;
  • I/O completion;
  • cancellation observation.

Example:

aji test --interleavings=10000

6. Deterministic selection

When select has multiple ready branches, deterministic mode must choose according to a stable rule and record the decision.

7. Execution limits

Wall-clock time MUST NOT determine whether a run, test or verification terminates or what its outcome is.

7.1 Fuel

A runner MAY bound execution with fuel: the number of AIR instructions executed.

  • Every instruction consumes one unit of fuel when it begins execution, including terminators, assert and call.
  • The instructions executed inside a callee consume fuel separately; a call costs one unit regardless of the callee.
  • If no fuel remains when an instruction is about to begin, execution stops before that instruction and the run ends with the outcome limit_exceeded (spec 07a "Run result"), reporting limit and steps (the number of instructions executed, equal to limit).

Fuel exhaustion is a decision of the execution environment, not behavior of the program:

  • it is not a trap and has no T code;
  • a program's semantics are the same with or without a fuel limit, except that a limited run may end early with limit_exceeded;
  • for a given module, inputs and fuel limit, the outcome is deterministic.

The run outcomes are therefore:

not_instantiated  the environment did not start the program (spec 05 §10.2)
returned          the program finished
trapped           the program failed (T0xxx)
limit_exceeded    the environment stopped the program

Running without a fuel limit is permitted (for example aji run program.air). Conformance, fuzz and stress runs MUST use a fuel limit.

7.2 Concurrent execution (from Phase 3)

With several tasks, fuel is global: the sum of instructions executed by all tasks. Two further, separate budgets apply to scheduling and MUST NOT be conflated with fuel:

Budget Bounds
fuel how long the program may execute
schedule budget how many interleavings schedule exploration examines
quantum how many instructions a task executes before a forced scheduling point