Skip to content

live --record-trace / --replay-trace: a session recorded and replayed exactly (Phase 5b, R49) - #184

Merged
transfix merged 1 commit into
mainfrom
feat/live-trace
Nov 15, 2026
Merged

transfix merged 1 commit into
mainfrom
feat/live-trace

Conversation

@transfix

Copy link
Copy Markdown
Contributor

This is Phase 5b of the plan: Laboratory R49, the live/replay harness. It records a live session's inputs and replays them exactly, built on libcvc's input trace (cvc.input_trace/v1, transfix/libcvc#1168, which is merged). That trace support isn't in a released pycvc yet, so CI's 3.7.13 skips the trace tests. They pass against a build of libcvc master.

grl-snam ariadne live austin-freedrive --plant kinematic --arms trained,untrained,constant --record-trace s.trace
grl-snam ariadne live austin-freedrive --replay-trace s.trace
grl-snam ariadne live austin-freedrive --replay-trace s.trace --arms trained=other.cvcnav,untrained,constant

Recording (grl_snam/ariadne/_trace.py, Recorder)

  • The clock: the session steps on the app's world_clock (0.01 s quantum, the navigator every 5 quanta), not live's own pacer. Every input therefore carries the tick that consumed it.
  • The header: it describes the first arm's world (nav_trace_header: the maps, the starts and goals, the policies' sha256). Its meta holds the arms (spec and .cvcnav sha256), the seed, the start, the goal, the plant, the frame and the GRL-SNAM build.
  • Settings: writes to the nav, nav_plant, run and world keys are recorded as they land. sim_world's own telemetry (e.g. nav.tick) is skipped.
  • Retarget: a Retarget is nav's own nav.retarget event. It goes through nav_trace_retarget on the first arm's world, and the same retarget is applied to the others. The UI's retarget is applied at the start of a frame, before the clock moves.
  • The hash: the state's hash is checked after each frame.
    • With one arm it is that arm's own nav_trace_state_hash, so libcvc's headless replay (cvc trace verify) replays a one-arm trace by itself (tested).
    • With several arms it is the sha256 of every arm's hash.
  • Without --arms, --record-trace records one arm, the trained policy, which live --arms: policies side by side, with Stats and Ledger windows (Laboratory Phase 5) #175 showed is the single-policy run tick for tick.

Replaying (Player)

  • What it does: it rebuilds the worlds from the trace, puts the clock in replay mode, writes the recorded sets at their ticks, sends nav's events to every arm's world, and compares every hash.
  • Headless: it runs to the end and prints whether the replay matches or the tick where it departs. It exits 1 if the recorded policies depart.
  • --arms: it runs other policies on the same inputs, reports where they depart, and exits 0.
  • Seeking: run_arms keeps its worlds in a holder that a seek back rebuilds. sim_world has no save and restore, so a seek back re-simulates from tick 0.
  • In a window: a Trace window in live.ari shows the hashes compared, with a Position slider and Restart. The Retarget controls are hidden in a replay.

v1 covers the kinematic plant. libcvc refuses to describe a world on a vehicle plant, because Jolt is deterministic only within one binary.

Tests: tests/test_lab_acceptance.py (the Laboratory's §9)

  • Test 5: one Retarget moves every arm's goal on the same tick, and the Stats rows differ.
  • Test 6, the inputs: the trace holds exactly one nav.retarget and one nav.vehicle.vmax set: the button press, and a slider write mid-run.
  • Test 6, exact replay: three arms replay with byte-identical poses, goals, telemetry and books, and the replay matches every hash, the end's included.
  • Test 6, libcvc's own replay: a one-arm session replays under nav_trace_replay with every hash matched.
  • Seeking: forward to 60 %, back to 20 % (re-simulated from tick 0), then to the end. Everything still matches, and the last pass is the recording byte for byte.
  • Test 6, two policy builds: two nets differ only in a hidden unit gated on the goal distance. The gate makes the unit exactly 0 until near the goal, because the C++ SiLU underflows below about -89.
    • The coefficients first differ at step 152 of 300 (7.65 s).
    • The poses match byte for byte until then, and first differ at step 289.
    • The replay reports departing at tick 1430 (step 286).

Results

  • On a build of libcvc master (31dd2270, with pycvc and pycvc_gl): the acceptance tests give 9 passed. With GL, the acceptance, arms, scrub, ports and runlog tests give 64 passed and 3 skipped.
  • cvc trace info reads the one-arm trace: a complete cvc.nav.sim_world/v1 world, 450 checks and an end hash; the trace is 49 KB.
  • On the catalog 3.7.13 closure (CI's): 156 passed and 12 skipped. The trace tests skip, and the refusal test checks that the flags say what they need.
  • black 26.5.1 and ruff 0.16 are clean.

… exactly (Phase 5b, R49)

On libcvc's input trace (cvc.input_trace/v1, transfix/libcvc#1168).

- grl_snam/ariadne/_trace.py: Recorder (the app's world_clock at 0.01 s, the navigator every 5
  quanta; the header describes the first arm's world with the arms, seed, start, goal, plant
  and frame in its meta; writes to nav/nav_plant/run/world recorded as they land, sim_world's
  own telemetry skipped; a Retarget is nav's own nav.retarget; the state's hash each frame) and
  Player (the clock in replay mode, the sets at their ticks, nav's events to every arm's world,
  every hash compared). The hash is the arm's own for one arm, so libcvc's headless replay
  (cvc trace verify) replays a one-arm trace; over every arm's world for several.
- live: --record-trace (without --arms: one arm, the trained policy) and --replay-trace
  (the recorded arms, or --arms: other policies on the same inputs). run_arms keeps its worlds
  in a holder that a seek back rebuilds (sim_world has no restore: from tick 0 again). Headless
  replay runs to the end and exits 1 when the recorded policies depart; a window has a Trace
  window with a Position slider and Restart. v1: the kinematic plant.
- tests/test_lab_acceptance.py: the Laboratory's §9 tests 5 and 6: one retarget for every arm
  with distinct Stats rows; exact replay (byte-identical poses, the same final hash); a one-arm
  trace in libcvc's own replay; seeking back; two policy builds matching until the first tick
  their coefficients differ. The trace tests skip on a pycvc without input traces (3.7.13).
@transfix
transfix merged commit 215eee2 into main Nov 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant