Commit Graph
3 Commits
Author SHA1 Message Date
Alessandro 5fc8826a41 Add opt-in Time Travel retention and capture controls
Add workspace-relative exclusions and an optional file-size limit, report
skipped files and history storage, and protect excluded files during restore.
Fail incomplete scans and stop queued automatic captures when disabled.

Keep snapshot expiry off by default. When enabled, retain recent snapshots,
the current state and full-tree checkpoint boundaries; replace refs atomically
and reclaim expired objects under the workspace lock. Retry interrupted GC,
stop child processes on maintenance timeout, and preserve workspace inactivity
across compaction. Checkpoints remain restorable but cannot be reverted.

Keep existing saved settings compatible and expose coverage and retention
controls in the plugin UI. Review against relevant frdel history informed
shared ownership and consistent capture/restore filtering.

Validation: 57 focused backend tests in the Docker framework runtime and 5
frontend store tests pass. Live UI checks covered workspace selection, diffs,
Travel, Revert, explicit current inspection, checkpoint actions, and legacy
settings save/reopen. Original settings were restored and disposable QA
project/history removed.
2026-11-12 16:11:15 +01:00
Alessandro 78d3f8d27d Protect Time Travel capture, restores, and cleanup
Treat Git paths literally so unusual filenames cannot expand into excluded files. Reject restores that would change excluded paths, nested Git workspaces, or files through directory symlinks.

Serialize complete workspace operations with reentrant cross-process locks shared by retention. Skip busy or symlinked histories, fail closed when owners cannot be enumerated, and count only successful cleanup.

Verified with 38 focused tests, including cross-process cleanup, concurrent snapshots, exclusion bypasses, and restore safety. Keep test shadow repositories isolated from user history.
2026-11-12 15:35:38 +01:00
King0James0 c42dffa54e feat: Time Travel shadow-repo retention (orphan cleanup, optional age-out, stale-lock repair)
Time Travel keeps a hidden git repository per workspace under
/a0/usr/.time_travel/workspaces/<id>/repo.git and snapshots on every file
change, but ships no retention: nothing deletes a shadow repository when its
chat or project is removed (chat_remove never touches .time_travel), there is
no delete/prune endpoint in the API or web UI, and a workspace whose 'git add'
ever exceeds GIT_TIMEOUT_SECONDS strands repo.git/index.lock, failing every
later snapshot with 'index.lock: File exists'. Observed on a live instance:
518 shadow repositories / 12 GB, most belonging to long-deleted chats, plus a
permanently wedged workspace.

This adds a throttled retention sweep driven from job_loop:

- Orphans: live workspace paths (project folders, the configured workdir,
  per-chat workdirs) are forward-enumerated and hashed with the existing
  workspace_id_for derivation; a shadow directory matching none of them is
  unreachable from the UI forever and is removed after a grace window.
- Optional age-out: retention_max_age_days (default 0 = keep forever) removes
  a live workspace's history when it has had no snapshot in N days. Time
  Travel lazily re-initializes an empty history on the next snapshot, so this
  is always safe for the feature.
- Stale locks: repo.git/index.lock older than retention_stale_lock_minutes is
  removed (git subprocesses are killed at GIT_TIMEOUT_SECONDS, so no
  legitimate lock lives that long), un-wedging future snapshots.
- Corrupt-repo set-asides (repo.git.invalid*) past the grace window.

Deletion is refused for any path outside the shadow root. Settings render in
the existing plugin-config pattern (default_config.yaml + webui/config.html,
settings_sections: agent): enable toggle, sweep interval, age-out days,
orphan grace, stale-lock age. Durable evidence lives next to the workspaces
dir: retention.json (running totals + last sweep stamp) and retention.log
(one JSON line per sweep naming everything removed, tail-capped at 1000).

Sweeps run in a worker thread off the event loop, at most one in flight,
default every 6 hours.

Tests: tests/test_time_travel_retention.py (config defaults/clamps, the full
sweep matrix, keep-forever default, disabled no-op, deletion guard, marker
accrual, per-sweep history + cap, throttle, and workspace_id_for parity).
2026-08-12 14:34:16 +02:00