Skip to content

feat: record workspace changes during each run (#257) - #308

Merged
regnull merged 3 commits into
mainfrom
feat/run-file-changes
Nov 18, 2026
Merged

regnull merged 3 commits into
mainfrom
feat/run-file-changes

Conversation

@regnull

@regnull regnull commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Records which workspace files changed while each run was active, plus the unified diff, without touching the workspace's own .git. The snapshot approach is ported from OpenCode's MIT-licensed snapshot/ service.

Closes #257.

How it works

  • Each workspace gets its own git store at <state dir>/snapshots/<hash of root>.
  • A run captures a tree (git add -A + write-tree) before it starts. When it ends, it captures a second tree and diffs the two.
  • The store keeps its index between captures, so after the first capture git only re-reads files whose size or modification time changed.
  • The terminal status is written first. The after-capture and the diff then run in a background task and are attached to the run when done, so a slow git add never delays or breaks a run's ending.

It is a time window, not attribution

The diff shows what changed while the run was active. Another bot in the same workspace, a person's editor, or a build can change files in that window too, so the UI says "Workspace changes". runs.changes_shared is set when another run was active in an overlapping workspace (the same root, or one inside the other) during the window, and the UI warns that some changes may belong to that other run.

Reliability

  • Every way out of execute() finishes the snapshot, except a run parked on a human. That covers exceptions or cancels at any await and the thread-deleted bail-out. Cancelling a run parked on a human (cancel_run) closes its window too. Without this, a leaked window would flag every later run in that workspace as shared.
  • Before-trees are pinned under refs/runs/<id>, so gc --auto never prunes the tree of a run that waits on a human for weeks. If the diff fails, the columns stay NULL instead of reading as "no changes".
  • Git handling:
    • Each git command has a 120s timeout, and the git process is killed on timeout or cancel.
    • A stale index.lock left by a killed git is removed.
    • init keeps PATH and HOME.
    • Type changes (T, e.g. a file replaced by a symlink) are listed.
    • The stored diff is capped at 200k characters, cut at a line boundary with a marker.

API and UI

  • RunOut carries changed_files and changes_shared. The diff is only on RunDetail (GET /runs/{id}): thread loads list every run, and diffs can be large. RunCard fetches it when "View diff" is opened.
  • Migration 0023 adds runs.changed_files (JSON), runs.diff (Text), and runs.changes_shared (Boolean).

Known limits

  • The workspace repo's own .git/info/exclude does not apply, because git reads info/exclude from the store. .gitignore files and global excludes do apply, and .openbot is always excluded.
  • A nested git repo inside the workspace is recorded as a gitlink, so edits inside it don't show up.
  • Snapshots need a state directory (OPENBOT_ROOT_DIRECTORY). Without one they are off.
  • Before-trees and open windows live in memory, so a restart loses the diffs of runs that were still in progress or parked.
  • There is no revert: bots share workspaces, so rolling back one run would wipe out other bots' edits.

Tests

  • Backend: 884 passed, ruff is clean. tests/test_snapshot.py has 18 tests:
    • store capture, diff, ignore rules and deletions
    • diff truncation
    • overlap windows, including nested roots
    • status written before the diff
    • shared flag when runs overlap
    • window closed when a run parked on a human is cancelled
    • window closed when execute() fails before its try block
    • ref pinning, stale index.lock recovery, and a failed diff giving no diff
  • Frontend: tsc is clean, 442 tests passed, and lint shows one existing warning.

🤖 Generated with Claude Code

@regnull
regnull force-pushed the feat/run-file-changes branch from 28b48d4 to 46670d6 Compare October 19, 2026 11:22
regnull and others added 3 commits November 17, 2026 21:21
Port OpenCode's snapshot approach (MIT-licensed, credit in snapshot.py) to record
which workspace files each run changed and a unified diff, without touching the
workspace's own .git.

- New SnapshotStore (backend/openbot/runtime/snapshot.py): per-workspace
  dedicated git repo under .openbot/snapshots/<hash> — git add -A + write-tree
  before/after each run, diff-tree for changed files + unified diff.
  Concurrent bots share one workspace safely: in-process serialization per store,
  git's own index.lock for cross-process, and .openbot always excluded.
- DB: migration 0023 adds changed_files (JSON) and diff (Text) to runs.
- Runner: _snapshot_capture_before at run start, _snapshot_attach_terminal at
  completion/failure/cancellation; CLI agent path updated too.
- API: RunOut schema exposes changed_files + diff.
- Frontend: RunCard renders a 'Changed' section (file count, filenames, collapsible
  unified diff) when changed_files is non-empty, consistent with existing card style.
- Tests: 7 tests in tests/test_snapshot.py covering store init, capture+diff,
  gitignore/OOB exclusion, no-change empty diff, and full runner wiring with
  actual tool calls.

All values are best-effort: a failed snapshot never blocks the run.
- Label run changes as workspace changes during the run, and flag runs whose
  window overlapped another run in the same workspace (runs.changes_shared).
- Record the terminal status first; the after-capture and diff run in a
  background task so a slow git add never delays or breaks a run's ending.
- Close the window when a run parked on a human is cancelled outside execute().
- Move the diff from RunOut to RunDetail; the UI fetches it when opened.
- Cap stored diffs at 200k chars, run git gc --auto on the store.
- Correct the docstring: the workspace's .git/info/exclude does not apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t robustness

- Open a run's window before its before-capture and close it only after the
  after-capture, so runs that queue on the store lock count as overlapping.
- Nested workspace roots (thread at . and thread at sub/) overlap.
- execute() wraps every exit: an exception or cancel at any await, or the
  thread-deleted bail-out, finishes the snapshot unless the run is parked.
- Pin before-trees under refs/runs/<id> so gc --auto never prunes them;
  a failed diff leaves the columns NULL instead of reading as no changes.
- git: 120s timeout, child killed on timeout/cancel, stale index.lock removed,
  init keeps the environment (PATH/HOME), info/ created, T status counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@regnull
regnull force-pushed the feat/run-file-changes branch from 46670d6 to 2ad980c Compare November 18, 2026 02:34
@regnull regnull changed the title feat: per-run snapshot-based file-change tracking (#257) feat: record workspace changes during each run (#257) Nov 18, 2026
@regnull
regnull marked this pull request as ready for review November 18, 2026 02:38
@regnull
regnull merged commit c174376 into main Nov 18, 2026
4 checks passed
@regnull
regnull deleted the feat/run-file-changes branch November 18, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Record and show each run's file changes

1 participant