Skip to content

feat: route_canonical_step2_result() を _cmd_produce() の全 stdout JSON 出力経路へ配線する - #2391

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-2389-route-canonical-step2-result-cli-wiring
Aug 29, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-2389-route-canonical-step2-result-cli-wiring

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

  • run_root_review_pipeline.py の _cmd_produce() が持つ全 5 つの stdout JSON 出力経路(成功時 / body fetch 失敗時 / VC budget エラー時 / transport failure 時 / artifact readback failure 時)に、route_canonical_step2_result() の呼び出し結果をトップレベル canonical_step2_route フィールドとして配線した(新設ヘルパー _emit_produce_result() に一本化)。
  • route_canonical_step2_result() 自体のロジックも修正: status: ok + verdict: approve + next_action: proceed の場合、旧来の STEP_4_5(step_4_5)ではなく新設の STEP_2_5(step_2_5)を返すようにし、Step 2.5 semantic design review applicability 判定を迂回しないようにした。
  • status: input_or_runtime_error かつ既知の構造化 error_code(reviewer_transport_environment_failure / artifact_readback_failed)は step_5_human_judgment_required として扱い、それ以外(body fetch 失敗・VC budget 超過を含む、Issue 実装: route_canonical_step2_result() を CLI / _cmd_produce() の出力に配線する #2389 の Out of Scope)は従来通り fail_closed_environment_or_integrity_failure のまま据え置いた。
  • issue-refinement-loop/SKILL.md / review-issue/SKILL.md / command_registry.py の canonical Step 2 consumer 記述を、canonical_step2_route を唯一の routing authority として読む旨に更新した。
  • 既存テスト(test_root_review_canonical_delivery.py)の STEP_4_5 期待値を STEP_2_5 へ更新し、新規テスト test_canonical_step2_route_wiring.py を追加して配線・route 変更・エラー系 route の区別を検証した。

本 PR は Closes #2389 として Issue #2389 をクローズする。

Checks

  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_canonical_step2_route_wiring.py -v — 12 passed(AC1-AC4 該当の -k フィルタもすべて個別 PASS 確認済み)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_root_review_canonical_delivery.py -q — 24 passed(AC5)
  • rg -n "canonical_step2_route" .claude/skills/issue-refinement-loop/SKILL.md .claude/skills/review-issue/SKILL.md .claude/skills/issue-refinement-loop/scripts/command_registry.py — 3ファイルすべてに出現(AC6)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_e2e.py .claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_readback_v2_ssot.py -q — 57 passed(AC7、既存 compact/artifact schema・inner retry・readback gate は無変更のまま PASS)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q — 1797 passed, 3 failed(既存 baseline でも同様に fail する test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch 3件のみで、本 PR の変更(コメント追記のみ)とは無関係。git stash した baseline でも同じ3件が同じ理由で fail することを確認済み)
  • uv run --locked python3 .claude/skills/create-issue/scripts/validate_japanese_content.py --file .claude/skills/issue-refinement-loop/SKILL.md --verbose / 同 review-issue/SKILL.md — 両方 PASS
  • pnpm typecheck / pnpm lint / pnpm test / pnpm build — 本 PR は TypeScript/JS フロントエンドファイルを一切変更しないため実行を省略した(Allowed Paths はすべて .claude/skills/** 配下の Python スクリプト・テスト・Markdown のみ)

Schema Change Applicability

  • decision: schema_change
  • reason: _cmd_produce() の stdout JSON(consumer 契約: issue-refinement-loop canonical Step 2 orchestrator)に新規トップレベルフィールド canonical_step2_route を追加し、かつ route_canonical_step2_result() の戻り値そのものを approve+proceed ケースで step_4_5 から step_2_5 へ変更したため、schema change として扱う。

Schema Consumer Inventory

# before

_cmd_produce() の stdout JSON トップレベルキー:
  schema, schema_version, status, issue_number, body_sha256,
  merged_review_result, artifact_path, compact_result,
  full_review_artifact, verified_transport_artifact
  (canonical_step2_route は存在しない。orchestrator は
   status / compact_result.verdict / compact_result.next_action を
   独自に読み取って routing を再計算する必要があった)

route_canonical_step2_result() の approve+proceed ケースの戻り値:
  STEP_4_5 ("step_4_5")

# after

_cmd_produce() の stdout JSON トップレベルキー(上記に追加):
  canonical_step2_route  # route_canonical_step2_result() の戻り値そのもの。
                          # 全5出力経路(成功時 / body fetch 失敗時 /
                          # VC budget エラー時 / transport failure 時 /
                          # artifact readback failure 時)で計算済み。

route_canonical_step2_result() の approve+proceed ケースの戻り値:
  STEP_2_5 ("step_2_5")  # Step 2.5 semantic design review applicability
                          # 判定を迂回しないようにするため
Consumer ファイル 更新有無 備考
.claude/skills/issue-refinement-loop/SKILL.md 更新済み Step 2 routing table を canonical_step2_route 唯一の routing authority として読む旨に更新。approve のターゲットを Step 2.5 へ修正
.claude/skills/review-issue/SKILL.md 更新済み 「Producer I/O ownership」節に canonical_step2_route が唯一の routing authority である旨を追記
.claude/skills/issue-refinement-loop/scripts/command_registry.py 更新済み root_review_pipeline.produce コマンド定義のコメントに canonical_step2_route 配線を追記(コメントのみ、実行時契約に変更なし)
.claude/skills/issue-refinement-loop/tests/test_root_review_canonical_delivery.py 更新済み STEP_4_5 を期待していた既存 assertion 2箇所を STEP_2_5 へ更新
.claude/skills/issue-refinement-loop/tests/test_canonical_step2_route_wiring.py 新規追加 配線・route変更・エラー系routeの区別を検証する新規テスト
.claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py 変更なし(対象外) route_canonical_step2_result() / canonical_step2_route を consume しない別系統のスクリプト(rewrite phase 後の next-action 決定専用)。呼び出し規約は本 Issue のスコープ外で変更していない

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
既存の approve+proceed ルーティングは STEP_4_5 から STEP_2_5 へ変わるが、Step 2.5 が semantic_review_applicable: false の場合は自身が直接 Step 4.5 へ進めるため、最終的な到達先の集合は変化しない(Step 2.5 の判定を迂回できなくなるだけ) yes - test_route_canonical_step2_result_approve_routes_to_step_2_5 / 既存 test_given_real_produce_output_when_routed_through_pure_router_end_to_end_then_no_agent_handoff_occurs(本PRで STEP_2_5 期待値へ更新し PASS) -
body fetch 失敗・VC budget 超過由来の input_or_runtime_error は今回変更せず fail-closed のまま据え置いた(Issue #2389 Out of Scope の明示要求) yes - test_produce_body_fetch_failure_stdout_top_level_field_present / test_produce_vc_budget_error_stdout_top_level_field_present(いずれも canonical_step2_route == fail_closed_environment_or_integrity_failure を確認) -
既知の producer error(reviewer_transport_environment_failure / artifact_readback_failed)以外の未知 error_code は fail-closed のままであり、新しい human-judgment 昇格経路が誤って未知エラーまで拾わない yes - test_route_canonical_step2_result_producer_error_route_distinction(unrecognized_error_code / missing_error_code の両方で fail-closed を確認) -
_cmd_produce() の戻り値型(既存の整数 exit code)・main() / sys.exit() の契約は変更していない yes - 全出力経路の return 0 / return 2 は本PRで変更なし(git diff で確認可能)。既存 test_root_review_pipeline_readback_v2_ssot.py / test_reviewer_transport_e2e.py 57件 PASS -

Notes

  • Related issue: 実装: route_canonical_step2_result() を CLI / _cmd_produce() の出力に配線する #2389
  • 動作検証(Runtime Verification Applicability: immediate)は、実 CLI(_cmd_produce())を実際に起動する production-shaped pytest(test_canonical_step2_route_wiring.py / test_root_review_canonical_delivery.py / test_reviewer_transport_e2e.py / test_root_review_pipeline_readback_v2_ssot.py)で実施し、fallback・SKIP は使用していない。
  • STEP_4_5("step_4_5")定数自体は削除していない(Issue 実装: route_canonical_step2_result() を CLI / _cmd_produce() の出力に配線する #2389 のスコープは「approve+proceed の戻り値」の変更のみであり、定数の削除・rename は要求されていない)。
  • test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch の 3 件は本 PR 変更前の baseline(git stash で本PRの差分を退避した状態)でも同一理由で fail することを確認済みであり、本 PR のスコープ外の既存環境依存の失敗である。

…出力経路へ配線する (#2389)

canonical Step 2 の routing authority を `canonical_step2_route`(produce
自身が計算する route_canonical_step2_result() の戻り値)へ一本化し、
orchestrator が status/verdict/next_action から独自に再計算しなくて済む
状態にする。あわせて approve+proceed の戻り値を STEP_4_5 から STEP_2_5 へ
修正し、Step 2.5 semantic design review applicability 判定を迂回しない
ようにする。既知の producer error_code(reviewer_transport_environment_failure
/ artifact_readback_failed)は STEP_5_HUMAN_JUDGMENT_REQUIRED として扱い、
それ以外(body fetch 失敗・VC budget 超過を含む)は従来通り fail-closed の
まま据え置く。

- run_root_review_pipeline.py: STEP_2_5 定数、_emit_produce_result() ヘルパー
  追加し、_cmd_produce() の全5出力経路をこれに統一
- test_root_review_canonical_delivery.py: STEP_4_5 期待値を STEP_2_5 へ更新
- test_canonical_step2_route_wiring.py: 新規追加、配線・route変更・エラー系
  routeの区別を検証
- issue-refinement-loop/SKILL.md, review-issue/SKILL.md, command_registry.py:
  canonical_step2_route を唯一の routing authority として読む旨に更新

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2391/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

PR Review (pr-review-judge)

Verdict: APPROVE

Linked Issue #2389 の live contract と PR diff・AC1-AC7・Allowed Paths・CI を独立検証しました。

  • Allowed Paths gate: status: ok(6変更ファイルすべて範囲内)
  • AC1-AC4: test_canonical_step2_route_wiring.py 12 passed
  • AC5: test_root_review_canonical_delivery.py 24 passed
  • AC6: canonical_step2_route 記述を3ファイルで確認
  • AC7: test_reviewer_transport_e2e.py + test_root_review_pipeline_readback_v2_ssot.py 57 passed
  • test_command_registry.py の3件failはPR head/origin/main baseline両方で同一失敗(本PRスコープ外の既存環境依存fail)であることを確認
  • CI (required, current-head): passed
  • Schema consumer inventory・Safety Claim Matrix確認済み

Blockers: なし

verdict: APPROVE
reviewed_head_sha: "43fd45676f888df7904f667ec7c18e5cdf6abe1f"
blockers: []
warnings:
  - "merge_state_status: BLOCKED(mergeable: MERGEABLE)。branch protection required context 'python-test' が現行ワークフローのcheck名と一致しない既存repo設定問題と見られ、本PRのdiffに起因しない。"
  - "python-test-core / e2e-core / e2e-responsive-matrix はレビュー時点でIN_PROGRESSだったが、branch protection required contextには含まれていない。"

@squne121 squne121 self-assigned this Aug 29, 2026
@squne121

Copy link
Copy Markdown
Owner Author

敵対的レビュー結果

判定

REQUEST_CHANGES — 現状のままではマージ非推奨です。

レビュー対象は draft の PR #2391、head は 43fd45676f888df7904f667ec7c18e5cdf6abe1f です。変更規模は六ファイル、追加四百五十八行・削除七十三行です。既存の APPROVE コメントは Allowed Paths、AC別テスト、CI成功を中心に判定していますが、後述する「実producerがそのrouteを生成可能か」という到達可能性までは検証できていません。

方向性には賛成です。

  • _emit_produce_result() に全stdout JSON出力を集約し、routeフィールドの付け忘れを防ぐ設計は良いです。
  • approve + proceed を直接 Step 4.5 へ送らず、Step 2.5 のセマンティックレビュー適用判定を必ず通す修正も正しいです。
  • _cmd_produce() の戻り値を整数の終了コードのまま保ち、JSONはstdoutに出す契約も妥当です。PythonのCLI終了規約とも整合しています。 ([Python documentation]1)

しかし、routeを一本化した一方で、そのrouteへ入力されるproducer契約が壊れたままです。


P0-1: status: ok + human_judgment_required は実producerから生成不能です

今回のPRは、次の組を有効な本番経路として扱っています。

status: ok
compact_result.verdict: needs-fix
compact_result.next_action: human_judgment_required
    ↓
canonical_step2_route: step_5_human_judgment_required

ところが、V2契約の実producerである reviewer_transport.py は、この出力を生成できません。

build_compact_v2() は next_action を入力として受け取らず、次の二択に固定しています。

action = "proceed" if verdict == "approve" else "request_changes"

さらに validate_compact_v2() も、以下の対応以外を不正値として拒否します。

approve   → proceed
needs-fix → request_changes

_semantic_verdict_and_count() も failure_class を見ず、verdict と blocking_issues の件数しか読みません。実際のtransport処理は、この二値から build_compact_v2() を呼び出しています。

その後 _cmd_produce() は、V2 compactの VERDICT と NEXT_ACTION をそのままトップレベル結果へ転写するだけです。ここにも merged_review_result.failure_class をrouteへ反映する処理はありません。

一方、review-issue/SKILL.md は、readiness結果が human_judgment の場合には、

  1. REVIEW_ISSUE_RESULT_V1.failure_class に contract_readiness_human_judgment が入る
  2. verdictは needs-fix のまま
  3. reviewer_transport.py が raw_result.failure_class を読み
  4. NEXT_ACTION: human_judgment_required に変換する

と説明しています。しかし、その三番目の処理は実装に存在しません。

したがって実際の経路は次のようになります。

failure_class: contract_readiness_human_judgment
verdict: needs-fix
    ↓ failure_classはV2 projectionで無視される
NEXT_ACTION: request_changes
    ↓
canonical_step2_route: step_4

つまり、環境不足・タイムアウト・判定不能など、Issue本文を書き換えても直らない状態が通常のrewrite loopへ送られるという、#2386で指摘された不具合はまだ残っています。

テストも不可能なpayloadを直接注入しています

新規テストは実producerを通さず、次の辞書を手作業で作っています。

for verdict in ("needs-fix", "approve"):
    {
        "status": "ok",
        "compact_result": {
            "verdict": verdict,
            "next_action": "human_judgment_required",
        },
    }

approve + human_judgment_required は現行V2 validatorが明示的に拒否する組です。このテストはproduction contractを検証するのではなく、productionでは作れない入力に対するrouter単体の動作を成功扱いしているため、false-greenです。

必須修正

最小修正としては、V2 wireを不用意に拡張するより、canonical_step2_route を計算するproducer側で、検証済みの merged_review_result.failure_class も参照する方が軽量です。

ただし、次のP0-2のとおり、現在の contract_readiness_human_judgment は環境不足やタイムアウトも含むため、これをそのまま「意味判断が必要」と扱ってはいけません。


P0-2: transport/artifact障害を「human judgment」に分類するのは既存設計への回帰です

PR #2391は、次の二つを step_5_human_judgment_required に送ります。

reviewer_transport_environment_failure
artifact_readback_failed

これは実装元であるIssue #2054の設計決定と直接衝突します。

#2054は、transport failureを、

transport_status: environment_failure
semantic_verdict: null

に収束させ、human_judgment_required と混同しないことを明示しています。対象にはspawn失敗、timeout、signal、empty/malformed output、artifact write/integrity failureが含まれます。

にもかかわらず、#2389はその既存決定をsupersedeする宣言なしに、transport failureとartifact readback failureをhuman judgmentへ変更しています。したがって、これは単なるPR実装上の問題ではなく、Issue #2389の契約自体をreframeすべき設計競合です。

分類としても不適切です。

  • artifact_readback_failed は「判断材料が信頼できない」というintegrity failureであり、Issue内容について人間に賛否を判断してもらう状態ではありません。
  • transport timeoutやspawn failureで必要なのは、再実行、依存関係修復、CLI状態確認などのoperator actionです。
  • これらを human_judgment_required にすると、自動処理可能な環境障害のたびにユーザーへ意味判断を要求し、趣味開発のワークフローを不必要に止めます。

さらに、同じ運用障害でも、

transport failure       → human_judgment_required
artifact readback失敗   → human_judgment_required
body fetch失敗          → fail_closed
VC budget超過           → fail_closed

と分かれており、運用者から見た復旧方法ではなく、たまたま付いている error_code によってUI上の意味が変わっています。

推奨する最小分類

新しい制御基盤やreceiptは不要です。同じStep 5表示処理を流用しても構いませんが、routeの意味は分けるべきです。

step_5_human_judgment_required
    真に意味・仕様・owner判断が必要な場合だけ

step_5_operator_intervention_required
    fetch、dependency、timeout、transport、artifact等の運用障害

fail_closed_environment_or_integrity_failure
    未知コード、型不正、契約不整合

特に、真のセマンティック判断経路は既にStep 2.5の join_review_results.py が human_judgment_required として所有しています。決定論的readinessの環境不足まで同じ意味に寄せる必要はありません。


P1-1: routerは「型不正をfail-closed」にできず例外終了します

Issue #2389のAC4は、未知payloadや型不正を fail_closed_environment_or_integrity_failure にすることを求めています。

しかし、現在の実装は次のとおりです。

compact_result = result.get("compact_result") or {}
verdict = compact_result.get("verdict")

このため、以下の入力ではroute値を返さず AttributeError になります。

{"status": "ok", "compact_result": ["unexpected"]}
{"status": "ok", "compact_result": "unexpected"}
{"status": "ok", "compact_result": 1}

result 自体が辞書以外でも同様です。 _emit_produce_result() はroute計算後にJSONをprintするため、この例外が起きるとfail-closed JSONさえstdoutへ出ません。

また、現在の第三分岐は、

if status == "ok" and next_action == "human_judgment_required":
    return STEP_5_HUMAN_JUDGMENT_REQUIRED

なので、次もStep 5になります。

approve   + human_judgment_required
verdict欠落 + human_judgment_required
未知verdict + human_judgment_required

これは「不整合な組はfail-closed」という同じ関数の説明と矛盾します。新規テストはむしろ approve + human_judgment_required を正しい期待値として固定しています。

必須修正

routerを全域関数にしてください。

from collections.abc import Mapping
from typing import Any

def route_canonical_step2_result(result: Any) -> str:
    if not isinstance(result, Mapping):
        return FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE

    compact = result.get("compact_result")
    if compact is None:
        compact = {}
    if not isinstance(compact, Mapping):
        return FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE

    status = result.get("status")
    verdict = compact.get("verdict")
    next_action = compact.get("next_action")

    if status == "ok" and verdict == "approve" and next_action == "proceed":
        return STEP_2_5

    if status == "ok" and verdict == "needs-fix" and next_action == "request_changes":
        return STEP_4

    # この分岐を残す場合でもexactなvalid combinationだけに限定する
    if (
        status == "ok"
        and verdict == "needs-fix"
        and next_action == "human_judgment_required"
    ):
        return STEP_5_HUMAN_JUDGMENT_REQUIRED

    ...

    return FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE

ただし、production V2がこの三番目の組を生成できないままなら、分岐自体を削除する方が正直です。


P1-2: テスト量に対して、最重要のproduction経路が未検証です

PRは新規・更新テストを多数追加し、関連suiteの成功を示しています。しかし実質的には次の状態です。

  • 実checker chainを通す成功テストはapprove経路。
  • human judgmentは手作り辞書。
  • transport failureは run_reviewer_transport() の戻り値を差し替え。
  • artifact readback failureは verify_artifact() の「一回目は成功、二回目は失敗」という呼び出し順依存のモンキーパッチ。
  • 実際の contract_readiness_human_judgment がproducerからどのrouteになるかは未検証。

特にartifactテストは、内部verifyと外側verifyの呼び出し順が変わるだけで壊れるため、守りたい契約より実装詳細への結合が強いです。

今回の四百五十八行の追加自体を問題視する必要はありません。ただし、その追加量で唯一重要なintegration gapを検出できていないため、現状はハーネス費用に対して保証が弱いです。

推奨するテスト構成

必要なのは次の四種類で十分です。

  1. pure router matrix

    • approve/needs-fix
    • 欠落値
    • 未知値
    • truthyなlist/string/int
    • 不正なcross-field組
  2. 実producerのapprove一件

    • 現在のproduction-shaped testを維持
  3. 実readiness障害一件

    • env_missing_dep、timeout等のfixtureを実checker chainへ通す
    • 最終routeがoperator分類になることを確認
  4. error payloadのparameterized test

    • _emit_produce_result() またはroute関数へエラーpayloadを直接入力
    • 既存artifact security suiteと重複する二段verify再現テストは削る

Claude CLI起動テスト、新しいreceipt、永続state、追加hookは必要ありません。


P2: 「唯一のrouting authority」へ移行したのに、指示面がまだ二重です

PR後の issue-refinement-loop/SKILL.md は canonical_step2_route を唯一のauthorityと説明していますが、同じ文章内に過去の compact_result.verdict / next_action 直接consumeの説明が大量に残っています。

run_root_review_pipeline.py のモジュールdocstringも、canonical Step 2が compact_result.verdict / next_action を直接consumeすると引き続き説明しています。

command_registry.py のコメントも、

  1. #2380としてcompact fieldsを直接consume
  2. #2389としてtop-level routeだけをconsume

という新旧説明を同じ箇所に併記しています。

これは単なるコメント整備ではありません。Claude Codeでは SKILL.md がClaudeの実行指示として読み込まれ、読み込まれた本文はコンテキストに残ります。公式ドキュメントも、主要指示を SKILL.md に置き、本文を簡潔に保つことを推奨しています。したがって、歴史説明の蓄積は毎回のコンテキスト消費と指示競合につながります。(Claude)

推奨修正

canonicalな手順は次だけに縮めるべきです。

1. root_review_pipeline.produce を実行する
2. stdoutのJSONを解析する
3. canonical_step2_routeだけで分岐する
4. 欠落・未知routeはfail-closedで停止する

#2049、#2054、#2380などの経緯はIssueまたはreference文書へ移動してください。特に、実装に存在しない「V2がfailure_classを見てNEXT_ACTIONを変換する」という記述は削除または実装と同時に直す必要があります。


推奨する最小fix delta

1. Issue #2389をreframeする

#2054との関係を明文化します。

architecture_decision:
  preserved:
    - transport failure is environment_failure
    - semantic_verdict remains null on transport/integrity failure
    - operational failure is not human semantic judgment

意図的に#2054を変更するなら supersedes を明記すべきですが、趣味開発の使い勝手を考えるとpreserveする方が適切です。

2. route分類を意味ベースにする

verified deterministic approve
    → step_2_5

verified deterministic needs-fix
    → step_4

genuine semantic/owner ambiguity
    → step_5_human_judgment_required

known environment/transport/integrity problem
    → step_5_operator_intervention_required

malformed/unknown combination
    → fail_closed_environment_or_integrity_failure

物理的には同じStep 5画面や処理を使って構いません。新しいワークフロー基盤は不要で、route名と説明を区別すれば十分です。

3. producerの到達可能な状態だけをrouter契約にする

現行V2を維持するなら、status: ok + human_judgment_required の架空のcompact組は削除します。

readinessの環境状態を上位routeへ反映したい場合は、既にartifact verification済みの merged_review_result.failure_class を _emit_produce_result() 内のroute計算で参照し、operator routeへ送るのが最小です。V2 wireの十一行grammarを拡張する必要はありません。

4. routerを例外なしの全域関数にする

result と compact_result のMapping型を確認し、未知型・未知組は必ずfail-closedの文字列を返します。

5. テストとSKILL本文を縮小する

実在するproduction状態を一件ずつ通し、手作りの不可能payloadを「正常系」とするテストを削除します。artifact hardening、inner retry、hash・symlink検証には変更不要です。


マージ条件

次の五点が満たされれば、このPRの目的は小さく実用的な形で達成できます。

  • 実 _cmd_produce() 出力から、宣言された全正常routeへ到達できる
  • operational failureがsemantic human judgmentとして表示されない
  • malformed payloadで例外終了せず、必ずfail-closed routeを返す
  • V2 producer、validator、SKILL記述が同じ状態集合を表す
  • 新しいreceipt・hook・永続stateを増やさず、テストを到達可能性中心に縮小する
verdict: REQUEST_CHANGES
reviewed_head_sha: "43fd45676f888df7904f667ec7c18e5cdf6abe1f"

blocking_findings:
  - id: P0-1
    summary: >
      status: ok + human_judgment_required はV2 producer/validatorから
      生成不能であり、実readiness human状態はstep_4へ誤配送される。
  - id: P0-2
    summary: >
      transport・artifact障害をhuman_judgment_requiredへ分類しており、
      Issue #2054のenvironment_failure分離契約と衝突する。
  - id: P1-1
    summary: >
      truthyな非dict compact_resultでAttributeErrorになり、
      AC4の型不正fail-closedを満たさない。

non_blocking_findings:
  - id: P1-2
    summary: >
      新規テストは到達不能payloadと呼び出し順依存mockを検証しており、
      production reachabilityを証明していない。
  - id: P2
    summary: >
      SKILL・module doc・registryコメントに新旧routing authorityが併存し、
      Claude Codeの実行指示面を肥大化させている。

Test added 2 commits August 29, 2026 16:44
…ail-closed に統一する

OWNER PR #2391 敵対的レビュー (P0-2, P1-1) を反映。result/compact_result が
Mapping でない場合は例外を送出せず fail_closed_environment_or_integrity_failure
を返すようにし、needs-fix + human_judgment_required の exact な組合せのみを
step_5_human_judgment_required とする。status: input_or_runtime_error は
既知/未知の error_code を問わず fail-closed とし、Issue #2054 の
transport_status: environment_failure / semantic_verdict: null 分離契約を
supersede せず preserve する。
@squne121

Copy link
Copy Markdown
Owner Author

fix_delta: P0-2 / P1-1 対応(head 690f3342)

OWNER 敵対的レビュー(issuecomment-5461056774)で指摘された P0-2・P1-1 を修正しました。Issue #2389 本文も同レビューを反映して改訂済みです。P0-1(producer 到達可能性)と P1-2/P2 の非 blocking 指摘は本 Issue のスコープ外(producer 側 reviewer_transport.py 等 Allowed Paths 外の変更を要するため)として今回は対応していません。

P1-1: route_canonical_step2_result() を全域関数化

isinstance(result, Mapping) / isinstance(compact_result, Mapping) を検証し、Mapping でない場合(list / str / int / None 等)は AttributeError を送出せず FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE を返すようにしました。

P1-1: human_judgment_required 分岐を exact な triple match に変更

status == "ok" and verdict == "needs-fix" and next_action == "human_judgment_required" の exact な組合せのみを STEP_5_HUMAN_JUDGMENT_REQUIRED とし、verdict を確認しない緩い一致(approve + human_judgment_required 等)は FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE にしました。

P0-2: 既知 error_code の human_judgment_required 特別ルーティングを削除

_KNOWN_PRODUCER_HUMAN_JUDGMENT_ERROR_CODES によるルーティング分岐を削除しました。status: input_or_runtime_error は既知(reviewer_transport_environment_failure / artifact_readback_failed)・未知の error_code を問わず一律 FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE を返します。Issue #2054 が確立した「transport/artifact 障害は environment_failure であり human_judgment_required と混同しない」という分離契約を supersede せず preserve します。

テスト更新

  • test_canonical_step2_route_wiring.py: transport failure / artifact readback failure の期待値を STEP_5_HUMAN_JUDGMENT_REQUIRED から FAIL_CLOSED_ENVIRONMENT_OR_INTEGRITY_FAILURE に変更。producer_error_route_distinction テストを producer_error_route_distinction_or_non_mapping_input(+ _never_raises パラメタライズ)に改名・拡張し、非 Mapping 入力(list/str/int/None、および compact_result が非 Mapping の場合)で例外を送出せず fail-closed を返すことを検証
  • test_root_review_canonical_delivery.py: approve + human_judgment_required を「正しく step_5 を返す」としていたケースを fail_closed_environment_or_integrity_failure を期待するよう修正し、既知 error_code 2種も fail-closed 期待のパラメータとして追加
  • SKILL.md の Step 2 routing table・ASCII 図を新しい exact-match / fail-closed 挙動に合わせて更新(500行予算内に収まるよう記述を圧縮)

検証結果(live Issue #2389 の Verification Commands、全 PASS)

AC1: test_canonical_step2_route_wiring.py -k top_level_field_present        -> 5 passed
AC2: test_canonical_step2_route_wiring.py -k approve_routes_to_step_2_5     -> 1 passed
AC3: test_canonical_step2_route_wiring.py -k needs_fix_and_human_judgment_routes -> 1 passed
AC4: test_canonical_step2_route_wiring.py -k producer_error_route_distinction_or_non_mapping_input -> 12 passed
AC5: test_root_review_canonical_delivery.py                                 -> 27 passed
AC6: rg canonical_step2_route (SKILL.md x2 / command_registry.py)           -> 11 matches
AC7: test_reviewer_transport_e2e.py + test_root_review_pipeline_readback_v2_ssot.py -> 57 passed

.claude/skills/issue-refinement-loop/tests/ 全体(1805+ tests)も実行し、今回の変更に起因する新規失敗はありません(既存の environment 依存 subprocess dispatch テスト3件は変更前から failing、pre-existing であることを stash で確認済み)。SKILL.md の500行予算テスト(test_thin_entrypoint.py / test_step_0f_parent_owned_preflight.py)も PASS。

@squne121

Copy link
Copy Markdown
Owner Author

PR Review (pr-review-judge) — fix_delta後の再レビュー

Verdict: APPROVE

OWNERレビュー(issuecomment-5461056774)で指摘されたP0-1/P0-2/P1-1について、head 690f3342 で以下を確認:

  • P1-1: route_canonical_step2_result() は非Mapping入力(list/str/int/None)で例外を送出せずfail_closed_environment_or_integrity_failureを返す。human_judgment_required分岐もverdict==needs-fixのexact triple matchのみに限定され、approve+human_judgment_requiredのような緩い一致はfail_closedになる。19 tests実測PASS。
  • P0-2: 既知transport/artifactエラーコードの特別ルーティングを削除し、status: input_or_runtime_errorは既知/未知問わず一律fail_closedを返すよう修正。Issue #2054のenvironment_failure分離契約と整合。
  • AC1-7全PASS、必須CI passed、Allowed Paths gate ok。

Blockers: なし

verdict: APPROVE
reviewed_head_sha: "690f33423af6bf397d82aaab92a28d6c03405a40"
blockers: []
warnings:
  - "P0-1(producer到達可能性)は本Issueの意図的スコープ外(reviewer_transport.pyはAllowed Paths外)。STEP_5_HUMAN_JUDGMENT_REQUIRED分岐は現状本番producerからは到達不能なまま。follow-up issue化が望ましい。"

@squne121
squne121 marked this pull request as ready for review August 29, 2026 08:10
@squne121
squne121 merged commit 888fcd8 into main Aug 29, 2026
25 checks passed
@squne121
squne121 deleted the worktree-issue-2389-route-canonical-step2-result-cli-wiring branch August 29, 2026 08:32
squne121 pushed a commit that referenced this pull request Aug 29, 2026
…ようにする (#2397)

reviewer_transport.py の build_compact_v2() に optional な failure_class
引数を追加し、merged_review_result.failure_class ==
contract_readiness_human_judgment (かつ verdict == needs-fix) の場合に
NEXT_ACTION: human_judgment_required を持つ V2 compact を生成できるようにした。
validate_compact_v2() も next_action の許容値域を
proceed | request_changes | human_judgment_required の3値に拡張し、
inconsistent な approve + human_judgment_required の組合せは引き続き
fail-closed で拒否する。

これにより run_root_review_pipeline.route_canonical_step2_result() が
判定する step_5_human_judgment_required 分岐が実際の producer 出力から
到達可能になる (PR #2391 owner P0-1 の follow-up)。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
squne121 added a commit that referenced this pull request Aug 30, 2026
…erator intervention route を追加する (#2398)

* feat: build_compact_v2() が human_judgment_required next_action を生成できるようにする (#2397)

reviewer_transport.py の build_compact_v2() に optional な failure_class
引数を追加し、merged_review_result.failure_class ==
contract_readiness_human_judgment (かつ verdict == needs-fix) の場合に
NEXT_ACTION: human_judgment_required を持つ V2 compact を生成できるようにした。
validate_compact_v2() も next_action の許容値域を
proceed | request_changes | human_judgment_required の3値に拡張し、
inconsistent な approve + human_judgment_required の組合せは引き続き
fail-closed で拒否する。

これにより run_root_review_pipeline.route_canonical_step2_result() が
判定する step_5_human_judgment_required 分岐が実際の producer 出力から
到達可能になる (PR #2391 owner P0-1 の follow-up)。

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

* revert: 旧設計(V2 wire三値化)実装を撤去し main と byte-identical に戻す (#2397)

Issue #2397 の reframe により、reviewer_transport.py への failure_class
引数追加・NEXT_ACTION 三値化・test_review_compact_v2_human_judgment.py
の新規追加は不要になったため撤去する。新設計は
route_canonical_step2_result() 側で failure_class を判定する。

* feat: route_canonical_step2_result() に verified failure_class ベースの operator intervention route を追加する (#2397)

merged_review_result.failure_class == "contract_readiness_human_judgment"
(env/tool/timeout/unknown 分類等、Issue 本文書き換えでは解消しない operator
起因の readiness 状態)を持つ needs-fix + request_changes の payload を、
新設の STEP_5_OPERATOR_INTERVENTION_REQUIRED route へ送る。Compact V2 wire
(NEXT_ACTION の proceed | request_changes 二値契約)は変更しない。

OWNER 敵対的レビュー(P0-1/P0-2/P0-3、issues/2397#issuecomment-5461878398)
の指摘に従い、前版 Issue の V2 wire 三値化案(reviewer_transport.py への
failure_class 引数追加・NEXT_ACTION 三値許容化)は撤去し、root-owned
route_canonical_step2_result() 側で判定する設計に作り直した。

* fix: termination-policy.md の見出しを Japanese Check 準拠に修正 (#2397)

CI の PR Body Japanese Check(changed markdown 全体検査)が新設見出し
「## `canonical_step2_route: ...` の termination payload(#2397)」を
prose block として検出し、日本語比率不足で fail していたため、見出し文言
に日本語を追加して修正した(意味・内容は変更なし)。

* fix: test_operator_intervention_route.py の E501 (ruff) を noqa で解消 (#2397)

CI の python-test-core ruff check が、Issue #2397 の Verification Commands
に必須の長い test 関数名(pytest -k 選択子として exact match が要求される)
に対し E501 (line too long) を報告していたため、既存コードベースの慣例
(# noqa: E501)に従い抑制した。関数名・テスト内容は変更しない。

* fix: command_not_allowed の誤分類を修正し operator intervention route の Scope Delta を反映する (#2397)

OWNER 敵対的レビュー (PR #2398, #2398 (comment))
の P0-1/P1-1/P1-2/P2-1 を反映する fix_delta。

- P0-1 (blocking): contract_readiness_check.py の
  _PREFLIGHT_CATEGORY_TO_READINESS に command_not_allowed -> needs_fix を
  追加。body-fixable な command_not_allowed が human_judgment (延いては
  operator intervention route) へ誤ってフォールバックする回帰を修正。
- 新規テストファイル test_operator_intervention_route_scope_delta.py で
  AC9-AC12 を実 _cmd_produce() 経路で検証 (command_not_allowed -> step_4
  回帰、真に operator-only な fixture -> step_5_operator_intervention_required、
  canonical_step2_disposition の付与)。
- 既存 test_operator_intervention_route.py の operator-only fixture を
  command_not_allowed から真の operator-only 状態 (jq + 存在しないパス ->
  unknown 分類 -> human_judgment 直行) へ差し替え (関数名は無変更)。
- run_root_review_pipeline.py に build_canonical_step2_disposition() を
  追加し、_cmd_produce() の全 stdout JSON 出力経路 (_emit_produce_result())
  に canonical_step2_disposition フィールドを配線 (AC12)。
- route_canonical_step2_result() / check_issue_contract.py の docstring
  から、撤回済みの「compact wire 側で failure_class から
  NEXT_ACTION: human_judgment_required を導出する」設計記述を除去し、
  現行の root-owned route 設計 (merged_review_result.failure_class を
  直接参照) の説明へ更新 (P2-1)。
- issue-refinement-loop/SKILL.md の Step 2 routing table と直後の要約に
  step_5_operator_intervention_required を独立した5番目の分岐として
  明記 (AC13)。

既知の未解決事項: .claude/skills/review-issue/tests/test_check_issue_contract.py
(Allowed Paths 外) の test_human_judgment_not_collapsed_to_needs_fix が
command_not_allowed フィクスチャの旧挙動 (human_judgment/blocked) を前提と
しており、本修正後は status: needs_fix になるため fail する。この
契約テストの期待値更新には Allowed Paths 拡張の Scope Delta が必要。

* fix: SKILL.md の thin entrypoint line budget (500行) 超過を解消する (#2397)

前コミットの Step 2 routing table 要約追記で SKILL.md が 505 行になり
test_skill_md_is_under_500_lines / test_skill_md_stays_within_line_budget
が fail していた。review phase routing summary を圧縮し 499 行に収める
(内容は変更せず改行のみ整理)。

* fix: command_not_allowed 誤分類回帰で fail する human_judgment fixture を差し替える (#2397)

CI(python-test-core)で確認された既存テスト退行を修正する。

`contract_readiness_check.py` の `_PREFLIGHT_CATEGORY_TO_READINESS` に
`command_not_allowed: needs_fix` を追加した(P0-1修正、意図的な挙動変更)結果、
`test_check_issue_contract.py::TestContractReadinessExecuteIntegration::
test_human_judgment_not_collapsed_to_needs_fix` が fail していた。

このテストの fixture (`_HUMAN_JUDGMENT_ISSUE_CONTENT`) は preflight の
許可コマンド一覧に無い `loop-protocol-nonexistent-tool-xyz-abc` を VC に使っており、
これは実行前に `command_not_allowed` として拒否される(body-fixable な状態、
Issue #2397 Scope Delta AC9 の意図どおり needs_fix になるべき状態)。

fixture を、Issue #2397 の新規テスト
(`test_operator_intervention_route.py` /
`test_operator_intervention_route_scope_delta.py`) と同じパターンである
`jq '.' fixture/<存在しないパス>.json` に差し替える。`jq` は許可コマンドのため
実際に実行されるが、参照先パスが存在しないため exit code 2 で失敗し、
`classify_result()` の既知パターンに一致せず `category: unknown` に分類される。
`unknown` は `_PREFLIGHT_CATEGORY_TO_READINESS` で human_judgment のまま維持される
genuine operator-only な状態であり、テスト関数名・「human_judgment に collapse
されないこと」を検証するアサーションの意図は変更していない。

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

* fix: AC11 operator-only fixture を決定論的な env_missing_dep へ差し替え、Step 5 分岐説明を修正する

Issue #2397 Scope Delta iteration 3(OWNER PR #2398 敵対的レビュー、3回目、
#2398 (comment))
の P0-1/P1-1/P1-2/P1-3 を反映する fix_delta。

- P0-1 (AC14): test_operator_intervention_route_scope_delta.py の
  `test_genuinely_operator_only_fixture_routes_to_operator_intervention` の
  fixture を、`jq` を存在しない path へ向ける `unknown` catch-all 分類
  トリックから、preflight の real subprocess execution boundary を PATH
  シムで monkeypatch し決定論的に `category: env_missing_dep` を発生させる
  方式へ差し替えた。壊れやすい
  `fixture/e2e_produce_operator_intervention_scope_delta_unknown.json`
  参照は削除。テスト関数名・アサーション内容は無変更。
- P1-1 (AC15): issue-refinement-loop/SKILL.md に、Step 5 operator
  intervention route の終了処理が `canonical_step2_disposition` の
  `termination_reason` / `termination_cause` をそのまま使用し独自に
  再導出しないことを明記した。
- P1-2 (AC16): issue-refinement-loop/SKILL.md の
  `step_5_human_judgment_required` の説明を、現行 Compact V2 producer
  からは生成されない defensive/legacy route である旨に修正した。
- P1-3 (AC17): run_root_review_pipeline.py の
  `FAILURE_CLASS_CONTRACT_READINESS_HUMAN_JUDGMENT` に、route-critical な
  既知 failure_class 値の single source of truth であることを明示する
  コメントを追加した。

Closes #2397

---------

Co-authored-by: Test <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

実装: route_canonical_step2_result() を CLI / _cmd_produce() の出力に配線する

1 participant