.nib guide std nib 0.3.1-pre

The journal, replay and handoff

Every answer the world gives a nib program crosses one seam, so a run can be written down, replayed without the world, and cut in one process to be finished in another.

A nib program reaches the world only by performing an interface operation, and every operation passes through one place in the evaluator. That single choke point is what the journal records, and the reason it needs no syntax: nothing in a program asks to be journalled.

Recording and replaying

$ WHO=ada nibc --run replay.nib --journal-out run.jsonl
hello, ada
greeted ada
$ WHO=bo nibc --run replay.nib --journal-in run.jsonl
hello, ada
greeted ada

The program reads WHO through @Env.Vars.get and prints through @Io.Print.println. On replay, WHO=bo changes nothing: the environment was a reading, and a replay serves readings from the journal without asking the host. Operations fall into three kinds:

  • readings — the host invents the answer (the clock, the environment, a file's bytes, randomness, a secret, a remote effector): recorded, and served from the journal on replay;
  • publications — the answer is fixed (println): performed again on replay, and checked against what was recorded;
  • pure builtins — simply run again.

An operation that reads the world but has no row in that table is refused while recording, so an incomplete journal is never written. Since format revision 5, operations of effectors declared in the program are recorded too, with the call they were made from and the fibre that made it.

The file

The journal is NDJSON. A header line names the program by a SHA-256 of its normalised declarations — a comment or a re-indented line does not change it — the runtime's identity, and the effect count; then one line per effect:

{"journal":"nib-journal","version":5,"program":"790a06f2…","entry":"replay.nib","runtime":"15f24566a233","wire":"","effects":2,"chain":"5b6ec009…"}
{"seq":1,"kind":"effect","op":"Env.Vars.get","effector":"Env.Process","argv":["WHO"],"outcome":{"value":"ada"},"prev":"d4dc1054…","digest":"b098f52c…",…}

The entries form a hash chain, an outcome is a value or a raise ({"error": {"name": …, "args": […]}}), and nibc --inspect-journal prints one. A replay refuses — before or while running, never by guessing — when the journal is another program's, when the run performs something other than the next recorded effect ("replay diverged at FILE:L:C: …"), or when the journal ends early. A refusal is not a raise: no rescue can catch it.

Handoff: cut here, finish there

The machine's continuation is a list of plain data frames, so a run can be captured at an operation boundary and adopted by another process:

$ nibc --run --capture job.frame --capture-after 1 handoff.nib
step 1
accepted — wrote 2747 bytes at job.frame, at operation Io.Print.println
$ nibc --run --adopt job.frame handoff.nib
step 2
step 3
adopted — continuing wire 'W' at operation Io.Print.println; the prefix was answered from the record and no operation before the cut was performed
60

The frame carries code as an AST and authority as interface names: the adopting process's wire decides which effector answers each one, so a frame cannot smuggle a capability. A cell, an effector, a builtin or a symbol can never be written into a frame. For a long-running process, SIGUSR1 publishes a frame to --outbox DIR and a session started with --inbox DIR adopts the newest on SIGUSR2. Nothing records which process owns a frame: adopting one twice performs its effects twice.

Hot swap

Under --run, SIGHUP re-reads the program's files and installs the new revision at the next boundary where the run is a frame, printing installed revision … (or revision unchanged). Effectors keep their state across a swap: a reload is not a restart.

The seam

All of this rests on one design rule, stated in the compiler tree's docs/seam.md as five walls a change may not breach: authority arrives only as an interface bound on a wire, never as a value; an operation's footprint is known when it starts; a cell, effector, builtin or symbol is never written into a frame; native operations are journalled in exactly one place; and a replay decides nothing the journal did not record.