Recordings and replay
A bug that a player hit once is hard to reproduce by hand. A Minekube game does not need you to reproduce it: the server recorded the session as data. You copy the recording into your project, and it becomes a test that runs in Bun.
Recordings
Section titled “Recordings”Every revision on the server writes its message log to a recording:
plugins/Minekube/recordings/<game>/<start>-<revision>.ndjson- One file per revision start.
<start>is the time the revision started, and<revision>is the first 8 hex digits of the SHA-256 of its bundle. - One line per entry. The first line is a Wire
Hello. Each following line is one entry of the Effect UIMessageLog: a message with the Model after it and the Commands it issued, a Command that started or ended, a Subscription, a failure. Messages and Models are encoded through the component’s Schemas, so the file is plain JSON. - Each entry carries
tick, the world’s game time when it happened. Clients see the same game time, so a client’s recording lines up with the server’s recording tick for tick. - One instance per start of the game. The component path is
/Minekube/<Name>[0], and[1]after a restart. - The server keeps the newest 50 recordings per game. Older ones are deleted when a new revision starts.
The runtime writes entries once per tick, off the event path. A recording that cannot be written turns itself off and says why in the server log. The game keeps running.
Bundles in a bot client are recorded the same way, to minekube/ in the client’s game directory.
Replays
Section titled “Replays”To turn a session into a test:
- Play the behavior on the dev server, or find the session where a player hit it.
- Copy its file from
plugins/into your project’sMinekube/ recordings/ <game>/ recordings/folder. - Run
bun test.
From then on, bun test replays it through your current rules, message by message:
The test that does it comes with every project:
import { decodeRecording } from "@minekube/games/testing";import { Glob } from "bun";import { describe, expect, test } from "bun:test";import { Effect } from "effect";import { Story } from "effect/ui/testing";import { Round } from "./Round.ts";
// Sessions recorded on the server, copied into recordings/, replay through today's rules.const root = `${import.meta.dir}/..`;describe("recorded sessions", () => { for (const recording of new Glob("recordings/*.ndjson").scanSync(root)) { test(recording, () => Effect.runPromise(Effect.gen(function* () { const log = yield* Effect.promise(() => Bun.file(`${root}/${recording}`).text()); const frames = yield* decodeRecording(log); const replay = Story.fromLog(Round, frames); expect(replay.divergence).toBeUndefined(); }))); }});Story.fromLog starts from the recorded Model, sends each recorded message through today’s update, and compares the Model and the Commands with what was recorded. It never runs Command bodies or Subscriptions, so a replay needs no server.
Read a divergence
Section titled “Read a divergence”- A divergence names the first message whose
updateproduced another Model or other Commands than the recording. If you changed the rule on purpose, record a new session and replace the file. Never edit a recording by hand. - A divergence on an unchanged rule means that
updateread something outside its arguments: the clock, a random number, a global. Move that value into a Command or into the message. - Check that something was replayed. A revision nobody played only has
Mounted.expect(replay.replayed).toBeGreaterThan(0)makes sure the test checked real messages. Story.fromLogreplays the first instance. Pass{ path }for another one, such as the instance after a restart.
What is planned
Section titled “What is planned”Today a recording holds the rules’ side of a session: messages, Models and Commands. The plan is to grow it into a full match record. None of the following exists yet.
| Planned | What it adds |
|---|---|
| A world track | The world stream of a camera next to the message log, on the same tick clock, so a replay shows what players saw. |
| Replay in the browser | A timeline that plays, pauses and scrubs a recorded match in the browser, next to the message log. |
| Checkpoints and seek | Full snapshots at intervals, so a viewer can jump to any tick without replaying from the start. |
| Clips | A shareable range of ticks from a recording, with access that its owner can revoke. |
The design learns from existing replay tools for Minecraft, such as Flashback, ReplayMod, ServerReplay and AdvancedReplay. The difference is that a Minekube recording replays the rules, not only the packets.
Related
Section titled “Related”- Devtools and message logs: read the same log live, with cause chains and Model diffs.
- Test rules with Stories: the Story API that replays use.
Was this helpful?
Thanks for the feedback.