Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#816"
goal_ref: "impl-review-loop 系の決定論的 gate 自動化と compact verdict 化により token/context 浪費を削減する"
change_kind: workflowRuntime Verification Applicability
decision: not_applicable
reason: "script 単体テスト(uv run pytest)で完結する。runtime UI / simulation 動作確認は不要"Parent Issue
Parent Goal Ref
- Goal: impl-review-loop 実行 1 回あたりの「人間
Y介入」「失敗コマンド再実行」「raw ログの main context 流入」を決定論的 script で排除する - Desired Destination: contract review 自動 materialize / CI verdict compactor / PR body repair planner / scope rollup self-validating 化 / hook identity 修正 / progressive disclosure / rtk shadow guard が repo に反映された状態(parent 導入: impl-review-loop 系の決定論的 gate 自動化と compact verdict 化による token/context 浪費削減 #816 のスコープ)
Current Validated Scope
plan_issue_scope_rollup.pyの出力にself_validationブロックを追加する(invocation_id/script_file_sha256/payload_sha256/schema_name/schema_version/hash_algorithm/canonicalization)payload_sha256はself_validationブロックを除外した canonical payload bytes の sha256 とする(自己参照を回避)- JSON 正規化方式:
json.dumps(payload_without_self_validation, ensure_ascii=False, sort_keys=True, separators=(",", ":"))の UTF-8 bytes(project-local 方式、RFC 8785 は採用しない) script_file_sha256はsha256(file-bytes)であり、Git blob hash ではないinvocation_idはuuid.uuid4()で script 内生成。--invocation-idoptional flag を追加し、未指定時のみ生成する(既存 runner の temp file naming contract を維持する).claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.pyを追加し、main thread / control-plane が 1 コマンドで result の完全性検証(sha 照合・schema 照合)を行えるようにするscope-rollup-runner.mdの検証手順を verify script 1 回の実行に置き換える(sha256sum/awk/$$依存を除去する)skipped_reasonの重複出力(実装: 戦闘中の debug pause/resume surface を追加する #786 ログで確認)の修正(duplicate key 検出 fixture または raw serialized output の key count テスト)
Remaining Parent Gaps
- scope rollup の判定ロジック(collision 判定基準)自体は変更しない
- impl-review-loop preparation 全体の見直しは parent 導入: impl-review-loop 系の決定論的 gate 自動化と compact verdict 化による token/context 浪費削減 #816 の contract 自動化 child で扱う
Hash Specification
Hash target for payload_sha256:
canonical = json.dumps(
{k: v for k, v in plan.items() if k != "self_validation"},
ensure_ascii=False,
sort_keys=True,
separators=(",", ":")
).encode("utf-8")
payload_sha256 = hashlib.sha256(canonical).hexdigest()
Hash target for script_file_sha256:
script_file_sha256 = hashlib.sha256(Path("plan_issue_scope_rollup.py").read_bytes()).hexdigest()
(sha256 of raw file bytes — NOT a Git blob hash)
Canonicalization: project-local (not RFC 8785)
Schema Layer Separation
# plan JSON (plan_issue_scope_rollup.py が生成)
schema_name: "ISSUE_SCOPE_ROLLUP_PLAN_V2"
schema_version: 2
self_validation:
invocation_id: "<uuid4>"
payload_sha256: "<sha256>"
script_file_sha256: "<sha256>"
hash_algorithm: "sha256"
canonicalization: "python-json-dumps-sort-keys-compact-utf8"
# runner marker (scope-rollup-runner が生成)
# ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1.schema_version: 1 は変更しない
# runner marker は plan layer の schema を別フィールドで参照する
result:
plan_schema_name: "ISSUE_SCOPE_ROLLUP_PLAN_V2"
plan_schema_version: 2
raw_plan_sha256: "<sha256 of plan JSON file bytes>"Exit Code Separation
plan_issue_scope_rollup.py (business result):
exit 0: success
exit 2: partial (current_issue not found)
verify_scope_rollup_result.py (integrity check):
exit 0: verified
exit 10: sha_mismatch
exit 20: schema_mismatch
exit 30: invalid_input (missing file / invalid JSON / duplicate key / non-object JSON)
verify script は plan_exit_code と verification_status を別フィールドで返す。
plan_exit_code=2 (partial) でも JSON の schema / hash が正しければ exit 0 verified を返す。
error priority: invalid_input > schema_mismatch > sha_mismatch > verified
verify_scope_rollup_result.py Stdout Contract
STATUS: verified|sha_mismatch|schema_mismatch|invalid_input
SUMMARY: <1 line>
RESULT_PATH: <path>
PAYLOAD_SHA256: <actual>
EXPECTED_PAYLOAD_SHA256: <expected>
SCRIPT_FILE_SHA256: <actual>
EXPECTED_SCRIPT_FILE_SHA256: <expected>
raw plan JSON を stdout に出力してはならない
Outcome
plan_issue_scope_rollup.py の self-validating 出力(self_validation ブロック)と verify_scope_rollup_result.py、対応する unit test、scope-rollup-runner.md の手順更新が 1 PR で追加され、scope rollup preflight の full verification が deferred にならず 1 コマンドで完結する状態。
In Scope
plan_issue_scope_rollup.pyの出力にself_validationブロックを追加する--invocation-idoptional CLI flag を追加し、未指定時はuuid.uuid4()で生成する- 既存 marker schema(
ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1)との後方互換を維持する(既存キーの削除・改名は行わない) - runner marker に
plan_schema_name/plan_schema_versionフィールドを追加する verify_scope_rollup_result.pyの実装(入力:--result-json <path>、exit code:0/10/20/30、stdout: fixed compact lines のみ)skipped_reasonの重複出力修正と duplicate key 検出テスト- 上記の unit test 追加
scope-rollup-runner.mdの検証手順更新(sha256sum/awk/$$を除去しverify_scope_rollup_result.py呼び出しに置き換える)
Out of Scope
- scope rollup の collision 判定基準・scope_context 仕様の変更(実装: scope collision 判定を構造化コンテキストで汎用化し、単語一致による誤エスカレーションを抑止する #550 で確定済みの設計を維持する)
- security gate の追加(設計: scope rollup から security escalation を分離した専用 security-risk gate skill を検討する #558 で扱う)
- impl-review-loop preparation の missing_contract_go 分岐変更(parent 導入: impl-review-loop 系の決定論的 gate 自動化と compact verdict 化による token/context 浪費削減 #816 の別 child)
- RFC 8785 採用
- Git blob hash の使用
Acceptance Criteria
- AC1:
plan_issue_scope_rollup.pyの出力にself_validation.payload_sha256の生成処理が存在する - AC2:
self_validation.payload_sha256はself_validationブロックを除外した canonical payload bytes の sha256 である(同一 logical payload から byte-stable な値が得られる) - AC3:
self_validation.script_file_sha256はsha256(file-bytes)として生成される(Git blob hash ではない) - AC4:
self_validation.invocation_idが uuid4 形式で生成される(--invocation-id未指定時) - AC5:
.claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.pyが存在する - AC6: valid な result JSON を渡すと exit 0
STATUS: verifiedを返す - AC7: result JSON の任意 field を改ざんすると exit 10
STATUS: sha_mismatchを返す - AC8:
schema_name/schema_version不一致は exit 20STATUS: schema_mismatchを返す - AC9: missing file / invalid JSON / duplicate key / non-object JSON は exit 30
STATUS: invalid_inputを返す - AC10: verify stdout は fixed compact lines のみで raw plan JSON を含まない
- AC11:
scope-rollup-runner.mdからsha256sum/awk/$$による検証手順が消え、verify_scope_rollup_resultへの参照が存在する - AC12: runner marker に
plan_schema_name/plan_schema_versionフィールドが追加され、既存ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1のキーが削除・改名されていない - AC13:
skipped_reasonが serialized output 内で candidate ごとに最大 1 回である - AC14: duplicate JSON keys を reject する fixture または raw key count テストが存在する
Verification Commands
# AC1
$ rg -n "payload_sha256" .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
# AC2
$ rg -n "payload_sha256" .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py
# AC3
$ rg -n "script_file_sha256" .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
# AC4
$ rg -n "invocation_id|uuid" .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
# AC5
$ test -f .claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.py
# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "verified"
# AC7
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "sha_mismatch"
# AC8
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "schema_mismatch"
# AC9
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "invalid_input"
# AC10
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "stdout"
# AC11
$ rg -n "verify_scope_rollup_result" .claude/agents/scope-rollup-runner.md
$ ! rg -n "sha256sum|awk" .claude/agents/scope-rollup-runner.md
# AC12
$ rg -n "plan_schema_name|plan_schema_version" .claude/agents/scope-rollup-runner.md
# AC13
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "skipped_reason"
# AC14
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_verify_scope_rollup_result.py -v -k "duplicate"Allowed Paths
- .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
- .claude/skills/issue-refinement-loop/scripts/verify_scope_rollup_result.py
- .claude/skills/issue-refinement-loop/tests/
- .claude/agents/scope-rollup-runner.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python(hashlib / json / uuid / pathlib)
Scope Delta(任意)
N/A
Delivery Rule
1 Issue = 1 PR、worktree で実装、Draft PR 既定issue-refinement-loop/scripts配下は 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791 系 child(実装: issue-refinement preflight wrapper(run_refinement_preflight.py)を追加し planner 入力契約を固定化する #792〜実装: issue-reviewer / issue-author に compact subagent result contract を導入し raw 出力の main 還流を止める #794)と同一ディレクトリのため、OPEN な該当 PR とのマージ順を contract review 時に確認し、必要なら直列化する
Notes for Reviewer
payload_sha256はself_validationブロック全体を除外した canonical payload の hash であり、最終 JSON bytes の hash ではない(固定点問題を回避)script_file_sha256は Git blob hash ではなく raw file bytes の sha256 である- JSON 正規化は
sort_keys=True, separators=(",", ":")の project-local 方式(RFC 8785 不採用) invocation_idは--invocation-idoptional flag で override 可能。runner は引き続きこの値を temp file 名に使える- plan exit code(業務結果)と verify exit code(完全性検証)は独立しており、
plan_exit_code=2でも hash / schema が正しければ verify はexit 0 verified
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 13, 2026
判定: REQUEST_CHANGES
#820 は必要な Issue です。親 #816 の「scope rollup の
invocation_id/ hash 検証が shell 依存で full verification できない」問題に正面から対応しています。#820 自体は open で、コメントは現時点でありません。ただし、現状の Issue 契約のまま実装すると、self-validating の中核である
result_sha256が自己参照ハッシュになって検証不能、または runner marker / plan JSON / verify script の schema 境界が曖昧 になります。実装前に本文修正が必要です。確認した関連コンテキスト
#820 は #816 の child で、#816 は
impl-review-loopの gate 自動化・compact verdict 化・token/context waste 削減を目的にしており、その中で #820 は scope rollup result の self-validating 化を担当しています。既存 runner は #625 で導入され、
scope-rollup-runnerが main context に rawgh issue/pr listを返さず marker だけ返す設計です。これは Claude Code 公式ドキュメントの「subagent は別 context で作業し summary だけ返す」という利用パターンにも合っています。 ([Claude API Docs]1)現在の
scope-rollup-runner.mdは、呼び出し元からinvocation_idを必須入力として受け取り、/tmp/scope_rollup_*_<invocation_id>.jsonに一時ファイルを書き、shell 側でsha256sumとawkを使ってSCRIPT_SHA/RESULT_SHAを計算します。一方、現在の
plan_issue_scope_rollup.pyはrun()がschema_version,repo,generated_at,source,body_sha256,input,candidatesを返し、CLI が最後にjson.dumps(..., indent=2)して stdout または--outputに書く構造です。現時点ではinvocation_id/script_blob_sha256/result_sha256は plan JSON 内にありません。ブロッカー
B1.
result_sha256の定義が自己参照になり得る#820 は
plan_issue_scope_rollup.pyがresult_sha256を result 内に自己生成して埋め込む、としています。しかし「最終 JSON ファイル全体の sha256」を JSON 内のresult_sha256に入れる設計だと、result_sha256を入れた瞬間にファイル bytes が変わるため、固定点問題になります。Python のhashlib自体は bytes-like object をupdate()し、hexdigest()で安全に文字列化できますが、何の bytes を hash するかを Issue が定義していません。([Python documentation]2)修正案はどちらかです。
result_sha256はresult_sha256フィールドを除外した canonical payload bytes の sha256 と定義する。result_sha256は runner marker 側の外部ファイル bytes hash として維持し、plan JSON 内にはpayload_sha256/plan_payload_sha256という別名を追加する。推奨は 2 です。既存 runner marker は
result.raw_plan_locationのファイル bytes sha256 と説明しているため、plan 自身に同名のresult_sha256を追加すると語義衝突します。B2. JSON canonicalization 仕様が未定義
#820 は hash verification を強化する Issue なのに、JSON の正規化方法が未定義です。現行コードは pretty JSON
indent=2で出力します。Python
json.dumpsはsort_keys=Trueで辞書キーをソートでき、separators=(',', ':')で whitespace を除去した compact JSON を作れます。これを使うなら「Python canonical JSON」として明記すべきです。RFC 8785 を採用しないなら、その非採用も明記してください。([Python documentation]3) ([Python documentation]3)最低限、Issue に以下を追加してください。
B3.
schema_versionが plan schema と runner marker schema で衝突している現在の plan は
SCHEMA_VERSION = 2でISSUE_SCOPE_ROLLUP_PLAN_V2相当です。一方、runner marker は
ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1としてschema_version: 1を返す契約です。#820 の「
schema_versionを result 内に埋め込む」は、どちらの schema を指すのか曖昧です。verify_scope_rollup_result.pyの exit 20schema_mismatchも、plan schema mismatch なのか runner marker mismatch なのか不明です。修正案:
B4.
invocation_idの責務移動が runner の入力契約を壊す#820 は shell
$$依存を廃止し、invocation_idを script 内生成に寄せる方針です。方向性は妥当です。Python 公式のuuid.uuid4()は暗号論的に安全な方法で random UUID を生成します。([Python documentation]4)ただし既存 runner は
invocation_idを必須入力として受け取り、その値を一時ファイル名に使います。したがって、#820 は次のどちらかを明記すべきです。
run_idを一時ファイル名用に生成し、plan script は別途invocation_idを生成する。plan_issue_scope_rollup.pyに--invocation-idoptional を追加し、未指定時だけuuid.uuid4()を生成する。推奨は後者です。既存 runner contract との互換性を保てます。
B5.
script_blob_sha256という名前が不正確既存 runner は
sha256sum <file>で script のファイル bytes を hash しています。しかし
script_blob_sha256という名前は、Git の blob object hash と誤解されます。Git blob hash は単純なファイル bytes sha256 ではありません。#820 ではscript_blob_sha256を使うなら、少なくともalgorithm: sha256(file-bytes)を明記すべきです。推奨フィールド:
既存 marker 互換のため
script_blob_sha256を残す場合も、alias として扱うべきです。B6. exit code の意味が integrity verification と business result で混ざっている
現在の
plan_issue_scope_rollup.pyはcurrent_issueが見つからない場合に exit 2 を返し、candidates: []の partial result を返す設計です。しかし runner は plan script の exit code 非 0 をすべて
runner_unavailableとして扱う契約です。#820 の verify script は integrity check なので、
plan_exit_codeとverification_statusを分離すべきです。たとえば、plan_exit_code=2でも JSON の schema/hash が正しければ verify はverifiedを返してよい。業務的に続行できるかは別 gate が判断するべきです。追加すべき contract:
{ "verification_status": "verified", "plan_exit_code": 2, "plan_status": "partial", "warnings": ["current_issue_not_found"] }B7.
skipped_reason重複修正の再現条件が不足している#820 は
skipped_reason重複出力を修正対象にしていますが、AC では「どの形式で重複していたのか」が固定されていません。JSON object の重複 key なら Pythonjson.loadsは例外を出さず、最後の値だけを採用します。公式 docs も repeated names は受け入れられ、最後の name-value pair だけが使われると説明しています。([Python documentation]3)つまり、重複 key を検出したいなら
object_pairs_hookを使った strict loader が必要です。単にjson.loadsで fixture を読むだけではskipped_reason重複バグを検出できません。追加 AC:
B8. Verification Commands が #793 の
$prefix 規律と矛盾する#820 の Verification Commands は
rg ...,test -f ...,uv run pytest ...,pnpm testのように$prefix なしで書かれています。#793 / PR #802 では Verification Commands の$prefix 欠落や broad path を検出するcheck_vc_scope.pyが導入されています。#820 は
.claude/skills/issue-refinement-loop/tests/と.claude/agents/scope-rollup-runner.mdを触るので、実装前に自分自身の VC を #793 準拠に直すべきです。修正版:
uv runは project environment を使って command を実行し、実行前に環境を up-to-date にするため、この repo の Python test VC と相性が良いです。([Astral Docs]5)B9.
verify_scope_rollup_result.pyの出力契約が弱い#820 は verify script の exit code だけ定義していますが、stdout contract がありません。#794 では compact stdout / artifact 分離 / raw output 禁止が重要な設計原則になっています。
verify script は raw plan JSON を stdout に出してはいけません。推奨 stdout は固定行のみです。
また、複数 mismatch がある場合の優先順位も固定してください。
修正版 Issue 契約の骨子
#820 は以下のように狭めると実装可能です。
追加すべき Acceptance Criteria
最終コメント案
そのまま Issue に貼るなら、こうです。
squne121 commentedon Jun 13, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 13, 2026
Contract Review Result
squne121 commentedon Jun 13, 2026
implement-issue: 実装完了 (2026-06-13T11:28:00Z)
Verification 結果
標準 4 コマンド
Python テスト
fix(#820): implement real script_file_sha256 verification and restore…
feat: scope rollup result を self-validating 化し verify を 1 コマンドに集約する (#…