feat: worktree-first isolation with delta analysis for parallel session safety#997
Open
feat: worktree-first isolation with delta analysis for parallel session safety#997
Conversation
Addresses obra#989: skill chain assumes frozen codebase during parallel sessions. Spec covers worktree creation at brainstorming start, session metadata tracking, uniform entry logic for downstream skills, and delta analysis with 3-level escalation before merge.
9 tasks covering: brainstorming worktree creation, session metadata entry logic for writing-plans/executing-plans/subagent-driven-development, using-git-worktrees integration updates, rebase + delta analysis in finishing skill, gitignore guidance, fallback mode, and cross-reference verification. Addresses obra#989.
Creates isolated workspace before any code analysis. Writes .superpowers-session.json to track base branch, base commit, and session stage. Falls back to current directory on platforms without worktree support. Addresses obra#989.
Adds 3-way metadata check: reuse existing worktree, continue in fallback mode, or create worktree for standalone invocations. Updates session stage to 'planning'. Addresses obra#989.
Adds 3-way metadata check before execution. Creates worktree only for standalone invocations; reuses existing worktree when coming through the brainstorming chain. Addresses obra#989.
Adds 3-way metadata check before execution. Creates worktree only for standalone invocations; reuses existing worktree when coming through the brainstorming chain. Addresses obra#989.
Brainstorming now calls this at Step 1 (not Phase 4). Downstream skills only create worktrees for standalone invocations. Addresses obra#989.
…g skill After tests pass, reads session metadata, rebases onto the original base branch, and runs delta analysis. Classifies drift as implementation (re-plan), spec (update spec + re-plan), or fundamental (restart brainstorming). Merge conflicts escalate to at least level 2. User confirms escalation before routing. Addresses obra#989.
Session metadata file is session-local and should not be committed. Addresses obra#989.
In fallback mode (no isolation), skips rebase and runs delta analysis by comparing all changes since session start. Addresses obra#989.
After any escalation fix completes, return to Step 2.5 for a fresh rebase + delta analysis. Only proceed to merge options when Level 0 is reached. Prevents race condition where more changes land on the base branch during user confirmation or delta fix execution. Found during manual testing. Addresses obra#989.
Prevents collisions when the same topic is brainstormed multiple times against the same commit. Branch name is now superpowers/<topic>-<short-hash>-<random> with 4 random hex chars. Found during manual testing. Addresses obra#989.
Instead of routing to brainstorming's present-design phase, Level 2 now reviews the spec against the base branch and asks the user clarifying questions where drift creates ambiguity. Prevents the agent from unilaterally updating the spec without user input. Found during manual testing. Addresses obra#989.
Add explicit warning not to explore codebase before creating the worktree. Agents were reading files on main before step 1, defeating the isolation guarantee. Addresses obra#989.
In fallback mode (no worktree), the session file must be written before any code exploration — the recorded commit hash marks the snapshot point. Updated the critical warning to account for both worktree and fallback paths. Addresses obra#989.
Author
|
Here is the output of Claude Code session, when the finishing-a-development-branch skill
|
Author
|
Here we catch a Level 2 drift before merging (where our new code still compiles but now it makes no sense), and successfully go back to clarifying questions |
Author
|
And here is a Level 3 result - fundamentally changed circumstances |
Author
|
I have updated the PR description to match the prescribed template. (Forry for missing it the first time.) |
Author
|
Any feedback on this, @obra ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem are you trying to solve?
When running multiple AI coding sessions in parallel against the same repo, the brainstorming → writing-plans → execution chain works against a codebase that may change at any time. Session A brainstorms and writes a spec against code state X, but by the time execution finishes, Session B has merged changes that invalidate the spec, plan, or implementation. The agent merges anyway because it has no mechanism to detect the drift.
Detailed problem description: #989
What does this PR change?
Moves worktree creation to step 1 of brainstorming (before code analysis), adds
.superpowers-session.jsonmetadata tracking across the skill chain, and adds rebase + delta analysis with 3-level escalation to the finishing skill before merge.Is this change appropriate for the core library?
Yes — this affects the fundamental skill chain used by all superpowers users. Parallel sessions are a natural workflow for any developer using AI coding agents. The fix is entirely within the existing skill infrastructure.
What alternatives did you consider?
Three approaches evaluated during brainstorming (documented in spec):
Does this PR contain multiple unrelated changes?
No. All changes serve the same goal: isolate the skill chain from parallel session interference. The worktree-first change and delta analysis are the two halves of the same solution (isolate at start, validate before merge).
Existing PRs
All three related PRs address the narrower problem of the missing worktree step. This PR subsumes them by moving the step earlier (step 1 vs after design approval) and adding the full delta analysis system that none of them include.
Environment tested
Evaluation
Rigor
superpowers:writing-skillsand completed adversarial pressure testing (paste results below)Note on writing-skills: We did not use the formal
writing-skillsRED-GREEN-REFACTOR cycle with subagent pressure testing. We tested iteratively through manual sessions, found and fixed rationalizations (agent skipping worktree, misclassifying drift levels, not looping), but did not document formal baseline behavior. We plan to run the full pressure testing cycle and update the PR with results before requesting final review.Note on behavior-shaping content: This PR adds new behavior-shaping content: escalation level definitions, Level 2 clarifying question instructions, worktree-before-exploration warning. These were validated through iterative manual testing (5 sessions, multiple drift scenarios), not formal evals. Each addition was prompted by a specific observed failure — agent misclassified Level 2, agent skipped questions, agent explored before worktree creation. We plan to run formal pressure testing before requesting final review.
Human review