Skip to content

実装: repair_diagnostics blocker が confidence: high の deterministic repair でも human_escalation を発火させる問題を修正する #2016

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Issue #889 / PR #952 が意図した通り、repair_issue_contract の deterministic かつ auto-safe な repair は human_escalation を発火させず、machine-actionable な needs_fix / repair_action signal として downstream へ伝播する(実際の Issue 本文 auto-mutation は follow-up Issue で扱う)"
change_kind: code

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: なし(単独改善のため N/A)
  • Desired Destination: なし(単独改善のため N/A)

Current Validated Scope

  • repair_issue_contract.py の producer 契約に versioned repair_action block(disposition の closed enum、repairs[] 全要素からの集約規則)を追加する
  • run_refinement_preflight.py の repair_diagnostics blocker 生成ロジックを disposition に応じて needs_fix(auto-safe)/ blocked(unsafe・unknown・混在)/ environment_failure(subprocess・artifact 異常)に分岐させる
  • refinement_preflight_result_v1.schema.json へ status: needs_fix と repair_action の canonical projection を additive に追加する
  • repair_issue_contract_result_v1.schema.json(新規)へ repair_action disposition schema を追加する
  • Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 の safe baseline-expect repair が false human_escalation する経路を fixture 化し、修正後の needs_fix ルーティングを end-to-end 検証する
  • 対応するテスト(新規 .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py および既存 .claude/skills/issue-refinement-loop/scripts/tests/test_repair_issue_contract.py / .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py)の追加・更新

Remaining Parent Gaps

なし

Runtime Verification Applicability

  • decision: not_applicable
  • reason: マージ済み実装は run_refinement_preflight.py の _run_repair_subprocess() が subprocess.run() で repair subprocess を実際に起動し、repair_issue_contract.py の secure_atomic_write_candidate() が os.open / fsync / os.replace による実ファイル I/O で candidate body を書き込む。これらの subprocess 起動・実ファイル I/O パスは PR 実装: repair_diagnostics blocker が deterministic な safe repair でも human_escalation する問題を修正する #2037 が追加した test_repair_diagnostics_routing.py / test_repair_issue_contract.py(symlink-safety テストを含む、実 subprocess・実ファイルシステム挙動を伴う pytest)によって unit/integration test の枠内で exercise・検証済みであり、GUI/ゲームランタイムでの実行や専用の runtime AC/VC/証跡パイプラインを要する immediate 区分の動作検証は本 Issue の変更範囲に含まれない。

Outcome

repair_issue_contract.py が producer 契約として versioned repair_action(disposition の closed enum: auto_apply_safe / human_review_required / informational / invalid_payload と、repairs[] 全要素からの集約規則。legacy record の missing confidence・複数 kind 混在も定義する)を返し、run_refinement_preflight.py がその repair_action.disposition を consume して、

  • auto_apply_safe の場合は generic blocker を追加せず STATUS: needs_fix / NEXT_ACTION: apply_deterministic_repair とし、diagnostics・candidate body artifact・original/repaired SHA を含む canonical repair_action を result schema・compact stdout の両方へ機械可読に投影する
  • human_review_required / informational / unknown kind / safe・unsafe 混在 / overlapping repair / unsupported producer version の場合は既存通り blockers へ追加し STATUS: blocked / NEXT_ACTION: human_judgment_required にする
  • repair subprocess の non-zero return code・timeout・invalid JSON・schema mismatch・input SHA 不一致・changed: true なのに mutating repair が 0 件・artifact write/readback failure はすべて STATUS: environment_failure / NEXT_ACTION: fix_environment にする

状態へ修正され、対応する新規 integration test と既存回帰テストが追加・PASS している状態。

実際の Issue 本文への auto-mutation(controlled issue-editor transaction・stale hash guard・GitHub readback・fresh preflight 再実行)は本 Issue の Outcome に含めない(Out of Scope 参照。理由は Background・Notes for Reviewer を参照)。

In Scope

  • repair_issue_contract.py の producer payload に repair_action(schema_version / disposition / original_body_sha256 / repaired_body_sha256 / diagnostics_artifact / candidate_body_artifact / repair_kinds / reason_codes)を追加し、repairs[] 全要素(legacy record の missing confidence を含む)から単一 disposition を決定する集約規則を実装する
  • run_refinement_preflight.py の repair_diagnostics blocker 生成ロジックを repair_action.disposition を consume するよう変更し、needs_fix / blocked / environment_failure の3ルートに分岐させる
  • _invoke_repair() の subprocess 呼び出しを fail-open から fail-closed に修正する(returncode 検査、timeout・invalid JSON・schema mismatch・input SHA 不一致・error フィールド・changed: true かつ mutating repair 0 件のケースをすべて environment_failure として扱う)
  • artifact 書き込みを既存 _atomic_write_json() と readback validation で行い、例外の無条件 silent pass(except Exception: pass)を廃止する
  • refinement_preflight_result_v1.schema.json へ status: needs_fix の enum 値と repair_action projection を additive に追加する
  • repair_issue_contract_result_v1.schema.json(新規)へ repair_action disposition の closed enum を追加する
  • run_refinement_preflight.py の compact stdout(STATUS / NEXT_ACTION / ARTIFACT)へ repair_action を機械可読に投影する(generic blocker の JSON 文字列内には埋め込まない)
  • issue-refinement-loop/SKILL.md の Step 0f canonical stdout フィールド説明へ STATUS: needs_fix / NEXT_ACTION: apply_deterministic_repair を追記する。orchestrator は現時点では auto-apply consumer を持たないため、apply_deterministic_repair 受信時は human 判断待ちの informational route として扱うことを明記する(decide_next_loop_action.py 等のロジック自体は変更しない)
  • Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 の再現ケースを fixture 化した end-to-end regression test を追加する
  • 上記に対応するユニットテスト・integration テストの追加・更新

Out of Scope

Acceptance Criteria

  • AC1: repair_issue_contract.py の結果が versioned repair_action block(disposition の closed enum、集約規則)を含み、legacy record(confidence 欠落)を含む repairs[] 全要素から単一 disposition を決定している
  • AC2: 既知の auto-safe repair(disposition: auto_apply_safe)が1件以上ある場合、run_refinement_preflight.py が generic blocker を追加せず STATUS: needs_fix / NEXT_ACTION: apply_deterministic_repair を返し、canonical repair_action(diagnostics・candidate body artifact・original/repaired SHA)を出力することをユニットテストで検証している
  • AC3: unknown kind・missing safety classification・非auto-safe repair・safe/unsafe 混在・overlapping repair・unsupported producer version のいずれかでは STATUS: blocked / NEXT_ACTION: human_judgment_required になることをユニットテストで検証している
  • AC4: repair subprocess の non-zero・timeout・invalid JSON・error フィールドあり・schema mismatch・input SHA 不一致・changed: true かつ mutating repair 0 件・artifact write/readback failure のいずれかでは STATUS: environment_failure / NEXT_ACTION: fix_environment になることをユニットテストで検証している
  • AC5: changed: false では既存の planner exit mapping が変更されないことをユニットテストで検証している
  • AC6: repair diagnostics と candidate body artifact が result schema・artifact map・compact stdout のすべてから機械的に参照でき、generic blocker の JSON 文字列内に埋め込まれていないことを検証している
  • AC7: Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 で発生した「safe baseline-expect repair → generic blocker → blocked → human_judgment_required」経路を fixture 化し、修正後は needs_fix / apply_deterministic_repair になることを end-to-end で検証している
  • AC8: 既存回帰テスト(test_repair_issue_contract.py / test_refinement_preflight.py)が regression なく PASS している

Verification Commands

# AC1
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_repair_action_disposition_aggregated_from_repairs -q
# AC2
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_known_safe_repair_routes_actionable_needs_fix -q
# AC3
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_unknown_or_mixed_repair_requires_human_judgment -q
# AC4
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_repair_process_and_artifact_failures_are_environment_failures -q
# AC5
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_no_change_repair_result_keeps_existing_planner_mapping -q
# AC6
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_repair_action_projected_in_result_schema_and_compact_stdout -q
# AC7
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_issue_2013_safe_repair_does_not_silent_pass_or_human_escalate -q
# AC8
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py .claude/skills/issue-refinement-loop/scripts/tests/test_repair_issue_contract.py .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -q

Allowed Paths

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json
  • .claude/skills/issue-refinement-loop/schemas/repair_issue_contract_result_v1.schema.json
  • .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py
  • .claude/skills/issue-refinement-loop/scripts/tests/test_repair_issue_contract.py
  • .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/SKILL.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合。ただし本 Issue の In Scope が定める additive な repair_action フィールド追加・status: needs_fix enum 追加自体は対象外とし、それを超える非後方互換な破壊的変更(既存 consumer が読める範囲を超える変更)が必要になった場合に限る
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合。具体的には、実際の Issue 本文 auto-mutation(controlled mutation transaction)の実装が必要と判明した場合(Out of Scope。follow-up Issue へ切り出す)、および Draft PR fix: trusted OWNER directive を contract update へ正規化 #2026(run_refinement_preflight.py を同時変更中)との rebase/stack 方針が実装時点で解決できないコンフリクトを起こした場合を含む
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

なし

Required Design References

  • docs/dev/agent-skill-boundaries.md
  • docs/dev/runtime-verification-policy.md

Scope Delta(該当時のみ記載)

N/A

Background

本注記(Runtime Verification Applicability の decision 訂正、Issue #2013 との関係の明確化)は PR #2037 マージ後、issue-refinement-loop による post-hoc ドキュメント訂正として追加された。

.claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py および run_refinement_preflight.py からの repair 呼び出し wiring は、以下の3段階の履歴で導入・拡張された。

  1. 原因となった wiring の導入: Issue 実装: baseline-expect VC annotation と deterministic repair pass で issue-refinement-loop 反復失敗を防ぐ #889(CLOSED)/ PR feat(#889): baseline-expect VC annotation と repair pass で baseline false-positive を防ぐ #893(MERGED)が repair_issue_contract.py・_invoke_repair()・run_refinement_preflight.py からの repair 呼び出し・changed: true を generic blocker へ変換する wiring を導入した。
  2. 後続 producer 拡張: Issue 実装: baseline_vc_preflight.py に --strict フラグを追加し annotation 欠落 VC を強制 needs_fix にする #899 / PR impl(#899): Add --strict flag to baseline_vc_preflight.py for annotation enforcement #952(MERGED, 2026-06-17)は 実装: 自機移動と Projectile 射撃システム #1 の後続変更として、strict baseline validation・inline baseline annotation repair・missing baseline annotation repair・一部 repair record への safety / confidence フィールドを追加した。PR impl(#899): Add --strict flag to baseline_vc_preflight.py for annotation enforcement #952 のレビューは「needs_fix であり human_escalation ではない」ことを満たしたと判定したが、変更ファイル一覧に run_refinement_preflight.py は含まれておらず、producer 単体の挙動が wrapper 統合まで検証されたわけではなかった。
  3. 実運用での再現: Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013(2026-08-08)自体は本 Issue とは無関係な調査 Issue(Claude Code custom SubAgent の spawn observability 非決定性の診断)だが、issue-refinement-loop を Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 を対象に実行していた最中に、producer の safe repair が generic blocker に再変換され STATUS: blocked / NEXT_ACTION: human_judgment_required になる経路が副次的に再現された(Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 の本文もこの repair_diagnostics の修正自体は本 Issue 実装: repair_diagnostics blocker が confidence: high の deterministic repair でも human_escalation を発火させる問題を修正する #2016 で追跡済みと明記している)。

Issue #2016 は当初、_repair_result の top-level confidence フィールドを参照する条件分岐追加として起票されたが、OWNER によるアドバーサリアルレビュー(#2016 コメント、レビュー基準 SHA 01b863302053be046a167f756ea08789ca8eea44、判定 REQUEST_CHANGES)により、以下の構造的欠陥が指摘された。

  • 現行 repair_issue_contract.py の run_repair() は top-level confidence を返さず、confidence は一部の repairs[] 要素のみが持つフィールドである(記述通りの実装は常に None になり成立しない)
  • blocker を追加しないだけでは needs_fix ではなく pass / proceed へ誤分類される(result schema に needs_fix status が存在しないため)
  • _invoke_repair() は subprocess の non-zero return code を検査せず、artifact 書き込みも例外を無条件に握りつぶす fail-open 設計であり、repair subsystem 自体の故障が silent pass になり得る
  • 「通常の rewrite loop で自動解消」を実現する mutation 実行経路(issue-editor handoff・stale hash guard・controlled mutation・readback)が定義されていない
  • 修正に必要な schema 変更(additionalProperties: false への追加)が、当初の Allowed Paths / Stop Conditions では禁止されており、Issue が自己矛盾していた

本 Issue の本文は上記レビューの「推奨する修正設計」「修正版 Acceptance Criteria 案」「Verification Commands 修正版」「必要な Allowed Paths」に基づいて全面的に書き直されている。ただし同コメントが示した2つの選択肢((a) Outcome を machine-actionable な needs_fix handoff までに縮小し実 mutation は別 Issue にする / (b) auto-resolve を維持し issue-editor handoff・controlled mutation まで In Scope に含める)のうち、1 Issue = 1 PR 原則と PR #2027(issue-editor cutover、Draft)への依存を避けるため、(a) を採用している。

なお Draft PR #2026 は同じ run_refinement_preflight.py を変更中であり、実装着手時は rebase またはスタック方針を確認すること(Stop Conditions 参照)。

参照: Issue #889, PR #893, Issue #899, PR #952, Issue #2013, PR #2026(Draft), PR #2027(Draft)

Notes for Reviewer

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 8, 2026
  2. squne121 commented on Aug 8, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES — 現在の Issue 契約のまま実装へ進めるべきではありません。

    問題自体は実在します。現在の run_refinement_preflight.py は、repair が changed: true を返すと repair_diagnostics を generic blocker に追加し、最終的に STATUS: blocked / NEXT_ACTION: human_judgment_required へ変換します。Issue #2013 でもこの経路が実際に再現されています。

    一方、Issue #2016 が要求している「top-level の repair_result.confidence を見て high なら blocker にしない」という修正は、現行 producer 契約に存在しないフィールドを前提としており、さらに blocker を消すだけでは needs_fix ではなく pass / proceed に誤分類される設計です。

    レビュー基準は 2026年8月8日時点の main、SHA 01b863302053be046a167f756ea08789ca8eea44 です。


    敵対的レビュー

    P0-1: Issue が要求する top-level confidence は producer に存在しない

    Issue #2016 の AC1 と In Scope は、_repair_result の confidence フィールドを直接参照することを要求しています。

    しかし、現行 repair_issue_contract.py の run_repair() が返す top-level payload は次だけです。

    • schema

    • dry_run

    • changed

    • original_body_sha256

    • repaired_body_sha256

    • repairs

    top-level の confidence や kind はありません。

    confidence: high があるのは一部の repairs[] 要素だけです。具体的には、後から追加された以下の repair record にはあります。

    • move_inline_baseline_expect_to_preceding_line

    • insert_baseline_expect_fail

    対して、以下の既存 kind は confidence を持ちません。

    • runtime_only_command

    • escaped_code_fence

    • non_target_fence

    したがって、例えば次の実装は成立しません。

    if _repair_result.get("confidence") == "high":
        ...
    

    常に None になるためです。

    また repairs[] の全要素を走査する実装に変えても、legacy record の missing confidence、informational record、複数 kind 混在時の集約規則が定義されていません。

    修正要求: producer 契約を変更対象に含めるか、consumer 側に versioned な closed allowlist と集約規則を定義してください。現在の Allowed Paths では producer を変更できないため、この時点で Issue 自身の Stop Condition に到達します。


    P0-2: blocker を追加しないだけでは needs_fix にならず、silent pass になる

    現行 preflight result の status enum は次の4種類だけです。

    pass
    warn
    blocked
    environment_failure
    

    needs_fix は存在しません。さらに schema は additionalProperties: false です。

    現在の _apply_exit_code_mapping() は、概ね次のように動きます。

    blockers が1件以上
      → blocked
    

    planner exit 0

    • planner_fail_closed false
    • unknown confidence なし
    • blocker なし
      → pass

    その後の next_action は次の固定マッピングです。

    pass                → proceed
    warn → proceed_with_notes
    blocked → human_judgment_required
    environment_failure → fix_environment

    つまり Issue #2016 の記述通りに high-confidence repair を blockers へ追加しないだけでは、

    changed: true
    safe deterministic repair
    blocker なし
    planner正常

    → STATUS: pass
    → NEXT_ACTION: proceed

    となります。

    これは needs_fix ではなく、未修復の Issue 本文をそのまま次工程へ流す false pass です。

    さらに repair_diagnostics.json のパスは現在 generic blocker の JSON 文字列にしか格納されていません。blocker を消すと、canonical result や compact stdout から repair artifact を発見する経路も消えます。canonical artifacts map に許可されているのは raw snapshot、planner input、preflight result の3種類だけです。

    修正要求: 「blocker を追加しない」ではなく、schema-backed な repair route を新設する必要があります。


    P0-3: repair subprocess と artifact 書き込みが fail-open

    現行 _invoke_repair() は subprocess.run() の returncode を確認しません。

    • check=True を指定していない

    • proc.returncode を評価しない

    • subprocess が non-zero でも stdout が JSON ならそのまま正常 payload として返す

    • JSON decode error、timeout、その他例外は changed: false を含む error payload に変換する

    Python の公式仕様上、subprocess.run() の check は既定で False です。non-zero を失敗として扱うには、check=True、returncode の検査、または check_returncode() が必要です。

    現在の wrapper は _repair_result.get("changed") is True の場合しか反応しないため、次の失敗が repair なしの正常状態として通過し得ます。

    • repair subprocess の non-zero

    • error JSON

    • stdout 不在

    • invalid JSON

    • timeout

    • producer schema drift

    • input body hash 不一致

    加えて artifact 書き込みは直接 write_text() を行い、例外を無条件に握りつぶします。

    except Exception:
    pass

    artifact 書き込みが失敗した場合は repair_artifact_path が None のため、changed: true であっても blocker が追加されません。

    これは今回の修正対象より深刻です。安全な repair を human escalation へ送る false positive と同時に、repair subsystem 自体の故障を pass にする false negative が存在します。

    修正要求: 以下はすべて environment_failure / fix_environment にしてください。

    • non-zero return code

    • timeout

    • invalid JSON

    • schema mismatch

    • error フィールドあり

    • input SHA 不一致

    • changed: true なのに mutating repair が0件

    • artifact write/readback failure

    • candidate body hash 不整合

    artifact は既存の _atomic_write_json() と readback validation を再利用すべきです。


    P0-4: 「通常の rewrite loop で自動解消」の実行経路が存在しない

    Issue #2016 の Outcome は、safe repair を needs_fix として body-author-fix rewrite loop へ流し、自動解消可能にすることを要求しています。

    しかし現在の producer は、修復後本文そのものを返しません。返すのは hashes と局所的な repair records だけです。

    また wrapper は dry-run repair を呼び出すだけで、

    • repaired body を planner に渡さない

    • candidate body artifact を保存しない

    • mutation command を結果に出さない

    • issue editor への handoff を生成しない

    • GitHub readback を検証しない

    という状態です。PR #893 の導入説明も、「repair は dry-run であり、planner は元の Issue 本文を受け取る」という構造です。

    したがって needs_fix シグナルを追加しても、誰が、何を入力として、どの controlled executor で本文を更新するかが未定義です。

    現在、既存 Issue 更新担当を issue-editor に切り替える PR #2027 が Draft で進行中です。#2016 の auto-apply lane は、この topology と整合させる必要があります。

    修正要求: 次のどちらかを選ぶ必要があります。

    1. 実装: repair_diagnostics blocker が confidence: high の deterministic repair でも human_escalation を発火させる問題を修正する #2016 の Outcome を「machine-actionable な needs_fix handoff を出す」までに縮小し、実 mutation は別 Issue にする。

    2. auto-resolve を維持するなら、issue-editor handoff、stale hash guard、controlled mutation、readback、fresh preflight まで 実装: repair_diagnostics blocker が confidence: high の deterministic repair でも human_escalation を発火させる問題を修正する #2016 の In Scope に含める。

    現在の契約は「自動解消」を主張しながら、その実装箇所をすべて Out of Scope にしています。


    P1-1: 原因導入 PR と後続拡張 PR を混同している

    Issue #2016 の Background は「Issue #889 / PR #952 が repair_issue_contract.py 等を導入した」と読める記述ですが、履歴は次の通りです。

    原因となった wiring の導入

    PR #893 が Issue #889 を閉じ、以下を導入しました。

    • repair_issue_contract.py

    • _invoke_repair()

    • run_refinement_preflight.py からの repair 呼び出し

    • changed: true を generic blocker へ変換する wiring

    後続 producer 拡張

    PR #952 は Issue #899 を閉じた後続変更です。

    • strict baseline validation

    • inline baseline annotation repair

    • missing baseline annotation repair

    • 一部 repair record への safety / confidence

    正しい因果関係は次です。

    #889 / PR #893
    generic repair blocker wiring を導入

    #899 / PR #952
    body-author-fixable な repair kind と high-confidence record を追加

    #2013
    producer の safe repair が generic blocker に再変換されることを実運用で再現

    PR #952 のレビューは「needs_fix not human_escalation」を満たしたと判定しましたが、変更ファイル一覧に run_refinement_preflight.py は含まれていません。producer 単体の挙動を wrapper integration まで検証したと誤認した integration false-green です。

    修正要求: Background と regression fixture をこの3段階の履歴に修正してください。


    P1-2: Acceptance Criteria と Verification Commands が false-green/hard-block を含む

    AC1 は実装前から通る

    AC1 のコマンドは次です。

    rg -n "confidence" run_refinement_preflight.py

    しかし現行 wrapper には、planner decision 用の _has_unknown_confidence() が既にあります。repair routing を一切変更しなくても rg は成功します。

    したがって AC1 は false-green です。

    AC2・AC3 は禁止されている pytest baseline 形

    Issue は既存ファイルに対して未実装テスト名を -k で選択しています。

    pytest test_refinement_preflight.py -k confidence_high_repair_not_blocked

    リポジトリの現行 body-authoring policy は、既存テストファイルへの未作成 -k を禁止しています。canonical baseline-fail は、Allowed Paths 内の まだ存在しない新規テストファイル + exact node-id です。

    pytest 公式仕様でも -k は収集済みテストを名前式で選択する機能であり、テストの存在証明ではありません。テストが収集されなければ exit code 5 です。

    _apply_exit_code_mapping() 単体では今回の AC を検証できない

    今回必要なのは次の一連の挙動です。

    producer payload
    → validation / classification
    → artifact write
    → result schema
    → status
    → next_action
    → compact stdout
    → downstream route

    _apply_exit_code_mapping() に空の blockers を渡して blocked でないことだけを確認しても、repair signal が消失して pass になった false-greenを検出できません。

    修正要求: 新規 integration test file を作り、run_preflight() から artifact と compact output まで検証してください。


    P1-3: 正しい修正に必要な schema 変更を Allowed Paths と Stop Conditions が禁止している

    現在の result schema は additionalProperties: false です。未宣言の repair_action、repair_diagnostics、needs_fix などを追加すれば schema validation に失敗します。

    JSON Schema の公式仕様でも、additionalProperties: false は properties または patternProperties に宣言されていないプロパティを拒否します。

    一方、Issue #2016 の Allowed Paths は wrapper と既存 test file の2つだけで、schema 変更は Stop Condition です。

    したがって正しい実装には schema 変更が必要なのに、契約上は schema 変更が判明した時点で停止しなければなりません。

    これは単なる不足ではなく、Issue が自分自身を実装不能にしている構造的矛盾です。


    P1-4: confidence を authorization として使う設計が弱い

    confidence: high は診断メタデータであり、「自動 mutation を許可してよい」という authorization と同義ではありません。

    少なくとも以下を閉じた契約として定義する必要があります。

    • auto-apply を許可する repair kind の closed enum

    • informational kind

    • human-review-required kind

    • unknown kind の扱い

    • missing confidence の扱い

    • safe と unsafe が混在した場合

    • changed: true, repairs: []

    • changed: false なのに mutating record がある場合

    • duplicate/overlapping repair

    • producer schema version 不一致

    • candidate hash 不一致

    特に次のような判定は危険です。

    all(r.get("confidence") == "high" for r in repairs)

    Python の all() は iterable が空でも True を返すため、repairs=[] を safe と誤判定し得ます。

    推奨: confidence とは別に、producer または versioned classifier が次のような明示的 disposition を出すべきです。

    auto_apply_safe
    human_review_required
    informational
    invalid_payload

    未知 kind が自己申告で confidence: high を返しても auto-apply してはいけません。


    P1-5: 現在進行中の変更との sequencing が未定義

    PR #2026 は Draft・open で、同じ run_refinement_preflight.py を変更しています。単なる rebase 競合だけでなく、preflight provenance と routing semantics を変更するため、#2016 はその上へ stack するか、マージ後に再設計する必要があります。

    また、隣接する open Issue として以下があります。

    これらは duplicate ではありませんが、result schema と downstream consumer の所有境界が重なります。#2016 だけが独自の非構造化 repair route を追加すると、再び SSOT が分裂します。

    さらに PR #2026 と #2027 の Safety Claim Matrix では、repair routing と直接関係しない claim の follow-up に #2016 が記載されています。#2016 を generic な「後で安全性を直す Issue」として参照しており、related graph を汚染しています。


    推奨する修正設計

    1. confidence ではなく versioned repair disposition を正本にする

    推奨 payload は以下です。

    repair_action:
    schema_version: repair_action/v1
    policy_version: deterministic-issue-repair/v1
    disposition: auto_apply_safe
    original_body_sha256: sha256:...
    repaired_body_sha256: sha256:...
    diagnostics_artifact: /absolute/path/repair_diagnostics.json
    candidate_body_artifact: /absolute/path/repaired_issue_body.md
    repair_kinds:
    - insert_baseline_expect_fail
    reason_codes:
    - deterministic_body_author_fix_available

    repair_action は canonical result と compact stdout の両方に投影し、artifact path は generic blocker 文字列の内部に埋め込まないでください。

    JSON Schema の if / then を使えば、disposition: auto_apply_safe の場合に candidate body、両 SHA、repair kinds を必須化できます。公式仕様上、if の評価結果で then または else の subschema を適用できます。

    2. wrapper-level needs_fix route を明示する

    推奨する判定表は次です。

    repair 結果 wrapper status next_action
    valid、changed: false 既存 planner mapping 既存動作
    valid、既知の safe mutating repair が1件以上 needs_fix apply_deterministic_repair
    unknown/missing/unsafe/mixed repair blocked human_judgment_required
    subprocess・schema・hash・artifact 異常 environment_failure fix_environment

    最も明確なのは、result schema に status: needs_fix を追加することです。

    互換性のため一時的に warn を再利用する案もありますが、現行 warn は proceed_with_notes なので、consumer 更新なしでは未修復本文を次工程へ送ります。単に warn に畳み込む修正は推奨しません。

    3. auto-apply は optimistic concurrency 付き transaction にする

    自動更新を Outcome に残す場合、処理は次の順序でなければなりません。

    1. live Issue body を再取得する。

    2. original_body_sha256 が dry-run 時点と一致することを検証する。

    3. current body に対して repair を再実行する。

    4. full candidate body を生成する。

    5. controlled issue-editor transaction で更新する。

    6. GitHub readback body hash を検証する。

    7. fresh preflight を再実行する。

    8. changed: false になったことを確認してから semantic refinement へ戻る。

    line number ベースで局所 patch を当てるべきではありません。producer の line number は section-relative なものを含み、同時編集にも弱いためです。


    修正版 Acceptance Criteria 案

    AC1: producer 契約

    repair_issue_contract の結果が versioned schema で検証され、repair ごとに closed enum の disposition または classifier が確定する。

    AC2: safe deterministic route

    既知の auto-safe repair が1件以上ある場合、

    • generic blocker を追加しない

    • status: needs_fix

    • next_action: apply_deterministic_repair

    • canonical repair_action

    • diagnostics と candidate body artifact

    • original/repaired SHA

    が出力される。

    AC3: unsafe/unknown route

    以下のいずれかでは blocked / human_judgment_required になる。

    • unknown kind

    • missing safety classification

    • non-auto-safe repair

    • safe/unsafe mixed

    • overlapping repair

    • unsupported producer version

    AC4: environment failure route

    以下のいずれかでは environment_failure / fix_environment になる。

    • subprocess non-zero

    • timeout

    • invalid JSON

    • payload error

    • schema mismatch

    • input SHA mismatch

    • changed: true かつ mutating repair 0件

    • artifact write/readback failure

    AC5: no-change regression

    changed: false では、現在の planner exit mapping が変更されない。

    AC6: canonical artifact projection

    repair diagnostics と candidate body が result schema、artifact map、compact stdout のすべてから機械的に参照できる。

    AC7: Issue #2013 integration fixture

    Issue #2013 で発生した

    safe baseline-expect repair
    → generic blocker
    → blocked
    → human_judgment_required
    

    を fixture 化し、修正後は needs_fix / apply_deterministic_repair になることを end-to-end で検証する。実際の dead-end は Issue #2013 のコメントでも記録されています。

    AC8: controlled mutation

    auto-apply を本 Issue に含める場合、stale hash 拒否、controlled issue-editor、readback、fresh preflight をテストする。

    AC9: integration regression

    producer 単体だけでなく、wrapper、schema、compact output、downstream decision consumer の回帰テストを通す。


    Verification Commands 修正版

    新しい test file を Allowed Paths に追加し、baseline では存在しない exact node-id を使用します。

    # AC2
    # baseline-expect: fail
    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_known_safe_repair_routes_actionable_needs_fix -q
    
    # AC3
    # baseline-expect: fail
    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_unknown_or_mixed_repair_requires_human_judgment -q
    
    # AC4
    # baseline-expect: fail
    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_repair_process_and_artifact_failures_are_environment_failures -q
    
    # AC7
    # baseline-expect: fail
    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py::test_issue_2013_safe_repair_does_not_silent_pass_or_human_escalate -q
    
    # regression
    $ uv run --locked pytest \
      .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py \
      .claude/skills/issue-refinement-loop/scripts/tests/test_repair_issue_contract.py \
      .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py \
      -q
    

    必要な Allowed Paths

    最低でも次を含める必要があります。

    .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
    .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
    .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json
    .claude/skills/issue-refinement-loop/schemas/repair_issue_contract_result_v1.schema.json
    .claude/skills/issue-refinement-loop/tests/test_repair_diagnostics_routing.py
    .claude/skills/issue-refinement-loop/scripts/tests/test_repair_issue_contract.py
    

    status: needs_fix または next_action: apply_deterministic_repair を downstream が consume するなら、さらに次が必要です。

    .claude/skills/issue-refinement-loop/SKILL.md
    該当する loop-state / next-action consumer
    対応する schema・reference・tests
    

    auto-mutation まで含める場合は、#2027 の issue-editor topology に対応する controlled transaction とテストも scope に追加する必要があります。


    実装順序

    1. Issue 実装: repair_diagnostics blocker が confidence: high の deterministic repair でも human_escalation を発火させる問題を修正する #2016 の Background、Outcome、AC、Allowed Paths、Stop Conditions を修正する。

    2. 同一ファイルを変更している Draft PR fix: trusted OWNER directive を contract update へ正規化 #2026 のマージまたは stack 方針を確定する。

    3. auto-apply を含める場合は PR feat: Codex issue creator と editor を分離 #2027 の issue-editor cutover と整合させる。

    4. producer schema、wrapper route、result schema、consumer を同じ contract snapshot に束縛する。

    5. Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 型の integration fixture を先に追加してから実装修正する。

    6. PR impl(#899): Add --strict flag to baseline_vc_preflight.py for annotation enforcement #952 で不足していた producer-to-wrapper integration を merge blocker にする。

    最終結論

    Issue #2016 は close や duplicate 判定ではなく、契約を書き直して維持すべきです。

    ただし現状のまま実装すると、主に次のどちらかになります。

    • confidence が取得できず、従来通り human escalation する。

    • blocker だけを消し、未修復 Issue を pass / proceed へ流す。

    後者は現在の問題より危険です。修正の本体は confidence 条件分岐ではなく、repair producer → wrapper → result schema → next-action consumer → controlled mutation の end-to-end routing contract です。

  3. squne121 commented on Aug 8, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告

    経緯

    1. iteration 1 review: VERDICT: needs-fix(4 blockers: Runtime Verification Applicability セクション欠落 / AC1 VC unexpected pass / AC2・AC3 が未作成テストへの -k 参照)
    2. rewrite: OWNER の anchor comment(P0-1〜P0-4, P1-1〜P1-5 の敵対的レビュー)に基づき Issue 本文を全面的に書き換え。producer 契約に存在しない confidence top-level 参照を廃し、versioned repair_action(disposition closed enum・集約規則)ベースの設計へ変更。Outcome を「machine-actionable な needs_fix handoff を出す」までに縮小し、実際の Issue 本文 auto-mutation は別 follow-up Issue に切り出した(OWNER レビューが提示した2択のうち (a) を採用)。AC1〜AC8・Verification Commands・Allowed Paths・Stop Conditions・Background の3段階履歴(実装: baseline-expect VC annotation と deterministic repair pass で issue-refinement-loop 反復失敗を防ぐ #889/PR#893 → 実装: baseline_vc_preflight.py に --strict フラグを追加し annotation 欠落 VC を強制 needs_fix にする #899/PR#952 → 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 再現)・Runtime Verification Applicability セクションを追加。
      • guard-issue-body.py(LP017)が Stop Conditions 標準6項目のうち2項目欠落を検出し初回 mutation を fail-closed で拒否 → 修正後に再実行し成功。
    3. iteration 2 review: VERDICT: approve(C1〜C11 全 pass、blockers 0)

    Final Gate

    issue-contract-review は本 loop 内では未実行(CONTRACT_REVIEW_RESULT_V1 の go snapshot が Issue 上に存在しない)。contract_review.gate_result: missing_go のため LOOP_HANDOFF_RESULT_V1.status は blocked とする。実装着手前に issue-contract-review を別途実行すること。

    LOOP_HANDOFF_RESULT_V1:
      status: blocked
      routing_action: blocked
      contract_review:
        status: blocked
        gate_result: missing_go
        latest_comment_url: null
        generated_at: null
        body_sha256: null
      metadata:
        title_prefix_ready: true
        phase_label_ready: false
      auto_fixes:
        result: blocked
        required: []
        skipped: []
      blockers: []
      reviewed_body_sha256: "sha256:a5c48e731c443a9ff7b23cd7acc192a762a2ad052d33e45e4e879342c7d06951"
  4. squne121 commented on Aug 8, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-08T09:27:00Z)

  5. added 2 commits that reference this issue on Aug 8, 2026
  6. squne121 commented on Aug 8, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-08-08)

    VERDICT: approve(1 iteration)

    PR #2037 マージ後の post-hoc ドキュメント訂正として、以下 2点の事実誤りを修正しました。

    1. Runtime Verification Applicability: reason を、マージ済み実装が実際に subprocess.run()(_run_repair_subprocess())と実ファイル I/O(secure_atomic_write_candidate() の os.open/fsync/os.replace)を伴う事実に基づく記述へ訂正(decision は AC タグ付与を伴う applicable/immediate への変更を避けるため not_applicable を維持し、pytest による検証カバレッジで担保している旨を明記)
    2. Background: Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 が本 Issue とは無関係な調査 Issue(spawn observability 診断)であり、issue-refinement-loop を Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 に対して実行中に症状が副次的に再現されたに過ぎないことを明確化

    AC/VC/Allowed Paths/Outcome/Scope/Machine-Readable Contract は無変更。Issue は CLOSED のまま。

    • 修正前 body SHA256: sha256:a5c48e731c443a9ff7b23cd7acc192a762a2ad052d33e45e4e879342c7d06951
    • 修正後 body SHA256: sha256:916f282f11e7f7080b1fdbe584ef8b13c10e8c044d9fd07c8ab3009ad350f5b5

    STATUS: approve
    NEXT_ACTION: none(追加対応不要)

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

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions