Skip to content

実装: issue-refinement-loop に Step 2.5 semantic design review lane を追加する - #2305

Merged
squne121 merged 8 commits into
mainfrom
worktree-issue-2296-semantic-design-review
Aug 23, 2026
Merged

squne121 merged 8 commits into
mainfrom
worktree-issue-2296-semantic-design-review

Conversation

@squne121

@squne121 squne121 commented Aug 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #2296 の実装です。issue-refinement-loop に Step 2.5 semantic design review lane を追加しました。deterministic checker(ISSUE_REVIEW_RESULT_COMPACT_V2)が VERDICT: approve を返した後にのみ、明示シグナル方式の semantic_review_trigger.py(semantic_review_applicable、before/after 比較は行わない)で適用可否を判定し、true の場合に限り新規 SubAgent issue-design-reviewer(Sonnet、per-invocation effort: high)を production producer semantic_review_transport.py 経由で起動・検証・保存します(起動形態は foreground/background いずれでもよく、完了を待たずに次工程へ進まない completion join barrier で担保する)。deterministic verdict と semantic assessment を合成する pure joiner join_review_results.py を追加し、effective_verdict(approve/needs-fix/human_judgment_required)を既存の Step 2 routing にそのまま渡します。decide_next_loop_action.py は無改修(git diff 空、AC4)です。

Owner の第2ラウンド敵対的レビュー(issuecomment-5380099946)指摘(P0-1: production wiring 欠落 / P0-2: materiality 呼称と実装の矛盾 / P0-3: モデル自己免責 / P1-1〜P1-5)はすべて Issue 契約改訂で解消済みの上で実装しています。

主な変更

  • .claude/agents/issue-design-reviewer.md(新規): read-only SubAgent。owner_disposition を出力しない制約を明記
  • .claude/skills/issue-refinement-loop/scripts/semantic_review_trigger.py(新規): 明示シグナルのみで semantic_review_applicable を判定する pure function
  • .claude/skills/issue-refinement-loop/scripts/semantic_review_transport.py(新規): pin-bundle / record-result の2フェーズ production producer。起動形態(foreground/background)自体は問わない completion join barrier を、mtime/timestamp の fail-closed 検証(弱い staleness heuristic であり genuine 実行の証明ではないことをコード内コメントで明記)で担保し、モデル自己免責出力を拒否する
  • .claude/skills/issue-refinement-loop/scripts/join_review_results.py(新規): effective_verdict を導出する pure joiner
  • .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py: extract_directive_markers() から severity-tagged 見出し(## P0-1 等)の誤マージを除去し、severity タグ抽出を独立した新規関数 extract_severity_tags()(+新規正規表現定数 _SEVERITY_TAGGED_HEADING_RE)に分離した(実装: issue-refinement-loop に Step 2.5 semantic design review lane を追加する #2296 OWNER adversarial review P1-4 で意図された two-function split。他の既存関数は無改修)
  • schemas/semantic_review_result_v1.schema.json(新規): モデル出力を assessment/findings のみに制限し、owner_disposition を別フィールドとして分離
  • .claude/agents/issue-editor.md: SEMANTIC_REWRITE_CONSTRAINTS_V1 契約を追加(既存 FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 と共存)
  • .claude/skills/edit-issue/SKILL.md: rewrite_lane discriminator を INPUT_CONTRACT に追加
  • .claude/skills/issue-refinement-loop/SKILL.md(499行、AC6)+ references/semantic-design-review.md(新規)+ references/anchor-comment-handling.md 拡張

AC10(#428 との重複要否)

#428(impl-review-loop/issue-refinement-loop の Step 3 adversarial review 例外ゲート化)と scope 隣接性を確認し、独立した機構であるため統合しないと判断しました。partial overlap の記録コメントを #428 に投稿済みです: #428 (comment)

本 PR は Closes #2296 として linked issue を close します。

Checks

  • pnpm typecheck: pass
  • pnpm lint: pass
  • pnpm test: 1871 passed / 1 failed(tests/retro-live-verification.test.ts の既存テストが 5000ms timeout。本 PR の変更ファイルと無関係、環境負荷起因の既存 flake。再実行で個別 pass を確認)
  • pnpm build: pass
  • uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 24 passed
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/: 1686 passed / 3 failed(TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch 系。本 PR 変更前の base HEAD でも同様に3件 fail する既存の環境依存 failure。本 PR の変更ファイルとは無関係)
  • 新規テスト(本 PR 追加分): test_semantic_review_trigger.py (14) / test_join_review_results.py (16) / test_semantic_review_transport.py (14, fake-agent-transport 統合テスト含む) / test_scope_signal_delta.py 拡張分 (5) すべて pass

Schema Change Applicability

- decision: schema_change

新規 schema schemas/semantic_review_result_v1.schema.json を追加した(既存 ISSUE_REVIEW_RESULT_COMPACT_V2 / LOOP_REWRITE_ROUTER_STATE_V1 にはフィールドを追加していない)。

Schema Consumer Inventory

# before
schema: (該当ファイルは存在しなかった)

# after
schema: SEMANTIC_REVIEW_RESULT_V1
fields: [schema, issue_number, body_sha256, prompt_version, requested_model, assessment, findings, artifact_valid, input_binding_valid, freshness_valid]
Consumer ファイル 更新有無 備考
.claude/skills/issue-refinement-loop/scripts/semantic_review_transport.py 新規追加 schema の唯一の producer/consumer。model 出力(assessment/findings)と transport-bound フィールドを合成して artifact を書き出す
.claude/skills/issue-refinement-loop/scripts/join_review_results.py 新規追加 assessment/findings を読み effective_verdict を導出する(schema ファイル自体は import しない、raw dict 経由)
.claude/agents/issue-design-reviewer.md 新規追加 schema の許可フィールドのみを出力するよう明記
既存 ISSUE_REVIEW_RESULT_COMPACT_V2 / LOOP_REWRITE_ROUTER_STATE_V1 の consumer 群 変更なし 本 PR はこれらのフィールドを一切変更していない(AC3)

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
issue-design-reviewer は Edit/Write/MultiEdit/Agent/Skill を持たず read-only である yes .claude/agents/issue-design-reviewer.md frontmatter の disallowedTools
モデル出力に owner_disposition が含まれる場合、transport は fail-closed で reject する(P0-3) yes semantic_review_transport.py::record_result() の model_self_disposition_forbidden 分岐、test_record_result_rejects_model_self_disposition_top_level / ..._inside_finding
transport は completion join barrier を通過する前の stale/fabricated result を受理しない(起動形態が foreground/background かは問わない、AC8) yes semantic_review_transport.py::record_result() の mtime/timestamp fail-closed 検証、test_record_result_rejects_stale_result_reused_without_genuine_wait / test_record_result_rejects_completed_at_not_after_pinned_at
decide_next_loop_action.py は本 PR で一切変更されない yes git diff --quiet HEAD -- .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py が exit 0
scope_signal_delta.py の変更は extract_directive_markers() の修正(severity-tagged 見出しの誤マージ除去)と、新規の独立関数 extract_severity_tags()(+新規正規表現定数 _SEVERITY_TAGGED_HEADING_RE)の追加の2点に限定される(#2296 OWNER adversarial review P1-4 で意図された two-function split であり、scope 逸脱ではない) yes git diff origin/main -- .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py で確認済み(extract_directive_markers() の修正+extract_severity_tags()/_SEVERITY_TAGGED_HEADING_RE の新規追加のみで、他の既存関数は無改修)、既存 51 テストが無改修で pass

Notes

  • 動作検証 AC(AC8, Runtime Verification Applicability: immediate)は fake-agent-transport による pytest 統合テストで検証しました。ジェニュインな Claude Code smoke(trigger → foreground agent 起動 → join → route)は、本 PR が実装した .claude/agents/issue-design-reviewer.md を実際の Agent tool で起動できる環境(このセッション自体が nested Agent 起動制約下にあるため、当該 PR 実装セッション内では実行不可)でのマージ前レビュー時に実施することを推奨します。
  • pnpm test の 1 件 timeout と issue-refinement-loop pytest の 3 件 failure は、いずれも本 PR の変更前 base HEAD でも再現する既存の環境依存 failure であることを確認済みです(無関係ファイル、無関係テストクラス)。

#2296)

deterministic checker が approve を返した後、明示シグナル方式の
semantic_review_trigger.py で適用可否を判定し、issue-design-reviewer
SubAgent の起動・検証・保存を担う semantic_review_transport.py と、
deterministic verdict と semantic assessment を合成する pure joiner
join_review_results.py を追加する。owner_disposition はモデル出力から
排除し(P0-3)、severity-tagged 見出し抽出は scope_signal_delta.py の
既存 extract_directive_markers() を拡張して実装する(P1-5)。
decide_next_loop_action.py は無改修のまま維持する(AC4)。

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-2305/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

fix_delta iteration 2 を適用しました。

  • .claude/skills/issue-refinement-loop/scripts/semantic_review_transport.py の未使用import (os, sys) を削除(ruff F401対応、ファイル内の他箇所で未使用であることを grep で確認済み)
  • uv run --locked ruff check .claude/scripts scripts schemas .claude/skills: All checks passed
  • pytest .claude/skills/issue-refinement-loop/tests/test_semantic_review_transport.py: 13 passed

new head SHA: c8c2465

Test added 3 commits August 22, 2026 23:55
.claude/agents/issue-design-reviewer.md の見出し「## 起動運用(...)」ブロックが
per-block Japanese ratio (0.089) で閾値 0.1 未満だったため、日本語表現を追加して
ratio 0.241 に改善(jp=13, tot=54)。技術的な契約内容は変更なし。

fix_delta iteration 3 (#2296, PR #2305, CI run 32579315341)
.claude/skills/issue-refinement-loop/SKILL.md の「### Step 2.5: Semantic Design
Review」見出しが完全英語(jp=0, total=31)で per-block ratio 0.000 となり閾値 0.1
未満だった。他の Step 見出し(例: Step 0/1/4)の日英併記パターンに合わせ、日本語
表記「セマンティック設計レビュー」を追加した。技術的な契約内容・参照先・呼び出し
規約は一切変更していない。

fix_delta iteration 4 (#2296, PR #2305, CI run 32580159449)
… ratio 不足を解消する

## 4. Join 見出しが英語のみ(jp=0, total=8)で per-block ratio 判定に失敗していたため、
既存の bilingual heading パターンに合わせて日本語併記に修正する。

Refs #2296
@squne121

Copy link
Copy Markdown
Owner Author

LOOP_VERDICT (impl-review-loop, final)

Mergeability: mergeable=MERGEABLE, merge_state_status=BLOCKED(Draft PR。branch protection上の必須人間承認待ちであり、実 Git conflict ではない)
Evidence Check: Verification Commands(AC1–AC10)を独立再実行し全PASS確認。Allowed Paths準拠(15変更ファイルが契約範囲内、read-onlyマーク3ファイルは無改修)。Required CI(test/build/lint/typecheck/validate-generated-artifact)は現head ae052a7b3946124d97ee7a1afc6dd53558413c42 で全green。
Blockers: なし
Non-blockers(warnings):

  • visual-impact-policy-trusted(非required check)が直前の連続pushによる stale workflow_run 判定で一時的にfailを表示(実ポリシー違反ではない)
  • PR本文のtest件数表記に軽微な誤差の可能性(non-blocking)
verdict: APPROVE
reviewed_head_sha: "ae052a7b3946124d97ee7a1afc6dd53558413c42"
blockers: []
warnings:
  - "visual-impact-policy-trusted (non-required) transient stale workflow_run artifact from rapid successive pushes"
  - "PR body test-count wording may have a minor discrepancy (non-blocking)"

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。Draft 継続が妥当です。

対象 head は現在も ae052a7b3946124d97ee7a1afc6dd53558413c42、PR は Open / Draft / mergeable、変更規模は 15 ファイル・+1788/-9 です。既存の impl-review-loop は APPROVE、Required CI も green ですが、PR 本文自身が「実 Claude Code の Agent tool を用いた trigger → agent → join → route は未実施で、fake-agent transport テストのみ」と明記しています。

設計の方向性は正しいです。親 Issue #2294、ADR Issue #2295、ADR #8 は、deterministic checker に semantic completeness を主張させず、LLM reviewer が AC・schema・protocol・orchestration を判断し、未解消の blocker/high finding を成功終了させないことを要求しています。#2273 は、deterministic な整形式検証が通っても、VC と protocol schema の意味的矛盾を見落とした実例です。

問題は、その正しい設計意図が production orchestration として閉じていないことです。


Blocking findings

P0-1: semantic reviewer にレビュー対象の Issue 本文が渡りません

semantic_review_transport.py::pin_bundle() は body_text の SHA-256 を計算しますが、永続化する bundle.json には本文も本文ファイルへの参照も入りません。

概略は次の状態です。

bundle = {
    "issue_number": ...,
    "invocation_id": ...,
    "body_sha256": ...,
    "prompt_version": ...,
    "requested_model": ...,
    "pinned_at": ...,
    "anchor_feedback": ...,
    "deterministic_findings": ...,
}

body_text / body_file はありません。一方、issue-design-reviewer は「input bundle に含まれる pinned body」を読む前提で定義されています。

Claude Code の named subagent は親会話の全コンテキストを継承せず、独自 system prompt と delegation task を持つ fresh context で開始します。したがって、親セッションが既に Issue 本文を読んでいても、それだけでは reviewer に本文は届きません。(Claude) (Claude)

semantic-design-review.md にも、Agent tool 呼び出し時に渡す具体的な task prompt、bundle.json のパス、本文ファイルのパスがありません。

影響

reviewer は以下のいずれかになります。

  • Issue 本文を読まずに repo や anchor feedback だけで判定する

  • 自力で対象 Issue を推測する

  • 「本文がない」と返す

  • 最悪の場合、本文を見ていないのに assessment: clear を返す

fake-agent transport テストは orchestrator が JSON ファイルを直接生成するため、この欠陥を検出できません。

最小修正

pin-bundle は invocation directory に次を保存してください。

<invocation_dir>/
├── bundle.json
└── body.md

bundle.json には最低限、次を入れます。

{
  "issue_number": 2296,
  "body_file": "body.md",
  "body_sha256": "...",
  "prompt_version": "v1"
}

Agent task は曖昧な自然言語ではなく、少なくとも次を明示すべきです。

Read <invocation_dir>/bundle.json and the body_file referenced by it.
Review exactly that pinned body.
Return one JSON object conforming to the raw semantic review schema.
Do not fetch or substitute a different Issue body.

P0-2: 「foreground」「effort: high」の production 契約が Claude Code 仕様と一致していません

PR は次を主張しています。

  • reviewer を foreground で起動する

  • per-invocation effort: high

  • mtime と timestamp により foreground 完了を構造的に証明する

しかし、実装された .claude/agents/issue-design-reviewer.md の frontmatter に model、effort、foreground 制御はありません。

現行 Claude Code 公式仕様では、subagent は v2.1.198 以降 background が既定で、Claude が必要に応じて foreground を選びます。また、fork mode ではすべての subagent が background になり、Agent tool の run_in_background 自体が除去されます。(Claude) (Claude)

モデルは per-invocation model が公式に定義されています。一方、effort の確実な設定経路として記載されているのは skill/subagent frontmatter、セッション設定、環境変数です。PR の「per-invocation effort: high」は文書化された契約になっていません。(Claude) (Claude)

また、次の条件は Agent が実行された証明になりません。

result_file.mtime > pinned_at
completed_at > pinned_at

これは単に「pin 後に何者かがファイルを作った」証拠です。fake test や orchestrator 自身によるファイル生成でも通ります。

推奨修正

この個人開発用途では、foreground を保証すること自体を要件から外す方がよいです。

必要なのは実装形態ではなく、次の join barrier です。

Agent の完了結果を受け取る前に record-result と join を実行してはならない。

background でも completion notification を待てば品質上の問題はありません。foreground を強制するためにセッション全体の background 機能を無効化すると、他の並列ワークフローを妨げます。

併せて agent frontmatter に次を置きます。

model: sonnet
effort: high

mtime は stale file の補助判定として残してもよいですが、「genuine Agent 実行」「foreground 完了」の証拠とは表現しないでください。


P0-3: joiner が矛盾・未知状態を fail-open で approve します

公開 head の join_review_results.py と同じ関数ロジックに入力を与えて再現した結果です。

入力 | 現在の結果 | 必要な結果 -- | -- | -- assessment=clear + blocker finding | approve | invalid / needs-fix assessment=findings + findings=[] | approve | invalid assessment=bogus + findings=[] | approve | transport error transport_status=error, retry_already_attempted=false | approve + warning | まず1回 retry

最も重大なのはこの分岐です。

if semantic_assessment == "clear":
    return approve

findings を見る前に return するため、blocker があっても clear の一語で無視されます。

さらに、未知の semantic_assessment や未知の transport_status を拒否する default branch がありません。空 findings ならそのまま approve に落ちます。

新規 JSON Schema は enum や field type を定義していますが、production transport と joiner は schema validator を呼ばず、独自の部分検証だけを行っています。また schema 自体にも、clear ⇔ findings が空、findings ⇔ findings が1件以上 という相関制約がありません。

このリポジトリには既に jsonschema>=4.0 が runtime dependency としてあるため、新しい依存関係や重いハーネスは不要です。

最小修正

record_result() で schema 全体を検証し、追加の semantic invariant を一か所だけ実装します。

if assessment == "clear" and findings:
    invalid

if assessment == "findings" and not findings:
invalid

joiner 側も defence-in-depth ではなく、単純な total function にします。

unknown enum/state       → transport error
open blocker/high → needs-fix
clear + zero findings → approve
medium/low only → approve + warning
transport failure → retry once
retry後もfailure → best_effortならapprove + 明示warning

assessment より findings を優先して計算すれば、clear + blocker の false approval は消せます。


P0-4: semantic finding から semantic rewrite への producer がありません

PR は受信側の契約を追加しています。

  • issue-editor.md: SEMANTIC_REWRITE_CONSTRAINTS_V1

  • edit-issue/SKILL.md: rewrite_lane: semantic

しかし Step 2.5 は、joiner の effective_verdict: needs-fix を通常の verdict として Step 4 に送る、としか定義していません。Step 4 も generic な opaque payload を issue-editor に渡すだけです。

一方、edit-issue の rewrite_lane は省略時に fail_closed_repair になります。つまり orchestrator が明示的に semantic を設定しなければ、semantic finding 用ではない既存の補修レーンが選ばれます。

issue-editor は semantic payload を受け取れるようになっていますが、validated artifact からその payload を作る canonical producer がありません。

影響

次の状態が成立します。

semantic reviewer: high finding
joiner: needs-fix
orchestrator: Step 4へ
issue-editor: semantic findingを受け取らない、またはdefault laneで処理
次ループ: finding未解消のまま再評価

これは ADR の最重要要件である「未解消 blocker/high を成功終了へ通さない」を満たしません。

最小修正

joiner の結果を、verdict だけでなく routing payload まで含む形にします。

effective_verdict: needs-fix
rewrite_lane: semantic
semantic_rewrite_constraints:
schema_version: SEMANTIC_REWRITE_CONSTRAINTS_V1
source_artifact: <validated semantic_review_result.json>
checked_body_sha256: <pinned hash>
findings:
- <open blocker/high findings only>
max_rewrite_attempts: 2
no_progress_route: human_judgment_required

Step 4 はこの payload を再構成せず、そのまま issue-editor に forward するのが安全かつ簡単です。


High-priority findings

P1-1: Owner disposition を偽装・欠落したデータでも blocker/high を無効化できます

schema は次を要求しています。

{
"status": "accepted",
"recorded_by": "owner"
}

しかし joiner は status in {"accepted", "deferred"} しか確認しません。したがって、次でも high finding が無効化されます。

{
"severity": "high",
"owner_disposition": {
"status": "accepted"
}
}

同一ロジックで再現すると approve になりました。schema と joiner が別々の現実を持っています。

暗号署名や複雑な権限証明は不要です。個人リポジトリなら、schema validation 後に以下だけを要求すれば十分です。

recorded_by == "owner"
status in {"accepted", "deferred"}
reason is non-empty

モデル raw result への owner_disposition 混入拒否は維持して構いません。


P1-2: cache と freshness 機構が、価値より誤承認リスクを増やしています

invocation_id は body_sha256 + prompt_version + requested_model から決定論的に作られるため、別セッションでも同じディレクトリを共有します。既存 result の cache 判定は、body hash、prompt version、model の一致だけを見ており、次を確認しません。

  • artifact_valid

  • input_binding_valid

  • freshness_valid

  • schema validity

  • issue number

  • 完全な state consistency

さらに record-result --current-body-sha256 は任意で、省略すると freshness_valid=True になります。

このレーンは explicit signal があるときだけ実行されるため、cache の便益は限定的です。個人開発では cache を堅牢化するための lock、session nonce、atomic CAS を増やすより、v1 では cache を削除して毎回 fresh review にする方が品質と保守性の両方で優れます。

併せて current_body_sha256 を production 手順では必須にしてください。


P1-3: trigger は classifier だけで、信頼できる signal producer がありません

reference の実行例は次の形です。

--input-json '{"checker_gap_count": 0, "heuristic_concern_count": 0, ...}'

... を含むため、そのままでは JSON として実行できません。また、どの existing artifact のどの field から、次を生成するかが定義されていません。

  • checker_gap_count

  • heuristic_concern_count

  • cross_contract_change

  • owner_decision_conflict

  • severity_tagged_anchor_findings

classifier 自体にも型 coercion の問題があります。

bool("false")  # True

したがって、JSON に文字列 "false" が入ると signal が true になります。negative count も受理されます。

修正案

新しい ledger や provenance system は不要です。build_semantic_review_trigger_input() の pure function を一つ追加し、既存の trusted artifact からだけ入力を生成します。

各 field は strict type にしてください。

bool field → JSON boolean のみ
count → integer >= 0
findings → list
unknown key → reject

より単純化するなら、v1 は以下だけでも十分です。

user_requested
semantic_rewrite_requested
schema_change
protocol_change
orchestration_change
severity-tagged anchor

曖昧な heuristic_concern_count は、実 consumer ができるまで削って構いません。


P1-4: P0-1 見出しが scope directive として扱われ、Acceptance Criteria を勝手に変更し得ます

PR は severity-tagged heading を generic な extract_directive_markers() に追加しています。しかしこの marker は semantic trigger 専用ではなく、既存の scope directive 判定と contract patch 生成にも使われます。

公開コードと同じロジックで次を評価しました。

## P0-1

  • architecture の責務分離を見直す

結果は次です。

directive_markers:
  • P0-1
    directive_confidence: explicit
    contract_patch_operations:
  • section: Acceptance Criteria
    op: append
    text: architecture の責務分離を見直す

未知 marker が fallback で revised acceptance criteria に分類されるためです。つまり、単なる重大度ラベルが scope-authoritative directive に昇格します。

これはセキュリティ問題ではなく、ハーネスが本来の Issue refinement を歪める実用上の欠陥です。

修正案

次を分離してください。

extract_directive_markers()
extract_severity_tags()

同じ regex helper を共有しても構いませんが、返す型と consumer は分けます。

回帰テストは明確です。

P0見出し + bullet
→ semantic trigger: true
→ directive confidence: inferred または markerなし
→ contract patch operation: 生成しない

P1-5: best-effort retry の契約が joiner に実装されていません

reference は transport failure 時に「一度だけ自動再実行し、それでも不能なら approve + warning」としています。ところが joiner は retry_already_attempted=false でも即座に approve します。boolean は warning 文字列へ埋め込むだけで、制御には使われていません。

個人開発向けの方針として、transport failure を merge blocker にする必要はありません。ただし次の順序は守るべきです。

first failure
→ retry

second failure
→ approve
→ terminal reportに SEMANTIC_REVIEW_UNAVAILABLE を残す

warning が中間 JSON にしか残らず、最終レポートで消える設計は避けてください。


非blockingだが修正した方がよい点

「read-only」は技術的保証ではありません

Agent は Edit/Write を持ちませんが Bash を持つため、ファイル更新や gh mutation は技術的には可能です。

ただし、この用途で Bash command filter や PreToolUse hook を追加する必要はありません。ワークフローを重くするだけです。Safety Claim Matrix を次の表現へ弱めれば十分です。

Edit/Write tool を持たない read-only intent の reviewer。Bash の非mutation利用は procedural contract。

テスト件数表記が不一致です

PR 本文は transport test 14件、途中コメントは 13件としています。既存 self-review もこれを warning として認識しています。実装品質への影響は小さいですが、PR 本文は head に合わせて直すべきです。


推奨する簡素な production フロー

この PR の目的には、cache・疑似foreground証跡・手動 artifact mutation より、次の直線的なフローが適しています。

deterministic approve
│
▼
unique invocation dirを作る
│
├── body.md
└── bundle.json
│
▼
issue-design-reviewerを起動
foreground/backgroundは問わない
完了結果を待つ
│
▼
strict JSON parse

  • JSON Schema validation
  • clear/findings相関検証
    │
    ├── clear
    │ └── approve
    │
    ├── medium/low only
    │ └── approve + terminal warning
    │
    ├── blocker/high
    │ └── rewrite_lane=semantic
    │ + findingsをissue-editorへforward
    │
    └── transport/schema failure
    └── retry once
    └── 再失敗ならapprove
    + SEMANTIC_REVIEW_UNAVAILABLE

残すべきもの

  • body SHA binding

  • strict JSON / JSON Schema validation

  • Agent completion join barrier

  • blocker/high の semantic rewrite forwarding

  • 一度だけの retry

  • final report への warning

削るべきもの

  • cross-session result cache

  • .pending の疑似証跡

  • mtime による genuine Agent 証明

  • foreground そのものの強制

  • model artifact への手作業 disposition 追記

  • severity tag と scope directive の共用

  • live Claude 呼び出しを Required CI にすること

  • cryptographic owner authentication

  • Bash mutation を止めるための追加ハーネス


マージ前に必要なテスト

最低限、次の回帰が必要です。

  1. pin-bundle 後に body.md が存在し、bundle の hash と一致する。

  2. clear + blocker finding は reject される。

  3. findings + [] と未知 assessment は reject される。

  4. recorded_by: owner がない disposition は blocker/high を無効化しない。

  5. transport error + retry=false は approve せず retry route へ進む。

  6. P0-1 見出しだけでは scope directive / AC patch が生成されない。

  7. high finding から rewrite_lane: semantic と同一 finding が issue-editor に届く。

  8. rewrite 後の再reviewで finding が消えるか、2回無進展なら human judgment へ進む。

加えて Required CI ではなく、マージ前の手動 smoke として、#2273 型の意図的な矛盾 fixtureを一度 genuine Claude Code Agent へ渡すべきです。

VCでは local/cloud/both
schemaでは local/cloud のみ

期待結果は次です。

deterministic approve
→ semantic trigger
→ high finding
→ semantic rewrite
→ fresh review clear

最終評価

#428 との統合を見送った判断、deterministic と semantic の責務分離、semantic rewrite を既存 fail-closed repair と別契約にした判断は妥当です。#428 側にも partial overlap が記録されており、ここを無理に統合する必要はありません。

ただし現在の APPROVE は、追加されたファイルとテストが契約上存在することを確認したものであり、semantic reviewer が正しい本文を読み、その finding が rewrite まで確実に届くことを確認したものではありません。

verdict: REQUEST_CHANGES
draft_should_remain: true
blocking:
  • pinned body is not delivered to the reviewer
  • Agent execution contract does not match Claude Code behavior
  • contradictory or unknown semantic states approve
  • semantic findings are not canonically forwarded to semantic rewrite
    required_before_ready:
  • body binding
  • schema and invariant validation
  • explicit semantic rewrite payload
  • completion join barrier
  • severity/directive parser separation
    recommended_simplification:
  • remove cache and pseudo-foreground evidence

現状のままでは、#2296 が解決しようとした「機械チェックは通るが意味的に壊れた Issue」を、別形式で再生産します。

# 判定

REQUEST_CHANGES。Draft 継続が妥当です。

対象 head は現在も ae052a7b3946124d97ee7a1afc6dd53558413c42、PR は Open / Draft / mergeable、変更規模は 15 ファイル・+1788/-9 です。既存の impl-review-loop は APPROVE、Required CI も green ですが、PR 本文自身が「実 Claude Code の Agent tool を用いた trigger → agent → join → route は未実施で、fake-agent transport テストのみ」と明記しています。

設計の方向性は正しいです。親 Issue #2294、ADR Issue #2295、ADR #8 は、deterministic checker に semantic completeness を主張させず、LLM reviewer が AC・schema・protocol・orchestration を判断し、未解消の blocker/high finding を成功終了させないことを要求しています。#2273 は、deterministic な整形式検証が通っても、VC と protocol schema の意味的矛盾を見落とした実例です。

問題は、その正しい設計意図が production orchestration として閉じていないことです。


Blocking findings

P0-1: semantic reviewer にレビュー対象の Issue 本文が渡りません

semantic_review_transport.py::pin_bundle() は body_text の SHA-256 を計算しますが、永続化する bundle.json には本文も本文ファイルへの参照も入りません。

概略は次の状態です。

bundle = {
    "issue_number": ...,
    "invocation_id": ...,
    "body_sha256": ...,
    "prompt_version": ...,
    "requested_model": ...,
    "pinned_at": ...,
    "anchor_feedback": ...,
    "deterministic_findings": ...,
}

body_text / body_file はありません。一方、issue-design-reviewer は「input bundle に含まれる pinned body」を読む前提で定義されています。

Claude Code の named subagent は親会話の全コンテキストを継承せず、独自 system prompt と delegation task を持つ fresh context で開始します。したがって、親セッションが既に Issue 本文を読んでいても、それだけでは reviewer に本文は届きません。([Claude]1) ([Claude]1)

semantic-design-review.md にも、Agent tool 呼び出し時に渡す具体的な task prompt、bundle.json のパス、本文ファイルのパスがありません。

影響

reviewer は以下のいずれかになります。

  • Issue 本文を読まずに repo や anchor feedback だけで判定する
  • 自力で対象 Issue を推測する
  • 「本文がない」と返す
  • 最悪の場合、本文を見ていないのに assessment: clear を返す

fake-agent transport テストは orchestrator が JSON ファイルを直接生成するため、この欠陥を検出できません。

最小修正

pin-bundle は invocation directory に次を保存してください。

<invocation_dir>/
├── bundle.json
└── body.md

bundle.json には最低限、次を入れます。

{
  "issue_number": 2296,
  "body_file": "body.md",
  "body_sha256": "...",
  "prompt_version": "v1"
}

Agent task は曖昧な自然言語ではなく、少なくとも次を明示すべきです。

Read <invocation_dir>/bundle.json and the body_file referenced by it.
Review exactly that pinned body.
Return one JSON object conforming to the raw semantic review schema.
Do not fetch or substitute a different Issue body.

P0-2: 「foreground」「effort: high」の production 契約が Claude Code 仕様と一致していません

PR は次を主張しています。

  • reviewer を foreground で起動する
  • per-invocation effort: high
  • mtime と timestamp により foreground 完了を構造的に証明する

しかし、実装された .claude/agents/issue-design-reviewer.md の frontmatter に model、effort、foreground 制御はありません。

現行 Claude Code 公式仕様では、subagent は v2.1.198 以降 background が既定で、Claude が必要に応じて foreground を選びます。また、fork mode ではすべての subagent が background になり、Agent tool の run_in_background 自体が除去されます。(Claude) (Claude)

モデルは per-invocation model が公式に定義されています。一方、effort の確実な設定経路として記載されているのは skill/subagent frontmatter、セッション設定、環境変数です。PR の「per-invocation effort: high」は文書化された契約になっていません。([Claude]1) ([Claude]2)

また、次の条件は Agent が実行された証明になりません。

result_file.mtime > pinned_at
completed_at > pinned_at

これは単に「pin 後に何者かがファイルを作った」証拠です。fake test や orchestrator 自身によるファイル生成でも通ります。

推奨修正

この個人開発用途では、foreground を保証すること自体を要件から外す方がよいです。

必要なのは実装形態ではなく、次の join barrier です。

Agent の完了結果を受け取る前に record-result と join を実行してはならない。

background でも completion notification を待てば品質上の問題はありません。foreground を強制するためにセッション全体の background 機能を無効化すると、他の並列ワークフローを妨げます。

併せて agent frontmatter に次を置きます。

model: sonnet
effort: high

mtime は stale file の補助判定として残してもよいですが、「genuine Agent 実行」「foreground 完了」の証拠とは表現しないでください。


P0-3: joiner が矛盾・未知状態を fail-open で approve します

公開 head の join_review_results.py と同じ関数ロジックに入力を与えて再現した結果です。

入力 現在の結果 必要な結果
assessment=clear + blocker finding approve invalid / needs-fix
assessment=findings + findings=[] approve invalid
assessment=bogus + findings=[] approve transport error
transport_status=error, retry_already_attempted=false approve + warning まず1回 retry

最も重大なのはこの分岐です。

if semantic_assessment == "clear":
    return approve

findings を見る前に return するため、blocker があっても clear の一語で無視されます。

さらに、未知の semantic_assessment や未知の transport_status を拒否する default branch がありません。空 findings ならそのまま approve に落ちます。

新規 JSON Schema は enum や field type を定義していますが、production transport と joiner は schema validator を呼ばず、独自の部分検証だけを行っています。また schema 自体にも、clear ⇔ findings が空、findings ⇔ findings が1件以上 という相関制約がありません。

このリポジトリには既に jsonschema>=4.0 が runtime dependency としてあるため、新しい依存関係や重いハーネスは不要です。

最小修正

record_result() で schema 全体を検証し、追加の semantic invariant を一か所だけ実装します。

if assessment == "clear" and findings:
    invalid

if assessment == "findings" and not findings:
    invalid

joiner 側も defence-in-depth ではなく、単純な total function にします。

unknown enum/state       → transport error
open blocker/high        → needs-fix
clear + zero findings    → approve
medium/low only          → approve + warning
transport failure        → retry once
retry後もfailure         → best_effortならapprove + 明示warning

assessment より findings を優先して計算すれば、clear + blocker の false approval は消せます。


P0-4: semantic finding から semantic rewrite への producer がありません

PR は受信側の契約を追加しています。

  • issue-editor.md: SEMANTIC_REWRITE_CONSTRAINTS_V1
  • edit-issue/SKILL.md: rewrite_lane: semantic

しかし Step 2.5 は、joiner の effective_verdict: needs-fix を通常の verdict として Step 4 に送る、としか定義していません。Step 4 も generic な opaque payload を issue-editor に渡すだけです。

一方、edit-issue の rewrite_lane は省略時に fail_closed_repair になります。つまり orchestrator が明示的に semantic を設定しなければ、semantic finding 用ではない既存の補修レーンが選ばれます。

issue-editor は semantic payload を受け取れるようになっていますが、validated artifact からその payload を作る canonical producer がありません。

影響

次の状態が成立します。

semantic reviewer: high finding
joiner: needs-fix
orchestrator: Step 4へ
issue-editor: semantic findingを受け取らない、またはdefault laneで処理
次ループ: finding未解消のまま再評価

これは ADR の最重要要件である「未解消 blocker/high を成功終了へ通さない」を満たしません。

最小修正

joiner の結果を、verdict だけでなく routing payload まで含む形にします。

effective_verdict: needs-fix
rewrite_lane: semantic
semantic_rewrite_constraints:
  schema_version: SEMANTIC_REWRITE_CONSTRAINTS_V1
  source_artifact: <validated semantic_review_result.json>
  checked_body_sha256: <pinned hash>
  findings:
    - <open blocker/high findings only>
  max_rewrite_attempts: 2
  no_progress_route: human_judgment_required

Step 4 はこの payload を再構成せず、そのまま issue-editor に forward するのが安全かつ簡単です。


High-priority findings

P1-1: Owner disposition を偽装・欠落したデータでも blocker/high を無効化できます

schema は次を要求しています。

{
  "status": "accepted",
  "recorded_by": "owner"
}

しかし joiner は status in {"accepted", "deferred"} しか確認しません。したがって、次でも high finding が無効化されます。

{
  "severity": "high",
  "owner_disposition": {
    "status": "accepted"
  }
}

同一ロジックで再現すると approve になりました。schema と joiner が別々の現実を持っています。

暗号署名や複雑な権限証明は不要です。個人リポジトリなら、schema validation 後に以下だけを要求すれば十分です。

recorded_by == "owner"
status in {"accepted", "deferred"}
reason is non-empty

モデル raw result への owner_disposition 混入拒否は維持して構いません。


P1-2: cache と freshness 機構が、価値より誤承認リスクを増やしています

invocation_id は body_sha256 + prompt_version + requested_model から決定論的に作られるため、別セッションでも同じディレクトリを共有します。既存 result の cache 判定は、body hash、prompt version、model の一致だけを見ており、次を確認しません。

  • artifact_valid
  • input_binding_valid
  • freshness_valid
  • schema validity
  • issue number
  • 完全な state consistency

さらに record-result --current-body-sha256 は任意で、省略すると freshness_valid=True になります。

このレーンは explicit signal があるときだけ実行されるため、cache の便益は限定的です。個人開発では cache を堅牢化するための lock、session nonce、atomic CAS を増やすより、v1 では cache を削除して毎回 fresh review にする方が品質と保守性の両方で優れます。

併せて current_body_sha256 を production 手順では必須にしてください。


P1-3: trigger は classifier だけで、信頼できる signal producer がありません

reference の実行例は次の形です。

--input-json '{"checker_gap_count": 0, "heuristic_concern_count": 0, ...}'

... を含むため、そのままでは JSON として実行できません。また、どの existing artifact のどの field から、次を生成するかが定義されていません。

  • checker_gap_count
  • heuristic_concern_count
  • cross_contract_change
  • owner_decision_conflict
  • severity_tagged_anchor_findings

classifier 自体にも型 coercion の問題があります。

bool("false")  # True

したがって、JSON に文字列 "false" が入ると signal が true になります。negative count も受理されます。

修正案

新しい ledger や provenance system は不要です。build_semantic_review_trigger_input() の pure function を一つ追加し、既存の trusted artifact からだけ入力を生成します。

各 field は strict type にしてください。

bool field → JSON boolean のみ
count      → integer >= 0
findings   → list
unknown key → reject

より単純化するなら、v1 は以下だけでも十分です。

user_requested
semantic_rewrite_requested
schema_change
protocol_change
orchestration_change
severity-tagged anchor

曖昧な heuristic_concern_count は、実 consumer ができるまで削って構いません。


P1-4: P0-1 見出しが scope directive として扱われ、Acceptance Criteria を勝手に変更し得ます

PR は severity-tagged heading を generic な extract_directive_markers() に追加しています。しかしこの marker は semantic trigger 専用ではなく、既存の scope directive 判定と contract patch 生成にも使われます。

公開コードと同じロジックで次を評価しました。

## P0-1

- architecture の責務分離を見直す

結果は次です。

directive_markers:
  - P0-1
directive_confidence: explicit
contract_patch_operations:
  - section: Acceptance Criteria
    op: append
    text: architecture の責務分離を見直す

未知 marker が fallback で revised acceptance criteria に分類されるためです。つまり、単なる重大度ラベルが scope-authoritative directive に昇格します。

これはセキュリティ問題ではなく、ハーネスが本来の Issue refinement を歪める実用上の欠陥です。

修正案

次を分離してください。

extract_directive_markers()
extract_severity_tags()

同じ regex helper を共有しても構いませんが、返す型と consumer は分けます。

回帰テストは明確です。

P0見出し + bullet
  → semantic trigger: true
  → directive confidence: inferred または markerなし
  → contract patch operation: 生成しない

P1-5: best-effort retry の契約が joiner に実装されていません

reference は transport failure 時に「一度だけ自動再実行し、それでも不能なら approve + warning」としています。ところが joiner は retry_already_attempted=false でも即座に approve します。boolean は warning 文字列へ埋め込むだけで、制御には使われていません。

個人開発向けの方針として、transport failure を merge blocker にする必要はありません。ただし次の順序は守るべきです。

first failure
  → retry

second failure
  → approve
  → terminal reportに SEMANTIC_REVIEW_UNAVAILABLE を残す

warning が中間 JSON にしか残らず、最終レポートで消える設計は避けてください。


非blockingだが修正した方がよい点

「read-only」は技術的保証ではありません

Agent は Edit/Write を持ちませんが Bash を持つため、ファイル更新や gh mutation は技術的には可能です。

ただし、この用途で Bash command filter や PreToolUse hook を追加する必要はありません。ワークフローを重くするだけです。Safety Claim Matrix を次の表現へ弱めれば十分です。

Edit/Write tool を持たない read-only intent の reviewer。Bash の非mutation利用は procedural contract。

テスト件数表記が不一致です

PR 本文は transport test 14件、途中コメントは 13件としています。既存 self-review もこれを warning として認識しています。実装品質への影響は小さいですが、PR 本文は head に合わせて直すべきです。


推奨する簡素な production フロー

この PR の目的には、cache・疑似foreground証跡・手動 artifact mutation より、次の直線的なフローが適しています。

deterministic approve
        │
        ▼
unique invocation dirを作る
        │
        ├── body.md
        └── bundle.json
        │
        ▼
issue-design-reviewerを起動
foreground/backgroundは問わない
完了結果を待つ
        │
        ▼
strict JSON parse
+ JSON Schema validation
+ clear/findings相関検証
        │
        ├── clear
        │     └── approve
        │
        ├── medium/low only
        │     └── approve + terminal warning
        │
        ├── blocker/high
        │     └── rewrite_lane=semantic
        │         + findingsをissue-editorへforward
        │
        └── transport/schema failure
              └── retry once
                    └── 再失敗ならapprove
                        + SEMANTIC_REVIEW_UNAVAILABLE

残すべきもの

  • body SHA binding
  • strict JSON / JSON Schema validation
  • Agent completion join barrier
  • blocker/high の semantic rewrite forwarding
  • 一度だけの retry
  • final report への warning

削るべきもの

  • cross-session result cache
  • .pending の疑似証跡
  • mtime による genuine Agent 証明
  • foreground そのものの強制
  • model artifact への手作業 disposition 追記
  • severity tag と scope directive の共用
  • live Claude 呼び出しを Required CI にすること
  • cryptographic owner authentication
  • Bash mutation を止めるための追加ハーネス

マージ前に必要なテスト

最低限、次の回帰が必要です。

  1. pin-bundle 後に body.md が存在し、bundle の hash と一致する。
  2. clear + blocker finding は reject される。
  3. findings + [] と未知 assessment は reject される。
  4. recorded_by: owner がない disposition は blocker/high を無効化しない。
  5. transport error + retry=false は approve せず retry route へ進む。
  6. P0-1 見出しだけでは scope directive / AC patch が生成されない。
  7. high finding から rewrite_lane: semantic と同一 finding が issue-editor に届く。
  8. rewrite 後の再reviewで finding が消えるか、2回無進展なら human judgment へ進む。

加えて Required CI ではなく、マージ前の手動 smoke として、#2273 型の意図的な矛盾 fixtureを一度 genuine Claude Code Agent へ渡すべきです。

VCでは local/cloud/both
schemaでは local/cloud のみ

期待結果は次です。

deterministic approve
→ semantic trigger
→ high finding
→ semantic rewrite
→ fresh review clear

最終評価

#428 との統合を見送った判断、deterministic と semantic の責務分離、semantic rewrite を既存 fail-closed repair と別契約にした判断は妥当です。#428 側にも partial overlap が記録されており、ここを無理に統合する必要はありません。

ただし現在の APPROVE は、追加されたファイルとテストが契約上存在することを確認したものであり、semantic reviewer が正しい本文を読み、その finding が rewrite まで確実に届くことを確認したものではありません。

verdict: REQUEST_CHANGES
draft_should_remain: true
blocking:
  - pinned body is not delivered to the reviewer
  - Agent execution contract does not match Claude Code behavior
  - contradictory or unknown semantic states approve
  - semantic findings are not canonically forwarded to semantic rewrite
required_before_ready:
  - body binding
  - schema and invariant validation
  - explicit semantic rewrite payload
  - completion join barrier
  - severity/directive parser separation
recommended_simplification:
  - remove cache and pseudo-foreground evidence

現状のままでは、#2296 が解決しようとした「機械チェックは通るが意味的に壊れた Issue」を、別形式で再生産します。

…ic design review lane に反映する (#2296)

PR #2305 への OWNER adversarial review (P0-1〜P0-4, P1-1〜P1-5) を全件解消する。

- P0-1: pin_bundle() が body.md を invocation dir に書き出し、bundle.json に
  body_file/body_sha256/prompt_version を記録するようにした。
  issue-design-reviewer.md にタスクプロンプトの正本を明記した。
- P0-2: model: sonnet / effort: high を issue-design-reviewer.md frontmatter に
  追加。foreground 保証・mtime を genuine execution の証明とする記述を全て
  削除し、completion join barrier / 弱いヒューリスティックへ言い換えた。
- P0-3: join_review_results.py を findings 優先の total function へ全面書き換え。
  schemas/semantic_review_result_v1.schema.json に assessment<->findings の
  相関 if/then 制約を追加し、semantic_review_transport.py が jsonschema で
  artifact を検証するようにした。
- P0-4: needs-fix が semantic finding 由来の場合、join_review_results.py が
  rewrite_lane: semantic + semantic_rewrite_constraints を返すようにし、
  issue-editor.md の契約に source_artifact/checked_body_sha256 を追加した。
- P1-1: owner_disposition は recorded_by=owner かつ reason 非空文字列を
  必須にした。
- P1-2: pin_bundle() のクロス invocation キャッシュを撤去し、
  record_result() の current_body_sha256 を必須引数にした。
- P1-3: semantic_review_trigger.py の bool/int 入力を strict 化し
  (bool("false") 誤判定を修正)、build_semantic_review_trigger_input() を
  追加した。
- P1-4: extract_severity_tags() を extract_directive_markers() から分離し、
  bare な severity heading が scope-authoritative directive として誤分類
  されないようにした。
- P1-5: transport failure 時、best_effort policy の一回目失敗は
  effective_verdict: retry を返すようにし、二回目失敗後のみ
  semantic_review_unavailable: true + SEMANTIC_REVIEW_UNAVAILABLE 警告で
  approve する。

回帰テストを test_semantic_review_transport.py / test_join_review_results.py /
test_semantic_review_trigger.py / test_scope_signal_delta.py に追加し、
decide_next_loop_action.py は無変更のまま維持した。

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

Copy link
Copy Markdown
Owner Author

OWNER adversarial review (iteration 6, #2305 (comment)) の P0-1〜P0-4 / P1-1〜P1-5 を全件解消し head 9c2d08dcb46cd6dbf9eb8bfb0d283494fa32ba07 へ push した。詳細は Issue #2296 のコメント(#2296 (comment) )を参照。

@squne121

Copy link
Copy Markdown
Owner Author

LOOP_VERDICT(impl-review-loop, 最終確定)

Mergeability: mergeable=MERGEABLE, merge_state_status=CLEAN(Draft PR。人間のReady化・マージ判断待ち)
Evidence Check: Issue #2296 の全 AC(AC1–AC10)を独立検証。Owner による2ラウンドの敵対的レビュー(P0-1〜P0-4, P1-1〜P1-5)を全て解消し、AC8 の Runtime Verification(genuine smoke)も実際の Claude Code Agent 起動で実施・証跡投稿済み。Issue契約・PR本文の内部矛盾も全て解消。Required CI 全green(環境要因のflaky failureは無関係ファイルで発生・当PR変更とは無関係と確認済み)。
Blockers: なし

verdict: APPROVE
reviewed_head_sha: "9c2d08dcb46cd6dbf9eb8bfb0d283494fa32ba07"
blockers: []
warnings:
  - "CI再実行中に無関係ファイル(test_isolated_anchor_single_authority.py)でGitHub APIレート制限によるflakeを観測したが、当PRの変更対象外であり現head では green。"

impl-review-loop 完了

Issue #2296 / PR #2305 の実装・検証・レビューループを完了。IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready として終了する。PR は人間のマージ判断待ち。

@squne121
squne121 marked this pull request as ready for review August 22, 2026 18:04
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 に Step 2.5 semantic design review lane を追加する

1 participant