tickets: on Windows, case-only twin ids can alias one plan file, and discard_unbuilt_plan can delete the twin's unbuilt plan

Đang mở
#964 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
cli, testing

Hướng nghiên cứu

Start with src/bmad_loop/tickettree.py around discard_unbuilt_plan and the case-twin guard in src/bmad_loop/stories.py; then trace how tickets.py find names plan files. Add regression coverage for the three-entry case-only ID layout on Windows, including the rollback path described in the issue. Done means the twins cannot alias a plan and discarding one ticket's unbuilt plan preserves the other's.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Status (needs confirmation)

  • Observed: on NTFS, an epic with three entries titled Cart model and ids X1, A1 and a1 gets plan names story-cart-model-A1-plan.md and story-cart-model-a1-plan.md from tickets.py find, which are one file. TicketTree.discard_unbuilt_plan("1.A1", <that path>) then deletes the file even though it holds ticket: a1 and was written for 1.a1. A twin plan with a body is refused (the frontmatter-only check), so only an unbuilt twin plan is at risk.
  • Observed controls: twins with two entries (same title, case-different titles, or different titles) get distinct names (story-cart-model-plan.md / story-cart-model-a1-plan.md, or …-rules-plan.md), and the discard leaves the twin's plan alone. A three-entry layout with a non-colliding third id (A2 instead of a1) also leaves the other plan alone.
  • Not driven: a tickets run in which this happens (a failed in-place attempt of one twin with rollback_on_failure = true while the other twin's plan is frontmatter-only). Also not driven: the wider consequence that both twins read and mark one shared plan file at all.
  • A tester should try: the layout above with [scm] isolation = "none", rollback_on_failure = true, and max_dev_attempts = 1. Start 1.a1 first and stop it at in-progress with a frontmatter-only plan, then run 1.A1 with a failing session, and check whether 1.a1's plan is gone. Please report whether a real run reaches the deletion.

Related: #963 (the same case-only twin ids alias the unit worktree and branch on Windows).

Summary

tickets.py disambiguates colliding title slugs with the entry id. For case-only twin ids, that suffix differs only by case, so on a case-insensitive filesystem both tickets resolve to one plan file. bmad-loop accepts case-only twin ids in tickets mode (stories mode refuses them), and discard_unbuilt_plan deletes a frontmatter-only plan without checking that its ticket: names the ref being rolled back. The deletion was observed through a direct TicketTree.discard_unbuilt_plan call; the proposed failed-run rollback sequence remains untested.

Environment

bmad-loop a5a8f097, Windows 11 10.0.26200 (NTFS), PowerShell 7.6.6 (SHELL unset), Python 3.13.2; pure calls (the real tickets.py find from the test suite's v7 sandbox, TicketTree.discard_unbuilt_plan); Linux oracle: n/a (on a case-sensitive filesystem the two plan names are two files; expected, not run).

Steps to reproduce (symbol level)

From a bmad-loop checkout at a5a8f097 after uv sync --all-extras, in PowerShell 7 with SHELL removed. The steps are complete and runnable as shown: save the script below as repro_twin_plan.py in the checkout root, then run:

Remove-Item Env:SHELL -ErrorAction SilentlyContinue
$env:PYTHONUTF8 = '1'
uv run python repro_twin_plan.py
import os, sys, tempfile
from pathlib import Path
sys.path.insert(0, "tests")
import conftest as C
from bmad_loop import tickettree
from bmad_loop.journal import Journal

root = Path(tempfile.mkdtemp(prefix="twin-plan-"))
(root / ".gitignore").write_text(C.V7_GITIGNORE, encoding="utf-8")
lay = C.install_bmad_v7(root)
C.write_ticket_tree(lay, (C.EpicSpec(1, "epic-cart", "Cart", (C.EntrySpec(1, "x"),)),))
(lay.initiative_folder / "epic-cart" / "tickets.toml").write_text(
    "".join(f'[[entry]]\nid = "{i}"\ntype = "story"\ntitle = "Cart model"\n\n' for i in ("X1", "A1", "a1")), encoding="utf-8")
C._commit_template(root)
plans = {r: Path(C.run_tickets(lay, "find", r)["plan"]) for r in ("1.A1", "1.a1")}
print({r: p.name for r, p in plans.items()}, "same file:", os.path.normcase(str(plans["1.A1"])) == os.path.normcase(str(plans["1.a1"])))
plans["1.a1"].write_bytes(b"---\nticket: a1\nstatus: in-progress\n---\n")   # 1.a1's unbuilt plan
(root / "run").mkdir()
print(tickettree.TicketTree(root).discard_unbuilt_plan("1.A1", plans["1.A1"], Journal(root / "run")))
print("1.a1's plan exists after 1.A1's discard:", plans["1.a1"].exists())

Observed (Windows, 2 of 2 runs; paths elided):

{'1.A1': 'story-cart-model-A1-plan.md', '1.a1': 'story-cart-model-a1-plan.md'} same file: True
PlanMark(ref='1.A1', …, before='in-progress', after='', outcome='discarded', created=False)
1.a1's plan exists after 1.A1's discard: False

For a non-colliding three-entry control, change the third entry id from a1 to A2, replace both lookup/use keys 1.a1 with 1.A2 throughout the script, and change the written frontmatter from ticket: a1 to ticket: A2. Keep the discard target 1.A1. Expected and observed: the plan names end in -A1-plan.md and -A2-plan.md, the discard returns outcome='noop', and the other plan remains present.

Source

At a5a8f097, src/bmad_loop/tickettree.py:530-565 (discard_unbuilt_plan): _locate(ref, plan) (:534) ties the path to what tickets.py find names for ref (here the shared file), then it reads the plan's status, refuses a plan with a body (:551-554) and unlinks it (:562). The plan's own ticket: is never compared with ref. Stories mode's case-twin guard is src/bmad_loop/stories.py:162-176. Source-derived: the inspected tickets source and engine contain no case-folded ticket-ID collision check; the direct TicketTree reproduction accepts these two refs. The full preflight and engine rollback route was not exercised.

Suggested fix

Not validated: refuse case-only twin ids in the tickets preflight, validate and run --dry-run, as stories mode does. Independently, have discard_unbuilt_plan refuse a plan whose ticket: does not name the ref.

Ngôn ngữ chính
Python
Star
196
Fork
78
Merge trung bình
9 giờ 24 phút
Pull request đã merge (30 ngày)
44

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bmad-code-org/bmad-loop

Tất cả issue của bmad-code-org/bmad-loop

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.