Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "issue-refinement-loop planner が parent issue に対して誤って fail_closed を返すバグを修正し、テンプレート正本設計を導入する"
change_kind: fixParent Issue
none
Parent Goal Ref
- Goal: plan_refinement_loop.py の required section チェックをテンプレート正本から導出し、issue_kind を考慮した条件分岐に修正する
- Desired Destination: N/A(独立 Issue)
Current Validated Scope
.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.pyの_check_missing_outcome()を YAML-parse 方式 + テンプレート正本化に置き換え.claude/skills/issue-refinement-loop/tests/にテストケース追加
Remaining Parent Gaps
なし
Outcome
plan_refinement_loop.py が .github/ISSUE_TEMPLATE/*.yml を正本として読み込み、issue_kind: parent / parent_mode: delivery-rollup の Issue で ## Outcome 欠落だけでは fail_closed を返さず、かつ issue_kind: implementation では従来どおり fail_closed を返す状態
Background
#483 の issue-refinement-loop 実行時に以下の fail_closed が発生した。
"fail_closed": {
"required": true,
"reason_codes": ["missing_required_section"],
"human_message": "Issue contract malformation detected: missing_required_section"
}
#483 は issue_kind: parent / parent_mode: delivery-rollup であり ## Outcome を持たない。
planner の _check_missing_outcome() が issue_kind を考慮せず全 Issue に対して ## Outcome を要求するため、parent tracker に refinement loop を適用できない。
また、現行スクリプトは必須セクション名を直接ハードコードしており、.github/ISSUE_TEMPLATE/*.yml の変更に自動追従できない。テンプレートを正本として読む設計が必要。
In Scope
plan_refinement_loop.pyの required section チェックをテンプレート正本化(.github/ISSUE_TEMPLATE/*.yml読み込み)issue_kindとparent_modeを Machine-Readable Contract YAML から parse する関数の実装issue_kind: parent/parent_mode: delivery-rollupに対する## Outcome免除ロジックissue_kind: implementationの## Outcome欠落 fail_closed の回帰保持- 新規テストケース追加(parent delivery-rollup、誤検知防止ケース)
Out of Scope
- 導入: M2: Combat MVP Gate を playable sortie まで実装する #483 を close 可能にすること
- child issue 完了判定を変更すること
- Product Acceptance / playtest 証跡の品質判定を緩和すること
- parent closure rule の自動判定を追加すること
- M2 完了判定
Acceptance Criteria
- AC1:
plan_refinement_loop.pyがissue_kind: parent/parent_mode: delivery-rollupの Issue に対して## Outcome欠落でfail_closedを返さない - AC2:
issue_kind: implementationの Issue では## Outcome欠落で従来どおりfail_closedを返す - AC3:
issue_kindおよびparent_modeは Machine-Readable Contract の fenced YAML をyaml.safe_load()相当で parse して取得する(plain substring search 禁止) - AC4: fenced code block 内や説明文中に
issue_kind: parentが出現するだけでは parent 扱いしない(誤検知防止) - AC5: 必須セクション集合を
.github/ISSUE_TEMPLATE/<issue_kind>.ymlのvalidations.required: trueなattributes.labelから導出する(スクリプト内へのセクション名ハードコード禁止) - AC6: テンプレート YAML の required label を変更したとき、スクリプト変更なしで検出対象が変わる
- AC7:
issue_kind: parent/parent_mode: delivery-rollupの parent delivery-rollup 必須セクション(## Summary,## Goal,## Parent Closure Rule,## Acceptance Criteria,## Verification Commands)が欠落している場合は別 reason_code で fail_closed を返す - AC8: 既存テスト(
tests/test_thin_entrypoint.py等)が PASS する - AC9:
issue_kind: parentに対する新規テストケースが追加される(Outline: parent delivery-rollup without Outcome → pass / implementation without Outcome → fail / fenced code 内に issue_kind: parent があるだけの implementation → parent 扱いしない)
Verification Commands
# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
# AC8
# AC9
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v
# 品質ゲート
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py.claude/skills/issue-refinement-loop/tests/.github/ISSUE_TEMPLATE/*.yml(読み取り対象;変更不要、テスト fixture 化する場合は tests/ 配下へコピー)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python / PyYAML(safe_load)
- GitHub Issue Forms YAML 仕様(attributes.label / validations.required)
Runtime Verification Applicability
decision: not_applicable
reason: "Python unit tests のみ。DOM/Canvas/server 起動不要"Implementation Notes
YAML parse が必須(plain substring search 禁止)
if "issue_kind: parent" in issue_body: のような文字列検索は、fenced code block 内の例示・説明文中の文字列でも誤判定する。
推奨関数分解:
def resolve_issue_template(issue_kind: str, repo_root: Path) -> Path: ...
def load_required_section_labels(template_path: Path) -> list[str]: ...
def extract_issue_body_sections(issue_body: str) -> set[str]: ...
def find_missing_required_sections(issue_body: str, template_path: Path) -> list[str]: ...
def _extract_machine_contract(issue_body: str) -> dict | None:
# fenced yaml を Machine-Readable Contract 直下から抽出
# yaml.safe_load で dict 化。dict でなければ malformed
...免除対象は parent_mode: delivery-rollup に限定
issue_kind == "parent" 全体を免除せず、parent_mode == "delivery-rollup" の場合のみ ## Outcome を免除する。
Heading parser の改善
line.startswith("## ") の代わりに:
HEADING_RE = re.compile(r"^[ \t]{0,3}##[ \t]+(?P<title>.+?)[ \t#]*$", re.MULTILINE)既存 fixture の維持
malformed/missing_outcome_section.md は issue_kind: implementation として維持する。
positive/parent_delivery_rollup_without_outcome.md を新規追加する。
Activity
squne121 commentedon May 31, 2026
結論
Issue #544 の問題設定は妥当です。#483 は issue_kind: parent / parent_mode: delivery-rollup で、## Outcome を持たず、代わりに ## Goal / ## Summary / child issue 完了で閉じる構造です。にもかかわらず現行 plan_refinement_loop.py は _check_missing_outcome() で単純に "## Outcome" not in issue_body を見ており、issue_kind を考慮していません。これは #544 の主張どおりバグです。
ただし、この Issue のまま実装すると雑な例外化になりやすいです。現状の Acceptance Criteria は「parent なら Outcome 不要 / implementation なら必要」だけですが、実装品質としては Machine-Readable Contract を正しく parse して issue_kind を判定することまで要求すべきです。
敵対的レビュー
Blocker 1: issue_kind: parent の検出方法が未指定
Issue #544 は「issue_kind を考慮」と書いていますが、どう取得するかを定義していません。現行コードは YAML block を文字列検索して contract_schema_version: だけ確認している実装です。
ここで if "issue_kind: parent" in issue_body: のような修正を入れると、以下で壊れます。
fenced code block 内の例示に issue_kind: parent があるだけで parent 扱いになる
コメントや説明文中の文字列で誤判定する
YAML の quote / spacing / ordering 差分で落ちる
malformed contract と valid parent contract の境界が曖昧になる
修正要求:
Machine-Readable Contract の fenced YAML を抽出し、yaml.safe_load() 相当で dict 化して issue_kind / parent_mode を判定すること。PyYAML では untrusted input に対して safe_load を使うべきと公式に説明されています。
Blocker 2: parent 全般で Outcome 不要にするのは過剰緩和
#544 の Summary は issue_kind: parent / parent_mode: delivery-rollup を対象にしていますが、Outcome 免除の AC は issue_kind: parent 全体に広がっています。
#483 では parent_mode: delivery-rollup、closure_mode: child-complete、Parent Closure Rule があり、Outcome の代替として Goal / Child Issues / closure rule が存在します。
修正要求:
単に issue_kind == "parent" で免除せず、少なくとも以下のどちらかに限定すべきです。
issue_kind == "parent" and parent_mode in {"delivery-rollup", "quality-gate", "routing-map", "decision-log"}
またはより安全に、
issue_kind == "parent" and parent_mode == "delivery-rollup"
今回の再発防止だけなら後者で十分です。
Blocker 3: 代替必須セクションが未定義
Outcome を免除するなら、parent issue に何が必須なのかを定義しないと fail-open になります。#483 には ## Summary, ## Goal, ## Child Issues, ## Parent Closure Rule, ## Acceptance Criteria, ## Verification Commands が存在します。
しかし #544 の AC は「Outcome 欠落で fail_closed しない」だけで、## Goal すらない parent を通してよいのか不明です。
修正要求:
parent delivery-rollup の最小 contract を明文化してください。
推奨:
parent delivery-rollup:
required_sections:
- Summary
- Goal
- Child Issues
- Parent Closure Rule
- Acceptance Criteria
- Verification Commands
not_required:
- Outcome
これを実装しないなら、今回の修正は「false positive を消すために validation を弱体化しただけ」になります。
Major 1: Markdown heading parser が脆い
現行 _extract_sections() は line.startswith("## ") だけを見ています。CommonMark の ATX heading は 0–3 spaces の indentation、tab/space、closing # などを許容します。
つまり、今後 ## Outcome ## や ## Outcome のような valid Markdown が入ったときに誤判定します。
修正要求:
_check_missing_outcome() 専用の文字列検索ではなく、heading 抽出を共通化してください。
例:
HEADING_RE = re.compile(r"^[ \t]{0,3}##[ \t]+(?P<title>.+?)[ \t#]*$", re.MULTILINE)
Python re は Unicode 文字列を扱え、re.MULTILINE で行頭 ^ を各行に適用できます。
Major 2: 既存 golden test との衝突を考慮していない
既存 test_plan_refinement_loop.py は fixture と golden JSON の完全一致を見ています。
今回 missing_outcome_section の期待値を変えると、既存の fail_closed テストが壊れる可能性があります。test_fail_closed.py でも missing Outcome は fail_closed になることを明示しています。
修正要求:
既存 fixture を壊さず、以下を追加する形にするべきです。
malformed/missing_outcome_section.md は issue_kind: implementation として維持
positive/parent_delivery_rollup_without_outcome.md を追加
malformed/implementation_missing_outcome.md を明示追加
golden JSON を追加・更新
pytest は parametrized test を標準的にサポートしているため、既存の golden fixture リストに parent ケースを足すのが自然です。
Major 3: #483 の本質問題と混線しやすい
#544 の Notes では「parent issue の Product Acceptance 問題は別 Blocker」としています。
これは正しい分離です。ただし実装者が #483 の M2 完了判定まで直そうとするとスコープ逸脱します。
修正要求:
Issue 本文に明確に追記すべきです。
Non-goal:
#483 は 5/7 child completed の状態で、M2 playable sortie の証跡 issue も child に含まれています。これは今回の planner bug 修正とは別問題です。
望ましい実装方針
最低限こう分解してください。
def _extract_machine_contract(issue_body: str) -> dict[str, Any] | None:
# fenced yaml を Machine-Readable Contract 直下から抽出
# yaml.safe_load
# dict でなければ malformed
def _issue_kind(issue_body: str) -> str | None:
contract = _extract_machine_contract(issue_body)
return contract.get("issue_kind") if contract else None
def _requires_outcome(issue_body: str) -> bool:
contract = _extract_machine_contract(issue_body)
if not contract:
return True
そのうえで、
if _requires_outcome(issue_body) and _check_missing_section(issue_body, "Outcome"):
fail_closed_reasons.append(FAIL_CLOSED_REASON_MISSING_SECTION)
にするのが安全です。
追加すべきテスト
必須:
parent delivery-rollup without Outcome => fail_closed.required=false
implementation without Outcome => fail_closed.required=true
parent delivery-rollup with Goal/Summary/Child Issues => pass
parent delivery-rollup missing Goal => fail_closed.required=true または別 reason
回帰テスト:
fenced code 内に issue_kind: parent がある implementation issue => parent 扱いしない
説明文中に issue_kind: parent があるだけ => parent 扱いしない
Outcome ## を Outcome として認識
Outcome を Outcome として認識
Issue #544 への具体的な追記案
Implementation Notes
Do not detect parent issues by plain substring search over the full issue body.
The planner must parse the fenced YAML Machine-Readable Contract and derive
issue_kind/parent_modefrom that parsed contract.## Outcomeis required forissue_kind: implementation.## Outcomeis not required forissue_kind: parentwithparent_mode: delivery-rollup, because delivery-rollup parents use## Goal,## Child Issues, and## Parent Closure Ruleas the parent-levelcontract.
For delivery-rollup parents, the planner must still fail closed if the
parent-level replacement sections are malformed or missing.
Non-goals
最終判定
Issue #544 は実装してよいが、現状の AC は弱いです。
そのまま実装すると parent 文字列を見つけたら Outcome validation を無効化する雑修正になり、contract validation の信頼性を落とします。
承認条件は次です。
Machine-Readable Contract を parse して issue_kind を判定する
免除対象を parent_mode: delivery-rollup に絞る
implementation の missing Outcome 回帰を保持する
parent delivery-rollup の代替必須セクションを定義する
fenced code / Markdown heading variant の誤判定テストを追加する
squne121 commentedon May 31, 2026
人間コメント
スクリプトがIssueテンプレートをハードコードしてないか?
Issueテンプレートを正本として、テンプレートの変更に追従できるようにしてほしい。
squne121 commentedon May 31, 2026
#544 (comment)
指摘は妥当です。現状 Issue #544 の修正方針は 「issue_kind: parent なら ## Outcome 欠落を許す」 になっていますが、それだとスクリプト側にテンプレート構造を再実装しているだけです。人間コメントの通り、Issue テンプレートを正本として読む設計に直すべきです。
判定
Issue #544 はこのままだと不十分。修正要求すべきです。
根拠は以下です。
plan_refinement_loop.py は _check_missing_outcome() で "## Outcome" not in issue_body を直接見ており、さらに plan_refinement_loop() 側で無条件に missing section として fail_closed に追加しています。これは明確にテンプレート見出しのハードコードです。
一方、リポジトリには .github/ISSUE_TEMPLATE 配下に implementation.yml と parent.yml が存在し、Issue 種別ごとに正本テンプレートが分かれています。 implementation.yml には Outcome が required textarea として定義され、parent.yml は Summary / Goal / Desired Destination などを持つ別構造です。 GitHub Issue Forms は .github/ISSUE_TEMPLATE 配下の YAML で定義され、入力内容は Issue body の Markdown に変換されます。
追加すべきコメント案
この修正方針はまだ危険です。
現状の Issue #544 は「issue_kind: parent のときだけ ## Outcome 欠落を許す」という条件分岐に見えますが、それだと
plan_refinement_loop.pyが Issue テンプレート構造をハードコードし続けます。要求したいのは以下です。
.github/ISSUE_TEMPLATE/*.ymlを正本として読むissue_kindから対応テンプレートを解決する.github/ISSUE_TEMPLATE/implementation.yml.github/ISSUE_TEMPLATE/parent.ymlbody[*].attributes.labelとvalidations.requiredから required section を導出する## Outcome,## Acceptance Criteria,## Verification Commands,## Goal,## Summaryなどの必須見出し集合を固定しない最低限、以下のような設計にしてください。
issue_kindを parseissue_kind→ template file path を解決type: input | textarea | dropdown | checkboxesかつvalidations.required: trueのattributes.labelを required section として抽出## <label>と照合missing_required_sectionにするこれにより、
parent.ymlがOutcomeを持たないならOutcome欠落では fail_closed しないし、将来 parent template にOutcomeを追加した場合は自動的に required になります。受け入れ条件も以下へ変更してください。
plan_refinement_loop.pyに required heading の固定リストを残さない.github/ISSUE_TEMPLATE/implementation.ymlの required fields からOutcome欠落を検出する.github/ISSUE_TEMPLATE/parent.ymlの required fields からSummary/Goal等の欠落を検出するparent.ymlにOutcomeが存在しない限り、parent issue のOutcome欠落では fail_closed しない実装方針
_check_missing_outcome() / _check_missing_ac() / _check_missing_vc() は廃止でよいです。代わりにこういう責務に分けるべきです。
def extract_issue_kind(issue_body: str) -> str | None:
...
def resolve_issue_template(issue_kind: str, repo_root: Path) -> Path:
...
def load_required_section_labels(template_path: Path) -> list[str]:
...
def extract_issue_body_sections(issue_body: str) -> set[str]:
...
def find_missing_required_sections(issue_body: str, template_path: Path) -> list[str]:
...
注意点として、GitHub Issue Forms の正本は id ではなく、生成される Issue body 上の見出しに対応する attributes.label です。GitHub の検証でも label の一意性が問題になるため、照合キーとして自然です。
Issue #544 の修正スコープも変えるべき
現在の Allowed Paths は plan_refinement_loop.py と tests だけですが、テンプレート正本化をやるなら .github/ISSUE_TEMPLATE/*.yml を読む必要があります。Issue 本文の Allowed Paths も以下を許可すべきです。
Allowed Paths
.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py.claude/skills/issue-refinement-loop/tests/.github/ISSUE_TEMPLATE/*.ymlただし、テンプレート自体を変更する必要は基本ありません。読み取り対象として必要、テスト fixture 化するなら fixture 側にコピーを持たせる形でも可です。
squne121 commentedon May 31, 2026
Contract Snapshot (2026-05-31T08:54:30Z)
plan_refinement_loop.pyが.github/ISSUE_TEMPLATE/*.ymlを正本として読み込み、issue_kind: parent/parent_mode: delivery-rollupの Issue で## Outcome欠落だけではfail_closedを返さず、かつissue_kind: implementationでは従来どおりfail_closedを返す状態uv run pytest .claude/skills/issue-refinement-loop/tests/ -v/pnpm typecheck/pnpm lint/pnpm test/pnpm build.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py/.claude/skills/issue-refinement-loop/tests//.github/ISSUE_TEMPLATE/*.yml(読み取りのみ).claude/worktrees/issue-544-issue-refinement-loop-planner-parent-delworktree-issue-544-issue-refinement-loop-planner-parent-delsqune121 commentedon May 31, 2026
implement-issue: 実装完了 (2026-05-31T09:04:15Z)
.claude/worktrees/issue-544-issue-refinement-loop-planner-parent-delworktree-issue-544-issue-refinement-loop-planner-parent-delfix(#544): address review blockers — fenced-code-aware parser, fail-c…
feat(#544): template-driven section validation for parent delivery-ro…
squne121 commentedon May 31, 2026
post-merge-cleanup: 完了 (2026-05-31T09:50:00Z)
.claude/worktrees/issue-544-issue-refinement-loop-planner-parent-del削除済みworktree-issue-544-issue-refinement-loop-planner-parent-del削除済み