Skip to content

feat: add isolated worktree execution for apply subagents (#182)#184

Merged
skr19930617 merged 1 commit into
mainfrom
apply-worktree-isolation
Apr 23, 2026
Merged

feat: add isolated worktree execution for apply subagents (#182)#184
skr19930617 merged 1 commit into
mainfrom
apply-worktree-isolation

Conversation

@skr19930617

Copy link
Copy Markdown
Owner

Summary

  • Introduce an optional isolated-worktree execution mode for /specflow.apply subagent-dispatched bundles. Dispatched subagents now run in ephemeral git worktrees at .specflow/worktrees/<run-id>/<bundle-id>/; the main agent remains the sole workflow-state mutator.
  • Add main-agent integration authority: inspect the worktree diff, cross-check against produced_artifacts, reject on undeclared_path / protected_path / empty_diff_on_success / patch_apply_failure, and import accepted patches via git apply --binary --index.
  • Extend task-planner status enum with subagent_failed and integration_rejected; add --allow-reset flag to specflow-advance-bundle for /specflow.fix_apply recovery paths. Retention policy: remove worktree on done, retain on failure.
  • Materialize main-workspace state (tracked + untracked) into each new worktree so later bundles in the same apply run observe earlier imports. Fail-fast on git worktree add failure — no silent fallback to inline execution.
  • Documentation: new docs/apply-worktree-recovery.md operator playbook covering diagnosis and recovery for both failure modes.

Issue

Closes #182

Introduce apply-worktree-isolation: dispatched subagent bundles now run
inside ephemeral git worktrees under .specflow/worktrees/<run>/<bundle>/.
The main agent remains the sole workflow-state mutator and gains the
integration authority role — inspecting each subagent's worktree diff,
cross-checking against produced_artifacts, and importing accepted patches
via git apply --binary --index. Integration rejects on undeclared paths,
protected-path touches (task-graph.json / tasks.md / .specflow/**),
empty-diff-on-success, or patch-apply failure; rejected bundles land in
the new integration_rejected status with their worktree retained for
/specflow.fix_apply. Subagent failures land in the new subagent_failed
status with the same retention. Workspace state (tracked + untracked) is
materialized into each new worktree so later bundles observe earlier
bundle imports. Fail-fast on worktree-add errors, no silent fallback to
inline execution.

- task-planner status enum extended to 6 values; --allow-reset gates
  reset transitions to pending from the new failure statuses.
- assignExecutionMode derives mode solely from the existing subagent-
  eligibility rule (no subagent-shared mode).
- Full git-apply coverage: creates, deletes, modifies, mode changes,
  renames, binary content (git diff --binary --find-renames +
  git apply --binary --index).
- Documentation: docs/apply-worktree-recovery.md operator playbook.
- 921/921 tests pass including 5 real-git integration tests that spawn
  actual git against temp repos.

Issue: #182
@skr19930617 skr19930617 merged commit 2e07b6a into main Apr 23, 2026
4 checks passed
@skr19930617 skr19930617 deleted the apply-worktree-isolation branch April 23, 2026 09:34
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.

Add isolated worktree execution for apply subagents with main-agent integration

1 participant