Pause anywhere

OpenCode's new bytecode VM for codemode can stop a running program, save it as bytes, and carry on later.

codemode lets a model write a short program instead of calling tools one at a time. By default those programs run on a tree-walking interpreter: fine for a few tool calls, but once a run starts, it's a fiber you can only wait on or kill.

The new engine compiles each program to bytecode and runs it on a small stack machine. Every bit of its state (frames, registers, heap, pending promises) lives in plain objects it owns, so it can be suspended: written out as bytes and resumed later, in this process or another one.

Here's one running. Pause it and the listing shows the exact expression the machine stopped at. Step it one instruction at a time, and each step is the real thing: the bytes are loaded into a fresh VM, it runs one instruction, and it's saved again.

Many futures

A pause is a value

The bytes are the whole program. Nothing in them points back at the page that made them, so you can resume the same bytes more than once. If the program asks for randomness, each copy gets its own.

Below, a garden is growing. Pause it, and its one snapshot becomes nine gardens that share a past and nothing after it. Pick the future you like and keep going from there.

Anywhere

Teleporting a running program

Bytes travel anywhere a message can. Every tab with this page open joins the same BroadcastChannel, and the tabs keep track of each other. There's only one program between them. Drag it onto another tab: this one suspends it, posts the bytes, and lets go once the other tab says it has resumed them. The trail is in the program's variables, so it arrives intact, mid-curve. No second tab? The small page in the frame is a separate document with its own VM, on the same channel.

That's the whole trick: a running program is just data. You can keep it, copy it, send it somewhere, and pick it up again.