tickets: a rollback-rearmed plan blocks the next in-place ticket as unowned dirt
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
調査の方向性
Start in src/bmad_loop/tickets_engine.py: inspect _after_code_rollback, _run_owned_paths, and _gate_dirty_initiative, then trace how _dispatch_ref checks the next ticket. Reproduce the two-ticket failure described in the issue and follow the owned-paths logic. Done means a failed ticket’s rollback-rearmed plan no longer blocks the independent next ticket, while unrelated dirty initiative files still trigger the gate.
索引モデルが issue の本文から書いたものです。
説明
Summary
With in-place isolation and [scm] rollback_on_failure = true, an attempt-created, untracked plan with a body survives a failed ticket's rollback and is re-armed to ready-for-dev. Keeping that nonterminal plan uncommitted is intentional. However, the next ticket's dirty-initiative gate exempts only the deferred-work ledger and pauses on the re-armed plan as a change "this run does not own". In the two-ticket reproduction, the first ticket is deferred and the independent second ticket never starts.
This is not the replan/rollback commit boundary declined in #946 (https://github.com/bmad-code-org/bmad-loop/pull/946#discussion_r4300943615): leaving the re-armed plan uncommitted is intended there, and this issue does not ask to commit it. The problem is that the next pick's dirty-initiative gate then counts that intended, bmad-loop-owned plan as a change "this run does not own" and stops the run.
Environment
bmad-loop a5a8f097, Windows 11 Enterprise 10.0.26200, PowerShell 7.6.6 (SHELL unset), Python 3.13.2; real bmad-loop run CLI with bmad-loop's MockAdapter serving the sessions (zero tokens). Linux oracle: same (Ubuntu under WSL, git 2.43.0).
Steps to reproduce
From a bmad-loop checkout at a5a8f097 after uv sync --all-extras, save the script below as repro.py in the checkout root and run it in PowerShell 7 with SHELL removed. The steps are complete and run as-is from that shell:
Remove-Item Env:SHELL -ErrorAction SilentlyContinue
$env:PYTHONUTF8 = '1'; $env:PYTHONPATH = 'tests'
uv run python repro.py
The script builds a committed v7 project (store tracked in the code checkout) with two independent tickets 1.1 and 1.2 in epic-cart, and the policy [scm] isolation = "none", rollback_on_failure = true, [limits] max_dev_attempts = 1. Every session is a scripted build-auto (no LLM). With REPRO_FAIL=1.1, 1.1's session writes code and a plan with a body at in-progress and commits nothing, so the dev verify fails ("spec status is 'in-progress', expected 'built'") and the ticket is deferred. The positive control lets 1.1 build normally.
# bmad-loop repro: run from a bmad-loop checkout (uv sync --all-extras), PowerShell 7:
# Remove-Item Env:SHELL -ErrorAction SilentlyContinue; $env:PYTHONUTF8='1'; $env:PYTHONPATH='tests'; uv run python repro.py
import json, os, subprocess, sys, time
from pathlib import Path
from conftest import EntrySpec, EpicSpec, install_bmad_v7, install_build_auto_v7_skill, write_ticket_tree
ROOT = Path(os.environ.get("REPRO_ROOT") or Path(os.environ.get("TEMP", "/tmp")) / "bmad-loop-repro")
ROOT.mkdir(parents=True, exist_ok=True)
os.environ.pop("SHELL", None)
# Keep the user's global git config (signing, hooks, excludes) out of the sandbox,
# as the test suite's own fixtures do; every child below inherits this.
os.environ["GIT_CONFIG_GLOBAL"] = str(ROOT / "no-such-gitconfig")
os.environ["XDG_CONFIG_HOME"] = str(ROOT)
def git(root, *args):
return subprocess.run(["git", "-C", str(root), *args], check=True, capture_output=True, text=True).stdout
def sandbox(name, entries, policy=""):
"""A committed v7 project (tracked store in the checkout), one epic `epic-cart`."""
root = ROOT / name
if root.exists():
subprocess.run(["cmd", "/c", "rmdir", "/s", "/q", str(root)] if os.name == "nt" else ["rm", "-rf", str(root)])
root.mkdir(parents=True)
(root / "src.txt").write_text("original\n", encoding="utf-8")
(root / ".gitignore").write_text(".bmad-loop/runs/\n_bmad/custom/*.user.toml\n", encoding="utf-8")
git(root, "init", "-q", "-b", "main")
git(root, "config", "user.email", "t@t")
git(root, "config", "user.name", "t")
write_ticket_tree(install_bmad_v7(root), (EpicSpec(1, "epic-cart", "Cart", tuple(entries)),))
install_build_auto_v7_skill(root)
(root / ".bmad-loop").mkdir()
(root / ".bmad-loop" / "policy.toml").write_text(
'[stories]\nsource = "tickets"\n\n[notify]\ndesktop = false\n\n' + policy, encoding="utf-8")
git(root, "add", "-A")
git(root, "commit", "-q", "-m", "sandbox")
return root
def tickets(cwd, *argv):
return subprocess.run([sys.executable, "-I", "-B", "-X", "utf8", "_bmad/method/scripts/tickets.py",
"--project-root", str(cwd), *argv], cwd=cwd, check=True, capture_output=True, text=True)
def fake_session(spec):
"""A scripted bmad-build-auto (no LLM): resolves the ticket with tickets.py find,
writes the plan, commits its own work. REPRO_FAIL=<ref> makes that ticket's attempt
fail (plan with a body at in-progress, nothing committed); REPRO_PARK=<ref> parks it
at awaiting-operator; REPRO_FOLLOWUP=1 adds followup_review_recommended to a dev result."""
from bmad_loop.adapters.base import SessionResult
cwd, ref = Path(spec.cwd), spec.env["BMAD_LOOP_STORY_KEY"]
found = json.loads(tickets(cwd, "find", ref).stdout)
plan, base = Path(found["plan"]), git(cwd, "rev-parse", "HEAD").strip()
status = "built"
if plan.is_file() and "status: built" in plan.read_text(encoding="utf-8"):
pass # a follow-up review pass: no change
elif spec.role == "dev" and ref == os.environ.get("REPRO_FAIL"):
status = "in-progress"
with open(cwd / "src.txt", "a", encoding="utf-8") as f:
f.write(f"half impl {ref}\n")
plan.write_text(f"---\nticket: {found['id']}\nstatus: in-progress\nbaseline_revision: {base}\n---\n\n# plan\n\nwork\n", encoding="utf-8")
else:
if spec.role == "dev" and ref == os.environ.get("REPRO_PARK"):
status = "awaiting-operator"
with open(cwd / "src.txt", "a", encoding="utf-8") as f:
f.write(f"impl {ref}\n")
extra = "operator_actions:\n - publish the DNS record\n" if status == "awaiting-operator" else ""
plan.write_text(f"---\nticket: {found['id']}\nstatus: {status}\nbaseline_revision: {base}\n{extra}---\n\n# plan\n\nwork\n", encoding="utf-8")
git(cwd, "add", "-A")
git(cwd, "commit", "-q", "-m", f"build {ref}")
result = {"workflow": "auto-dev", "spec_file": str(plan), "status": status}
if spec.role == "dev" and os.environ.get("REPRO_FOLLOWUP"):
result["followup_review_recommended"] = True
return SessionResult(status="completed", result_json=result)
def bmad_loop(root, *argv, env=None, background=False):
"""One real `bmad-loop` CLI call, in its own process, with every session role served
by `fake_session` through bmad-loop's MockAdapter (so nothing spawns an agent)."""
cmd = [sys.executable, __file__, "--child", argv[0], "--project", str(root), *argv[1:]]
e = dict(os.environ, **(env or {}))
if background:
return subprocess.Popen(cmd, env=e, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
p = subprocess.run(cmd, env=e, capture_output=True, text=True)
print(f"$ bmad-loop {' '.join(argv)} -> rc={p.returncode}")
print(" " + (p.stdout + p.stderr).strip().replace("\n", "\n "))
return p.returncode
def run_dir(root):
return sorted((root / ".bmad-loop" / "runs").iterdir())[-1]
def state(root):
return json.loads((run_dir(root) / "state.json").read_text(encoding="utf-8"))
def journal(root, *kinds):
rows = [json.loads(x) for x in (run_dir(root) / "journal.jsonl").read_text(encoding="utf-8").splitlines()]
return [r for r in rows if r["kind"] in kinds]
if len(sys.argv) > 1 and sys.argv[1] == "--child":
from bmad_loop import cli
from bmad_loop.adapters.mock import MockAdapter
adapter = MockAdapter([fake_session] * 20)
cli._make_adapters = lambda *a, **k: {role: adapter for role in cli.ROLES}
sys.exit(cli.main(sys.argv[2:]))
# --- a failed in-place attempt, rolled back and re-armed, then the next ticket -------
POLICY = ('[review]\nenabled = false\n\n[scm]\nisolation = "none"\nrollback_on_failure = true\n\n'
'[limits]\nmax_dev_attempts = 1\n')
TWO = [EntrySpec(1, "Cart model"), EntrySpec(2, "Cart rules")] # independent tickets
for fail in ("1.1", ""): # "" is the positive control: 1.1 builds
root = sandbox("rb-" + (fail or "control"), TWO, POLICY)
print(f"\n### REPRO_FAIL={fail!r}")
bmad_loop(root, "run", env={"REPRO_FAIL": fail})
st = state(root)
print("tasks:", {k: v["phase"] for k, v in st["tasks"].items()})
print("paused_stage:", st["paused_stage"])
print("journal ticket-mark:", [(r["ref"], r["reason"], r["before"], r["after"]) for r in journal(root, "ticket-mark")])
print("git status --porcelain:", git(root, "status", "--porcelain").strip() or "(clean)")
Selected output from Windows runs (2/2 identical):
### REPRO_FAIL='1.1'
$ bmad-loop run -> rc=0
run <run>: 0 done, 1 deferred, 0 escalated, 0 tokens
PAUSED: the initiative folder _bmad-output/initiative-demo has uncommitted changes this run does not own (_bmad-output/initiative-demo/epic-cart/story-cart-model-plan.md); commit or stash them before 1.2 is built, because the ticket's commit stages the whole tree — then `bmad-loop resume <run>`
tasks: {'1.1': 'deferred'}
paused_stage: ticket-tree
journal ticket-mark: [('1.1', 'rollback', 'in-progress', 'ready-for-dev')]
git status --porcelain: ?? _bmad-output/initiative-demo/epic-cart/story-cart-model-plan.md
### REPRO_FAIL=''
$ bmad-loop run -> rc=0
run <run>: 2 done, 0 deferred, 0 escalated, 0 tokens
tasks: {'1.1': 'done', '1.2': 'done'}
paused_stage: epic-boundary
git status --porcelain: (clean)
Expected vs actual
| actual | expected | |
|---|---|---|
| next pick after 1.1 is deferred and its plan re-armed | pause ticket-tree (dirty-initiative) naming 1.1's plan as a change "this run does not own"; 1.2 never starts |
1.2 is dispatched: the only dirt in the initiative folder is the plan this run's own rollback re-armed (docs/tickets-guide.md: "A code rollback re-arms the plan too: a plan past ready-for-dev returns to ready-for-dev"); the ticket-tree row for uncommitted changes is about changes "the run does not own" |
Linux
The same two-ticket scenario was reported in a git archive a5a8f097 copy on Ubuntu (git 2.43.0, Python 3.13.2), using the mock adapter. The transcript below covers engine behavior; it does not test live tmux transport.
RESULT (a) CONTROL 1.1 builds: paused_stage=epic-boundary key=epic-cart tasks={'1.1': 'done', '1.2': 'done'} sessions=2
RESULT (a) TRIGGER 1.1 fails: paused_stage=ticket-tree key=1.2 tasks={'1.1': 'deferred'} sessions=1
Source
src/bmad_loop/tickets_engine.py:2027-2067 (a5a8f097), _after_code_rollback, preserves attempt-created untracked plans across reset, discards a frontmatter-only plan, and marks a plan with a body ready-for-dev with reason rollback. The reproduction observed that re-armed plan still untracked in the initiative folder.
src/bmad_loop/tickets_engine.py:483-493, _run_owned_paths, returns only the repo-relative deferred-work ledger path. The decisive source excerpt is return frozenset({ledger.as_posix()}); a bound or re-armed ticket plan is not included.
src/bmad_loop/tickets_engine.py:429-481 (_gate_dirty_initiative, called from _dispatch_ref at :387 before every dispatch): any dirty path under the initiative folder not in that set pauses with HALT_DIRTY_INITIATIVE.
Observed with a scratch copy of the module in which _run_owned_paths also returns the plans bound to this run's tasks: on the same failed and re-armed 1.1, the pick dispatches 1.2 and the run ends with {'1.1': 'deferred', '1.2': 'done'}. So the narrow owned set is what stops the run.
Suggested fix
Not validated: count the plans this run re-armed after a rollback as run-owned in _run_owned_paths. Observed with a scratch copy that owns every plan bound to this run's tasks: 1.2 dispatches and the run ends {1.1: deferred, 1.2: done}, and 1.1's re-armed ready-for-dev plan is committed by 1.2's unit commit (git add -A), so the tree ends clean. If a plan of another ticket must not ride a unit's commit, the owned plan also needs to be excluded from that unit's staging.
The fix should preserve the plan body and the existing nonterminal commit boundary. The exemption must not silently claim unrelated or subsequently edited plans merely because a task is bound to their path.
- 主要言語
- Python
- スター
- 196
- フォーク
- 78
- 平均マージ
- 9時間 24分
- マージ済み PR(30日)
- 44
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bmad-code-org/bmad-loop のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bmad-code-org/bmad-loop#1063 ·
メンテナーはふだん 1 日以内に返信
-
psmux: task window name starting with '-' creates no window; session reads as crashed対応中かも @RECOHA が 8 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 82/100
bmad-code-org/bmad-loop#1061 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
bmad-code-org/bmad-loop#1057 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
bmad-code-org/bmad-loop#973 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
bmad-code-org/bmad-loop#965 ·
メンテナーはふだん 1 日以内に返信
bmad-code-org/bmad-loop の issue をすべて見る
似ている issue
-
accepted
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
future-agi/future-agi#5274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
GenericMappingTools/pygmt#5014 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
w3c/feedvalidator#204 ·
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%対応中かも @sumitkhond111-del が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bmad-code-org/BMAD-METHOD#3358 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
open-mmlab/mmcv#3352 ·