Repository navigation
Snapshots Hibernation
Baseline of the engine state snapshots (a tree of points kept in a pool of 1 MiB chunks, with undo, redo, branches, saves and eviction), the boot snapshot cache, and hibernation of the whole conversation to the disk with resume at the next boot.
The system SHALL allocate at boot a snapshot pool of 1024 chunks of 1 MiB, halving the request down to 64 MiB while the arena cannot provide it, and SHALL save the prefilled boot prefix as point #0 (the root) on the branch main.
Source: kernel/src/snap.rs CHUNK, POOL_MIB, goto, init_root; kernel/src/agent.rs init
- WHEN the kernel finishes booting
-
THEN
/treeshows#0labelled "boot prefix" with the namemainand the marker "<- here"
The system SHALL save each finished turn as a new point with the next id, as a child of the node holding the live rows, storing the KV rows from the parent's position to the new position, their token ids and the whole DeltaNet block R, and SHALL make it the current point and the tip of the current branch; a turn that added no tokens is not saved. Source: kernel/src/snap.rs gc, save, restore_root, commit
- WHEN the user asks two questions after boot
-
THEN
/tree alllists#1and#2,#2carries the namemainand is marked "<- here"
The system SHALL keep at most 256 points and 64 names, and SHALL accept a branch or save name only if it is 1 to 16 characters of a-z, 0-9, _ and - and not already used.
Source: kernel/src/snap.rs MAX_NODES, MAX_NAMES, valid_name, branch, save_cmd
-
WHEN the user types
/save My-Point - THEN "usage: /save NAME (1-16 of a-z 0-9 _ -)" is printed and no name is added
The system SHALL, before saving a point, free space until 64 chunks beyond the need are free: first by thinning (R freed, rows kept) the least recently visited unnamed point that is not current and not among the last 16 points of the current history, then by dropping the oldest anonymous leaf off the current history last visited 32 or more turns ago, else the oldest one of any age. Source: kernel/src/snap.rs DROP_AGE, is_leaf, free_slot
-
WHEN a leaf off the current history carries only an unpinned kernel name such as
main@5 - THEN it is a drop candidate like an unnamed leaf
-
WHEN the pool is full of anonymous leaves of
/clearconversations all visited fewer than 32 turns ago - THEN the oldest of them is dropped ("snap: dropped #N" in the kernel log) and the new turn is saved
The system SHALL never thin or drop, during eviction, a point that carries a branch name, a /save name, or a pinned kernel name.
Source: kernel/src/snap.rs thin_candidate, drop_candidate
-
WHEN the user ran
/save keep1on an old point and the pool fills up - THEN that point is neither thinned nor dropped
The system SHALL, when eviction cannot make room, leave the turn unsaved, print "[snap] pool full: this turn is not saved and Ctrl-C would lose it. /drop something or /save less", and show * in the prompt until a point is restored or saved.
Source: kernel/src/snap.rs commit, last_question, prompt, status
- WHEN a turn's save is refused
-
THEN the prompt reads "ringzero[main*]> " and
/snapsays "live state NOT saved (pool full)"
The system SHALL restore a thinned point by copying R from its nearest ancestor that still has one and replaying the stored token ids from there, printing whether the resulting R hash matches the one stored at thinning; Ctrl-C during the replay SHALL keep the previous current point; after a successful replay R is stored again when there is room. Source: kernel/src/snap.rs save, restore
-
WHEN the user runs
/switch #2and#2is thinned - THEN "[snap] #2 was thinned: replaying N tokens from #M" is printed, then "[snap] replay done, R hash matches the stored one"
The system SHALL move /undo [N] back N points (default 1) along the current history and /redo [N] forward N points (default 1) toward the branch tip, and for each point stepped over by an undo whose turn had tool side effects SHALL print "[undo] note: #ID ran ...; the machine keeps it."
Source: kernel/src/snap.rs valid_name, redo; kernel/src/shell.rs run
-
WHEN the user types
/undoat the root, or/redoat the branch tip - THEN "[undo] nothing to undo (at the boot prefix)" or "[redo] nothing to redo (at the tip of BRANCH)" is printed
-
WHEN the last turn called
write_fileand the user types/undo - THEN the current point is the previous one and a note says the machine keeps the write
The system SHALL show the prompt as "ringzero[BRANCH]> ", with "~K" after the branch name when the current point is K steps behind the branch tip and * when the live state is unsaved.
Source: kernel/src/snap.rs last_question, prompt
-
WHEN the user types
/undo 2onmain - THEN the prompt is "ringzero[main~2]> "
The system SHALL, when a turn is committed while the current point is behind the tip, or when the branch moves off its history, give the old tip the kernel name "BRANCH@ID" if no other name points at it, so it stays reachable. Source: kernel/src/snap.rs steps, keep, restore, goto, commit
-
WHEN on
mainat#3the user types/undothen asks a new question -
THEN
/treeshows#3with the namemain@3and the new point is the tip ofmain
The system SHALL provide /branch NAME (a new branch at the current point that becomes current), /save NAME (a save name on the current point, "kept until /drop NAME"), and /switch NAME|#ID or /load NAME|#ID, where a branch name switches branch and a save name or point id moves the current branch there; switching to a kernel-named branch on purpose makes it a user branch that is never dropped.
Source: kernel/src/snap.rs branch, switch; kernel/src/shell.rs run
-
WHEN the user types
/switch nosuch - THEN "[switch] no branch, save or point 'nosuch' (/tree lists them)" is printed
The system SHALL let /drop NAME remove any name except the current branch and then drop every unnamed leaf left unreferenced, and SHALL let /drop #ID remove a point only if it is not the root, not current, not on the current history, has no later points and has no names, printing the MiB freed.
Source: kernel/src/snap.rs free_slot, gc, drop_cmd
-
WHEN the user types
/drop #1while#2is a child of#1 - THEN "[drop] #1 is on the current line, has later points or has names: drop those first" is printed
The system SHALL, on /clear, name the old tip "BRANCH@ID" (unless the tip is the root or already named) and move the current branch and point to the root.
Source: kernel/src/snap.rs commit, new_line; kernel/src/agent.rs reset
-
WHEN the user types
/clearonmainat#4 -
THEN the current point is
#0and#4carries the namemain@4
The system SHALL, when a compaction is committed as point N, add the pinned save name "pre-compact-N" on the point before it and unpin every earlier pre-compact name, so only the latest uncompacted line is protected from eviction. Source: kernel/src/snap.rs commit
- WHEN the second compaction of a session is committed
-
THEN
pre-compact-2is pinned andpre-compact-1becomes evictable
The system SHALL provide /tree (compact tree, inner points of linear runs collapsed to "... N more"), /tree all (every point), /snap (current point, pool use, last save and restore timings, and the state hash when the live state is the saved point), and !set snappool MIB accepting 64 up to the allocated pool size and never set below the chunks in use.
Source: kernel/src/snap.rs drop_cmd, max_mib; kernel/src/shell.rs set_setting, run
-
WHEN the user types
!set snappool 10 - THEN "error: snappool must be 64..N MiB" is printed
The system SHALL write the prefilled boot prefix (token ids, every K/V plane's rows, R) to /var/lib/ringzero/bootsnap.bin with a 48-byte RZBS header keyed by the prefix token ids, the model hash, the engine build hash and the KV geometry, and SHALL load it at the next boot instead of prefilling only when magic, version, key, geometry, size, checksum and token count all match.
Source: kernel/src/snap.rs init_root, load_prefix; kernel/src/agent.rs build_prefix, init
-
WHEN the kernel boots with a different engine build than the one that wrote
/var/lib/ringzero/bootsnap.bin - THEN "boot cache: miss (key differs (model, prefix or engine changed)), prefilling N tokens" is logged and the cache is rewritten
The system SHALL write the hibernation image /var/lib/ringzero/hib/image.bin on /hibernate and on every !poweroff (not on !reboot), SHALL on /hibernate discard delete the image and stop the next poweroffs of this session from writing one until a plain /hibernate, and SHALL on /hibernate status print the image size or "[hib] no image: the next boot starts fresh".
Source: kernel/src/hib.rs SKIP, boot, cmd; kernel/src/sys.rs poweroff, reboot; kernel/src/shell.rs run
-
WHEN the user types
/hibernate discardthen!poweroff - THEN the image is deleted, the log says "hib: poweroff without an image (/hibernate discard)", and the next boot starts a fresh conversation
The hibernation image SHALL hold a 64-byte RZHB version 1 header (key, state hash, sizes, checksum, pool chunk count), the metadata of every non-root point (with its question, answer and side-effect texts) and every name, the KV row chunks of every non-root point, R of the current point only, and the agent settings (temperature, think, constrain, compaction percent and count, color) and transcript.
Source: kernel/src/snap.rs load_prefix, hib_save; kernel/src/hib.rs key, extra
-
WHEN
!poweroffruns while the live state is ahead of the current point - THEN the image holds the current point, not the unsaved live state
The system SHALL at boot resume the image only if magic, version, key (boot snapshot key mixed with "ringzero hibernate v1"), pool chunk count, boot prefix length, sizes and checksum match, restoring tree, names, settings and transcript with every point but the current one thinned, and logging the state hash as "same as saved" or "DIFFERS from the saved one"; else it SHALL start fresh. Source: kernel/src/hib.rs key, apply, save, boot; kernel/src/snap.rs hdr_u, txt; kernel/src/main.rs kmain
-
WHEN the kernel boots with a different model than the one that wrote
/var/lib/ringzero/hib/image.bin - THEN "hib: image /var/lib/ringzero/hib/image.bin not resumed (key differs ...), fresh conversation; /hibernate discard deletes it" is logged
- WHEN the kernel boots with the same model, prefix, engine and pool size
-
THEN "hib: resumed #N on BRANCH (ctx P), K points ... same as saved" is logged and
/treeshows the hibernated tree
The system SHALL delete /var/lib/ringzero/hib/image.bin when writing it fails, and SHALL write nothing when no disk is mounted or the boot has not finished.
Source: kernel/src/hib.rs apply, save
-
WHEN the disk write of the image fails during
/hibernate - THEN the file is removed and "hib: hibernate not saved (...), the next boot starts fresh" is logged
OPEN: the docs state that R is 19.27 MiB (about 20 chunks) per point and KV rows cost about 12 KiB per token; the code takes both from engine constants at run time (CTX_DN_ZERO_BYTES, head dim, KV heads, full-attention layers), so the system SHALL be checked against /snap, which prints "R N KiB per point, N KV rows per MiB chunk", rather than against a fixed number.
Source: kernel/src/snap.rs r_bytes, kv_chunks; docs/SNAPSHOTS_V1_RESULT.md section "Times and memory per point"
-
WHEN the user types
/snapon the shipped Qwen3.5 2B edition - THEN the printed R size per point is compared with 19 728 KiB from the docs
-
/loadis an alias of/switchin code (both call the same function); the help text describes/load NAMEas "go to a saved point" only. Intended behaviour for/load main(a branch name) is not documented. - Resume restores R only for the current point; whether a visit to another point after resume always matches the stored R hash is measured in docs, not checked by code beyond the printed comparison.
Source of this page: openspec/specs/snapshots-hibernation/spec.md
Generated from openspec/specs at 0221909 by tools/wiki_gen.py. Do not edit here: change the spec and regenerate.