Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1154"
goal_ref: "agent-skill-runtime-hook-relaxation"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: AI agent の skill 実行経路を、security hook を無効化せずに通せるようにする。
- Desired Destination:
issue-refinement-loopの producer / publisher 契約が、root allow 設計とは独立に fail-closed で動作し、schema mismatch や output budget 違反時に termination report 直接投稿へ逸脱しない状態。
Current Validated Scope
.claude/skills/issue-refinement-loop/scripts/配下の producer / publisher 契約のうち、output_budget_violation、schema_mismatch、termination_bypassに関わる fail-closed 動作だけを対象にするrun_refinement_preflight.py/compact_review_result.py/compact_author_result.py/publish_termination_report.py周辺の異常時 routing を検証し、termination report 直接投稿へ進まない契約を固定する- 対応テストは
.claude/skills/issue-refinement-loop/scripts/tests/に閉じる
Remaining Parent Gaps
preflight.run以外の skill runtime command の root allow 拡張publish_termination_report.pyの mutation-capable root allow policy- registry の追加 command ID を privileged set に広げる設計
Outcome
issue-refinement-loop の producer / publisher 系が schema mismatch、output budget violation、termination bypass 試行時に fail-closed で停止し、artifact path と reason を返しつつ direct termination report 投稿へ進まないことをテスト付きで保証した状態。
In Scope
- output budget 契約の機械可読 field 保持と raw dump 抑止
- schema mismatch 時の
environment_failure/human_judgment_requiredrouting 固定 - termination report 直接投稿バイパスの防止
- 上記の fixture / pytest 追加
- 必要最小限の docs 更新
Out of Scope
- root allow policy や privileged executor の導入
publish_termination_report.py自体を root から許可する設計preflight.run以外の runtime command 拡張- guard / settings の exact command class 実装
Acceptance Criteria
- AC1: producer / compact producer の全異常系は、canonical failure envelope を stdout に出す。 必須 fields: STATUS, NEXT_ACTION, REASON_CODE, ARTIFACT, ARTIFACT_SHA256。 stdout は 2048 UTF-8 bytes 以下。raw issue body / raw comment / raw diff / raw renderer body は stdout に出さない。
- AC2: schema mismatch は script ごとの fixture matrix で検証する。 run_refinement_preflight.py / compact_review_result.py / compact_author_result.py の各 failure path が environment_failure または human_judgment_required に routing され、failure artifact を残す。
- AC3: output budget violation は REASON_CODE=output_budget_violation で fail-closed し、 original output は stdout に出さず sha256 / byte_count / bounded preview を artifact にだけ保存する。
- AC4: termination_bypass_denied の negative test を持つ。 producer failure / compact schema mismatch / output budget violation のいずれでも publish_termination_report.py、publish()、_post_github_comment() は呼ばれない。
- AC5: 実装: issue-refinement-loop producer の fail-closed routing を固定する #1165 は root allow / privileged executor / termination_report.publish policy を実装しない。 docs に 実装: hooks: preflight.run 専用 privileged executor を root checkout から安全実行可能にする #1154 / 実装: issue-refinement-loop producer の fail-closed routing を固定する #1165 / 実装: hooks: publish_termination_report 用 controlled mutation policy を分離する #1166 の責務分割を明記する。
- AC6: compact_author_result.py は ISSUE_AUTHOR_RESULT_V1 の schema validation を追加するか、 schema-less consumer として検査対象フィールド・拒否条件を明文化し、fixture で固定する。
- AC7: artifact path は production invocation で .claude/artifacts/issue-refinement-loop// 以下に固定する。 --artifact-dir 自由指定や --repo-root 省略は canonical path として扱わない。
- AC8: 標準ゲート pnpm typecheck / lint / test / build が PASS。
Verification Commands
# baseline-expect: fail
# AC1
# AC2
$ rg -n "def test_review_compact_schema_mismatch_emits_failure_artifact" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC3
$ rg -n "def test_review_compact_output_budget_violation_is_machine_readable" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC2
# AC6
$ rg -n "def test_author_compact_schema_mismatch_emits_failure_artifact" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC2
$ rg -n "def test_preflight_planner_fail_closed_payload_invalid_routes_environment_failure" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC4
$ rg -n "def test_producer_failure_never_invokes_publish_termination_report" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC4
$ rg -n "def test_termination_bypass_fixture_call_count_zero" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC1
$ rg -n "def test_failure_stdout_never_contains_raw_issue_body_or_comment" .claude/skills/issue-refinement-loop/scripts/tests/
# baseline-expect: fail
# AC5
$ rg -n "1154.*1165.*1166" docs/dev/agent-skill-boundaries.md
# baseline-expect: fail
# AC7
$ rg -n "artifacts/issue-refinement-loop" .claude/skills/issue-refinement-loop/scripts/tests/
# AC8
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
.claude/skills/issue-refinement-loop/scripts/docs/dev/agent-skill-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- root allow policy の変更まで同一 PR に含めないと成立しないと判明した場合
Required Skills
- Python 3
- pytest
Scope Delta(任意)
N/A
Runtime Verification Applicability
本 Issue の変更対象はワークフロー文書・スクリプトのみです。ゲームの実行時動作には影響しません。
decision: not_applicable
reason: "Workflow documentation and script changes only. No runtime game behavior changed."Delivery Rule
1 Issue = 1 PR。worktree: worktree-issue-{N}-producer-fail-closed-routing。Draft PR で起票。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 26, 2026
判定
REQUEST_CHANGES。#1165 の目的は妥当ですが、現行 contract のまま実装すると “fail-closed routing” が hollow test になりやすいです。
確認した範囲では、#1165 自体にコメントはなく、実質的な判断材料は parent #1154、#1154 のレビューコメント、#1137 / PR #1139 / PR #1143 の guard 境界議論、sibling #1166 の
publish_termination_report.pymutation policy 分離です。#1165 は「producer / publisher の異常系を fail-closed に固定する」Issue であり、root allow・privileged executor・publish_termination_report.pyの controlled mutation policy は明示的に out of scope です。P0-1: compact producer の失敗経路が “artifact path + reason” 契約を満たしていない
#1165 の Outcome は、schema mismatch / output budget violation / termination bypass 試行時に fail-closed で停止し、artifact path と reason を返す状態を求めています。ところが現行
compact_review_result.pyは JSON parse error・schema/value error・stdout 2048 bytes 超過時にSTATUS: failedと stderr エラーだけを出して exit 2 し、NEXT_ACTION、REASON_CODE、ARTIFACTを返しません。同じ問題は
compact_author_result.pyにもあります。JSON parse error、input read error、conversionValueError、stdout budget violation のいずれも、失敗 artifact を生成せず、機械可読のNEXT_ACTION/ reason / artifact path を返しません。必須修正: #1165 の AC は「エラー時にも必ず canonical failure envelope を出す」と明記すべきです。最低限、以下の stdout を producer 共通 contract にしてください。
さらに、failure artifact には raw body/comment をそのまま出さず、
producer_id、reason_code、input_sha256、stderr_sha256、redaction_applied、publisher_allowed: falseを入れるべきです。P0-2:
termination_bypassの境界が #1166 と混線している#1165 は
publish_termination_report.pyの root allow policy を out of scope にしています。一方、対象ファイルにはpublish_termination_report.pyが含まれており、AC3 は「termination report 直接投稿へ進まない契約」を固定するとしています。これはそのままだと、publisher の controlled mutation policy まで #1165 で直したくなる危険な境界です。現行 publisher は
publishable=trueの renderer result を受けると_post_github_comment()を呼び、内部でgh issue comment <issue> --body-file -を実行しますが、--repoを渡していません。GitHub CLI のgh issue commentは--body-file -で stdin を本文にでき、親 option として--repo <OWNER/REPO>を持ちます。したがって remote mutation として扱うなら repo binding は必須です。 ([GitHub CLI]1) (GitHub CLI)この問題は #1166 が正しく切り出しています。#1166 は
termination_report.publishを別 policy / 別 executor / repo・issue・artifact・env・idempotency binding 付きの controlled remote mutation として扱い、direct script allow を deny する設計です。#1165 側でやるべきことは、publisher を安全に root allow することではなく、producer 異常系から publisher が呼ばれないことを fixture で証明することです。必須修正: #1165 の AC3 は次に差し替えるべきです。
P0-3:
run_refinement_preflight.pyは一部良いが、全失敗経路で artifact を保証していないrun_refinement_preflight.pyは canonical stdout fields を明示し、raw issue body/comments を stdout に出さない設計になっています。これは #1165 の AC1 方向に合っています。また、planner fail-closed payload の rewrite constraints が非 string・非 JSON serializable・invariant mismatch の場合に
planner_fail_closed_payload_invalid等を足し、_apply_exit_code_mapping()側で environment failure に倒す経路もあります。この設計は PR #1071 の reason semantics / consumer rewrite budget 修正と整合しています。ただし、fixture input schema invalid などの early failure は
_emit_failure_result()にraw_snapshot/planner_inputが渡らず、artifact を書けない経路があります。#1165 の Outcome が「artifact path と reason」を要求するなら、early failure 用の minimal failure artifact を必須にする必要があります。必須修正:
run_refinement_preflight.pyも compact scripts も、失敗時 artifact writer を共通化してください。raw_snapshotが存在しない場合でも、少なくともproducer_id、phase、reason_code、exit_code、input_origin、input_sha256、raw_payload_stored: falseを持つ failure artifact を書くべきです。P0-4:
compact_author_result.pyは schema mismatch を十分に検出していないcompact_review_result.pyは review result schema を読み、jsonschema.validate()を呼んでいます。一方、
compact_author_result.pyは status と body hash を中心に見ており、ISSUE_AUTHOR_RESULT_V1の producer schema 全体を validate していません。つまり、status=okとchecked_body_sha256だけがある不完全 payload が、意図せず通る可能性があります。必須修正: #1165 の schema mismatch fixture matrix に、最低限この 2 系統を入れてください。
compact_author_result.pyには author result schema validation を追加するか、意図的に schema-less consumer にするなら、その理由と検査対象フィールドを Issue contract に固定する必要があります。P0-5: output budget violation の検査対象が stdout だけでは足りない
現行 compact scripts は stdout 2048 bytes 超過を検出しますが、超過時に artifact を残さず、
STATUS: failedだけを出します。これは「budget violation で fail-closed」とは言えても、orchestrator が次の route を機械判定できません。必須修正: output budget violation は、次の仕様で固定すべきです。
Claude Code hooks は hook output に長さ上限があり、上限超過時はファイル保存と preview/path 置換になるため、producer 側でも「出しすぎた後に runtime が処理してくれる」前提にしない方がよいです。([Claude Platform Docs]2)
P1-1: artifact containment は root allow とは別に、handoff artifact として最低限固定すべき
#1154 のレビューは、
mutation:falseや registry metadata を認可根拠にせず、effect/path binding を持つ単一 executor に寄せるべきだと指摘しています。特にcompact_review_result.pyは--repo-rootが optional で、--artifact-dirが自由指定できる点が既にリスクとして挙げられています。現行
compact_review_result.py/compact_author_result.pyはrepo_rootが渡された場合だけPath.resolve().is_relative_to(base)で containment を確認します。CLI では--artifact-dirが任意で、--repo-rootは optional です。Python の
Path.resolve()は symlink と..を解決できますが、PurePath.is_relative_to()は文字列ベースで filesystem にアクセスせず、..も特別扱いしません。したがって privileged path policy では、単なる lexical containment ではなく、realpath / symlink component / regular file / owner-mode / size を明示的に扱う必要があります。([Python documentation]3) ([Python documentation]3)#1165 での落としどころ: root-level hardening は #1154 / #1166 に残してよいです。ただし #1165 の producer failure artifact は、少なくとも production path では
.claude/artifacts/issue-refinement-loop/<issue>/...に固定し、test でも--repo-rootなしの任意--artifact-dir成功を canonical path として扱わないでください。P1-2: docs AC5 は弱い。責務境界を明文化しないと再発する
docs/dev/agent-skill-boundaries.mdは Agent / Skill 責務境界の SSOT とされています。現行 docs にはissue-refinement-loopが thin orchestrator で、raw context を保持・再解釈しないという責務境界がありますが、#1154 / #1165 / #1166 の三分割はまだ十分に固定されていません。必須修正: docs には次の責務分割を明記してください。
Codex の PreToolUse hooks は Bash / apply_patch / MCP tool calls を intercept できますが、別 tool path で同等作業ができるため完全な enforcement boundary ではない、と公式 docs が明記しています。Claude Code でも Bash hook
iffilter は best-effort で、hard allow/deny には permission system を使うべきとされています。docs では「supported Bash PreToolUse path の guardrail」であって sandbox ではない、と書くべきです。([OpenAI 開発者]4) ([Claude Platform Docs]2)P1-3: テストが
rgexistence check に寄ると hollow になる#1165 の Verification Commands は
rgによる存在確認が中心です。これは baseline check としては有用ですが、#1139 / #1143 の経緯を見ると、関数直接呼び出しや存在確認だけでは実行経路の欠陥を隠します。PR #1139 の OWNER review では、preflight / materialize が実 hook route では deny されるのに、テストが関数直接呼び出しで隠していたことが blocker になりました。#1165 では hook route を直接扱わないにしても、最低限 behavioral fixture にしてください。
修正版 Acceptance Criteria 案
現行 AC1〜AC6 は抽象度が高すぎます。次のように落とすべきです。
実装品質メモ
subprocess.run()は args sequence で渡す方が推奨され、shell=Trueは shell を介します。また POSIX では executable resolution が cwd / env / PATH に影響され得るため、privileged 経路ではsys.executableや canonical path、明示 env を使う方が安全です。#1165 の producer tests でも、shell string の逆照合ではなく argv / call count / artifact content を検証してください。([Python documentation]5)shlexは shell-like syntax の lexical analyzer であり、quote()も非 POSIX shell では正しさが保証されないため、authorization boundary として使うべきではありません。#1154 で問題になった registry reverse matching や newline bypass の再導入を避けるには、producer failure routing のテストも「文字列に含まれるか」ではなく、実際に publisher 関数が呼ばれないことを検証してください。([Python documentation]6) ([Python documentation]6)最終結論
#1165 は必要です。ただし現行 contract は、実装者が「エラー時に
STATUS: failedを出すだけ」「rgでテスト名だけ置く」「publisher を触らずに termination bypass を名目だけ固定する」実装でも通ってしまう余地があります。着手前に、failure envelope、artifact guarantee、publisher non-invocation、#1154/#1165/#1166 の責務分割を AC に明記してください。
その修正後であれば、#1165 は root allow とは独立した producer fail-closed hardening Issue として成立します。
squne121 commentedon Jun 26, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 26, 2026
CONTRACT_REVIEW_RESULT_V1
status: go
source: all_checks_pass
issued_at: 2026-06-27
VC Preflight Summary
rg -n "def test_review_compact_schema_mismatch_emits_failure_artifact"rg -n "def test_review_compact_output_budget_violation_is_machine_readable"rg -n "def test_author_compact_schema_mismatch_emits_failure_artifact"rg -n "def test_preflight_planner_fail_closed_payload_invalid_routes_environment_failure"rg -n "def test_producer_failure_never_invokes_publish_termination_report"rg -n "def test_termination_bypass_fixture_call_count_zero"rg -n "def test_failure_stdout_never_contains_raw_issue_body_or_comment"rg -n "1154.*1165.*1166" docs/dev/agent-skill-boundaries.mdrg -n "artifacts/issue-refinement-loop"pnpm typecheckpnpm lintpnpm testpnpm buildChecks
Result: この Issue は実装着手可能です。
squne121 commentedon Jun 26, 2026
Contract Review Result
docs(agent-skill-boundaries): document issue-refinement-loop producer…
squne121 commentedon Jun 26, 2026
IMPLEMENT_RESULT_V1:
status: ok
pr_url: #1194
pr_number: 1194
head_sha: fb6682f
branch: worktree-issue-1165-issue-refinement-loop-producer-fail-clos
issue_number: 1165
allowed_paths_compliance: true
verification_summary:
- "11 新規 pytest PASS (test_producer_fail_closed.py — AC1-AC7)"
- "34 skill pytest PASS (既存 23 + 新規 11)"
- "pnpm typecheck: PASS"
- "pnpm lint: PASS"
- "pnpm test: 1123 PASS"
- "pnpm build: PASS"
- "test_model_routing.py: 21 PASS"
key_implementation_notes:
- "jsonschema.ValidationError は jsonschema 4.x では ValueError サブクラスでないため except (ValueError, Exception) で補足"
- "compact_review_result.py / compact_author_result.py に _write_failure_artifact() + _emit_failure_envelope() 追加"
- "compact_author_result.py に ISSUE_AUTHOR_RESULT_V1_SCHEMA_LESS_CONTRACT 定数追加 (AC6)"
- "docs/dev/agent-skill-boundaries.md に #1154/#1165/#1166 責務分割テーブル追加 (AC5)"
fix(issue-refinement-loop): apply OWNER iter1 P0 fixes for PR #1194
fix(issue-refinement-loop): add fail-closed routing to compact produc…
fix: python-test-plan.json に scripts/trust-root/tests/ を登録する (#1454)
feat: publish lane authorization の external trust root を確立する (#1457)