Heuristic:ARCANGEL0 EVA Workspace Snapshot Bounds
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Debugging |
| Last Updated | 2026-10-29 12:00 GMT |
Overview
Cap workspace undo snapshots at 2MB per file, 64MB total workspace, and 8MB per delta to prevent memory exhaustion.
Description
Mitsu's workspace undo system captures snapshots of the working directory to enable per-turn rewinds. To prevent unbounded memory consumption, three hard limits are enforced: each individual file must be under 2MB (`_MAX_FILE_BYTES`), the total snapshot must be under 64MB (`_MAX_WORKSPACE_BYTES`), and the diff (before-images of changed files) must be under 8MB (`_MAX_DELTA_BYTES`). If any limit is exceeded, the snapshot or diff returns `None`, and the undo operation is gracefully skipped for that turn. Sensitive files (private keys, `.env`, credentials) and dangerous directories (`.git`, `.ssh`, `.venv`) are always excluded.
Usage
Apply this heuristic when capturing or diffing workspace snapshots. The bounds are constants — not configurable at runtime. If a snapshot fails (returns `None`), the undo feature is silently disabled for that turn rather than crashing or consuming excessive memory.
The Insight (Rule of Thumb)
- Action: Enforce `_MAX_FILE_BYTES = 2MB`, `_MAX_WORKSPACE_BYTES = 64MB`, `_MAX_DELTA_BYTES = 8MB`.
- Value: Hard-coded constants; not configurable.
- Trade-off: Large workspaces or binary-heavy projects may not support undo, but memory stays bounded.
- Compatibility: Symlinks are never followed. Sensitive files are always skipped.
Reasoning
Workspace snapshots are stored in memory (as `dict[str, bytes]`) and diffs are base64-encoded. Without bounds, a large workspace with binary artifacts, virtual environments, or build outputs could exhaust available RAM. The 2MB per-file limit filters out large binaries and databases. The 64MB total cap bounds peak memory. The 8MB delta cap ensures base64-encoded undo data stays manageable in the session JSON file. Returning `None` on overflow is a safe degradation — the user simply loses undo for that turn.
Code Evidence
Constants from `workspace/undo.py:30-32`:
_MAX_FILE_BYTES = 2 * 1024 * 1024
_MAX_WORKSPACE_BYTES = 64 * 1024 * 1024
_MAX_DELTA_BYTES = 8 * 1024 * 1024
Size enforcement from `workspace/undo.py:72-74`:
if size > _MAX_FILE_BYTES or total + size > _MAX_WORKSPACE_BYTES:
return None
Delta limit from `workspace/undo.py:100-102`:
total += len(old)
if total > _MAX_DELTA_BYTES:
return None
Sensitive file detection from `workspace/undo.py:36-50`:
def _is_sensitive(path: Path) -> bool:
name = path.name.casefold()
return (
name.startswith(".env")
or name in {
"id_rsa", "id_ed25519", "credentials", "credentials.json",
"secrets.json", "tokens.json", "backup-codes.txt", "backup_codes.txt",
}
or name.endswith((".pem", ".key", ".p12", ".pfx"))
)
Skipped directories from `workspace/undo.py:13-29`:
_SKIP_DIRECTORIES = {
".git", ".mitsu", ".aws", ".gnupg", ".pytest_cache", ".ruff_cache",
".secrets", ".ssh", ".tox", ".venv", "__pycache__", "build", "dist",
"node_modules", "venv",
}