You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agent-time-travel.md
+22-17Lines changed: 22 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,15 @@
4
4
5
5
Agent Time-Travel lets a user review an agent’s coding session and jump back to precise moments in time to intervene by inserting a new chat message. Seeking to a timestamp restores the corresponding filesystem state using filesystem snapshots (FsSnapshots). The feature integrates across CLI, TUI, WebUI, and REST, and builds on the snapshot provider model referenced by other docs (see `docs/fs-snapshots/overview.md`).
6
6
7
+
### Implementation Phasing
8
+
9
+
The initial implementation will focus on supporting regular FsSnapshot on copy-on-write (CoW) Linux filesystems (such as ZFS, Btrfs, and NILFS2), using a session recorder based on Claude Code hooks. An end-to-end prototype will be developed for the entire Agent Time-Travel system, including session recording, timeline navigation, and snapshot/seek/branch operations, to validate the core workflow and user experience. Once this prototype is functional, we will incrementally add support for additional recording and snapshotting mechanisms, including user-space overlay filesystems for macOS and Windows, and advanced recording integrations.
10
+
7
11
### Goals
8
12
9
13
- Enable scrubbing through an agent session with exact visual terminal playback and consistent filesystem state.
10
14
- Allow the user to pause at any moment, inspect the workspace at that time, and create a new SessionBranch with an injected instruction.
11
-
- Provide first-class support for ZFS/Btrfs/NILFS2 where available; offer robust fallbacks on APFS (macOS), VSS (Windows), and non‑CoW Linux.
15
+
- Provide first-class support for ZFS/Btrfs/NILFS2 where available; offer robust fallbacks on non‑CoW Linux, macOS and Windows through file system in user space CoW overlays.
12
16
- Expose a consistent API and UX across WebUI, TUI, and CLI.
13
17
14
18
### Non-Goals
@@ -24,15 +28,15 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
24
28
-**FsSnapshot**: A SessionMoment that has an associated filesystem snapshot reference (snapshot created near‑synchronously with the moment).
25
29
-**SessionFrame**: A visual state at a specific timestamp; the player can seek and render the SessionFrame.
26
30
-**SessionTimeline**: The ordered set of events (logs, SessionMoments, FsSnapshots, resizes) across a session.
27
-
-**SessionBranch**: A new session created from an FsSnapshot’s filesystem state with an injected chat message.
31
+
-**SessionBranch**: A new session created from a SessionMoment and its associated FsSnapshot’s filesystem state with an injected chat message.
28
32
29
33
### Architecture Overview
30
34
31
-
-**Recorder**: Captures terminal output as an asciinema session recording (preferred) or ttyrec; emits SessionMoments at logical boundaries (e.g., per-command).
-**Recorder**: Captures terminal output as an asciinema session recording (preferred) or ttyrec; emits SessionMoments at logical boundaries (e.g., per-command). The initial prototype will use a recorder based on Claude Code hooks.
-**Snapshot Provider Abstraction**: Chooses provider per host (ZFS → Btrfs → NILFS2 → Overlay → copy; FSKit/WinFsp overlays on macOS/Windows). See Provider Matrix below.
38
+
-**SessionTimeline Service (REST)**: Lists FsSnapshots/SessionMoments, seeks, and creates SessionBranches; streams session recording events via SSE.
39
+
-**Players (WebUI/TUI)**: Embed the session recording; render streaming SessionRecordings in real-time and allows seeking to arbitrary SessionFrames; orchestrate SessionBranch actions.
36
40
-**Workspace Manager**: Mounts read-only snapshots for inspection and prepares writable clones/upper layers for SessionBranches.
37
41
38
42
### SessionRecording and SessionTimeline Model
@@ -57,12 +61,12 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
57
61
- Overlay fallback: lower = base tree, upper/work on fast storage (tmpfs or RAM-backed NILFS2/zram/brd) for ephemeral SessionBranches.
58
62
- Copy fallback: `cp --reflink=auto` when possible; otherwise deep copy (last resort).
59
63
- macOS:
60
-
-APFS snapshots: read-only, instantaneous; mountable for inspection. For SessionBranch, create an overlay-style writable workspace using a read-only snapshot as lower with a writable upper (FSKit backend when available) or fast copy-on-write file clones where feasible.
64
+
-User-space overlay: Use FSKit to provide a copy-on-write overlay filesystem for both inspection and SessionBranching, as APFS snapshots are not fast enough for our needs.
61
65
- Windows:
62
-
-VSS shadow copies: read-only snapshots at volume level; expose snapshot content for inspection. For SessionBranch, materialize a writable workspace via differencing VHD(X) layered over the snapshot materialization or by copying-on-write using a WinFsp-backed overlay.
66
+
-User-space overlay: Use WinFsp to provide a copy-on-write overlay filesystem for both inspection and SessionBranching, as VSS snapshots are not fast enough for our needs.
63
67
64
68
-**SessionBranch Semantics**:
65
-
- Writable clones are native on ZFS/Btrfs. On APFS/VSS, SessionBranching is emulated via overlay or virtual disk differencing over the read-only snapshot view.
69
+
- Writable clones are native on ZFS/Btrfs. On macOS and Windows, SessionBranching is implemented via user-space overlay filesystems (FSKit/WinFsp) rather than native snapshotting.
66
70
- SessionBranches are isolated workspaces; original session remains immutable.
67
71
68
72
### User‑Space Filesystem Overlay (macOS and Windows)
@@ -78,6 +82,7 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
78
82
- bash: `trap DEBUG` + `PROMPT_COMMAND` pair to delimit commands.
-**Runtime Integration**: The runner emits session timeline events (SSE) at milestones; the snapshot manager aligns nearest FsSnapshot ≤ timestamp.
85
+
-**Multi‑OS Sync Fence**: When multi‑OS testing is enabled, each execution cycle performs `fs_snapshot_and_sync` on the leader (create FsSnapshot, then fence Mutagen sessions to followers) before invoking `run_everywhere`. See `docs/multi-os-testing.md`.
81
86
-**Advanced (future)**: eBPF capture of PTY I/O and/or FS mutations; rr-based post‑facto reconstruction of session recordings; out of scope for v1 but compatible with this model.
82
87
83
88
### REST API Extensions
@@ -130,7 +135,7 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
130
135
131
136
### WebUI UX
132
137
133
-
-**Player Panel**: Embed `<asciinema-player>` with `poster`, SessionMoments, and a scrubber. Time cursor shows nearest FsSnapshot and label.
138
+
-**Player Panel**: Embed `<asciinema-player>` with SessionMoments and a scrubber. Time cursor shows nearest FsSnapshot and label.
134
139
-**Pause & Intervene**: On pause, surface “Inspect snapshot” and “SessionBranch from here”.
135
140
-**Inspect Snapshot**: Mounts read‑only view; open a lightweight file browser and offer “Open IDE at this point”.
136
141
-**SessionBranch From Here**: Dialog to enter an injected message and name; creates a new session (SessionBranch); link both sessions for side‑by‑side comparison.
@@ -156,17 +161,17 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
156
161
157
162
-**Keystrokes**: If input capture is enabled, redact known password prompts (heuristics based on ECHO off and common prompts). Make input capture opt‑in.
158
163
-**Access Control**: SessionTimeline/seek/SessionBranch require the same permissions as session access; snapshot mounts use least‑privilege read‑only where applicable.
159
-
-**Data Retention**: Separate retention for recordings vs snapshots; defaults minimize data exposure. Encrypt at rest when stored remotely.
164
+
-**Data Retention**: Separate retention for session recordings vs snapshots; defaults minimize data exposure. Encrypt at rest when stored remotely.
160
165
161
166
### Performance, Retention, and Limits
162
167
163
168
-**Snapshot Rate Limits**: Min interval between FsSnapshots; coalesce within a small window (e.g., 250–500 ms) to avoid bursty commands creating many snapshots.
164
169
-**Retention**: Policies by count/age/size. Prune unreferenced checkpoints (e.g., NILFS2) and expired provider snapshots.
165
-
-**Storage**: Cast files compressed; offload to object storage. Mounts are short‑lived and garbage‑collected.
170
+
-**Storage**: Session recording files compressed; offload to object storage. Mounts are short‑lived and garbage‑collected.
166
171
167
172
### Failure Modes and Recovery
168
173
169
-
-**Snapshot Creation Fails**: Create a SessionMoment with `fsSnapshot=false` and reason; continue recording; allow manual retry.
174
+
-**Snapshot Creation Fails**: Create a SessionMoment with `fsSnapshot=false` and reason; continue session recording; allow manual retry.
170
175
-**Seek Failure**: Report provider error and suggest nearest valid FsSnapshot.
171
176
-**Provider Degraded**: Fall back per provider preference, with explicit event logged to the session timeline.
172
177
@@ -175,14 +180,14 @@ Agent Time-Travel lets a user review an agent’s coding session and jump back t
175
180
-**ZFS**: Snapshots and clones — ideal for FsSnapshots and SessionBranches.
176
181
-**Btrfs**: Subvolume snapshots — ideal for FsSnapshots and SessionBranches.
177
182
-**NILFS2**: Continuous checkpoints; promote to snapshots; mount via `cp=<cno>`; SessionBranch via overlay.
178
-
-**APFS**: Read‑only snapshots; SessionBranch via overlay or file clones (no native writable clone of snapshot).
179
-
-**VSS**: Read‑only shadow copies; SessionBranch via differencing VHD/overlay.
183
+
-**APFS**: Not targeted; APFS snapshots are not fast enough for our needs. Use FSKit overlay instead.
184
+
-**VSS**: Not targeted; VSS snapshots are not fast enough for our needs. Use WinFsp overlay instead.
180
185
-**Overlay/Copy**: Universal fallbacks when CoW is unavailable.
181
186
182
187
### Open Issues and Future Work
183
188
184
189
- eBPF PTY and FS hooks for automatic, runner‑independent capture.
185
-
- rr‑based post‑facto reconstruction of casts and fine‑grained FsSnapshots.
190
+
- rr‑based post‑facto reconstruction of session recordings and fine‑grained FsSnapshots.
186
191
- IPBT integration for advanced session timeline browsing on ttyrec recordings.
187
192
- FSKit backend maturation on macOS for robust overlay SessionBranching without kexts.
188
193
- Windows containers integration to provide stronger per‑session isolation when SessionBranching.
## Multi‑OS Testing — Leader/Followers, Sync, and run_everywhere
2
+
3
+
### Summary
4
+
5
+
Enable agents to validate builds and tests across multiple operating systems in parallel with a simple, reliable flow:
6
+
7
+
- The Linux host acts as the leader workspace (preferred for CoW FsSnapshots and orchestration).
8
+
- One or more follower workspaces (macOS, Windows, Linux) mirror the leader via Mutagen high‑speed file sync.
9
+
- Each execution cycle fences the filesystem state (FsSnapshot + sync) and then invokes project‑defined commands everywhere via `run_everywhere`.
10
+
11
+
### Goals
12
+
13
+
- Deterministic, low‑latency propagation of file changes from leader to followers.
14
+
- Atomic test execution view based on a consistent leader FsSnapshot.
15
+
- Simple project integration via a single `run_everywhere` entrypoint and tagging.
16
+
- Minimal OS‑specific logic inside agents; orchestration handled by the runner.
17
+
- Avoid the complexity of filesystem snapshots on followers. The snapshots of the leader are sufficient to restore any filesystem state on the followers as well.
18
+
19
+
### Terminology
20
+
21
+
-**Leader**: The primary workspace on Linux (snapshot‑enabled when possible).
22
+
-**Followers**: Secondary workspaces on other OSes, receiving file updates via Mutagen.
23
+
-**Sync Fence**: An explicit operation ensuring all follower file trees match the leader FsSnapshot before execution.
24
+
-**run_everywhere**: Project command that runs an action (e.g., build/test) on selected hosts and returns output of the command execution to the agent running on the leader.
25
+
26
+
### Architecture
27
+
28
+
1) Workspace Topology
29
+
- Leader path (e.g., `/workspaces/proj`) is the source of truth.
30
+
- Mutagen sessions map leader→follower working directories with optimized ignores.
31
+
- Followers are prepared using container/VM/native shells; Windows may still use the `S:` drive mapping even when not using the WinFsp overlay (which is not required in a follower configuration).
32
+
33
+
2) Execution Cycle
34
+
- Agent edits files on the leader.
35
+
- Runner executes `fs_snapshot_and_sync`:
36
+
- Create a leader FsSnapshot (native CoW when available; FSKit/WinFsp overlay fallback otherwise).
37
+
- Issue a sync fence: wait until Mutagen confirms followers are in sync with the leader snapshot content.
38
+
- The agent is instructed to invoke `run_everywhere` with appropriate selectors in the agent instructions inserted automatically by agents-workflow.
39
+
40
+
3) Selectors
41
+
-`--host <name>`: run on a single follower by host name.
42
+
-`--tag <tag>`: run on all followers tagged with `<tag>` (e.g., `os=windows`, `gpu=nvidia`).
43
+
By default, the supplied command is executed on all configured followers (the default).
44
+
45
+
### Snapshot Strategy
46
+
47
+
- Leader on CoW FS (ZFS/Btrfs/NILFS2):
48
+
- Only the leader creates FsSnapshots; followers rely on sync fence to reflect that exact state.
49
+
- Leader without CoW (Windows‑only/macos‑only projects):
50
+
- Use user‑space overlay (FSKit/WinFsp) for the leader to provide efficient CoW behavior.
51
+
- Followers still rely on sync fence; no follower snapshots required.
52
+
53
+
### Mutagen Integration
54
+
55
+
- Use Mutagen to establish persistent, resilient sync sessions (bidirectional disabled; leader→followers only).
56
+
- Sync ignores: `node_modules`, `.venv`, `target`, `build`, large caches unless explicitly needed; per‑project config via `.agents/mutagen.yml`.
57
+
- Sync fence API: wait for `watchState == consistent` across all selected followers with a timeout and backoff.
58
+
59
+
### Project Contract: run_everywhere
60
+
61
+
The `run_everywhere` command is available in the dev environment of the project as part of the agent-workflow suite (which is pre-installed in the base docker images provided by agents-workflow (see `devcontainer-design.md`)):
62
+
63
+
- Parameter parsing for `--host`, `--tag`, `--all`, and pass‑through of the command/action (e.g., `build`, `test`, `lint`).
0 commit comments