Skip to content

feat(git): Ephemeral Git Worktree Sandboxing for Zero-Pollution Contract Execution #15

Description

@sdageltc

Summary & Motivation

When an autonomous agent attempts a complex code task, it may modify multiple files, generate syntax errors, or fail verification checks. If the task fails or requires multiple divergent retries, leftover uncommitted changes or broken diffs in the working tree can pollute subsequent attempts or corrupt the user's active branch.

We want to introduce Ephemeral Git Worktree Sandboxing: running each contract execution attempt in an isolated, temporary Git worktree (.letitloop/worktrees/<task_id>_<attempt>) that is automatically cleanly merged to the main branch upon passing verification, or pruned on failure.


Architectural Proposal

  1. WorktreeSandbox Manager (orchestrator/worktree_sandbox.py):
    • Creates an isolated branch and worktree directory: git worktree add -b letitloop/<task_id>_<attempt> <worktree_path> HEAD.
    • Executes the worker adapter strictly inside <worktree_path>.
    • Runs deterministic verifiers (test_command, linter, static analysis) inside the worktree.
  2. Atomic Merge on Success:
    • If verification and QC review pass (PASS), merge the worktree branch into the base branch using fast-forward or squash merge.
    • If verification fails (FAIL), prune the worktree: git worktree remove --force <worktree_path> and discard the scratch branch.
  3. Zero Host Branch Contamination:
    • Ensures the developer's live workspace remains 100% pristine and compiling at all times.

Key Files & Areas

  • orchestrator/worktree_sandbox.py: New worktree lifecycle manager.
  • orchestrator/supervisor.py: Wrap _execute_single_contract with worktree isolation.
  • orchestrator/cli.py: Add --worktree flag to lil run and lil resume.
  • tests/test_worktree_sandbox.py: Unit and integration tests.

Acceptance Criteria

  • Worker modifications occur strictly within the ephemeral worktree directory.
  • Failed attempts leave 0 residual uncommitted files in the main repository.
  • Successful attempts merge cleanly into the target branch without conflicts.
  • Pruning cleans up both the worktree folder and the local git branch reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureCore control loop and system architectureenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions