tickets: on Windows, stopping during tickets.py next or mark leaves a ticket-tree pause
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 56/100
Línea de trabajo
The report identifies the stop request handling and the tickets.py next and tickets.py mark calls, but names no repository source files or tests. Start by tracing how the CLI handles stop requests while waiting for those subprocesses, then compare with the verify control described in the repro. Done means a hard stop during next or mark leaves the run stopped without a ticket-tree pause or repair instruction.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
On native Windows, a hard stop reaches the engine through stop-request.json. In three runs, stopping while bmad-loop waited on tickets.py next or the tracked-store commit window's mark 1.1 done interrupted the child and left paused_stage=ticket-tree; stopped was also true, and status displayed PAUSED (ticket-tree). The next case recorded tree-fault, while the mark case additionally instructed the operator to fix the ticket tree even though the stop was intentional. Stopping during the verify control left stopped=true with no pause.
On Linux, bmad-loop stop also sends SIGTERM, which unwinds the engine first, so the same stop ends as a plain stop there; but the same request delivered through the stop-request file alone, the only channel native Windows has, pauses the Linux run at ticket-tree too (measured 3/3). The fold is platform-independent; Windows is where every hard stop reaches it. The operator asked for a stop and is told to repair a tree that is fine.
Environment
bmad-loop a5a8f097, Windows 11 Enterprise 10.0.26200, PowerShell 7.6.6 (SHELL unset), Python 3.13.2; real bmad-loop run and bmad-loop stop CLI, bmad-loop's MockAdapter serving the sessions (zero tokens). Linux oracle (Ubuntu under WSL, git 2.43.0): differs through bmad-loop stop (SIGTERM wins, stopped, 3/3); same when only the request file is delivered (paused at ticket-tree, 3/3).
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 runnable as shown:
Remove-Item Env:SHELL -ErrorAction SilentlyContinue
$env:PYTHONUTF8 = '1'; $env:PYTHONPATH = 'tests'
uv run python repro.py
The script builds a committed v7 project (ticket store tracked in the checkout) with tickets 1.1 and 1.2 (after 1.1) and starts bmad-loop run in the background. To make the race deterministic it splices a 40-second sleep into the project's own tickets.py for one verb (committed, so the tree is clean), waits until that call is in flight, then runs bmad-loop stop <run> (a hard stop). Three cases: verify (positive control: a [verify] commands entry that sleeps instead, no tickets.py change), next (the pick's read), mark (mark 1.1 done in the tracked-store commit window). Sessions are a scripted build-auto (no LLM). If a case fails to set up, the script kills its background run: the whole process tree on Windows (taskkill /T), only the run process elsewhere.
# 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 hard stop that lands while bmad-loop waits on tickets.py ----------------------
VERIFY_PY = "import os, time\nopen(os.path.join('.git', 'in-verify'), 'w').close()\ntime.sleep(40)\n"
def slow_tickets(root, verb, need):
"""Make the project's tickets.py sleep 40 s on `<verb> ...need` (marker .git/in-<verb>)."""
script = root / "_bmad" / "method" / "scripts" / "tickets.py"
text = script.read_text(encoding="utf-8")
anchor = 'if __name__ == "__main__":\n'
hook = (anchor + " import os as _o, time as _t\n"
f" if all(a in sys.argv for a in {(verb, *need)!r}):\n"
f" open(_o.path.join('.git', 'in-{verb}'), 'w').close(); _t.sleep(40)\n")
script.write_text(text.replace(anchor, hook), encoding="utf-8")
git(root, "add", "-A")
git(root, "commit", "-q", "-m", "slow tickets.py")
TWO = [EntrySpec(1, "Cart model"), EntrySpec(2, "Cart rules", after=(1,))]
for case in ("verify", "next", "mark"): # "verify" is the positive control
policy = '[review]\nenabled = false\n'
if case == "verify":
policy += f"\n[verify]\ncommands = ['\"{sys.executable}\" .git/slow-verify.py']\n"
root = sandbox(f"stop-{case}", TWO, policy)
if case == "verify":
(root / ".git" / "slow-verify.py").write_text(VERIFY_PY, encoding="utf-8")
else:
slow_tickets(root, case, ("done",) if case == "mark" else ())
print(f"\n### hard stop while waiting on: {case}")
run = bmad_loop(root, "run", background=True)
marker = root / ".git" / f"in-{case}"
try:
for _ in range(300):
if marker.exists() or run.poll() is not None:
break
time.sleep(0.2)
if not marker.exists() or run.poll() is not None:
raise SystemExit(f"setup failed: the run never reached the {case} call (rc={run.poll()})")
bmad_loop(root, "stop", run_dir(root).name)
out, _ = run.communicate(timeout=120)
finally:
if run.poll() is None: # never leave this case's run (and its sleeping child) behind
subprocess.run(["taskkill", "/PID", str(run.pid), "/T", "/F"] if os.name == "nt"
else ["kill", "-9", str(run.pid)], capture_output=True)
run.communicate()
print(f"run exited rc={run.returncode}:\n " + out.strip().replace("\n", "\n "))
st = state(root)
print("state: stopped =", st.get("stopped"), "| paused_stage =", st["paused_stage"])
print("paused_reason:", st["paused_reason"])
bmad_loop(root, "status", run_dir(root).name)
Output (Windows, PowerShell 7.6.6 with SHELL removed, 3/3 identical; trimmed to the relevant lines, run ids written as <run>):
### hard stop while waiting on: verify
$ bmad-loop stop <run> -> rc=0
run <run> stopped
run exited rc=0:
run <run>: 0 done, 0 deferred, 0 escalated, 0 tokens
state: stopped = True | paused_stage = None
### hard stop while waiting on: next
$ bmad-loop stop <run> -> rc=0
run <run> stopped
run exited rc=0:
PAUSED: tickets.py interrupted: tickets.py next: interrupted by a stop request — then `bmad-loop resume <run>`
state: stopped = True | paused_stage = ticket-tree
$ bmad-loop status <run> -> rc=0
status: PAUSED (ticket-tree) — tickets.py interrupted: tickets.py next: interrupted by a stop request — then `bmad-loop resume <run>`
### hard stop while waiting on: mark
$ bmad-loop stop <run> -> rc=0
run <run> stopped
run exited rc=0:
PAUSED: marking 1.1 done failed (tickets.py interrupted: tickets.py mark: interrupted by a stop request) — the unit is verified but not committed; fix the ticket tree, then `bmad-loop resume <run>`
state: stopped = True | paused_stage = ticket-tree
$ bmad-loop status <run> -> rc=0
status: PAUSED (ticket-tree) — marking 1.1 done failed (…) — the unit is verified but not committed; fix the ticket tree, then `bmad-loop resume <run>`
The journal of the next case carries ticket-pick-halt with cause = tree-fault, stage = ticket-tree, then run-paused. The mark case journals ticket-mark with outcome = failed (before = built, after = built), then run-paused.
Expected vs actual
| actual (Windows) | expected (docs/reference/run-state.md, Stopping a run: hard stop "End state: stopped, resumable"; the verify control) |
|
|---|---|---|
stop during tickets.py next |
stopped = true, paused_stage = ticket-tree, tree-fault, "tickets.py interrupted", status = PAUSED |
stopped = true, paused_stage = null |
stop during tickets.py mark 1.1 done |
stopped = true, paused_stage = ticket-tree, "marking 1.1 done failed … fix the ticket tree" |
stopped = true, paused_stage = null |
The issue is the extra pause and its repair instruction, not the stopped flag: on Windows the state records stopped = true together with paused_stage = ticket-tree.
Linux
The same script in a git archive a5a8f097 copy under WSL (Ubuntu, git 2.43.0, Python 3.13.2, tmux 3.4), three runs each (run 1 shown, trimmed to the relevant lines; runs 2 and 3 identical apart from run ids, written as <run>).
Through bmad-loop stop (request file, then SIGTERM), 3/3:
### hard stop while waiting on: verify
$ bmad-loop stop <run> -> rc=0
run exited rc=0:
state: stopped = True | paused_stage = None
### hard stop while waiting on: next
$ bmad-loop stop <run> -> rc=0
run exited rc=0:
state: stopped = True | paused_stage = None
### hard stop while waiting on: mark
$ bmad-loop stop <run> -> rc=0
run exited rc=0:
state: stopped = True | paused_stage = None
journal next: "kind": "run-stop"
journal mark: "kind": "run-stop"
The same script with bmad-loop stop replaced by writing a hard stop-request.json only (no signal), 3/3. The replaced line is bmad_loop(root, "stop", run_dir(root).name); in its place the script writes {"requested_at": "<now>", "mode": "hard"} to run_dir(root) / "stop-request.json":
### hard stop while waiting on: verify
$ (wrote a hard stop-request.json, no signal)
run exited rc=0:
state: stopped = True | paused_stage = None
### hard stop while waiting on: next
$ (wrote a hard stop-request.json, no signal)
run exited rc=0:
PAUSED: tickets.py interrupted: tickets.py next: interrupted by a stop request — then `bmad-loop resume <run>`
state: stopped = False | paused_stage = ticket-tree
status: PAUSED (ticket-tree) — tickets.py interrupted: tickets.py next: interrupted by a stop request — then `bmad-loop resume <run>`
### hard stop while waiting on: mark
$ (wrote a hard stop-request.json, no signal)
run exited rc=0:
PAUSED: marking 1.1 done failed (tickets.py interrupted: tickets.py mark: interrupted by a stop request) — the unit is verified but not committed; fix the ticket tree, then `bmad-loop resume <run>`
state: stopped = False | paused_stage = ticket-tree
status: PAUSED (ticket-tree) — marking 1.1 done failed (tickets.py interrupted: tickets.py mark: interrupted by a stop request) — the unit is verified but not committed; fix the ticket tree, then `bmad-loop resume <run>`
journal next: "kind": "ticket-pick-halt" "kind": "run-paused" "kind": "stop-request-discarded"
journal mark: "kind": "run-paused" "kind": "stop-request-discarded"
So the mechanism is the tickets error fold, on every platform; the Windows/Linux difference is only which channel reaches the engine first. Why the bmad-loop stop row differs: stop_run lodges the stop-request file first and then signals the engine (runs.py:3118 writes the request, :3145 signals it through host.terminate). On POSIX that signal is SIGTERM, whose handler (engine.py:1413-1444) unwinds the loop as RunStopped; native Windows has no inter-process SIGTERM (runs.py:3050-3057), so there the engine learns of the stop only through the file, which the tickets.py child supervisor polls. One side difference: with the file alone, Linux records stopped = False and journals the request as stop-request-discarded, while Windows records stopped = True with the pause. Either way status says PAUSED.
Source
src/bmad_loop/tickettree.py:700-703 (a5a8f097): an interrupted child becomes a tickets error.
def _result(run: childrun.ChildRun, verb: str, *, json_out: bool) -> dict[str, object] | str:
"""Map one finished child onto the module's error contract."""
if run.interrupted:
raise TicketsInterrupted(f"tickets.py {verb}: interrupted by a stop request")
src/bmad_loop/tickets_source.py:725-727, the pick folds every tickets error, interrupted included, into a tree fault:
except TicketsError as e:
cause = HALT_PIN_MISMATCH if e.kind == "pin-mismatch" else HALT_TREE_FAULT
return Halt(cause, "", None, f"tickets.py {e.kind}: {e}")
src/bmad_loop/tickets_engine.py:1634-1639 and :1661-1669, the tracked-store commit window's mark: except TicketsError → _pause_mark_done → RunPaused(… "fix the ticket tree" …, PAUSE_TICKET_TREE, …). The post-landing mark (:1746-1747) folds the same way (source-derived, not driven).
For contrast, the engine's verify path raises a stop for the same child state (engine.py:7044-7045): if any(result.interrupted for result in results): raise RunStopped(via="stop-request").
Suggested fix
Not validated: treat TicketsInterrupted like an interrupted verify child, raising RunStopped(via="stop-request") (in TicketsWorkSource.decide and at the mark sites) instead of folding it into a tree fault or a mark failure.
- Lenguaje dominante
- Python
- Estrellas
- 196
- Forks
- 78
- Merge medio
- 9 h 24 min
- PR fusionados (30 d)
- 44
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bmad-code-org/bmad-loop
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
bmad-code-org/bmad-loop#1063 ·
Los mantenedores suelen responder en 1 día
-
psmux: task window name starting with '-' creates no window; session reads as crashedPosiblemente ocupada @RECOHA la tomó hace 8 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
bmad-code-org/bmad-loop#1061 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
bmad-code-org/bmad-loop#1057 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
bmad-code-org/bmad-loop#973 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bmad-code-org/bmad-loop#965 ·
Los mantenedores suelen responder en 1 día
Todos los issues de bmad-code-org/bmad-loop
Issues similares
-
Ubuntu for Debian DevelopersAbiertoDMB documentation good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
ubuntu/ubuntu-project-docs#921 ·
Los mantenedores suelen responder en 1 día
-
⏳ Pending feedback 🐛 Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jumpserver/jumpserver#18282 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
ClickHouse/loom#2014 ·
Los mantenedores suelen responder en 1 día
-
accepted
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
future-agi/future-agi#5274 ·
Los mantenedores suelen responder en 1 día
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 2 días