Skip to content

fix: issue-refinement-loop の scope_signal_guard 停止を valid termination_cause に正規化する #919

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "scope_signal_guard 停止時の termination_cause を valid enum に正規化し、一発で termination report が投稿されるようにする"
change_kind: code

Parent Issue

none(単独修正)

Parent Goal Ref

  • Goal: issue-refinement-loop の scope_signal_guard 停止が termination report publish failure なく完了する
  • Desired Destination: scope_signal_guard.triggered=true の停止で valid termination_cause: human_judgment_required が自動的に選ばれ、publish が一発で成功する状態

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/ 内の orchestrator / termination payload assembly 箇所で scope_signal_guard.triggered=true 時の termination_cause 正規化を実装する
  • .claude/skills/issue-refinement-loop/tests/ に regression fixture を追加する
  • .claude/skills/issue-refinement-loop/references/termination-policy.md に正規化手順を反映する
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md に orchestrator 向け注記を追記する
  • .claude/skills/issue-refinement-loop/SKILL.md に正規化手順を明記する

Remaining Parent Gaps

  • #922(scope_signal_guard 停止時の next-agent prompt 生成)は本 Issue の正規化が前提となるが、別 Issue で対応
  • 他の stop condition(scope_change 等)の termination_cause 正規化は必要に応じて別 Issue で対応

Background

Issue #907 の issue-refinement-loop で scope_signal_guard.triggered=true により human escalation 停止した際、termination report の publish が termination_cause: scope_signal_guard_triggered を渡して失敗した。

render_termination_report.py の valid termination_cause は human_judgment_required / max_iterations_exceeded / needs_fix_at_iteration_limit / null のみであり、planner の reason_code と termination_cause の語彙が混同された。根本原因は「caller が scope_signal_guard.reason_code を termination_cause に直接渡した」点であり、renderer の enum を拡張することは Non-Goal。

参考: #907 停止コメント

Outcome

scope_signal_guard.triggered=true のとき、orchestrator が termination_cause: human_judgment_required を自動的に使用し、planner の reason_code は blockers_summary / diagnostics に保持された状態になる。scope_signal_guard_triggered を termination_cause として renderer/publisher に直接渡す経路は fail-closed のまま維持され、pytest の regression test で確認できる。

In Scope

  • .claude/skills/issue-refinement-loop/SKILL.md
    • scope_signal_guard 停止時の termination_cause 正規化手順を明記する
  • .claude/skills/issue-refinement-loop/scripts/ 内の orchestrator 呼び出し箇所
    • scope_signal_guard.triggered=true の場合、termination_cause: human_judgment_required に正規化する
    • planner の reason_code は blockers_summary に追記する
  • .claude/skills/issue-refinement-loop/tests/
    • scope_signal_guard.reason_code=new_allowed_path_layer の fixture で、publisher に渡る termination_cause が human_judgment_required になること
    • invalid termination_cause: scope_signal_guard_triggered を renderer/publisher に直接渡す fixture が fail-closed になること(pytest 全体は PASS)
  • .claude/skills/issue-refinement-loop/references/termination-policy.md
    • scope_signal_guard 停止時の termination payload 組み立て手順を反映する
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md
    • triggered=true 時の termination_cause 正規化について orchestrator 向け注記を追記する

Out of Scope

  • render_termination_report.py の VALID_TERMINATION_CAUSES enum への scope_signal_guard_triggered 追加
  • plan_refinement_loop.py の判定ロジック変更
  • scope_signal_guard 自体の停止条件の変更
  • #922 の next-agent prompt 生成ロジックの変更(別 Issue)
  • scope_signal_guard 以外の stop condition の termination_cause 正規化

Allowed Paths

  • .claude/skills/issue-refinement-loop/SKILL.md
  • .claude/skills/issue-refinement-loop/scripts/
  • .claude/skills/issue-refinement-loop/tests/
  • .claude/skills/issue-refinement-loop/schemas/
  • .claude/skills/issue-refinement-loop/references/termination-policy.md
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md

Additional Constraints

  • render_termination_report.py の VALID_TERMINATION_CAUSES に scope_signal_guard_triggered を追加してはならない。
  • planner の scope_signal_guard.reason_code と termination report の termination_cause を混同してはならない。
  • scope_signal_guard.triggered=true の停止では、termination report input の termination_cause を human_judgment_required に正規化する。
  • reason_code は blockers_summary / diagnostics artifact に保持する。
  • renderer の enum を緩めるのではなく、orchestrator / termination payload assembly 側で正規化する。

Acceptance Criteria

  • AC1: scope_signal_guard.triggered=true かつ reason_code=new_allowed_path_layer の fixture で、termination report input の termination_cause が human_judgment_required になる
  • AC2: scope_signal_guard.reason_code は blockers_summary または diagnostics artifact に残り、終了コメントまたは artifact から確認できる
  • AC3: scope_signal_guard_triggered を termination_cause として renderer/publisher に直接渡す fixture は fail-closed になり、pytest の regression test 自体は PASS する
  • AC4: max_iterations_exceeded / needs_fix_at_iteration_limit / 明示的 human_judgment_required の既存挙動が変わらない
  • AC5: SKILL.md に scope_signal_guard 停止時の termination_cause 正規化手順が明記されている

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v

# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v

# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v

# AC4
$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v
$ pnpm typecheck
$ pnpm lint

# AC5
# baseline-expect: pass
$ rg -n "scope_signal_guard" .claude/skills/issue-refinement-loop/SKILL.md

Runtime Verification Applicability

applicability: not_applicable
decision: not_applicable
reason: 全 AC は pytest fixture で決定論的に検証可能であり、外部サービス・CI 実行時依存はない。

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • render_termination_report.py の enum 変更が必要と判断した場合(Non-Goal 確認のうえ停止)
  • plan_refinement_loop.py の判定ロジック変更が必要と判断した場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • scope_signal_guard 以外の停止条件への波及が判明した場合
  • 既存テストの大規模改変が必要と判断した場合(小規模な fixture 追加のみが許容範囲)

Required Skills

  • Python(pytest fixture 設計・subprocess / renderer 呼び出し検証)
  • issue-refinement-loop の orchestrator / termination flow の理解

Non-Goals

  • render_termination_report.py の enum 拡張(既存 enum を維持する)
  • plan_refinement_loop.py の判定ロジック変更
  • scope_signal_guard 自体の停止条件の変更
  • #922 の next-agent prompt 生成ロジックの変更(別 Issue)

Activity

  1. added
    bug
    on Jun 14, 2026
  2. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    結論: #919 は実施価値があります。ただし現状の Issue は、証跡・Allowed Paths・AC3 が弱く、このまま Claude Code / Codex CLI に投げると「renderer enum をいじる」「既存テストをなぞるだけ」「pytest を意図的に失敗させる」方向に逸れるリスクがあります。

    敵対的レビュー

    1. 参照証跡が弱い

    #919 は「#907 で termination_cause: scope_signal_guard_triggered を渡して publish が失敗した」と書いていますが、参照先として挙げている #907 停止コメント自体は、最終的に termination_cause: human_judgment_required で投稿されています。つまり、#919 の主張する失敗は 現在の参照コメントからは直接確認できません。Issue 本文には、失敗した artifact、stderr、session log、または invalid payload の実例を追加すべきです。

    2. 修正場所は renderer ではなく、termination payload 組み立て側

    render_termination_report.py はすでに VALID_TERMINATION_CAUSES として needs_fix_at_iteration_limit / max_iterations_exceeded / human_judgment_required / None を持ち、invalid cause を reject する設計です。ここに scope_signal_guard_triggered を足すのは、#919 の Non-Goal とも衝突します。([GitHub]1)

    既存の PR #833 は、human_escalation で cause 未指定なら human_judgment_required に補完し、blocker_summary legacy alias を blockers_summary に正規化する修正でした。つまり今回の問題は「missing cause fallback」ではなく、planner reason_code を termination_cause に混入させる caller 側バグです。

    3. Allowed Paths が不足している

    #919 は SKILL.md を In Scope にしていますが、現行 SKILL.md は Step 5 の終了条件を references/termination-policy.md に委譲し、scope_signal_guard の意味論も reference 側を読ませる構造です。scope-signal-guard.md も「planner を SSOT とし、orchestrator は triggered / excluded_by_anchor_reframe / reason_code を consume するだけ」と明記しています。したがって、Allowed Paths に少なくとも次を追加すべきです。([GitHub]2)

    .claude/skills/issue-refinement-loop/references/termination-policy.md
    .claude/skills/issue-refinement-loop/references/scope-signal-guard.md
    

    4. AC3 の表現が危険

    現状の AC3 は「scope_signal_guard_triggered を termination_cause に渡す経路がテストで失敗する(pytest で exit 1)」となっていますが、これは回帰テストとして曖昧です。pytest 全体は PASS すべきで、失敗すべきなのはテスト内で起動する renderer/publisher subprocess、または _validate_input() の対象入力です。

    修正案:

    - [ ] AC3: `termination_cause: scope_signal_guard_triggered` を renderer/publisher に直接渡す fixture は fail-closed になり、pytest の regression test 自体は PASS する

    pytest では @pytest.mark.parametrize で複数入力・期待値を並べられるため、valid cause と invalid cause を同じテーブルで固定するのが妥当です。([docs.pytest.org]3)

    5. #922 との依存関係を明示すべき

    #922 は「Issue #907 型の scope_signal_guard 停止で valid termination_cause を使う prompt が生成される」ことを AC にしています。#919 が未解決のまま #922 を進めると、next-agent prompt 側が独自に正規化ロジックを持ち始めるリスクがあります。#922 は #919 の後続、または #919 で追加する helper を reuse する依存関係にした方がよいです。

    Issue 本文に追記すべき改善案

    ## Additional Constraints
    
    - `scope_signal_guard_triggered` / `new_allowed_path_layer` などの planner diagnostic reason_code を `termination_cause` enum に追加してはならない。
    - `termination_cause` は termination report schema の coarse cause として維持する。
    - planner の `scope_signal_guard.reason_code` は `blockers_summary`、local artifact、または diagnostics に保持する。
    - renderer の enum を緩めるのではなく、orchestrator / next-action decision / termination payload assembly 側で正規化する。
    
    ## Additional Allowed Paths
    
    - `.claude/skills/issue-refinement-loop/references/termination-policy.md`
    - `.claude/skills/issue-refinement-loop/references/scope-signal-guard.md`
    
    ## Revised Acceptance Criteria
    
    - [ ] AC1: `scope_signal_guard.triggered=true` かつ `reason_code=new_allowed_path_layer` の fixture で、termination report input の `termination_cause` が `human_judgment_required` になる
    - [ ] AC2: `scope_signal_guard.reason_code` は `blockers_summary` または diagnostics artifact に残り、GitHub comment からも確認できる
    - [ ] AC3: `scope_signal_guard_triggered` を `termination_cause` として renderer/publisher に直接渡す fixture は fail-closed になり、pytest の regression test 自体は PASS する
    - [ ] AC4: `max_iterations_exceeded` / `needs_fix_at_iteration_limit` / explicit `human_judgment_required` の既存挙動を変えない
    - [ ] AC5: #922 の next-agent prompt 生成は、この正規化後の valid `termination_cause` を前提にする

    実装方針

    実装者にはこう指示するのが安全です。

    #919 を実装してください。
    
    重要:
    - `render_termination_report.py` の `VALID_TERMINATION_CAUSES` に `scope_signal_guard_triggered` を追加しないでください。
    - planner の `scope_signal_guard.reason_code` と termination report の `termination_cause` を混同しないでください。
    - `scope_signal_guard.triggered=true` の停止では、termination report input の `termination_cause` を `human_judgment_required` に正規化してください。
    - `reason_code` は `blockers_summary` / diagnostics artifact に保持してください。
    - pytest 全体は PASS させてください。AC3 は「invalid input が fail-closed になることを pytest で確認する」という意味に修正してください。
    
    優先調査:
    - `.claude/skills/issue-refinement-loop/scripts/` 内で termination report input を組み立てている箇所
    - `decide_next_loop_action.py` / `test_decide_next_loop_action.py`
    - `publish_termination_report.py` 呼び出し前の payload assembly
    - `references/termination-policy.md`
    - `references/scope-signal-guard.md`
    
    期待する最終状態:
    - #907 型の scope_signal_guard stop で、一発で publishable な termination report が生成される
    - comment には `Termination cause: human_judgment_required` が出る
    - blocker には `scope_signal_guard.triggered=true` と `reason_code: new_allowed_path_layer` が残る
    - invalid `termination_cause: scope_signal_guard_triggered` は fail-closed のまま維持される
    

    外部仕様的にも、JSON Schema の enum は固定値集合に制限するための仕組みなので、diagnostic code を enum に混ぜて拡張するより、enum は固定し、入力正規化レイヤーで mapping する方が筋がよいです。([json-schema.org]4)

  3. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    CONTRACT_REVIEW_RESULT_V1

    schema: CONTRACT_REVIEW_RESULT_V1
    status: go
    issue_number: 919
    generated_at: "2026-06-15T10:00:00Z"
    
    checks:
      template_compliance: pass
      state_label: pass       # state/needs-human なし
      allowed_paths_present: pass
      vc_present: pass
      stop_conditions_complete: pass
      product_spec_check:
        applicability: not_applicable
        decision: pass
      worktree_branch_collision: pass
      ac_verifiability: pass
      next_action: implement
      blocked_reasons: []
    
    vc_preflight:
      status: pass
      summary:
        expected_fail: 0
        unexpected_pass: 0
        blocked: 0
        human_judgment: 0
        expected_pass: 7
        skipped: 0
      classifications:
        - ac: AC1
          command: "uv run pytest .claude/skills/issue-refinement-loop/tests/ -v"
          scope_class: regression_gate
          decision: go
        - ac: AC2
          command: "uv run pytest .claude/skills/issue-refinement-loop/tests/ -v"
          scope_class: regression_gate
          decision: go
        - ac: AC3
          command: "uv run pytest .claude/skills/issue-refinement-loop/tests/ -v"
          scope_class: regression_gate
          decision: go
        - ac: AC4
          command: "uv run pytest .claude/skills/issue-refinement-loop/tests/ -v"
          scope_class: regression_gate
          decision: go
        - ac: AC4
          command: "pnpm typecheck"
          scope_class: regression_gate
          decision: go
        - ac: AC4
          command: "pnpm lint"
          scope_class: regression_gate
          decision: go
        - ac: AC5
          command: "rg -n \"scope_signal_guard\" .claude/skills/issue-refinement-loop/SKILL.md"
          scope_class: regression_gate
          decision: go
    
    contract_snapshot:
      outcome: "scope_signal_guard.triggered=true のとき、orchestrator が termination_cause: human_judgment_required を自動的に使用し、planner の reason_code は blockers_summary/diagnostics に保持された状態になる"
      acceptance_criteria:
        - "AC1: scope_signal_guard.triggered=true かつ reason_code=new_allowed_path_layer の fixture で termination_cause が human_judgment_required になる"
        - "AC2: scope_signal_guard.reason_code は blockers_summary または diagnostics artifact に残り確認できる"
        - "AC3: scope_signal_guard_triggered を termination_cause として renderer/publisher に直接渡す fixture は fail-closed になり pytest 全体は PASS する"
        - "AC4: max_iterations_exceeded / needs_fix_at_iteration_limit / 明示的 human_judgment_required の既存挙動が変わらない"
        - "AC5: SKILL.md に scope_signal_guard 停止時の termination_cause 正規化手順が明記されている"
      allowed_paths:
        - .claude/skills/issue-refinement-loop/SKILL.md
        - .claude/skills/issue-refinement-loop/scripts/
        - .claude/skills/issue-refinement-loop/tests/
        - .claude/skills/issue-refinement-loop/schemas/
        - .claude/skills/issue-refinement-loop/references/termination-policy.md
        - .claude/skills/issue-refinement-loop/references/scope-signal-guard.md
      worktree: .claude/worktrees/issue-919-scope-signal-guard-norm
      branch: worktree-issue-919-scope-signal-guard-norm
      body_sha256: "sha256:4d4540030dfc659bd4d48f040e24551dd8b140ab30d11fc8f82e3d1addbb88de"
      runtime_verification_applicability: not_applicable
  5. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    IMPLEMENTATION_RESULT_V1

    status: complete
    pr_url: https://github.com/squne121/loop-protocol/pull/924
    branch: worktree-issue-919-scope-signal-guard-norm
    vc_summary:
      pytest_issue_refinement_loop: pass  # 677 passed
      typecheck: pass
      lint: pass
      rg_scope_signal_guard_skill_md: pass  # 7 マッチ(行 82, 129, 227, 229, 233, 236, 238)
    blockers: []

    AC 充足確認

    AC 状態 証跡
    AC1 ✅ PASS test_decide_emits_termination_cause_human_judgment_required, test_termination_cause_from_decide_renders_successfully
    AC2 ✅ PASS test_reason_code_new_allowed_path_layer_in_blockers, test_blockers_summary_can_hold_reason_code
    AC3 ✅ PASS test_scope_signal_guard_triggered_as_cause_is_rejected, test_renderer_fails_closed_with_invalid_cause, test_cli_renderer_returns_invalid_input_for_scope_signal_guard_triggered
    AC4 ✅ PASS test_decide_max_iterations_exceeded_still_works, test_decide_approve_still_works, test_max_iterations_exceeded_cause_still_valid 他
    AC5 ✅ PASS SKILL.md L227 に scope_signal_guard 停止時の termination_cause 正規化手順 セクションを追加
  6. added 5 commits that reference this issue on Jun 15, 2026
  7. added a commit that references this issue on Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions