Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: correctness
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: ['3.10', '3.13']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}
- run: python -m pip install .
- run: python -m unittest discover -s tests -v
- run: python demo.py
- run: python benchmark.py --files 20 --size-kib 4 --iterations 3 --json benchmark-results-ci.json
- uses: actions/upload-artifact@v4
with:
name: benchmark-${{ matrix.os }}-${{ matrix.python }}
path: benchmark-results-ci.json
32 changes: 11 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
```
# Python
__pycache__/
*.pyc
*.pyo
*.pyd

# Dependencies
venv/
*.py[cod]
.venv/
venv/
.env
.env.local
*.env.*

# Logs and temp files
*.log
*.tmp

# Editors
.env.*
*.egg-info/
build/
dist/
.pytest_cache/
.coverage
workspace/
*.snapshots/
benchmark-results*.json
.vscode/
.idea/
```node_modules/
.next/
dist/
build/
node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Sarvesh Tamse

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
189 changes: 128 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,157 @@
# Git-for-Agent-Workspaces
# Git for Agent Workspaces

## Sub-Second Filesystem Rollback for AI Agent Workspaces
Verified filesystem checkpoints around agent commands. Maintained by **Sarvesh Tamse**.

**The Dedalus Gap:** Dedalus snapshots the entire VM (RAM + Disk). But if an agent just writes bad code or deletes a config file, rolling back 8GB of RAM takes too long and loses other good work. Enterprises need an "Undo" button just for the agent's workspace.
An agent edits a working project, deletes a configuration file, or leaves a failed
experiment behind. This tool records the workspace **before** the action and
restores that checkpoint if the command exits unsuccessfully.

### What This Project Builds
This is a Python systems prototype with a defined recovery contract and executable
failure tests. It uses content-addressed storage and staged directory replacement.
It does not use OverlayFS or promise a fixed rollback latency.

A lightweight daemon using **overlayfs** that snapshots only the `/workspace` directory before every major agent tool call. If the agent breaks the build, this daemon reverts the filesystem in **<50 milliseconds** without touching the VM's memory state.
## Try it

### The 10/10 Proof
Requires Python 3.10 or newer. No third-party runtime dependencies.

- **Full VM memory snapshot rollback:** ~800ms
- **Workspace-only rollback (this project):** ~40ms

Includes a demo of an agent writing a buggy Python script, failing a test, and the system instantly reverting the file so the LLM can try again.
```bash
git clone https://github.com/sarvesh2003dev/Git-for-Agent-Workspaces.git
cd Git-for-Agent-Workspaces
python demo.py
python -m unittest discover -s tests -v
```

## Architecture
The demo runs a real child process that damages a temporary fixture, observes
failure, restores the pre-action checkpoint, checks the recovered tree, and reruns
the original tests. It is a deterministic scripted agent action, not an LLM call.
It leaves your own files alone.

```
┌─────────────────────────────────────────────────────────┐
│ Agent Workspace │
│ /workspace │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Snapshot Daemon │ │
│ │ (watcher.py) │ │
│ └─────────────────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ ▼ ▼ ▼ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │Snapshot │ │Snapshot │ │Snapshot │ │
│ │ t0 │ │ t1 │ │ t2 │ │
│ │(clean) │ │(pre- │ │(pre- │ │
│ │ │ │ edit) │ │ run) │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────────┘
```
## Use it

## Quick Start
Run these commands from **outside** the workspace directory. The workspace must
be owned by this workflow, with no other processes writing to it.

```bash
# Install dependencies
pip install -r requirements.txt

# Initialize the snapshot system
python init_workspace.py
python workspace_cli.py --workspace ./workspace init
python workspace_cli.py --workspace ./workspace snapshot --label before-edit
python workspace_cli.py --workspace ./workspace list
python workspace_cli.py --workspace ./workspace run -- python action.py
python workspace_cli.py --workspace ./workspace verify SNAPSHOT_ID
python workspace_cli.py --workspace ./workspace restore SNAPSHOT_ID
python workspace_cli.py --workspace ./workspace stats
python workspace_cli.py --workspace ./workspace prune --keep 10
```

# Start the snapshot daemon
python watcher.py &
Put your project and `action.py` inside the workspace before running the action.
The child command runs with that directory as its current directory. A successful
command keeps its changes. A failed command is restored and its original nonzero
exit code is returned. Recovery errors return exit code 2 and print a diagnostic.
An interrupted invocation retains its checkpoint for manual recovery after all
writers have stopped.

# Run the benchmark
python benchmark.py
To install the optional command-line entry point:

# Run the demo
python demo.py
```bash
python -m pip install .
workspace-checkpoint --workspace ./workspace list
```

## Components
The store defaults to a sibling directory, `workspace.snapshots`. Override it
with `--snapshot-dir`; the store and workspace must not contain one another.
All workspace files are included, even ignored files and secrets. Protect the
store with the same access controls as the workspace.

- `snapshot_daemon.py` - Core overlayfs-based snapshot engine
- `watcher.py` - File watcher that triggers snapshots before agent actions
- `benchmark.py` - Performance comparison (VM snapshot vs workspace snapshot)
- `demo.py` - Interactive demo of agent failure and instant rollback
- `init_workspace.py` - Initialize the workspace snapshot infrastructure

## API Usage
## Python API

```python
from snapshot_daemon import WorkspaceSnapshotter
from workspace_cli import run_checkpointed

snap = WorkspaceSnapshotter("./workspace") # must already exist
result = run_checkpointed(snap, ["python", "action.py"])
print(result["snapshot_id"], result["returncode"], result["restored"])

# Explicit checkpoints for another tool integration:
with snap.transaction():
checkpoint = snap.create_snapshot("before-tool")
# Run your foreground tool here; wait for all writes to finish.
# On failure:
snap.rollback(checkpoint)
```

# Initialize
snap = WorkspaceSnapshotter("/workspace")
Use the transaction across checkpoint/action/restore when multiple cooperating
clients share a store. The lock does not stop an unrelated editor or agent.

# Create a snapshot before agent action
snapshot_id = snap.create_snapshot("before_code_edit")
## What is implemented

# Agent does something bad...
- Full SHA-256 content addressing; identical bytes share one stored object.
- Fresh content hashing on every checkpoint, without an mtime-only cache.
- Manifests record files, directory structure (including empty directories), and
basic mode bits and modification times. Snapshot IDs are collision-resistant.
- A cross-process store lock and on-disk manifests avoid stale client inventories.
- Missing or corrupt content fails verification before restoration changes the
workspace.
- A staged tree and recovery journal protect the previous tree during replacement.
- Symlinks, Windows reparse points, and special files are rejected rather than
followed. Workspace/store overlap is rejected.
- Retention removes expired checkpoints and reclaims unreferenced content.

# Rollback instantly (<50ms)
snap.rollback(snapshot_id)
See [the design and failure contract](docs/DESIGN.md) for the limits behind these
statements. See the [tests](tests) for executable evidence.

# Workspace is restored!
## Measure it

```bash
python benchmark.py --files 200 --size-kib 16 --iterations 10 --seed 42 --json benchmark-results.json
```

The benchmark compares measured checkpoint and restore work against an actual
directory-copy baseline on the same seeded fixture. It checks recovered state
for each sample and records raw samples and latency distributions.

There is no simulated VM baseline and no claimed Dedalus speedup. Timing depends
on file count, bytes, storage, OS, cache state, and integrity checks. Snapshotting
reads the full tree; restoration materializes the full checkpoint. Deduplication
reduces stored bytes for repeated content, not the amount of data a restore must
write.

Measured local results, raw samples, and test environments are in
[VALIDATION.md](docs/VALIDATION.md). The content store was slower than the
copy baseline in that experiment and used less retained storage.

## Scope and limits

This is for an **owned, idle filesystem tree** between foreground actions.

- It is not a sandbox or a security boundary against malicious concurrent writers.
- It does not snapshot RAM, running processes, databases, network calls, or external
service state. Restoring files cannot undo those side effects.
- Processes with open files, memory mappings, or working directories inside the
workspace must stop before restoration. The workspace directory is replaced.
- The rename sequence has a brief visibility gap. It is recoverable, not a single
atomic switch for concurrent readers.
- POSIX basic permissions are tracked; Windows permissions are more limited.
Ownership, ACLs, extended attributes, access/creation times, hard-link identity, and sparse
file layout are outside the supported metadata contract.
- Local filesystems only. Network filesystems and sudden power-loss recovery have
not been validated. Keep independent backups of important data.
- Version 1 stores are not silently upgraded. Use a fresh version 2 store after
separately preserving any old snapshots.

The original automatic watcher was removed: filesystem notifications arrive
after changes and cannot establish an exact pre-action boundary. `watcher.py`
now delegates to the explicit CLI; `--daemon` is no longer supported.

## Why this problem

Workspace-level recovery is relevant to persistent computers used by coding
agents. The useful question is whether a tool can provide a trustworthy pre-action
checkpoint with acceptable overhead on a specified workload.

This repository investigates that question. It is not affiliated with Dedalus,
has not been benchmarked on Dedalus Machines, and does not claim to fix a verified
deficiency in their platform.

## License

MIT
[MIT](LICENSE) — Sarvesh Tamse.
Loading
Loading