Skip to content

feat(git): workspace turn checkpointing via git shadow refs for safe rollback - #635

Open
cagdasyurekli wants to merge 1 commit into
andrewyng:mainfrom
cagdasyurekli:feat/issue-614-workspace-checkpoints
Open

feat(git): workspace turn checkpointing via git shadow refs for safe rollback#635
cagdasyurekli wants to merge 1 commit into
andrewyng:mainfrom
cagdasyurekli:feat/issue-614-workspace-checkpoints

Conversation

@cagdasyurekli

Copy link
Copy Markdown

Resolves #614

Summary

Implements automatic workspace turn checkpointing via lightweight git shadow refs (refs/openworker/checkpoints/<session_id>/<turn_index>) and introduces the revert_turn tool and engine method for safe workspace rollback without polluting git history or HEAD.

Key Changes

  1. Lightweight Shadow Ref Mechanism (coworker/tools/git.py):
    • create_checkpoint(workspace, session_id, turn_index): Uses an isolated temporary index file (GIT_INDEX_FILE=<tmp>) to stage all tracked, modified, and untracked changes (git add -A), write the tree (git write-tree), create a commit (git commit-tree), and point a shadow ref (refs/openworker/checkpoints/<session_id>/<turn_index>) to it. Leaves the repository's real index, HEAD, and working branches untouched.
    • list_checkpoints(workspace, session_id): Enumerates available shadow checkpoint refs.
    • restore_checkpoint(workspace, session_id, turn_index): Restores workspace files to the checkpointed snapshot via git checkout <ref> -- ., and safely prunes newly created untracked files while preserving .git and .gitignored files.
    • revert_turn tool: Registered under git_tools, exposing an interactive or programmatically invokable rollback tool.
  2. TurnEngine Integration (coworker/engine.py):
    • Automatically snapshots the workspace before the first local write tool (write_local_file, replace_file_content, run_shell, apply_patch, etc.) executes in a given turn.
    • Provides engine.revert_turn(turn_index) to rollback the working tree.
  3. Session & Catalog Wiring (coworker/agent.py, coworker/agents/base.py, coworker/catalog.py):
    • Passes session_id to AgentContext and git_tools.
  4. Risk Classification (coworker/risk.py):
    • Classifies revert_turn as RiskClass.WRITE_LOCAL requiring explicit confirmation/approval where applicable.
  5. Comprehensive Tests (tests/test_git_checkpoints.py):
    • Added unit tests covering checkpoint creation, listing, restoration of modified/deleted files, removal of newly created files, preservation of .gitignored files, and engine integration during agent turns.

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.

[Feature Request] Workspace turn checkpointing via lightweight git shadow refs for safe rollback

1 participant