04. Time-Travel, Snapshots & Forking
πͺπΈ Ver este capΓtulo en EspaΓ±ol
A defining capability of openonyx is that the agent's entire state lives in a deterministic EAV graph that can be snapshotted, inspected, replayed offline, rolled back on disk, and forked without mutating the original timeline.
1. Session Vault (.onyx/vault/) & --auto-save
To keep your repository root free of stray .snaps_* folders, fork siblings, and .tr files, openonyx centralizes session storage inside <workspace>/.onyx/vault/:
<workspace>/.onyx/vault/
βββ .gitignore # created automatically with `*`
βββ 20261121-103500_qwen3-coder_main/ # created by --auto-save
β βββ snapshots.onyxpack
β βββ 20261121-103500_qwen3-coder_main.tr
βββ 20261121-103500_qwen3-coder_main.fork-t12/ # branch created by /fork or /rewind
βββ feat-auth/ # --snapshot-dir feat-auth --record chat.tr
β βββ snapshots.onyxpack
β βββ chat.tr
βββ unassigned/ # standalone --record solo.tr (no snapshot-dir)
βββ solo.tr
Routing Rules
--auto-save(orONYX_AUTO_SAVE=1): automatically creates<workspace>/.onyx/vault/<YYYYMMDD-HHMMSS>_<model>[_<branch|goal>]/storing bothsnapshots.onyxpackand<id>.trtogether, showsvault:<id>in the TUI header, and prints the exactopenonyx chat --resume <id>command on exit.- Short names (no
/or\separators):--snapshot-dir feat-authβ.onyx/vault/feat-auth/--snapshot-dir feat-auth --record chat.trβ placeschat.trinside.onyx/vault/feat-auth/chat.tr.--record solo.tr(without--snapshot-dir) β places it in.onyx/vault/unassigned/solo.tr.
- Explicit paths preserved verbatim: any absolute path or path containing
/or\(./my-dir,C:\tmp\snaps,../other) is used as-is. - Transparent lookup on read:
--resume,inspect,rewind,replay, anddoctorcheck literal paths first and automatically resolve short names inside.onyx/vault/(and.onyx/vault/unassigned/for.trfiles). - Automatic Git & tool isolation:
openonyxwrites.onyx/vault/.gitignore(*) automatically sogit statusand/undoGit checkpoints never index vault files, whileWorkspacePolicyhides.onyx/vault/fromfs_list/glob_files/code_searchand protects it as read-only Control Plane.
2. How snapshots.onyxpack & Milestones Work
Whenever snapshot saving is enabled (--auto-save or --snapshot-dir <dir>), MilestoneSnapshotSystem captures snapshots only at meaningful transitions:
initβ initial session state.spawnβ root agent or subagent creation.approval:<tool>β pending mutating tool approval.tool:<tool>/tool_error:<tool>β tool observation or error.cmd:/agent,cmd:/undo,cmd:/rewind,cmd:/fork,cmd:/compact,cmd:/mode ...,cmd:/newβ slash commands.settled,failed,exitβ turn completion or clean exit.periodicβ optional periodic frames when--snapshot-every <n>is passed.
All milestones are stored in a single append-only compressed container <dir>/snapshots.onyxpack (ONYXPK1 frames with zlib compression, canonical ONYXAG\x01\0 graph payloads, and 64-bit FNV-1a checksums):
- Crash tolerance: truncated trailing bytes from interrupted writes are safely ignored on read and healed automatically on the next append.
- Legacy compatibility: older directories containing
tick-*.binfiles remain readable via transparent fallback. - Optional retention: full history is kept by default so every tick stays rewindable; pass
--max-snapshots <n>for opt-in sliding-window retention (keepsinit+ latestn - 1milestones).
3. Inspecting Sessions (openonyx inspect)
Audit any session with zero API keys and zero disk mutations:
# List all milestones: tick, tag, compressed/raw size, FNV-1a checksum, and Git tree_sha
openonyx inspect feat-auth --list
# Machine-readable JSON output
openonyx inspect feat-auth --list --json
# Inspect the latest milestone or a specific tick
openonyx inspect feat-auth
openonyx inspect feat-auth --tick 24
openonyx inspect feat-auth --tick 24 --json
4. Step-by-Step Rollback (/undo)
Before every fs_write or fs_edit in BUILD mode, WorkspaceToolBridge captures a lightweight Git tree checkpoint using a temporary GIT_INDEX_FILE (git add -A + git write-tree):
- Never touches
HEADor your commits. - Never alters your staging index (
git add). - Works even in freshly initialized repositories with an unborn
HEAD.
Running /undo in openonyx chat:
- Marks the latest reversible effect as undone in the EAV graph (
ws.effect.undone). - Restores the exact pre-mutation
tree_shaon disk (restore_git_tree_checkpoint_for_targets). - Safe cleanup of newly created files: if the undone effect was an
fs_writethat created a new untracked file,/undodeletes it cleanly without touching unrelated untracked user files. - Invalidates session caches (
fs_readandscent_outline) so the agent sees the restored file contents.
5. Live In-Session Forking & Rewind (Inside the TUI)
When running chat with --auto-save, --snapshot-dir, or --resume, you can branch and rewind without leaving the TUI or overwriting the original timeline:
/fork [name] β Branch from Current Tick
/fork parser-experiment
# or omit name (creates <dir>.fork-t<tick>):
/fork
- Copies all milestones up to the current tick into a sibling directory inside
.onyx/vault/. - Switches the live
SharedPackStoreto the new branch and updates thevault:<session>badge in the header. - Leaves the original
snapshots.onyxpack100% untouched.
/rewind [tick] β Rewind Live Inside the TUI
# 1. List available milestones with ticks, tags, and Git checkpoints
/rewind
# 2. Rewind to tick 18 (or nearest prior milestone <= 18)
/rewind 18
- Active-work guard: if any agent is busy or an LLM request is in flight,
/rewindrefuses to run until settled. - Non-destructive by default: automatically forks into
<dir>.fork-t18, restores the graph to the target tick, reconciles orphaned disk effects (restoring Git tree + cleaning post-tickfs_writefiles), and prints a summary inMemory & Trace.
6. CLI Time-Travel & Forking
Resume from Latest Milestone
openonyx chat --resume feat-auth
Resume from a Historical Tick into a Safe Fork
# Creates .onyx/vault/feat-auth.fork-t12 and opens the TUI at tick 12 (original preserved)
openonyx chat --resume feat-auth --tick 12
# Specify a custom fork name inside .onyx/vault/
openonyx chat --resume feat-auth --tick 12 --fork-dir feat-auth-alt
# Equivalent via rewind --interactive / --tui
openonyx rewind feat-auth 12 --interactive
openonyx rewind feat-auth 12 --tui --fork-dir feat-auth-alt
Opt-In In-Place Truncation (--truncate-future)
To intentionally overwrite the original pack discarding ticks after <tick> instead of creating a sibling fork:
openonyx chat --resume feat-auth --tick 12 --truncate-future
Headless Rewind with --dry-run & Transcript Replay
# 1. Preview orphaned effects and Git rollback plan without touching disk
openonyx rewind feat-auth 12 --dry-run
# 2. Rewind and replay deterministically from a transcript (0 HTTP calls)
openonyx rewind feat-auth 12 --transcript chat.tr
7. Transcripts & 100% Offline Replay (ONYXTR2)
Recording with --auto-save or --record <file> writes all LLM decisions, structured tool calls (call_id), slash commands (Tab, /mode, /undo, /compact, etc.), and checkpoint markers ([checkpoint:<head>:<tree>]). The time debugger's 0-token primitives are sealed in the transcript as /__onyx_det_* (shell !cmd, /read, /inject, /step, /step-llm, and /graph surgery): replay reproduces them bit-for-bit with 0 I/O and 0 network (no command is re-executed).
# Record a session in the vault
openonyx chat --auto-save
# Replay offline later (0 network calls, 0 API key, 0 disk writes)
openonyx replay 20261121-103500_qwen3-coder_main.tr --snapshot-dir replay-check
8. Health Audit (openonyx doctor)
After a crash, network interruption, or before a delicate rewind, run:
openonyx doctor --snapshot-dir feat-auth --transcript chat.tr
doctor verifies:
- Git worktree health and any stray root
*.tr/snaps*artifacts. - Session vault status (
.onyx/vault/sessions,unassigned/transcripts, and.onyx/vault/.gitignore). snapshots.onyxpackintegrity (ONYXPK1header, FNV-1a checksums,ONYXAGgraph payloads, truncated-tail detection) and legacytick-*.binfiles.- Validity of Git
tree_shaobjects referenced in the side-effect ledger. - Transcript header and parse integrity (
ONYXTR1/ONYXTR2). - Host OS sandbox driver (
bwrap/sandbox-exec/win32-job) and OCI container CLI. sprout.tomlsyntax, acyclic DAG, container runtime, and occupied ports (if present).
9. Web Parity: the Time Debugger in openonyx serve
The embedded PWA has full parity with the TUI time debugger (SDD-07 Phase 4A): the same session state feeds both surfaces, so what you do from the browser affects the live session and vice versa.
- Tick pill: the header shows
#tick-pill(an accessible button). Live it readstick N; under freeze or with the cursor anchored in the past it readsβΈ X/Yand auto-opens the amber Time Debugger bar (you can close it; it reopens on the next freeze). - Amber bar: status (
βΈ TIME FROZEN Β· tick X / present Y/LIVE Β· tick Y), a slider that snaps to the nearest available tick (purged/future ticks are rejected with an actionable notice), β/βΆ buttons,Freeze/Present,Step,Step 1 LLM, andResumeβ the last three go through the sealed command tunnel (/step 1,/step-llm,/go), not the scrub API: the branch is applied in the session with its gates. - Ephemeral API:
POST /api/v1/time/scrub(JSON:action: freeze|unfreeze|return_to_present|scrub_to|scrub_delta) mutates only the debugger's RAM state β 0 disk, 0 bus events β and replies with the updatedtime_debugsnapshot. It inherits the Bearer auth and CSRF guard of every/api/v1/*endpoint (401 without credentials, 403 cross-site, actionable 400 for future/purged ticks or unknown actions). - Plain prompts under freeze:
POST /api/v1/commandanswers409 Conflictwith an actionable message (Paused in TIME FROZEN: use /go to resume or /inject to stage memoryβ¦);/go,/graph β¦,/inject β¦,/read β¦,/step β¦,/step-llm,/timeand!cmdkeep working. - Memory surgery in the UI: with the root agent frozen, each root memory exposes
β(edit via a dialog β flat/graph edit-mem <seq> <text>) andΓ(delete with confirmation β/graph drop-mem <seq>). - Projection preview & revert notice: the Web snapshot carries the full
time_debugblock (frozen,cursor_tick,present_tick,available_ticks,pending_revert_filesfrom the live graph's effects, 0 I/O) and, with--snapshot-dir+ a real LLM target, thebench_hint: a copy-pasteopenonyx bench --snapshot-dir β¦ --tick β¦ --models provider:modelcommand to compare the live model against a deterministic benchmark from the same cursor (SDD-05 Β§9.4 synergy).
Non-goal: Sprout and MCP server effects are external process side effects: TimeFreeze (TUI or Web) does not rewind them.
β 03. Modes, Permissions & OS Sandbox Β· English Index Β· Next: 05. Tools, Scent, Sprout & Skills β