Skip to content
Get started

Live swap and lifetime

View as Markdown

The moment Minekube Games is built around: someone has an idea while playing and tries it right where they play. A rule changes; the server, the proxy and every player’s connection stay up.

You (alex) and sam play on your dev server; the Minecraft window is yours. sam asks for an aqua score; you change NamedTextColor.GOLD to AQUA in src/game.ts and save. mk dev installs the new bundle, the chat says "[games] Reloaded my-game (5d2e7b18)", nobody is disconnected, and your next score shows in aqua, starting over at 1 because a new revision starts from init.
  • One dev server. Changes go onto the running server, on the same connection you play on. There is no second server to keep in step and no restart for a game change: a save reaches the server you are standing on, and nobody reconnects.
  • Others keep playing. A restart throws everyone out. A swap changes the rules under them; your friend keeps building while the new revision installs.
  • The same move in production. mk deploy rolls a version out to the servers a selector picks, and each swaps it in the same way mk dev does. Planned: at a point the game says is safe, such as the end of a round. See Controlled updates.

A revision is named by the hash of the bundle’s content: Reloaded my-game (5d2e7b18) names the first 8 hex digits of its SHA-256. The runtime reloads only when that hash changes, so a tool that rewrites the same bundle many times a second does not restart your game and announce it to every player. The same name appears in the server’s messages, in each recording’s file name and in the devtools, so a session always says which code it ran.

A broken bundle never replaces a working one

Section titled “A broken bundle never replaces a working one”

The runtime evaluates the new bundle in a fresh context, on a thread of its own, before it touches the running one; only starting it and the swap run on the server thread, so the server keeps ticking while a bundle loads. Performance has the measured stall. If evaluation fails, the old revision keeps running and the server says so: my-game: bundle rejected, keeping the previous revision. A typo while you play costs you a message in chat, not the game.

  • The world does. Blocks and entities belong to the server, so a new revision finds them where the old one left them. Make init idempotent: the launcher example places its sign only if it is not there.
  • The game’s Model does not. A new revision starts with a fresh Model from init. The previous session stays in its recording: the agent scene on Devtools and message logs finds a friend’s points there after a save.
  • What the old revision registered does not. Its scope closes: listeners, tasks, fibers and long-running Commands end. Things it created in the world, such as boss bars or teams, are its own to remove; pair them with their removal in Effect.acquireRelease.

A bug in a running game, such as a Java exception in a Command, fails the component. Left alone, a failed root would stay dead until the next save while its other listeners kept running. Instead the game starts over from init, like a reload, and the runtime reports what failed. A game that fails more than three times in a minute stays off until its next revision, so a crash in init cannot loop on the server thread. Every child component is its own failure boundary: give each player or arena its own child, and one player’s bug does not restart everyone’s round.

The details, with every runtime message, are in Game structure and Devtools and agents.

Was this helpful?