Repository navigation
fix: capability-preflight probe ordering, Spark validation, deadline test fidelity (#2401) - #2410
Conversation
…test fidelity (#2401) Bounded follow-up for the merged PR #2394 review findings: - Reorder capability-preflight probes so required GitHub probes (github_auth -> github_repo_read -> controlled_github_read) run before the optional spark_env_only probe, sharing one absolute deadline. - Add a Spark JSON payload validator that normalizes malformed/invalid shapes (non-dict top level, non-bool binary_available, missing/non-dict chatgpt_auth, non-bool chatgpt_auth.available) into the existing structured malformed-output reason instead of risking an uncaught AttributeError. - Add scripts/claude-gpt/tests/test_capability_preflight_review_fixes.py covering probe ordering (AC1), spark-starvation degrade semantics (AC2), malformed Spark payload handling (AC3), the single shared absolute deadline (AC4), and a hermetic real root-to-producer subprocess boundary test faking only the external gh leaf CLI (AC5). - Remove the filename-based timeout-ownership blacklist test (AC6). - Mark the real-subprocess test_workflow_capability_returns_structured_result with @pytest.mark.github_live (optional live coverage, not part of this Issue's hermetic close evidence). - Update the pre-existing shared-deadline probe-order assertion in test_workflow_capability_preflight_deadline.py to the new gh/gh/gh/sh order (required by implementing AC1). Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #2410 closed). |
PR Review VerdictMergeability
Evidence Check
Blockersなし Non-blockers / Warningsなし verdict: APPROVE
reviewed_head_sha: "99926493fb1f46c67db3677d728798c44188dcbd"
blockers: []
warnings: [] |
判定verdict: REQUEST_CHANGES
reviewed_head_sha: "99926493fb1f46c67db3677d728798c44188dcbd"
production_implementation: broadly_sound
blocking_findings:
P0: 0
P1: 1
non_blocking_findings:
P2: 3
merge_condition:
- "AC5で deadline の root→producer transport を実際に観測する"
- "fake CLI trace の証跡を実テストと一致させる"
- "AC2/AC3のテスト説明を実際に通る境界へ合わせる"PR #2410 は現在も Draft・OPEN・mergeable で、対象 head は 本番コードの方向性は正しいです。 P1-1: AC5 は real subprocess を起動しているが、deadline transport を証明していない
既存の 実装上、root は deadline 引数を渡し、producer parser もそれを さらに、PR 本文の AC5 証跡には事実と異なる説明があります。
実際の producer は root repo probe として、 ["gh", "repo", "view", repo, "--json", "name"]を実行します。ところが fake fixture が厳密に検査しているのは別形式の、 です。現在の 最小修正新しい共通ハーネスや production 変更は不要です。AC5 テスト内だけで次を行えば十分です。
これで、「root が引数を作る」「子プロセスへ渡る」「producer parser が使用する」「leaf CLI は fake だけ」という連鎖を、重い基盤なしで固定できます。 P2-1: AC2 テストは「Spark timeout」ではなく「Spark 起動前の deadline exhaustion」を試しているPR #2394 の元 finding は、optional Spark probe が実際に開始され、その timeout によって残り共有予算を使い切るケースでした。Python の 現在の新テストは、三つの GitHub probe が fake clock を です。これは有用な no-spawn-on-exhaustion テストですが、「Spark が正の timeout を受け取って開始され、TimeoutExpired になった」という AC2 の本来のシナリオではありません。 最小修正は、現在のテストを次の条件に変えることです。 そして以下を確認します。 既存の P2-2: malformed payload テストは、新しく修正した
|
…指摘へ整合させる (#2401) PR #2410 への OWNER REQUEST_CHANGES (P1-1/P2-1/P2-2) fix_delta。 - AC5 (test_root_to_producer_transports_deadline_with_fake_external_clis): 実 subprocess.run をラップして root が構築した producer argv を記録し `--deadline-monotonic-ns` の一意存在と整数値を検証。fake `gh` wrapper 自体が sys.argv[1:] を JSON line で記録するようにし、fixture の calls[] (非厳密トレース) に頼らず 3 回の gh 呼び出しの exact argv/order を照合。spark_mode=None 固定条件で decision=="ready" を厳密化。 --deadline-monotonic-ns 0 で実 producer を直接起動し GitHub subprocess が一切 spawn しないことを確認する境界テストを追加。 - AC2 (test_required_probes_run_before_optional_spark_and_starvation_degrades): spawn 前 deadline 消費シナリオ(既存 test_expired_deadline_spawns_no_new_process でカバー済み)ではなく、spark probe が正の残り timeout で spawn し TimeoutExpired を受ける実シナリオへ変更。 - AC3: 実 _run_env_only_preflight() を直接呼び出し (assess() 経由の monkeypatch 迂回なし) chatgpt_auth: null の malformed 判定境界を検証 する追加ケースを1件追加。既存6ケースは維持。 - test_producer_cli_without_deadline_creates_local_deadline を test_producer_cli_without_deadline_passes_none_to_assess へリネーム (挙動変更なし、AC4新規テストとの役割分担を明記)。 Allowed Paths内2ファイルのみ変更。focused suite 25 pass、full scripts/claude-gpt/tests/ suite 344 pass, 1 skip。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
PR Review Verdict (iteration 1, fix_delta 対応)OWNER の REQUEST_CHANGES(https://github.com/squne121/loop-protocol/pull/2410#issuecomment-5465398027)で指摘された P1-1 / P2-1 / P2-2 が、実際のコード・テストを独立に読んで解消済みであることを確認しました。 Mergeability
Evidence Check
P1-1(blocking, OWNER指摘)解消確認
P2-1 / P2-2(OWNER指摘)解消確認
Blockersなし Non-blockers / Warningsなし verdict: APPROVE
reviewed_head_sha: "fb3cdabb8ccca41ddc138e3bd3a8afb0587c7f4c"
blockers: []
warnings: [] |
Summary
scripts/claude-gpt/workflow_capability_preflight.pyのassess()を再構成し、必須の GitHub プローブ(github_auth→github_repo_read(github_auth完了時のみ)→controlled_github_read(root auth の成否に関わらず独立実行))を、任意のspark_env_onlyプローブより 先に 実行するようにしました。共有の絶対 monotonic deadline はそのまま維持しています。_validate_spark_env_payload()を追加し、binary_available: bool/chatgpt_auth: object/chatgpt_auth.available: boolのみを検証します。chatgpt_authが dict でない場合に.get("available")を呼び出して未捕捉のAttributeErrorが発生していた既存バグを、構造化された malformed-output 理由へ正規化することで解消しました。scripts/claude-gpt/tests/test_capability_preflight_review_fixes.pyを追加し、AC1(プローブ順序)、AC2(Spark starvation による degrade)、AC3(malformed Spark payload の非例外処理)、AC4(assess(deadline_ns=None)が単一の共有 deadline を全プローブへ不変のまま伝播すること)、AC5(実サブプロセス境界を横断する hermetic テスト。外部リーフ CLI であるghのみを PATH 経由の fake でスタブ化し、producer サブプロセスおよびその結果はスタブ化しない)を検証しています。test_timeout_taxonomy_compat.py内)を削除しました(AC6)。競合する timeout-ownership モジュールが存在しないことは、恒久的な filename blacklist ではなく PR レビュー時に一度確認する運用へ変更します。test_workflow_capability_returns_structured_result()に@pytest.mark.github_liveマーカーを付与し、任意のライブカバレッジとして扱い、本 Issue の hermetic close evidence からは除外しました。test_workflow_capability_preflight_deadline.pyの既存アサーション(プローブ呼び出し順序)を、新しい順序["gh", "gh", "gh", "sh"]に更新しました(Issue 実装: Address remaining capability preflight review findings #2401 の Notes for Reviewer が明示する、AC1 実装に必須の破壊的変更です)。ghfixture が exact argv contract を強制していると PR 本文が誤って主張していた」という P1 指摘、および AC2/AC3 のテストが実際の境界を通っていなかったという P2 指摘を、テストファイルのみの変更で解消しました。詳細は下記 Runtime Verification Evidence を参照してください。Checks
pnpm typecheckpnpm lintpnpm testpnpm buildscripts/claude-gpt/配下の Python スクリプトと pytest のみを変更しており、TypeScript / JavaScript ファイルは一切変更していません。そのため上記 4 コマンドはこの diff に対して意味のある検証を行いません(フロントエンド toolchain が本 worktree に未インストールのため、実行コストに対して得られる signal がありません)。代わりに Issue 実装: Address remaining capability preflight review findings #2401 の Verification Commands(uv run --locked pytest .../rgの 7 コマンド)を PR 本文下部の Runtime Verification Evidence セクションで全て実行・記録しています。ruff checkは変更ファイル全てでAll checks passed!を確認済みです。Schema Change Applicability
not_schema_changeCLAUDE_GPT_WORKFLOW_CAPABILITIES_V1の producer/consumer 境界フィールド集合(schema/profile/decision/checks.{uv,spark,github}/actor_capabilities/reasons)は変更していません。変更したのはassess()内部のプローブ実行順序と、Spark JSON payload の検証ロジックのみで、外部から観測可能なキー・型・意味は不変です。Schema Consumer Inventory
N/A(
not_schema_changeのため)。Safety Claim Matrix
github_auth/github_repo_read/controlled_github_read)は、任意のspark_env_onlyプローブより常に先に実行され、Spark プローブの starvation が必須プローブの実行そのものを妨げることはないbinary_available/ missing・non-dictchatgpt_auth/ non-boolchatgpt_auth.available)は、未捕捉例外を発生させず既存の構造化 malformed-output reason へ正規化されるassess(deadline_ns=None)は_local_deadline_ns()を通じて厳密に 1 回だけ共有絶対 deadline を生成し、全ての適用対象プローブへ不変のまま渡すtest_no_broker_dependency_reference/ probe 実装はgh auth status/gh repo view/gh api ... --jq {name}の read-only 呼び出しのみRuntime Verification Evidence(動作検証証跡)
Issue #2401 の
## Runtime Verification Applicability(decision: immediate)に基づき、artifact_requirementsが指定する形式(focused pytest コマンド・exit status・pass count・producer argv / fake-CLI invocation trace の要約)で証跡を記載します。skip_conditions: noneのため SKIP 経路はありません。AC1: 必須プローブ順序
Exit Code: 0 / Pass Count: 2/2
test_required_probes_run_before_optional_spark_and_starvation_degrades: 制御された monotonic clock 下で、observed argv 順序が["gh", "gh", "gh", "sh"](必須3プローブが先に完了し、任意の spark(sh)プローブはその後に spawn される)であることを確認。test_controlled_github_read_runs_independently_of_root_auth_failure: rootgithub_authを故意に失敗させ、observed argv 順序から["gh", "auth"]は1回、["gh", "repo"](github_repo_read)は0回(正しくスキップ)、["gh", "api"](controlled_github_read)は実行済みであることを確認。AC2: Spark starvation は degrade(block ではない)
Exit Code: 0 / Pass Count: 1/1
sh)が一切 spawn されないケース)のみを検証しており、AC2 が実際に述べる「spark プローブが正の残り timeout で spawn しTimeoutExpiredを受ける」シナリオを検証していませんでした(spawn 前 no-spawn ケースは既存のtest_expired_deadline_spawns_no_new_process(test_workflow_capability_preflight_deadline.py、AC7 の focused suite に含まれる)で別途カバー済み)。修正後は monotonic clock を、必須3プローブ完了後も正の残り timeout が spark プローブへ渡るよう調整し、subprocess.runの fake がshargv に対して実際にsubprocess.TimeoutExpiredを送出するようにしました。shが正の timeout(0 より大きい値)で spawn され timeout することを確認したうえで、spark_mode="preferred"/spark_fallback="allowed"でdecision == degraded(blockedではない)かつchecks.github.auth/repo_read == True、actor_capabilities.controlled_github_read.status == "ready"を確認。AC3: malformed Spark payload は非例外・構造化 reason
Exit Code: 0 / Pass Count: 7/7(既存 parametrize 6ケース: invalid_json / non_dict_top_level / non_bool_binary_available / missing_chatgpt_auth / non_dict_chatgpt_auth / non_bool_chatgpt_auth_available、+ fix_delta で追加した1ケース)
non_dict_chatgpt_auth(chatgpt_auth: "connected")ケースが、修正前はenv_only_result.get("chatgpt_auth", {}).get("available")で未捕捉AttributeErrorを発生させていたバグの直接的な回帰テストです。全6ケースで assess() は例外を送出せず、preferred/allowed→degraded、required/forbidden→blockedを確認。wcp._run_env_only_preflight自体を monkeypatch して事前構築済みProbeOutcomeをassess()へ渡すため、_run_env_only_preflight()自身の JSON パース +_validate_spark_env_payload()境界は実際には経由していませんでした(assess()内の重複パス経由のみ検証)。追加したtest_run_env_only_preflight_rejects_null_chatgpt_auth_via_real_functionはsubprocess.runのみを fake 化し、{"binary_available": true, "chatgpt_auth": null}を実際の_run_env_only_preflight()(monkeypatch なし)へ通し、PROBE_MALFORMED_OUTPUTになることを確認しています。AC4: 単一共有 deadline
Exit Code: 0 / Pass Count: 1/1
_local_deadline_ns()の呼び出し回数が厳密に1回であること、かつ全4プローブ(github_auth/github_repo_read/controlled_github_read/spark_env_only)が観測した deadline 値が同一 sentinel 値であることを確認。assess()自体は monkeypatch で置き換えていない実関数呼び出しです。AC5: 実 root-to-producer サブプロセス境界(hermetic)
Exit Code: 0 / Pass Count: 3/3
fix_delta(P1-1): 旧証跡は producer が正しい引数を受け取り fake
ghから正しく応答されたことを直接観測しておらず(decision in ("ready", "degraded")という緩い比較のみ)、また「fakeghfixture が exact argv contract を強制する」という PR 本文の主張は、実際には_github_repo_read_probe()が発行するgh repo view <repo> --json nameが fixture の--jq nameWithOwner専用の厳密分岐に一致せず、stdout を検証しない permissive な互換分岐(--jsonはあるがnameWithOwnerを含まないため何も出力せず exit 0 のみ)を通過していただけで誤りでした。この修正で以下をテスト自身が直接観測・検証するようにしました(fixture 自体・Allowed Paths 外は変更していません):test_root_to_producer_transports_deadline_with_fake_external_clis:root_entry_router.subprocess.runの実体を保存したうえで記録用ラッパーに差し替え(実関数へ委譲、置き換えではない)、root が実際に構築した producer argv を記録。--deadline-monotonic-nsがちょうど1回、正の整数値付きで存在することを確認。さらに_install_fake_gh()のghwrapper 自体(テストファイル内、fixture 本体は未変更)がFAKE_GH_CALL_LOG環境変数経由で自分のsys.argv[1:]を JSON line として記録するようにし、実 producer が発行した3回のgh呼び出しの exact argv と順序をauth status→repo view <repo> --json name→api --hostname github.com repos/<repo> --jq {name}として直接照合。spark_mode=None固定条件でdecision == "ready"(in ("ready", "degraded")ではなく厳密比較)に強化。test_producer_zero_deadline_spawns_no_github_subprocess(新規、item e): 実 producer スクリプトを--deadline-monotonic-ns 0で直接(root_entry_router を経由せず)起動し、fakeghの call log が空/未生成のまま(GitHub subprocess が一切 spawn されない)であること、およびreasonsにpreflight_deadline_exhausted:系の理由が含まれdecision == blockedであることを確認。test_root_to_producer_boundary_reports_blocked_on_fake_gh_auth_failure(既存、変更なし): 同一境界を通じて producer 自身のdecision: blockedverdict(transport レベルの synthetic failure ではない)が root consumer にそのまま届くことを確認済み。なお、fake
ghfixture(scripts/claude-gpt/tests/fixtures/fake_gh.py、Allowed Paths 外・未変更)自体はgh repo view <repo> --json nameの shape を exact-argv 検証しません(--jq nameWithOwner専用の厳密分岐のみ exact-argv、--json nameは permissive 互換分岐です)。exact argv/order の保証は、この修正でテスト自身が追加した call-log ラッパーによるものであり、fixture の組み込み検証ではありません。AC6: filename blacklist テストの削除
Exit Code: 0(
rg自体は該当文字列なしで exit 1、否定形の VC は exit 0)AC7: focused suite 一括実行
Exit Code: 0 / Pass Count: 25/25(fix_delta で追加した2テストを含む:
test_run_env_only_preflight_rejects_null_chatgpt_auth_via_real_function/test_producer_zero_deadline_spawns_no_github_subprocess)。ライブ GitHub アクセス・provider credential・ユーザーghCLI 設定は一切不要(ghは_install_fake_ghの PATH wrapper で完全にスタブ化、その他のテストはwcp.subprocess.runの monkeypatch で完結)。test_expired_deadline_spawns_no_new_process(no-spawn-on-exhaustion 回帰)も含めて全 PASS。追加の全体回帰確認として、
scripts/claude-gpt/tests/配下の全テスト(test_actor_scoped_capability_probe.py/test_spark_fallback_route.py/test_workflow_capability_preflight.py(github_liveマーカー付き1件は deselected)/ 本 Issue の Allowed Paths 外の既存テストを含む)も PASS することを確認しています。Notes
.claude/skills/issue-refinement-loop/scripts/root_entry_router.pyは Allowed Paths に含めておらず未変更です(Issue 実装: Address remaining capability preflight review findings #2401 の Notes for Reviewer の指示どおり、AC5 は既存 fixture パターンを再利用するのみで当該ファイルを変更していません)。