Skip to content

feat(resolve): intent-gap patch-restore re-drive + inline-review-layer preflight#76

Closed
pbean wants to merge 1 commit into
mainfrom
feat/intent-gap-patch-restore
Closed

feat(resolve): intent-gap patch-restore re-drive + inline-review-layer preflight#76
pbean wants to merge 1 commit into
mainfrom
feat/intent-gap-patch-restore

Conversation

@pbean

@pbean pbean commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Integrates the July 4–6 upstream bmad-dev-auto changes into bmad-loop. Two phases; the rest of that upstream batch needed no orchestrator work (blocking-condition renames, checkbox/template tweaks, and customize.toml plumbing are all skill-internal or already carried by worktree provisioning).

Phase A — provisioning + doc alignment

  • Preflight now covers the inline review layers. bmad-loop validate / run-start require the three review hunters bmad-dev-auto's step-04 invokes — bmad-review-adversarial-general, bmad-review-edge-case-hunter, and the new bmad-review-verification-gap (BMAD-METHOD#2550) — plus a customize.toml marker on bmad-dev-auto (the review-layer config from #2535/#2550). A pre-July bmm install missing any is reported with remediation instead of failing mid-run.
  • Refreshed the devcontract in-review reconcile note and documented verify.finalize_commit's intentional residual-artifact squash (#2563).
  • Docs: README skill table + prereqs, FEATURES review-layer/resolve notes, CHANGELOG.

Phase B — intent-gap patch-restore re-drive (BMAD-METHOD#2564)

A review-stage intent gap halt now saves the reverted attempt as a patch file. When the human confirms the attempted reading was actually correct, bmad-loop resolve re-arms the spec to in-review (not ready-for-dev), latches the patch, and the engine re-applies it onto the baseline after every reset of the re-drive — so the re-driven session resumes review on the restored diff instead of re-implementing from scratch.

  • model.StoryTask.restore_patch (persisted, legacy-defaulting); verify.apply_patch; runs.rearm_escalation(..., restore_patch=) with the in-review vs ready-for-dev branch and a restore journal field.
  • Engine._restore_patch is applied inside the _dev_phase dispatch loop, gated on feedback is None (fresh attempt or non-fixable rollback — never a fixable-feedback retry that kept the tree). On apply failure it escalates rather than dispatch onto a half-restored tree; the latch clears on commit.
    • Seam note: placed in the dev loop rather than literally in _rollback_or_pause so the patch always lands after the clean baseline_untracked snapshot — otherwise a mid-re-drive reset would preserve the patch's own new files and then collide with the re-apply. The plan explicitly left the exact seam to the implementation.
  • cli: --restore-patch <path> flag (hand-driven) + strict path validation + resolution.json passthrough for the interactive agent; resolve.read_resolution; bmad-loop-resolve SKILL.md guidance for the "attempted reading was correct" option.

Scope was limited to story runs; the sweep-workflow equivalent is tracked in #75.

Testing

  • Full pytest: 1431 passed, 1 skipped. New tests cover model round-trip/legacy defaults, apply_patch success/conflict/missing, restore-vs-plain re-arm + journal, patch-applied-before-dispatch, mid-re-drive re-apply + protected-patch survival, apply-failure-escalates, latch-cleared-on-commit, and the CLI flag / resolution.json / missing-file paths.
  • trunk check (full, unfiltered): clean.

Note: two pre-existing test_module_skills_sync failures for bmad-loop-setup exist in the local dev workspace only (gitignored .claude/.agents copies drifted ahead of canonical, unrelated to this PR, skipped in CI). This PR re-seeded the bmad-loop-resolve copies it touched.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a restore-patch recovery flow for paused runs, letting a previously saved change be reapplied during resume.
    • Expanded preflight checks so runs now flag missing review prerequisites earlier, with clearer guidance before execution stalls.
  • Bug Fixes

    • Improved handling of failed patch reapplication to avoid resuming on a partially restored tree.
    • Enhanced resolution handling so invalid restore paths are rejected with clearer errors.
  • Documentation

    • Updated release and user docs to describe the new recovery flow, prerequisites, and review behavior.

…r preflight

Integrate the July 4-6 upstream bmad-dev-auto changes into bmad-loop.

Phase A - provisioning + doc alignment:
- install: require bmad-review-verification-gap (BMAD-METHOD #2550) and a
  bmad-dev-auto customize.toml marker in the base-skill preflight; the three
  inline step-04 review hunters are now all bmm prerequisites
- devcontract: refresh the in-review reconcile note (restore path re-arms TO
  in-review pre-session; reconcile semantics unchanged)
- verify: document finalize_commit's intentional residual-artifact squash (#2563)
- docs: README skill table, FEATURES review-layer + resolve notes, CHANGELOG

Phase B - intent-gap patch-restore re-drive (BMAD-METHOD #2564):
A review-stage intent-gap halt now saves the reverted attempt as a patch file.
When the attempted reading was correct, bmad-loop resolve re-arms the spec to
in-review and re-applies that patch onto the baseline before the re-drive, so
the session resumes review (step-04) on the restored diff instead of
re-implementing from scratch.
- model.StoryTask.restore_patch latch; verify.apply_patch; runs.rearm_escalation
  restore branch (in-review vs ready-for-dev + restore journal field)
- engine: Engine._restore_patch applied in the dev loop gated on feedback-is-None
  (escalates rather than dispatch on apply failure; cleared on commit)
- cli: --restore-patch flag + strict validation + resolution.json passthrough
- resolve.read_resolution; bmad-loop-resolve SKILL.md guidance

Sweep-workflow extension tracked in #75.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b026e943-e494-4bf3-b544-6d52161838e7

📥 Commits

Reviewing files that changed from the base of the PR and between b0cce05 and 29ba684.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • README.md
  • docs/FEATURES.md
  • src/bmad_loop/cli.py
  • src/bmad_loop/data/skills/bmad-loop-resolve/SKILL.md
  • src/bmad_loop/devcontract.py
  • src/bmad_loop/engine.py
  • src/bmad_loop/install.py
  • src/bmad_loop/model.py
  • src/bmad_loop/resolve.py
  • src/bmad_loop/runs.py
  • src/bmad_loop/verify.py
  • tests/test_cli.py
  • tests/test_engine.py
  • tests/test_install.py
  • tests/test_model.py
  • tests/test_runs.py
  • tests/test_verify.py

Walkthrough

This PR adds an intent-gap patch-restore recovery flow: escalated stories can latch a saved patch (restore_patch) via rearm_escalation, which the engine reapplies onto the baseline before re-dispatching dev sessions. CLI gains a --restore-patch flag; install.py expands required review-hunter skills and customize.toml checks.

Changes

Intent-gap patch-restore and preflight expansion

Layer / File(s) Summary
StoryTask restore_patch field
src/bmad_loop/model.py, tests/test_model.py
Adds restore_patch field with serialization/deserialization support and round-trip/legacy-default tests.
rearm_escalation restore mode
src/bmad_loop/runs.py, tests/test_runs.py
rearm_escalation gains a restore_patch kw-only parameter that latches the patch, routes spec status to in-review vs ready-for-dev, and journals restore mode.
apply_patch helper
src/bmad_loop/verify.py, tests/test_verify.py
Adds apply_patch to apply a saved diff via git apply, raising GitError on missing file or conflict; extends finalize_commit docs.
resolution.json reader
src/bmad_loop/resolve.py
Adds read_resolution to load/validate the resolve agent's marker file.
Engine dev-phase restoration
src/bmad_loop/engine.py, src/bmad_loop/devcontract.py, tests/test_engine.py
Adds Engine._restore_patch, wired into the dev loop before dispatch and cleared on commit; escalates on apply failure; adds unit and end-to-end tests including a rollback scenario.
CLI --restore-patch flag
src/bmad_loop/cli.py, tests/test_cli.py
Adds _resolve_restore_patch helper and --restore-patch PATH argument, wired into cmd_resolve's re-arm flow; tests cover explicit flag, invalid path, and interactive resolution.json sourcing.
Skill and documentation updates
src/bmad_loop/data/skills/bmad-loop-resolve/SKILL.md, CHANGELOG.md, README.md, docs/FEATURES.md
Documents restore_patch schema and intent-gap special-case handling, plus changelog/README/features descriptions of the new flow.
Expanded review-hunter preflight
src/bmad_loop/install.py, tests/test_install.py, README.md
DEV_BASE_SKILLS requires bmad-review-verification-gap and customize.toml; docstring and tests updated accordingly.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Human
    participant CLI as bmad-loop CLI (resolve)
    participant Runs as runs.rearm_escalation
    participant Engine
    participant Verify as verify.apply_patch

    Human->>CLI: resolve --restore-patch PATH / resolution.json
    CLI->>CLI: _resolve_restore_patch (validate path)
    CLI->>Runs: rearm_escalation(restore_patch)
    Runs->>Runs: latch task.restore_patch, set spec status "in-review"
    Runs-->>CLI: story_key
    CLI-->>Human: re-armed (restoring attempted change)
    Engine->>Engine: _dev_phase (feedback is None)
    Engine->>Engine: _restore_patch(task)
    Engine->>Verify: apply_patch(repo, patch_path)
    alt patch applies
        Verify-->>Engine: success
        Engine->>Engine: dispatch dev session on restored tree
        Engine->>Engine: commit, clear restore_patch latch
    else patch fails
        Verify-->>Engine: GitError
        Engine->>Engine: journal attempt-restore-failed, raise RunPaused
    end
Loading

Possibly related PRs

  • bmad-code-org/bmad-loop#53: Modifies the same runs.rearm_escalation code path for restore_patch/in-review re-arming and ## Auto Run Result stripping logic.

Poem

A patch once lost, now hops back home,
Baseline restored where feet once roamed. 🐇
With --restore-patch I dig anew,
No half-restored tree to stumble through.
Verification-gap now guards the burrow tight—
Thump thump! The loop resumes just right. 🥕

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/intent-gap-patch-restore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pbean pbean closed this Jul 6, 2026
@augmentcode

augmentcode Bot commented Jul 6, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Integrates July 4–6 upstream bmad-dev-auto behavior into bmad-loop, focusing on (1) tighter preflight validation for inline review layers and (2) a new “intent-gap patch-restore” recovery path.

Changes:

  • Adds preflight checks to require the three step-04 review-layer skills (bmad-review-adversarial-general, bmad-review-edge-case-hunter, bmad-review-verification-gap) and a customize.toml marker for bmad-dev-auto.
  • Implements intent-gap patch-restore re-drive: persist StoryTask.restore_patch, re-arm escalations to in-review, and re-apply the saved patch onto baseline after resets.
  • Extends bmad-loop resolve with --restore-patch and resolution.json passthrough for interactive resolves.
  • Adds verify.apply_patch() and engine wiring to apply (or escalate on failure) before dispatching dev sessions.
  • Updates journaling/install validation and refreshes docs (README/FEATURES/CHANGELOG) to reflect the new requirements and behavior.
  • Adds thorough tests covering model round-trips, CLI flag handling, re-arm semantics, patch apply success/conflict/missing, and mid-re-drive re-apply behavior.
Technical Notes: Patch restore is applied only when dispatching from a clean baseline (not fixable-feedback retries) and the latch is cleared once the story commit finalizes.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/bmad_loop/cli.py
patch = Path(raw)
if not patch.is_absolute():
patch = project / patch
patch = patch.resolve()

@augmentcode augmentcode Bot Jul 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/bmad_loop/cli.py:627 — Path.resolve() can raise in some filesystem edge cases (e.g., symlink loops or permission errors); since --restore-patch is user-supplied input, an uncaught exception here would crash bmad-loop resolve instead of producing the intended validation failure.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread src/bmad_loop/engine.py
if not patch.is_absolute():
patch = self.workspace.root / patch
try:
verify.apply_patch(self.workspace.root, patch)

@augmentcode augmentcode Bot Jul 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/bmad_loop/engine.py:892 — If git apply fails, it can leave the working tree partially modified; escalating immediately without restoring a known baseline could leave the paused run in a confusing half-applied state for subsequent recovery/debugging.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

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.

1 participant