tools/record-replay/ — record/replay harness (plan todo 16)
A deterministic, dependency-free (pure-Python + the frozen ctypes contract) harness that
records frames published to the shared-memory IPC frame contract into a fixture file and
replays them back — into the emitter/shim or any consumer — on a fake clock, with no
wall-clock sleeps. It is the project's top test asset: it lets the emitter/shim be exercised
with no webcam/tracker and reproduces any failure frame-for-frame.
Package vkrr
vkrr/
clock.py FakeClock — monotonic virtual time in microseconds; replay's only time source
buffer.py ContractFrameBuffer — Python mirror of the C triple-buffer publish/read protocol
fixture.py VKRR fixture format: write_fixture / read_fixture + clean truncation/format errors
harness.py Recorder (newest-wins capture) + Replayer (fake-clock replay) + synthetic frames
__main__.py `python -m vkrr` demo: record -> replay -> prove byte-identical, no wall sleeps
The harness builds on tracker/contract.py (the frozen, versioned IPC contract, todo 2): a
recorded frame is the FrameData struct — SkeletonFrame + depth/color buffer descriptors +
frame number + QPC-style timestamp — paired with its publish sequence number.
Fixture format (.vkrr)
Fixed-width, little-endian, self-describing so a truncated or contract-drifted file is rejected cleanly instead of replayed as garbage:
header : magic b"VKRR" | format_version u32 | contract_version u32 | frame_data_size u32 | frame_count u32
record : sequence u64 | frame_data (sizeof(FrameData) bytes) # repeated frame_count times
read_fixture raises TruncatedFixtureError on a short header/record and FixtureFormatError
on bad magic, an unsupported format version, a frame_data_size mismatch (contract drift), or
trailing bytes.
Usage
import vkrr
# record frames published to the contract (newest-wins, like the triple buffer)
buffer, recorder = vkrr.ContractFrameBuffer(), vkrr.Recorder()
buffer.publish(frame_data); recorder.poll(buffer)
recorder.write("session.vkrr")
# replay deterministically into any consumer on a fake clock (no sleeps)
clock = vkrr.FakeClock()
vkrr.Replayer.from_fixture("session.vkrr", clock).replay(lambda seq, frame: consume(frame))
# or back into the frame contract:
vkrr.Replayer.from_fixture("session.vkrr").replay_into(vkrr.ContractFrameBuffer())
Tests
tests/test_record_replay.py (run from the repo root):
.venv/bin/pytest -q tests/test_record_replay.py
It records a synthetic sequence, replays it, asserts byte-identical frames out and monotonic frame numbers, reproduces the exact recorded sequence back into the contract, and asserts a truncated/corrupt fixture errors cleanly.