Skip to content

feat: issue-refinement-loop に人間 Decision 検出分岐を追加する (#96) - #128

Merged
squne121 merged 2 commits into
mainfrom
worktree-issue-96-issue-refinement-loop-human-decision-bra
May 21, 2026
Merged

squne121 merged 2 commits into
mainfrom
worktree-issue-96-issue-refinement-loop-human-decision-bra

Conversation

@squne121

@squne121 squne121 commented May 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • ## Inputs に anchor_comment_url(任意)を追加し、Step 0a でコメント本文を gh api で取得して LOOP_STATE.anchor_comment に格納する手順を追加
  • Step 0b に4分類コメント分類器(superseded_by_decision / reframe_in_place / feedback_update_required / human_escalation)を追加
  • Step 0c に superseded_by_decision 分岐の4ステップ手順(issue-author ドラフト → create-issue → gh issue close --reason "not planned" → close コメント記録)を追加
  • LOOP_STATE.termination_reason に superseded_by_decision を追加、anchor_comment フィールドを追加
  • Step 5 テーブルと ループ終了判定テーブルに superseded_by_decision 行を追加

Closes #96

Verification Results

  • AC1: PASS(superseded_by_decision が7箇所)
  • AC2: PASS(人間 Decision シグナル の記述あり)
  • AC3: PASS(gh issue close / クローズ の記述あり)
  • AC4: PASS(issue-author が Step 0c 行116 でもヒット)
  • AC5: PASS(anchor_comment_url が Inputs に存在)
  • AC6: PASS(feedback_update_required / reframe_in_place の4分類記述あり)
  • AC7: PASS(not planned が記述あり)
  • AC8: PASS(count=7)

VC(B3〜B7):

コマンド 結果
B3 schema check PASS
B4 validation check PASS
B5 atomic close check PASS
B6 idempotency check PASS
B7 contract check PASS
pnpm typecheck PASS
pnpm lint PASS
pnpm test PASS (5/5)
pnpm build PASS
uv run pytest test_model_routing.py PASS (21/21)

Allowed Paths Compliance

変更ファイル: .claude/skills/issue-refinement-loop/SKILL.md のみ(Allowed Paths 内)

改善点・観察事項(REQUEST_CHANGES 対応後)

今回の REQUEST_CHANGES で気づいた設計上の改善点

  • 暫定分類と最終分類の分離の重要性(B1): superseded_by_decision を即時確定していた設計は、コメントが事実主張を含む場合に誤クローズリスクがあった。preliminary → codebase/web 検証 → final という2段階にすることで、フロー制御の正確性が大幅に向上する
  • Step 入力契約の明示化(B2): SubAgent への入力仕様が曖昧なままでは実装者(AI/人間)が anchor comment をどのように注入するかを推測しなければならない。入力テンプレートを YAML で明示することで委任境界が明確になる
  • LOOP_STATE スキーマの拡張(B3): preliminary_classification / final_classification / scope_impact を State に持つことで、フロー途中でもループ状態が常に自己説明的になり、デバッグや人間レビューが容易になる

実装中に判明した追加の観察事項

  • SubAgent 委任設計: ALTERNATIVE_ISSUE_DRAFT_V1 のような出力契約を定義することで、SubAgent の返答フォーマットが保証され、main thread がその後の create-issue 呼び出しを確実に実行できる。出力契約なしでは呼び出し元が SubAgent の自由形式テキストをパースするリスクが生じる
  • 冪等性設計(B6): anchor_comment_url を持つ既存 OPEN Issue を検索してから新規起票を判断する設計は、ネットワーク障害・retry・複数回起動のシナリオで重複 Issue を防ぐ。同一 URL を Background に持つ Issue の検索は gh issue list + --search で実装可能
  • B5 の統合 close コマンド: gh issue close --comment の単一コマンドにより、close と close コメントの間の「半クローズ状態」(close だけ実行されて comment が失敗するケース)が排除される。これはトランザクション的な一貫性の改善
  • anchor_comment_url のリポジトリ名ハードコード(既存観察の継続): Step 0a の gh api repos/squne121/loop-protocol/... はリポジトリ名をハードコードしている。動的取得への改善は follow-up Issue が望ましい

🤖 Generated with Claude Code

anchor_comment_url(任意)入力と Step 0 コメント分類器(4分類)を追加し、
superseded_by_decision 分岐では gh issue close --reason "not planned" で
対象 Issue をクローズして代替 Issue 番号を close コメントへ記録する手順を明文化する。
これにより refinement loop が前提否決済み Issue を誤って approve へ磨かないようにする。

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=CLEAN

Evidence Check

AC 詳細照合

  • AC1: superseded_by_decision が追加行に 7 箇所(LOOP_STATE.termination_reason 定義 + Step 5 テーブル含む)
  • AC2: 「人間 Decision シグナル」「人間 Decision」が追加行に 3 箇所
  • AC3: gh issue close / クローズ が追加行に 6 箇所
  • AC4: issue-author が Step 0c(Decision 分岐)の委譲先記述で確認
  • AC5: anchor_comment_url が ## Inputs セクションに追加
  • AC6: feedback_update_required / reframe_in_place が4分類テーブルに記載
  • AC7: gh issue close <issue_number> --reason "not planned" が明記
  • AC8: superseded_by_decision が 2 箇所以上(7 箇所)

Blockers

なし

Non-blockers(任意改善)

  • PR 本文で指摘されている gh api repos/squne121/loop-protocol/... のリポジトリ名ハードコードは follow-up Issue 化が推奨されているが、今回のスコープ外の軽微な改善であり merge 非阻害

LOOP_VERDICT

verdict: APPROVE
blockers: []
mergeable: MERGEABLE
mergeStateStatus: CLEAN
reviewed_head_sha: f4f76984909db33d20171f3c73881e3390bc82dd

@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES / No-Go as-is

PR #128 は AC の文字列充足と CI は通っていますが、実運用の control-plane としてはまだ危険です。特に「コメント分類 → superseded_by_decision → 代替 Issue 起票 → 元 Issue close」という破壊的分岐に対して、事実確認・対象コメント検証・冪等性・失敗時復旧が不足しています。PR 本文上も変更は .claude/skills/issue-refinement-loop/SKILL.md のみで、既存レビューは AC 8/8 PASS を根拠に APPROVE していますが、レビュー内容は構文・文字列照合寄りです。

主要 Blockers

1. Step 0b が「事実確認前」に分類してしまう

#96 の背景は、#79 のように「コメントの主張が Issue 前提を覆すか」をコードベース調査で確認する必要があるケースです。#79 のコメントでは「retry は既に実装済みなので、Issue は retry 追加ではなく retry contract 固定に直すべき」とされており、これは人間の close Decision ではなく、コードベース事実に基づく再フレームです。

しかし PR #128 の Step 0b は LOOP_STATE.anchor_comment.snapshot を読んだ直後に4分類し、superseded_by_decision なら Step 0c に進みます。codebase-investigator / web-researcher による検証は Step 1 以降なので、分類順序が逆です。

修正方針:

Step 0b は「暫定分類」に留める。
anchor comment が repo 実装事実・外部仕様・既存 Issue/PR 事実を主張する場合は、
Step 0b-verification を挟み、検証結果を LOOP_STATE に格納してから最終分類する。

最低限、superseded_by_decision は以下の AND 条件にしてください。

superseded_by_decision:
  required:
    - human explicitly says close / do not implement / replace this issue
    - issue outcome cannot be repaired in-place
    - alternative destination can be deterministically created or reused

2. reframe_in_place / feedback_update_required の分岐が宣言だけで、実行可能な入力契約になっていない

PR は「anchor comment を codebase-investigator と Step 4 の reviewer_feedback_text に注入」と書いていますが、Step 1 の実際の入力テンプレートは issue_number と focus_topics のままで、Step 4 も review-issue の diff_proposal を整形した文字列のままです。つまり、分類器の2分岐が control-flow 上は存在しても、後続 SubAgent への渡し方が未定義です。

修正方針:

Step 1 inputs:
  issue_number: <LOOP_STATE.issue_number>
  focus_topics: ...
  anchor_comment:
    url: <LOOP_STATE.anchor_comment.url>
    snapshot: <LOOP_STATE.anchor_comment.snapshot>
    classification: <...>
    required_checks:
      - verify whether the comment invalidates Outcome / In Scope / AC
      - distinguish fact correction from scope replacement

Step 4 inputs:
  reviewer_feedback_text: <review-issue diff_proposal + anchor_comment normalized feedback>
  anchor_comment_feedback:
    classification: reframe_in_place | feedback_update_required
    required_edits: ...

3. LOOP_STATE が分類結果を保持できない

本文では「分類根拠と分類を LOOP_STATE に記録」と書いていますが、追加された LOOP_STATE.anchor_comment は url と snapshot だけです。classification、classification_reason、verified_claims、alternative_issue_number、close_comment_posted などがありません。これでは実行後監査も失敗復旧もできません。

推奨スキーマ:

anchor_comment:
  url: null
  id: null
  issue_number: null
  snapshot: null
  classification: null  # preliminary | final の区別も可
  classification_reason: null
  verified_claims: []
  unresolved_claims: []
  scope_impact: null     # none | amend | replace | ambiguous

superseded_decision:
  decision_summary: null
  alternative_issue_number: null
  alternative_issue_url: null
  close_reason: null
  close_comment_posted: false

4. anchor_comment_url の検証が弱く、別 Issue のコメントで対象 Issue を close できる

現在の取得手順は URL 末尾の数値を抜き出して issues/comments/$COMMENT_ID を取得するだけです。GitHub REST API には issue comment ID からコメントを取得する endpoint 自体はありますが、レスポンスには issue_url も含まれます。PR の手順では、取得したコメントが <issue_number> に属しているか検証していません。([GitHub Docs]1)

この欠陥は深刻です。同じ repo 内の別 Issue コメントを anchor_comment_url として渡した場合、誤って対象 Issue を not planned close する経路が残ります。

修正方針:

comment_json=$(gh api "repos/$OWNER/$REPO/issues/comments/$COMMENT_ID")
comment_issue_number=$(echo "$comment_json" | jq -r '.issue_url | capture("/issues/(?<n>[0-9]+)$").n')

test "$comment_issue_number" = "<issue_number>" || {
  echo "anchor_comment_url does not belong to target issue"
  exit 1
}

5. close と close コメントが2コマンドに分離され、監査ログ欠落リスクがある

PR の Step 0c は先に gh issue close --reason "not planned" を実行し、その後 gh issue comment で close コメントを投稿します。後段が失敗すると、Issue は閉じたが代替 Issue / Decision / anchor comment の監査ログがない状態になります。gh issue close は --comment と --reason を同時に受け取れるため、少なくとも単一 CLI 呼び出しに寄せるべきです。([GitHub CLI]2)

修正案:

gh issue close <issue_number> \
  --reason "not planned" \
  --comment "$(cat <<EOF
## issue-refinement-loop: クローズ ($(date -u +%Y-%m-%dT%H:%M:%SZ))

- termination_reason: superseded_by_decision
- anchor_comment: <anchor_comment_url>
- Decision 要約: <Decision の要約>
- 代替 Issue: #<代替 Issue 番号>
- 次アクション: 代替 Issue #<代替 Issue 番号> を起点に refinement を再開してください
EOF
)"

6. 代替 Issue 起票が冪等ではない

#76 の実例では close + 代替 Issue #92 が妥当でした。コメントに「Issue はクローズ」と明示され、後続 Issue #92 / #95 / #96 へ整理されています。

しかし PR #128 の Step 0c は、再実行時に既存の代替 Issue を検出する手順がありません。create-issue skill 側には類似 Issue 検出や重複チェックの仕組みがありますが、Step 0c の代替 Issue 起票に「既存 close コメント・既存代替 Issue・同一 anchor comment の再利用」を必須化していません。

追加すべき前処理:

Step 0c-0: Idempotency preflight
- 元 Issue コメントに `termination_reason: superseded_by_decision` が既にあるか確認
- 既に `代替 Issue: #N` がある場合、新規起票せず #N を再利用
- 同一 anchor_comment_url を Background に持つ open/closed Issue を検索
- 既存 destination が見つかったら create-issue を呼ばない

7. SubAgent への委任仕様が曖昧

Claude Code 公式ドキュメントでは、SubAgent は独自 context window・独自 system prompt・独立 permissions で動きます。したがって、親スレッドが読んだ Issue 本文、anchor comment、Decision 要約、期待する出力形式は明示的に渡す必要があります。([Claude API Docs]3)

PR #128 の「issue-author SubAgent に渡して代替 Issue 本文案を作成」は弱いです。issue-author が何を返すべきか、create-issue skill にどの形で渡すか、代替 Issue を review-issue で検査するかが未定義です。Claude Code では skills を frontmatter で preload でき、full skill content が注入されるため、issue-author が create-issue を直接扱うのか、main thread が扱うのかも明示すべきです。([Claude API Docs]3)

推奨出力契約:

ALTERNATIVE_ISSUE_DRAFT_V1:
  title: string
  body: string
  rationale:
    source_issue: <issue_number>
    anchor_comment_url: string
    decision_summary: string
  validation:
    preserves_parent_goal: true | false
    allowed_paths_defined: true | false
    ac_vc_complete: true | false

8. #92 型の「コメントで新要件追加」には対応し始めているが、判定がまだ粗い

#92 の関連コメントでは、No-Go as-is / Revise before implementation や AC 追加が入った場合、close ではなく本文更新として扱うべきことが記録されています。

PR #128 は feedback_update_required を追加していますが、検出条件が「AC/VC/In Scope の追加・修正を要求」程度で、#92 のような「本文は変わっていないがコメントが最新仕様」という stale approval 問題に対する処理が不十分です。

追加すべき判定:

If anchor comment contains:
- No-Go as-is
- Revise before implementation
- AC追加 / VC追加 / In Scope変更
- 本文に未反映の adversarial review

Then:
- last_verdict を無効化
- review-issue approve 済みでも needs-fix として扱う
- reviewer_feedback_text に anchor comment を正規化して渡す

最小パッチ方針

この PR を merge 可能にする最小修正は次です。

  1. Step 0b を「暫定分類」に変更し、事実確認が必要な comment は codebase-investigator / web-researcher を先に通す。
  2. LOOP_STATE.anchor_comment に id / issue_number / classification / classification_reason / verified_claims / scope_impact を追加する。
  3. anchor_comment_url 取得後、コメントの issue_url が対象 <issue_number> と一致することを検証する。
  4. reframe_in_place / feedback_update_required の Step 1・Step 4 入力テンプレートを実際に更新する。
  5. Step 0c に冪等性 preflight を追加し、既存代替 Issue を再利用する。
  6. close は gh issue close --reason "not planned" --comment ... に統合する。
  7. issue-author の代替 Issue draft 出力を ALTERNATIVE_ISSUE_DRAFT_V1 のような機械可読契約にする。
  8. Step 5 の汎用完了コメントテンプレートから superseded_by_decision を明示的に除外するか、専用テンプレートに分離する。

PR に貼れるレビューコメント案

## Verdict: REQUEST_CHANGES

AC/CI は通っていますが、`superseded_by_decision` が破壊的操作(代替 Issue 起票 + 元 Issue close)を行う分岐としては安全性が不足しています。

### Blockers

1. Step 0b が anchor comment を事実確認前に分類しており、#79 型の「コメント主張の repo reality 検証が必要なケース」を誤って close 分岐へ送る危険があります。
2. `anchor_comment_url` から取得したコメントが対象 `<issue_number>` に属することを検証していません。別 Issue のコメントで対象 Issue を close できる経路が残ります。
3. `reframe_in_place` / `feedback_update_required` は宣言されていますが、Step 1 / Step 4 の実入力テンプレートに anchor comment が渡されていません。
4. `LOOP_STATE` に classification / rationale / verified_claims / alternative_issue_number がなく、分類根拠・復旧・監査ができません。
5. close と close コメントが別コマンドで、コメント投稿失敗時に監査ログなし close が発生します。`gh issue close --reason "not planned" --comment ...` に統合してください。
6. 代替 Issue 起票が冪等ではありません。再実行時に既存代替 Issue を検出・再利用する preflight が必要です。
7. `issue-author` への代替 Issue draft 委任に機械可読な入出力契約がありません。

### Required fix

- Step 0b を preliminary classification に変更し、必要に応じて codebase/web fact-check を挟む
- anchor comment の issue 所属検証を追加
- LOOP_STATE を拡張
- Step 1 / Step 4 input contract を更新
- Step 0c に idempotency preflight を追加
- close を `--comment` 付き単一コマンドへ変更
- alternative issue draft の output schema を追加

現状のまま ready/merge すると、修正で済む Issue を誤って close + 再起票する運用事故が起き得ます。

総括

#96 の方向性は正しいです。#76 のような「明示 Decision + Issue close」ケース、#92 のような「新要件追加で本文更新」ケース、#79 のような「事実確認により前提修正」ケースを分ける必要があります。PR #128 は分類名を導入した点は前進ですが、実行順序・入力契約・冪等性・監査ログの設計が未完成です。現時点では merge ではなく修正要求が妥当です。

B1: Step 0b を「暫定分類」に変更し superseded_by_decision の AND 条件を明記
B2: Step 1 / Step 4 への anchor_comment 入力契約テンプレートを追記
B3: LOOP_STATE.anchor_comment スキーマに preliminary/final_classification,
    verified_claims, unresolved_claims, scope_impact, superseded_decision を追加
B4: Step 0a に comment の issue 所属検証コマンドを追加
B5: close + コメント投稿を gh issue close --comment 単一コマンドに統合
B6: Step 0c-0 に Idempotency preflight を追加(既存代替 Issue の再利用)
B7: ALTERNATIVE_ISSUE_DRAFT_V1 出力契約を定義し main thread による起票を明記
B8: Step 2 に stale approval 無効化条件(No-Go as-is 等)を追記

Verification Commands セクションに B3〜B7 の rg チェックを追加。
全品質ゲート (typecheck / lint / test / build / pytest) PASS。

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=CLEAN

Evidence Check

  • AC coverage: 8/8 PASS(diff 内追加行で全 AC を確認)

    • AC1: superseded_by_decision が diff 追加行に 13 箇所(LOOP_STATE termination_reason 定義 + Step 5 テーブル他)PASS
    • AC2: 人間 Decision シグナル 列ヘッダ、人間 Decision により Issue の前提が覆されている場合 記述あり PASS
    • AC3: gh issue close <issue_number> \ --reason "not planned" \ --comment ... コマンド、クローズ 記述あり PASS
    • AC4: issue-author が Step 0c(行 116 付近)と Step 4 の両コンテキストで記述あり PASS
    • AC5: anchor_comment_url が ## Inputs セクションに追加 PASS
    • AC6: feedback_update_required / reframe_in_place が4分類テーブルに存在 PASS
    • AC7: --reason "not planned" 記述あり PASS
    • AC8: superseded_by_decision が diff 追加行に 13 箇所(LOOP_STATE + Step 5 + ループ終了判定テーブル他)PASS
  • 前回 REQUEST_CHANGES Blockers 解消確認(B1〜B8):

    • B1: Step 0b が preliminary classification に変更され、AND 条件付き superseded_by_decision 確定条件を明記。Step 1 後に final_classification を確定する2段階フロー追加 PASS
    • B2: Step 1 inputs に anchor_comment.url / snapshot / classification / required_checks フィールドを追加。Step 4 inputs に anchor_comment_feedback: { classification, required_edits } を追加 PASS
    • B3: LOOP_STATE に preliminary_classification / final_classification / classification_reason / verified_claims / unresolved_claims / scope_impact および superseded_decision サブスキーマ追加 PASS
    • B4: comment_issue_number=$(echo "$comment_json" | jq -r '.issue_url | capture("/issues/(?<n>[0-9]+)$").n') で issue 所属検証を追加 PASS
    • B5: gh issue close <issue_number> \ --reason "not planned" \ --comment "..." の単一コマンドに統合(close と close コメントが分離しない)PASS
    • B6: Step 0c-0 Idempotency preflight 追加(既存代替 Issue 検索・再利用)PASS
    • B7: ALTERNATIVE_ISSUE_DRAFT_V1 YAML 出力契約(title / body / rationale / validation)定義追加 PASS
    • B8: Step 2 に No-Go as-is / Revise before implementation / AC追加 / VC追加 / In Scope変更 / 本文に未反映 adversarial review の各条件で last_verdict 無効化と needs-fix 扱いへの切り替えロジックを追加 PASS
  • Allowed Paths: .claude/skills/issue-refinement-loop/SKILL.md のみ変更 → 遵守

  • CI Verification: build / lint / python-test / test / typecheck 全 PASS(5/5)

  • 検証コマンド結果: PR 本文の ## Verification Results に AC1〜AC8 および B3〜B7 拡張VC、pnpm 4コマンド、pytest 21/21 の結果が明記

Blockers

なし

Non-blockers(任意改善)

  • gh api repos/squne121/loop-protocol/issues/comments/$COMMENT_ID の OWNER/REPO が今も静的埋め込みになっている点は、PR 本文の「既存観察」に記録されており、follow-up Issue #127 に整理済みとの記載あり。このスコープでは non-blocker

LOOP_VERDICT

verdict: APPROVE
blockers: []
mergeable: MERGEABLE
mergeStateStatus: CLEAN
reviewed_head_sha: 6dfc1449c6a2ff9238abbf52fcc930d7c466bbd7

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.

改善: issue-refinement-loop に「対象コメントが Issue 前提を覆す人間 Decision を含む場合」の分岐を追加する

1 participant