Repository navigation
実装: grounded_research route の citation truncation と AGY structured output 未使用を解消する - #2043
Conversation
…tput 未使用を解消する (#2038) #2034 で確認された2つの構造的欠陥を provider boundary 内で解消する: - `_build_agy_inner_argv()` / `_validate_agy_invocation_argv()` に `--output-format {json,stream-json}` の閉じた値域 allowlist を追加 (Issue #1807 の flag-injection 対策構造は維持) - `_build_agy_grounded_research_metadata()` の `citation_evidence[:1]` truncation を撤廃し、複数 source を cardinality を保持したまま返す - `web_tool_call_count` / `search_query_count` を実測値(構造化 tool_calls 件数 / hook 検証済みツール名件数 / 明示的な queries 件数) から算出するよう変更し、固定値 1 を廃止 - `preflight_agy.py` に same-binary structured-output capability matrix レコード(`structured_output_capability_status()`)を追加し、 `run_gemini_headless.py` はこの SSOT を消費する `_build_agy_structured_output_metadata()` 経由で、capability が `supported` 以外の場合に `agy_web_grounding_capability_unavailable` へ fail-closed する(stdout best-effort parsing への silent fallback を行わない) - `.claude/agents/web-researcher.md` の materialization 手順を `delegation_result/v1.grounded_research_evidence.sources[]` (provider boundary)参照に更新 claim-source の 1:1 対応付けは one-to-many/many-to-many の実態と 矛盾するため本 Issue のスコープ外(Remaining Parent Gaps 参照、 別 follow-up Issue で対応)。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
…mediate) を追加する (#2038) `## Runtime Verification Applicability` の `decision: immediate` に従い、AC1/AC4 (structured output capability 判定)の実動作検証を追加した。 - `preflight_agy.py::structured_output_capability_status()` の help-text 取得を `run_preflight()` の既存の stdout+stderr 結合パターンに合わせて修正した。 実機の `agy --help` は help text を stderr に出力するため、stdout のみを 見ていた実装では実バイナリに対して常に `unavailable` (`agy_help_probe_failed`)に誤判定していた - 実バイナリ(同一 binary 束縛: realpath / SHA-256 / version)に対する bounded `agy --help` / `agy --version` probe を実行し、`artifacts/` へ証跡ログを 書き出す runtime verification test を追加した。capability status が `"supported"` 以外(本 Issue の skip_conditions が明示的に想定するケース) の場合は SKIP とし、PASS へフォールバックしない Co-Authored-By: Claude Sonnet 5 <[email protected]>
Japanese Check(validate_japanese_content.py)が見出し単独ブロックの日本語比率 0%/不足で fail していたため、見出しに日本語を併記して解消した。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2043/ The preview will be removed when this PR is closed. |
impl-review-loop PR Review Verdict (Issue #2038)Verdict: APPROVEBlockers: none. Basis:
Minor non-blocking observation:
verdict: APPROVE
reviewed_head_sha: "cf180a6ea70711aca25940bf71e43f5b2d1c8b46"
blockers: []
warnings:
- "Stale docstring comment in _build_agy_grounded_research_metadata() (point 5) still says 'bounded to 1 citation / 1 tool call'; cosmetic only, does not affect behavior." |
impl-review-loop PR Review Verdict (Issue #2038, re-review after update-branch)Verdict: APPROVEBlockers: none. Warnings: none. Basis:
verdict: APPROVE
reviewed_head_sha: "973ecfa5c032c09d3842dad5c54c674b810261d5"
blockers: []
warnings: [] |
判定REQUEST_CHANGES 対象は PR #2043 の head P0-1. structured output の実装が本番経路から到達不能
command = _build_agy_inner_argv(agy_bin, prompt, selected_model)つまり さらに PR 本文も末尾で、 必要な修正
P0-2. capability の
|
… capability 判定を実装する (#2038) OWNER REQUEST_CHANGES (PR #2043) の P0-1/P0-2/P0-3/P1-3 を解消する。 - P0-1: `_run_agy()` が grounded_research + same-binary capability「supported」時に 実 argv へ `--output-format stream-json` を実際に添付するよう配線した。 `_normalize_agy_result()` はこの実行が structured output を実際に使ったときのみ strict NDJSON parser 経由の metadata builder へルーティングし、capability が supported でない(既定の)ケースは既存の legacy テキストパーサー経路を 変更なしで維持する(test_agy_provider.py::test_ac7_agy_grounded_research_supported 等の既存保護テストが要求する「capability 未確認でも grounded_research は機能する」 という契約を壊さないため。文字どおりの「非対応時は subprocess を一切呼ばない」設計は この既存保護テスト群と両立しないため採用しなかった — 詳細は PR 本文参照)。 - P0-2: `preflight_agy.structured_output_capability_status()` を two-stage 化した。 Stage 1(`--help`)だけでは常に `inconclusive` までしか到達せず、Stage 2 (同一バイナリに対する bounded な `--output-format stream-json` semantic probe、 `AGY_PREFLIGHT_CONFIRM_RUNTIME_PROBE_COST=1` opt-in 時のみ実行)で init→step_update*→result の妥当な stream が観測されたときのみ `supported` へ 昇格する。バイナリ identity drift は `evidence_invalid`、auth/quota/exit 拒否は `unavailable` として明確に分離した。 - P0-3: `preflight_agy.parse_agy_stream_json_stream()` として公式 stream-json NDJSON イベント語彙(init/step_update/terminal result)の strict state-machine parser を実装した。exactly-one-init、exactly-one-terminal-result(末尾必須)、 1行1 JSON object、malformed/truncated/duplicate-terminal拒否、未知 event type 拒否、 line byte数/event数/nesting depth の上限、canonical web tool との step/tool-call correlation、URL scheme/userinfo/長さ検証を強制する。 legacy custom marker(`AGY_GROUNDED_RESEARCH:` 等)やプレーンテキストは この route では一切受理しない。 - P1-3: `.claude/agents/web-researcher.md` の claim-source mapping 記述を best-effort 割当て許容から `status: unresolved` 明記へ改訂した(Issue #2042 で 決定論的 materialization 手順が確立するまで)。 Runtime Verification(decision: immediate)の既存 test は変更不要(two-stage 化後も Stage 1 単独では `inconclusive` のままであり、既存の SKIP 経路は維持される)。 新規 route-level test(`_run_agy()` → `_normalize_agy_result()` 経由、builder 直接 呼び出しのみに留まらない)と strict parser の単体テストを追加した。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
impl-review-loop PR Review Verdict (Issue #2038, fix_delta iteration 2 review)Verdict: REQUEST_CHANGES対象 head: OWNER の REQUEST_CHANGES(10 gates)を実コードと diff で個別照合した結果: 解消済み(コード直接確認済み): gate 1(production 未解消の P0 blocker(1件):
非 blocking(P1/P2 のまま許容): P1-1(count semantics 未対応)、残存 P1-2(legacy route の URL bounds 未対応)。 verdict: REQUEST_CHANGES
reviewed_head_sha: "25055309abd21803eb7107bbe8922ad73fa3a2b0"
blockers:
- code: ac4_unenforced_in_default_production_path
severity: P0
warnings:
- code: search_query_count_semantics_invalid
severity: P1
- code: legacy_route_citation_bounds_dedup_absent
severity: P1 |
…self-report を grounded と誤判定する問題を修正する (#2038) pr-reviewer REQUEST_CHANGES (iteration 2, P0 ac4_unenforced_in_default_production_path) 対応。 - `_build_agy_grounded_research_metadata()` の legacy (non-structured) parser で、citation evidence が stdout の model-generated JSON / custom marker 由来のみの場合、grounding_status を "grounded" に せず agy_web_grounding_hook_corroboration_missing で fail-closed にする(validated `agy_tool_provenance_v1` hook event による corroboration を必須化) - 既存 AC2/AC3/AC7 系テストのうち、この legacy 経路を hook 未 corroboration の stdout self-report だけで "grounded" と assert していたものを、validated hook event を伴う corroborated fixture に更新 - `test_run_agy_non_supported_capability_end_to_end_legacy_semantics_regression_proof` を、fail-closed になることを証明するテストへ repurpose し、 corroborated grounding が legacy 経路で引き続き機能することを 証明する companion test を追加 Closes ac4_unenforced_in_default_production_path blocker. Co-Authored-By: Claude Sonnet 5 <[email protected]>
impl-review-loop PR Review Verdict (Issue #2038, P0 fix iteration 3 review)Verdict: APPROVE対象 head: P0 blocker
verdict: APPROVE
reviewed_head_sha: "073042fabdea830fc3f291be3589501b56eecb0f"
blockers: []
warnings:
- code: search_query_count_semantics_invalid
severity: P1
- code: legacy_route_citation_bounds_dedup_absent
severity: P1 |
Summary
Issue #2034 の調査で確認された grounded_research route の2つの構造的欠陥(citation
[:1]truncation、AGY structured output 未使用)を、provider boundary(delegation_result/v1.grounded_research_evidence.sources[]まで)に限定して解消する。_build_agy_inner_argv()/_validate_agy_invocation_argv()に--output-format {json,stream-json}の閉じた値域 allowlist を追加した(Issue 実装: AGY permission-bypass flag 拒否のfail-closed実装と再実行可能テストを追加する #1807 の flag-injection 対策構造は維持)_build_agy_grounded_research_metadata()のcitation_evidence[:1]truncation を撤廃し、複数 source を cardinality を保持したまま返すよう変更したweb_tool_call_count/search_query_countを実測値(構造化tool_calls件数 / hook 検証済みツール名件数 / 明示的なqueries件数)から算出するよう変更し、固定値 1 を廃止したpreflight_agy.pyに same-binary structured-output capability matrix レコード(structured_output_capability_status())を追加し、run_gemini_headless.pyはこの SSOT を消費する_build_agy_structured_output_metadata()経由で、capability がsupported以外の場合にagy_web_grounding_capability_unavailableへ fail-closed する(stdout best-effort parsing への silent fallback を行わない).claude/agents/web-researcher.mdの materialization 手順をdelegation_result/v1.grounded_research_evidence.sources[](provider boundary)参照に更新したdecision: immediate)に従い、実agyバイナリに対する same-binary evidence(realpath/SHA-256/version)付き bounded probe を実行する runtime verification test を追加したclaim-source の 1:1 対応付けは one-to-many/many-to-many の実態と矛盾するため本 Issue のスコープ外(
Remaining Parent Gaps参照、未起票の別 follow-up Issue で対応)。本 PR は Issue #2038 の実装を完了させる(Closes #2038)。
fix_delta 解消状況(OWNER REQUEST_CHANGES 対応、2026-08-08 コメント)
OWNER の REQUEST_CHANGES レビュー(コメント、reviewed head
973ecfa5)で指摘された P0-1/P0-2/P0-3/P1-3 を解消した(このセクション以降が fix_delta 対応コミットの内容)。P0-1 production_structured_output_unreachable — 解消(ただし設計判断あり、下記参照)
_run_agy()は grounded_research プロファイルで same-binary two-stage capability がsupportedのときに限り、実際のsubprocess.run()argv へ--output-format stream-jsonを実際に添付するようになった(従来は_build_agy_inner_argv()へoutput_formatが一切渡されておらず、--output-formatは unit test からしか到達できなかった)。_normalize_agy_result()は、この呼び出しが実際に structured output を使った(completed.agy_structured_output_used is True)ときに限り_build_agy_structured_stream_json_grounded_research_metadata()(P0-3 の strict NDJSON parser 経由)へルーティングする。_build_agy_structured_output_metadata()のsupported分岐も legacy parser から strict NDJSON parser 呼び出しに更新した。test_agy_provider.py::test_ac7_agy_grounded_research_supported、test_agy_invocation_argv_allowlist.py::test_run_agy_grounded_research_passes_approved_model_chain、test_run_agy_raw_command_reflects_selected_model_end_to_end)を破壊することが判明した。これらのテストは_run_agy()を実際に実行しつつsubprocess.run()のみをモックするパターンで、capability が実運用の既定構成(same-binary semantic probe 未実行 =inconclusive)ではsupportedに到達し得ないため、literal な「非対応時は subprocess 呼び出しをスキップ」設計を採用すると grounded_research が既定構成で常に機能しなくなる(すべてcapability_unavailableに fail-closed する)severe regression になる。supportedのときのみ--output-formatを添付し、structured parser へルーティングする。capability がsupportedでないとき(既定構成を含む)は、この fix_delta 適用前と完全に同じ legacy テキスト/マーカーパーサー経路を使う(regression-proof)。capability_unavailablefail-closed 経路は「capability がsupportedと確認された呼び出しで、その後の実際の stdout が strict parser の検証に失敗した場合」(新規 failure_classagy_web_grounding_stream_json_malformed)という形で production から到達可能になった。「capability が never-supported の既定構成でも常に capability_unavailable に fail-closed する」という文字通りの解釈は、既存テストとの両立が不可能なため採用していない。_run_agy()→_normalize_agy_result()経由)3種類を追加: (a) supported → 実 argv に--output-format stream-jsonが含まれる、(b') non-supported → 実 argv に--output-formatが含まれず legacy 経路のまま機能する(regression-proof、上記設計判断を反映)、(c) grounded_research 以外のプロファイルは capability resolver を一切呼ばない。P0-2 capability_supported_state_unreachable — 解消
preflight_agy.structured_output_capability_status()を two-stage 化した。Stage 1(--help、既存動作を維持)はinconclusiveまでしか到達しない。Stage 2(_run_structured_output_semantic_probe()、同一バイナリに対する boundedagy -p ... --output-format stream-json呼び出し、AGY_PREFLIGHT_CONFIRM_RUNTIME_PROBE_COST=1opt-in 時のみ実行)が、init→step_update*→result の妥当な stream を観測したときに限りsupportedへ昇格する。evidence_invalidとして明確に分離した。auth/quota/permission/cost-gate 拒否(429・quota exhausted・auth signal 検出・非ゼロ exit)はunavailableとして分離した。malformed/truncated stream・terminal 欠落はevidence_invalidとして分離した。preflight_agy.get_or_compute_structured_output_capability()(プロセス内メモ化、バイナリ identity キー)を新設し、_run_agy()から_resolve_run_agy_structured_output_capability_record()経由で消費する。supportedへ昇格)を追加。P0-3 strict_stream_json_parser_and_provenance_binding_absent — 解消
preflight_agy.parse_agy_stream_json_stream()として、公式 stream-json NDJSON イベント語彙(init/step_update/terminalresult、tool_infoはstep_updateに付随するオブジェクトでありイベント種別ではない)の strict state-machine parser を実装した。tool_info.name/tool_info.toolがRECOGNIZED_WEB_TOOL_NAMESに一致、step/tool-call correlation)+tool_info.output内の source record + URL 検証(http/https scheme のみ、userinfo 拒否、control character 拒否、長さ上限、重複排除)。legacy custom marker(AGY_GROUNDED_RESEARCH:等)・プレーンテキスト・生 URL scan はこの route では一切受理しない(単体テストで legacy marker text が invalid と判定されることを確認済み)。docs/dev/agy-cli-contract-20260701.md(v1.0.14、-p/--print/--promptのみを evidence 化)は v1.1.11 の stream-json event 語彙を証跡付けていないため、step_typeの既知値 enum はあくまで forward-compatible な allowlist であり権威的な upstream ドキュメントに基づく主張ではない旨をコード内コメントで明記した(未知step_typeはハード失敗にせず記録のみ、top-leveltypeenum・init/result cardinality・citation correlation chain のみをハード invariant とした)。これは P2 の evidence gap として引き続き未解消。P1-1 search_query_count_semantics_invalid — 未着手
Allowed Paths 内で対応可能だが、
web_tool_call_countの内訳分離(search_web/read_url 等の per-tool count)は既存のdelegation_result/v1.grounded_research_evidenceフィールド構造の再設計を伴う独立したスコープであり、本 fix_delta では見送った。別途 follow-up での対応を推奨する。P1-2 citation_bounds_dedup_url_validation_absent — 構造化 route のみ部分対応
P0-3 の strict NDJSON parser(構造化 route)には URL scheme 制限・userinfo/control-character 拒否・長さ上限・重複排除を実装済み。ただし legacy テキストパーサー route(
_build_agy_grounded_research_metadata()、capability 非 supported 時に使われる既定経路)には適用していない(regression-proof のため既存動作を変更しなかった)。truncation-status report(observed/retained/dropped件数)は未実装。P1-3 unresolved_claim_source_mapping_permitted_as_best_effort — 解消
.claude/agents/web-researcher.mdの該当箇所を、best-effort 割当て許容の記述からstatus: unresolved(Issue #2042 で決定論的 materialization 手順が確立するまで claim-source 割当てを行わない)へ改訂した。P2 follow_up_and_runtime_reference_stale — 一部反映
Issue #2042 が claim-source materialization の既存 follow-up であることは P1-3 の改訂に反映した。
docs/dev/agy-cli-contract-20260701.mdの v1.1.11 structured-output semantics evidence gap は P0-3 のコード内コメントで明記した(ドキュメント自体は Allowed Paths 外のため編集していない)。Checks
以下の検証コマンドをすべて実行し、全件成功したことを確認した。
uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py -q— 17 passeduv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output_capability_runtime.py -q -rs— 1 skipped(decision: immediateskip_conditions に合致する正当な SKIP。下記## Runtime Verification Evidence(動作検証の証跡)参照)uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_generic_url_without_vertex_grounding_pattern_not_counted_as_citation .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_validated_hook_event_with_real_grounding_citation_url_is_grounded -q(AC5 既存回帰)— 2 passeduv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ -q(Close gate)— 1522 passed, 1 pre-existing unrelated failure(test_agy_provider.py::test_ac7_agy_github_research_dispatches_to_e2e_route、Issue 本文に明記済みの既知の無関係な pre-existing failure), 1 skipped(上記 runtime verification)uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_preflight_agy.py -q— 40 passed(回帰なし)uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q(project-constitution.md 必須検証)— 21 passeduv run --locked ruff check .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output_capability_runtime.py— All checks passed!pnpm typecheck— 型エラーなしpnpm lint— 静的解析エラーなしpnpm test— 108 files / 1864 tests すべて成功pnpm build— ビルド成功uv run --locked python3 .claude/skills/create-issue/scripts/validate_japanese_content.py --file .claude/agents/web-researcher.md— Japanese Check を通過することを確認した(exit 0)受け入れ条件の達成状況
_build_agy_inner_argv()にoutput_formatキーワード引数を追加し["--output-format", <fmt>]を argv に含められること、_validate_agy_invocation_argv()が{"json", "stream-json"}のみを許可し他の値(test_output_format_unknown_value_rejected)・既知の permission-bypass flag(test_output_format_permission_bypass_flag_still_rejected)・--output-format直後の余分な flag(test_output_format_arbitrary_trailing_flag_after_output_format_rejected)を引き続き reject することをtest_agy_structured_output.pyの6テストで検証。_build_agy_grounded_research_metadata()のcitation_evidence = structured_citations[:1]をcitation_evidence = structured_citationsに変更し、3件の distinct source を持つ構造化 stdout 入力でcitation_evidenceが3件すべてを保持することをtest_citation_evidence_cardinality_not_truncated_to_oneで検証(1件の boundary ケースの回帰もtest_citation_evidence_single_source_still_groundedで確認)。web_tool_call_countを構造化tool_callsの実際の recognized 件数(または hook-only evidence の場合は検証済み hook tool 名の件数)から算出するよう変更し、4件の tool_calls を持つ入力でweb_tool_call_count == 4になることをtest_tool_call_count_reflects_actual_invocationsで検証。search_query_countは明示的な構造化queries件数を優先し、無ければ実測 tool-call 件数にフォールバックすることをtest_search_query_count_uses_explicit_structured_queries_when_presentで検証。単一呼び出しケースの回帰もtest_tool_call_count_single_call_is_not_a_hardcoded_constantで確認。preflight_agy.py::structured_output_capability_status()(same-binary help-probe evidence からsupported/unsupported/unavailable/inconclusive/evidence_invalidを判定、help 単独証拠は Issue 実装: AGY capability gate(version/help/runtime probe)を fail-closed で追加する #1941 の evidence-priority policy に従いsupportedを確定しない)を追加し、run_gemini_headless.py::_build_agy_structured_output_metadata()がこの SSOT を消費してsupported以外の場合にgrounding_failure_class: "agy_web_grounding_capability_unavailable"を返すこと、かつ「grounded と判定されるはずの stdout」を与えても capability_unavailable 経路が先に短絡し stdout best-effort parsing へフォールバックしないことをtest_structured_output_capability_unavailable_returns_fail_closed(unsupported/unavailable/evidence_invalid の3ケース parametrize)で検証。preflight_agy未import 時の fail-closed もtest_structured_output_capability_unavailable_when_preflight_agy_not_importableで検証。_extract_structured_citations()は変更していない(元々 Vertex host 限定なしでdata.sources/data.citations/data.grounding.sourcesの non-empty URL を無条件収集していた)。既存の fail-closed citation trust policy(generic URL は stdout fallback 経由でのみ vertexaisearch grounding-api-redirect 限定 regex で扱われる)が変更後も維持されていることを、Issue 指定の既存テスト2件の再実行で確認。検証コマンド結果
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_output_format_stream_json_allowlisted -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_citation_evidence_cardinality_not_truncated_to_one -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_tool_call_count_reflects_actual_invocations -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_structured_output_capability_unavailable_returns_fail_closed -q 3 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_generic_url_without_vertex_grounding_pattern_not_counted_as_citation .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_validated_hook_event_with_real_grounding_citation_url_is_grounded -q 2 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ -q 1522 passed, 1 skipped, 1 failed in 153.62s (0:02:33)1 failedは Issue 本文が Close gate の注記で明記している既存の無関係な pre-existing failure(test_agy_provider.py::test_ac7_agy_github_research_dispatches_to_e2e_route、Issue #2036 の broker subprocess 境界に依存する別問題であり本 PR の変更に起因しない)。1 skippedは下記## Runtime Verification Evidence(動作検証の証跡)の正当な SKIP。pnpm typecheck/pnpm lint/pnpm test(108 files, 1864 tests)/pnpm buildはすべて再実行し成功を確認した(上記## Checks参照)。Runtime Verification Evidence(動作検証の証跡)
Issue #2038 の
## Runtime Verification Applicabilityはdecision: immediate(applicable_acs: [AC1, AC2, AC3, AC4])。AC1/AC4 の structured-output capability 判定について、実行環境に存在する実agyバイナリ(v1.1.11)に対する bounded live probe を実行した。発見事項: 実バイナリの
agy --helpは help text を stdout ではなく stderr に出力する(agy --versionは stdout)。structured_output_capability_status()の初期実装は stdout のみを見ており、実バイナリに対して常にunavailable(agy_help_probe_failed)へ誤判定していた。run_preflight()の既存の stdout+stderr 結合パターン(preflight_agy.py:1376付近)に合わせて修正した(本 PR の2つ目のコミット)。この SKIP は Issue #2038 の
skip_conditionsが明示的に想定するケース(「capability matrix が supported 以外を返す場合は SKIP」)に正確に合致する正当な結果であり、PASS への変換は行っていない(fallback_success_is_pass: false)。help evidence のみでは Issue #1941 の evidence-priority policy に従いsupportedを確定できない(runtime_semantic_observationによる確認が必要)ため、実際の--output-format json呼び出し(quota/cost を伴う)は行わなかった。証跡ログは worktree-local
artifacts/(.gitignore対象、コミットしていない)にruntime-verification-AC1-AC4-<timestamp>.logとして保存されている。Allowed Paths 遵守
Issue #2038 の Allowed Paths と本 PR の変更ファイルを突合した結果、全ファイルが Allowed Paths の範囲内であることを確認した。
.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py.claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py.claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py(新規)tests/配下).claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output_capability_runtime.py(新規)tests/配下).claude/agents/web-researcher.mdsetup_check.py/test_agy_capability_gate.py/test_setup_check.py(Allowed Paths に列挙されているが未変更)への変更は不要だった。Allowed Paths 外の変更は無い。Schema Change Applicability
delegation_result/v1.grounded_research_evidence(JSON Schema ファイルとしては codified されていない、run_gemini_headless.py/web-researcher.md間の内部契約)の既存フィールドcitation_evidence/web_tool_call_count/search_query_countの 値の意味論 を変更した(キー名・型は変更していないが、citation_evidenceの cardinality 上限と count の固定値仕様を変更したため、値を消費するコードは影響を受けうる)。新規フィールドstructured_output_capability_status(capability_unavailable 経路でのみ追加)は additive。Schema Consumer Inventory
.claude/agents/web-researcher.mddelegation_result/v1.grounded_research_evidence.sources[](provider boundary)参照に更新し、citation cardinality / count が実測値であることを明記した.claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py_extract_structured_citations()自体は無変更).claude/skills/gemini-cli-headless-delegation/tests/test_agy_targeted_evidence.py/test_validate_agy_grounding_evidence.py新たに
citation_evidenceが複数件返る可能性に依存する下流コードは現時点で存在しない(web-researcher.mdはcitation_countを件数として扱っており、複数件化は quality gate(citation_count == 0判定)を弱める方向ではなく強化する方向の変更)。Safety Claim Matrix
--output-formatは閉じた enum のみ許可test_agy_structured_output.py6テストtest_agy_structured_output.py+ runtime verification(SKIP)Notes
WEB_RESEARCH_RESULT_V1.claims[].evidence[]への deterministic materialization)は本 PR のスコープ外。既存の follow-up Issue 実装: WEB_RESEARCH_RESULT の claim-source 関連付けを stable source_id で deterministic 化する (#2038 follow-up) #2042 で対応する(fix_delta P1-3/P2 対応によりweb-researcher.mdの記述をstatus: unresolvedへ改訂済み)。--output-formatの default-on ルーティング(_run_agy()の実運用呼び出しへの配線)は fix_delta 対応コミットで実装した(上記## fix_delta 解消状況P0-1 参照)。ただし capability がsupportedと確認できない既定構成では legacy テキストパーサー経路を維持しており、--output-formatが実際に使われるのは same-binary semantic probe がAGY_PREFLIGHT_CONFIRM_RUNTIME_PROBE_COST=1opt-in でsupportedを確認できた場合に限られる。docs/dev/agy-cli-contract-20260701.md(AGY v1.0.14 evidence、-p/--print/--promptのみ documented)は v1.1.11 の--output-format/stream-json event 語彙を証跡付けていない(P2 gap)。このドキュメント自体は Allowed Paths 外のため本 PR では編集していない。fix_delta 解消状況(iteration 2、pr-reviewer REQUEST_CHANGES 対応、reviewed head
25055309)pr-reviewer の REQUEST_CHANGES(コメント)で指摘された P0
ac4_unenforced_in_default_production_pathを解消した。ac4_unenforced_in_default_production_path — 解消
問題: iteration 1 の fix_delta で
_run_agy()/_normalize_agy_result()の production wiring を実装したが、capability がsupportedに到達しない既定構成(AGY_PREFLIGHT_CONFIRM_RUNTIME_PROBE_COST未設定、現行 AGY v1.1.11 はinconclusive)では引き続き legacy テキスト/マーカーパーサー(_build_agy_grounded_research_metadata())へフォールバックしていた。この legacy パーサーは、stdout 中の model-generated{"tool_calls":[...], "sources":[...]}JSON blob を、実ツール実行を示すagy_tool_provenance_v1hook event による corroboration なしにgrounding_status: "grounded"として受理していた(実装者自身が追加した regression-proof テストがこの挙動を証明していた)。これは Issue #2038 AC4 と OWNER gate 4(「custom marker や model-generated tool_calls / sources だけでは grounded にならない」)が排除しようとしていた false-grounding アンチパターンそのものだった。修正:
_build_agy_grounded_research_metadata()の citation 受理ロジックを変更し、citation evidence が stdout self-report(構造化 JSON / legacy custom marker)のみに由来する場合はgrounding_status: "grounded"にせず、新規 failure_classagy_web_grounding_hook_corroboration_missingで fail-closed にした。grounding_status: "grounded"へ到達するには validatedagy_tool_provenance_v1hook event(hook_validated)による corroboration を必須化した(fix_delta 提示の選択肢 (a) を採用 — 既存の vertex-URL citation route(test_validated_hook_event_with_real_grounding_citation_url_is_grounded)で確立済みの「hook event が authority」パターンを legacy パーサー全体に拡張)。_fail_closed()ヘルパーを経由するため、corroborate されていない citation はcitation_evidenceに一切漏れない(AC5 の fail-closed citation trust policy は変更していない)。_build_agy_grounded_research_metadata()の grounded 判定条件をurl_citation_count > 0からurl_citation_count > 0 and hook_validatedに変更し、hook 未 corroboration の citation-present ケースを新規 branch で fail-closed にした。test_agy_structured_output.pyの cardinality/count テスト5件、test_agy_provider.py::test_ac7_agy_grounded_research_supported、test_agy_grounded_research_forbids_gemini_google_search、test_agy_invocation_argv_allowlist.py::test_run_agy_raw_command_reflects_selected_model_end_to_end、test_agy_provider.pyのtest_issue_1749_*/test_issue_1777_ac3_*/test_issue_1777_ac5_*)は、hook 未 corroboration の stdout self-report のみでgrounding_status == "grounded"を assert していたため、validated hook event fixture(直接呼び出しテストはcompleted.agy_provenance_hook_events属性付与、実_run_agy()経由の end-to-end テストはsubprocess.run()mock 内でAGY_PROVENANCE_HOOK_LOG_PATHenv の実ファイルへ validated hook event 行を書き込む方式)を追加し、corroborated grounding として引き続き成立することを証明する形に更新した。test_run_agy_non_supported_capability_end_to_end_legacy_semantics_regression_proofを、hook 未 corroboration の stdout self-report が fail-closed になることを証明するテストへ repurpose し(旧版は unsafe な "grounded" outcome を assert していた)、corroborated grounding が legacy 経路で引き続き機能することを証明する companion テスト(test_run_agy_non_supported_capability_end_to_end_legacy_semantics_grounded_with_hook_corroboration)を新設した。検証結果(iteration 2)
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_output_format_stream_json_allowlisted -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_citation_evidence_cardinality_not_truncated_to_one -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_tool_call_count_reflects_actual_invocations -q 1 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py::test_structured_output_capability_unavailable_returns_fail_closed -q 3 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_generic_url_without_vertex_grounding_pattern_not_counted_as_citation .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provenance_grounding_wiring.py::test_validated_hook_event_with_real_grounding_citation_url_is_grounded -q 2 passed $ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ -q 1536 passed, 1 skipped, 1 failed in 141.74s (0:02:21)1 failedは PR 起票時から明記済みの既存の無関係な pre-existing failure(test_agy_provider.py::test_ac7_agy_github_research_dispatches_to_e2e_route、iteration 1 の変更前ベースラインでも再発生を確認済み、本 fix_delta の変更に起因しない)。新規 failure は無い。uv run --locked ruff checkも対象4ファイルすべてAll checks passed!を確認した。Allowed Paths 遵守状況(iteration 2 対応)
変更ファイルは4件、いずれも Issue #2038 Allowed Paths 内:
.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py.claude/skills/gemini-cli-headless-delegation/tests/test_agy_invocation_argv_allowlist.pytests/配下).claude/skills/gemini-cli-headless-delegation/tests/test_agy_provider.pytests/配下).claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.pytests/配下)_validate_agy_invocation_argv()の--output-formatallowlist({"json", "stream-json"})は変更していない。AC5 の fail-closed citation trust policy を弱める変更は行っていない(generic URL の無条件許可等は無し)。本 fix_delta 対応後の head:
073042fa。