When we tell people that a replay in a deterministic hypervisor is the same run, the first question is always the same: really? Bit for bit? It is a fair question, because it is a strong promise. The short answer is that execution is deterministic on the CPU architecture the run was recorded on, and that you don’t have to take our word for it, because you can check it yourself. This post explains why a recording belongs to its original CPU architecture, what the state of a machine actually consists of, and how TestFlows Machine confirms that a replay reaches the same state, bit for bit, using a small example that boots Linux and prints 256 random bytes from /dev/random.
CPU architecture dependency
A machine runs on a real processor. To make it fast, the hypervisor does not interpret instructions one by one. Instead, the processor executes them directly, and the hypervisor steps in only at the points where the machine needs something from outside, for example, a timer interrupt, a disk request or a read of the clock. Those points, and what came back at each of them, are what a run log records. Everything in between them is the processor’s own work, and that is what makes the recording tied to the processors that do that work exactly the same way.
We can highlight three main reasons that tie a recording to its CPU.
The first is what the machine is told about the processor. When Linux boots, it asks the CPU who it is using the CPUID instruction which reads back the vendor, the family, the model, the stepping and the list of CPU features. It then patches its own code to match it. For example, it picks the fastest implementation of a routine for the features it finds, and it applies the workarounds for any errata (known misbehaviors or quirks) that apply to that exact model. This means that two different processors run different instructions from the very same disk and the very same start. Even though we hide some of what the processor reports, such as its brand string and the instructions that produce random numbers in hardware, things like the family, model and features stay as the processor reports them, because hiding them would change what the kernel does.
The second is how a position in a run is measured. For example, to stop a replay at exactly the point where the recording took an interrupt, Machine needs a count that advances identically every time the same code runs. It uses the processor’s PMC counters for this, together with the instruction pointer and a hash of the registers. How a processor counts, and how far its counter can run past the point it was asked to stop at, is a property of its family. A family that counts differently lands on a different point.
The third is the virtualization path itself. For example, AMD and Intel processors provide virtualization through different hardware interfaces, and the hypervisor code that decides where a run can stop therefore differs between them.
For these reasons, every run carries the CPUID table its machine saw, and Machine refuses to start, fork or replay a run in a session whose processor reports a different table.
The refusal says “This session’s CPU differs from the one the run was recorded on.” and suggests starting the run in a session of its class or recording it again.
Making runs portable between families would take a fixed, named CPU model presented to every machine, the way some hypervisors do for live migration with the proof that the counters of the two families agree. But while we can change software, we can’t control hardware, so until then, the cost is small: on new hardware, the program must be run again, and the new recording replays exactly but will not match a run on the old hardware.
What the state of a machine is
“The state of a machine” sounds like an abstraction, but it is just bits. At any point of a run, it is a finite, concrete sequence of zeros and ones, and we can precisely name every part of it:
- Each vCPU: its general registers and instruction pointer, its segment and control registers, the x87, SSE and AVX registers, the debug registers, the model-specific registers, its local interrupt controller and timer, and any exception or interrupt it has pending.
- The interrupt controllers and timers shared by the vCPUs.
- Every device: the serial ports, the keyboard controller, and all the others.
- Memory: every byte of RAM.
- The disk: every block of it.
If two machines hold the same bits in all of these, they are the same machine state. Nothing else in theory exists that could make them behave differently from that point on.
Confirming the state
There are two ways we confirm a replay.
First, while a replay runs, Machine checks every recorded entry. Each entry carries the instruction pointer, the count and a hash of the registers at the point the recording stopped, and the replay has to arrive at all three. Each entry also carries hashes of the rest of the vCPU state, computed in groups, and each of the devices. If any of them differs, the replay reports a divergence at that entry, and the group that differs says where to look.
Second, hashing all of memory and the whole disk at every entry is expensive, so it is off by default. Instead, at any point, the
machine hashcommand computes every hash of the machine as it stands, memory and disk included, so two machines stopped at the same entry can be compared in full. For debugging,--mem-hashand--disk-hashoncreateorforkmake a run hash memory and the disk at every entry, so that a replay of it compares them at every entry too and finds the first one where they differ.
A small example
Let’s see how Machine boots the kernel, starts Docker, and runs one command using the ubuntu:24.04 Docker container. The command prints a greeting and the date, then reads 256 bytes from /dev/random and prints them in hex. Random numbers here are a good test, as on a normal computer you expect every run to print different bytes.
This is how we built a disk from the image, created a run from it, and ran it until the machine powered off:
1 | $ machine sessions create blog-determinism |
The run took 5.213 seconds of machine time and 33,452 entries, from the first line of the kernel to the reboot. Here is the part of its output where the container runs, with the entries that printed each line:
1 | $ machine output hello-random -n 219:240 |
The first lines of the boot look like this:
1 | ENTRIES SOURCE LINE OUTPUT |
The date is March 1, 2026, three seconds after the machine’s clock started, because a machine’s clock starts at its own base time and advances with what the machine executes, not with the clock on the wall. The complete output of the run, all 275 lines of the console from the kernel’s first message to the reboot, together with the container’s own output stream and the entries of every line, can be found in hello-random.log.
Replaying it
To replay the example, we forked the run at its first checkpoint, which is the very start of the machine, and replayed the branch to the end:
1 | $ machine fork hello-random --from 1 --name hello-random-replay |
In our run, the replay took about 8.5 seconds of real time, and it printed every line of every source again, the same 256 bytes among them. Then we compared the machines themselves, both stopped at entry 33452:
1 | $ machine hash hello-random-replay |
machine hash hello-random printed the same 22 hashes: memory, the disk, the eight devices, the interrupts held for delivery, and the eleven parts of the vCPU. Each hash stands for the bits listed in the previous section, and machine dump shows the bits themselves. Here are the vCPU’s general registers at the last entry of the original run:
1 | $ machine dump hello-random --show regs |
Fun fact, the
0xfee1deadinr15is the magic number Linux passes to itsrebootsystem call, still in the register as the machine powers off.
Let’s now look at something that can be confusing.
Replayable vs repeatable
Replayable and repeatable properties are easy to interpret as meaning the same. However, we say a run is replayable when a replay of its recording reproduces it exactly. A run is repeatable when recording it again, from the same start with the same commands, produces the same recording.
Every run in Machine is replayable but not every run is repeatable, and Machine does not need it to be, because a replay never records anything: it follows the recording it was given.
But in the case of our example run, it is repeatable because its session class records repeatable runs by default, and machine describe indicates this by showing Repeatable: true. To show that it is actually repeatable, we created a second run from the same disk and recorded it from scratch:
1 | $ machine create hello-random-again --disk hello-random |
The new recording also took 5.213108010 seconds of machine time, ended at entry 33452, printed the same 256 bytes and reached the same 22 hashes.
So why don’t all runs repeat? To see why, you need to know one thing about how a machine executes: it runs in dispatches.
A dispatch is a stretch of execution on one vCPU that the processor runs at full speed. At the end of each one, the hypervisor takes control back to handle what the machine asked for, record an entry, accept commands and give the next vCPU its turn. A dispatch ends when the machine needs the hypervisor, for example to read the disk, when a timer is due, or when the vCPU has retired its count budget.
But code that never needs the hypervisor and never advances the count would keep a dispatch running forever. So every dispatch also has a bound in host time, 1 second by default, set with the --dispatch-bound option of create. When it is reached, the hypervisor stops the dispatch wherever it is, and the machine always comes back to answer commands.
Therefore, some recordings made again can differ from the first one for reasons that have nothing to do with the program:
- A stop placed by host time. Where the dispatch bound stops a dispatch depends on how fast the host ran during that second.
- Loops that never advance the count. The counter does not advance in such a loop, so the stop that ends its dispatch is placed by the dispatch bound or hits its stop limit.
- Counter skid. The processor’s counter interrupts some distance past the point it was asked to stop at, and the distance varies.
- A missed stop. A repeatable run interrupts before each count stop and steps from there, but it can still miss the stop, for example when the counter skids too far. The stop then lands later, and the recording still replays.
- A user command.
machine cancel, or Ctrl-C, stops the machine wherever it happens to be at that moment. - A choice drawn without a seed. A fault or a delay given without
--seeddraws a seed and shows it. The recording keeps the seed, so a replay follows it, but a new recording draws another one.
For a repeatable run, machine describe shows how far a new recording would repeat it. The Repeats To: tip message means all of it is repeatable, as is the case for our hello-random example. Otherwise, the line names the first entry that would not repeat and what placed it, such as a host-time stop.
It is important to note that in every one of these cases, the recording is still replayable. This is because each stop is recorded with its instruction pointer, its count and its register hashes, so a replay arrives at the same stop no matter how the recording got there.
Changing the inputs
Another factor is inputs. A replay reproduces a run because it gives the machine the same inputs. Change an input, and the run changes with it. For our example, two inputs matter: the seed of the machine’s random number generator device, and the rate of its clock.
Let’s see what happened when we forked the run at its first checkpoint with another seed and ran the branch to the end:
1 | $ machine fork hello-random --at 1 --name hello-random-seed7 --rng-seed 7 |
The bytes are different, but the date is not. The boot also took a little longer, 5.289 seconds of machine time instead of 5.213.
Then we forked it again with the original seed and doubled the clock rate, from 10 to 20 nanoseconds of machine time:
1 | $ machine fork hello-random --at 1 --name hello-random-rate20 |
The boot took 10.969 seconds of machine time instead of 5.213, and the date moved from 00:00:03 to 00:00:08, as expected. The random bytes changed as well, even though the seed did not.
This is because the Linux random number generator mixes the timing of interrupts and the time stamp counter into its pool, so the machine’s clock is one of its inputs. However, both changes are recorded like everything else: a replay of the hello-random-rate20 branch printed the same output as the branch and reached the exact same 22 hashes.
| Run | Seed | Clock rate | Machine time | Date | First random bytes |
|---|---|---|---|---|---|
hello-random |
0 | 10 | 5.213 s | 00:00:03 | 05 47 34 4b |
hello-random-replay |
0 | 10 | 5.213 s | 00:00:03 | 05 47 34 4b |
hello-random-seed7 |
7 | 10 | 5.289 s | 00:00:03 | f7 7e 81 3f |
hello-random-rate20 |
0 | 20 | 10.969 s | 00:00:08 | 74 b2 99 ab |
When a replay diverges
Of course, our goal is that every recording replays without divergence, every time. A replay that converges on one recording does not prove that the next one will, which is why Machine checks every entry of every replay rather than trusting that it worked.
But just like the announcements you hear on an airplane, in case of unexpected turbulence, if a replay of yours ever reports a divergence, keep the run and its branches, and ping us at support@testflows.com with the session, the run, the entry the replay stopped at, and provide the commands that led to it. We will definitely investigate it. In general, a divergence is either a recording that captured a point the replay cannot reach, or something on the host that interfered with the replay, and we want to know about both so that it doesn’t happen again.
Conclusion
So, is execution really deterministic? On the CPU it was recorded on, yes, literally. The state of a machine is a sequence of bits, the replay reaches the same bits, and machine hash lets you check it yourself, from memory and disk down to each register group of each vCPU.
In this post, we used a machine with a single vCPU. Machines with many vCPUs replay the same way, but that is the subject of the next post. So stay tuned and keep testing!
Don’t forget to try all of this by yourself. Sign up for free and run your own programs deterministically.