Repository navigation
fix: AGY stream-jsonパーサを現行公式event-key形式に一致させる - #2527
Conversation
parse_agy_stream_json_stream()が旧来の`type`直下キー形式を前提としていたため、 現行公式AGY stream-json形式(`event`判別キー、`step_update`/`result`ペイロード のネスト、terminalは`result.response`)を解析できない不整合をOWNER REQUEST_CHANGESに基づき修正する。 - preflight_agy.py: parse_agy_stream_json_stream()を`event`キー判別・ `step_update`ネストペイロード読み取りに書き換え。ACTIVE/DONE状態の重複 step_updateをtool_call_records/source_recordsで二重カウントしないガード を追加。RECOGNIZED_WEB_TOOL_NAMESに実機確認済みのtool名 (search_web/read_url_content/open_browser_url)を追加。 - run_gemini_headless.py: _normalize_agy_result()がstructured parse成功時に raw stdout(NDJSON全体)ではなくterminal result.responseからresponse_text/ result_surface.summaryを構築するよう修正。 _build_agy_structured_stream_json_grounded_research_metadata()に、 tool_info.outputに構造化sourceがない場合のterminal answer URL候補抽出 (citation_candidates_unverifiedとして扱い、groundedへの自動昇格はしない) を追加。 - test_preflight_agy.py / test_agy_structured_output.py: 現行event-key形式の fixtureへ移行し、旧type-key形式が守っていたmalformed/missing-terminal/ duplicate-terminal検査の意味を移植。旧type-key形式が互換shimとして残って いないことを確認する回帰テストを追加。 pre-existing bwrap-sandboxing起因の2件のテスト失敗 (test_run_agy_supported_capability_end_to_end_uses_structured_parser / test_run_agy_legacy_citations_without_provenance_are_candidates_for_native_quality_check) はbaseline(本fix前)でも同様に失敗することを独立確認済み。本Issueの stream-json形式修正とは無関係。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2527/ The preview will be removed when this PR is closed. |
Verdict: APPROVERe-review after mechanical
BlockersNone. verdict: APPROVE
reviewed_head_sha: "88eff0ec79e25a90a1571b63c5eac44b9dce3e17"
blockers: []
warnings:
- "Carried forward from prior approved pass (code unchanged): dual-lens clean-room review (security-boundary + experimental-validity, per SKILL.md 4.7) for this grounded_research/AGY-adjacent change was performed in a single pass rather than two separate reviewer instances."
- "Carried forward from prior approved pass (code unchanged): minor redundant reparse call in _normalize_agy_result() for the grounded_research profile — non-blocking style note." |
判定:REQUEST_CHANGES — 終端検証と返却経路の小規模な修正を推奨公式形式へ合わせる方向は正しく、通常の回答を レビュー対象は 今回の独立検証は、コードと公式資料の静的照合です。認証済みAGYの実行、pytestの再実行、実処理時間の測定は行っていません。 以下の入力例は、コード上の問題を示すために構成したものです。 1. P2・マージ前修正:壊れたterminalを |
| 段階 | 現在の挙動 |
|---|---|
| parser | status: valid |
| grounding metadata | tool-derived sourceがあるためgrounded |
| 回答抽出 | result.responseがないため抽出できない |
| wrapper | raw NDJSONをresponse_textへ戻す |
| 最終結果 | ok: trueになり、summaryも回答ではなくイベント列から導出される |
これは、既存fixtureのsource形状、metadataの昇格条件、wrapperのfallbackを組み合わせた帰結です。この不正入力を実機が通常出すという主張ではありません。問題は、「壊れたterminal」と「正常に回答を抽出できたstream」を区別できていないことです。
推奨修正
terminalの個数検査に加えて、回答抽出に必要な最小限のpayload検証を同じparser、または共有する抽出処理へ追加してください。少なくとも result の欠落・非object、成功terminalの response 欠落・非stringを、正常な回答抽出と同じ状態にしないことが必要です。
ただし、ERRORを返したstreamまで構文不正にする必要はありません。 公式仕様でも実行失敗はstatusとerrorで表されます。streamの構造、プロセス終了コード、回答の有無は分けて扱うべきです。([Google Antigravity]1)
既存の「parse失敗時は従来のfallbackを維持する」という方針まで撤回する必要はありません。直すべきなのは、回答を取り出せない入力をparserが正常と判定し、それが成功した返却へつながる部分です。
2. P2・既存不具合の残存:検索語にRESOURCE_EXHAUSTEDがあるだけで引用候補を捨てる
対象:
run_gemini_headless.py::_build_agy_structured_stream_json_grounded_research_metadata()、4659–4664行付近。
この処理はstructured payloadを読む前に、NDJSON全体へ次の判定を行っています。
if _QUOTA_EXHAUSTED_RE.search(stdout):
return _fail_closed(
grounding_status="failed",
grounding_backend="none",
grounding_failure_class="agy_web_grounding_quota_exhausted",
)正規表現には RESOURCE_EXHAUSTED、quota exhaustedなどが含まれ、失敗分岐ではcitation_evidenceが空になります。
したがって、「Google APIのRESOURCE_EXHAUSTEDエラーへの対処を調べる」正常な検索でも、例えばtool引数が次のようになれば該当します。
{
"name": "search_web",
"parameters": {
"query": "Google API RESOURCE_EXHAUSTED troubleshooting"
}
}その後にSUCCESSのterminalと有用な回答・引用URLが返っていても、検索語を実エラーと誤認して、AGY attemptをquota失敗にします。引用候補の抽出処理に到達しないため、候補も失われます。最終的なweb-researcherが必ず失敗するわけではありませんが、正常なAGY結果を捨て、不要な再調査へ進ませる原因になります。
推奨修正
structured経路では、quota判定を失敗した実行のエラー情報へ限定してください。成功したstream内の検索語、toolの通常出力、回答本文にエラー名が登場しただけで実行失敗へ変更しない、という修正です。
また、途中のtoolが失敗しても最終的に代替手段で回答できた場合があるため、tool errorの存在だけで最終結果を一律失敗にするのも避けるべきです。
この判定自体は今回の差分で新設されたものではなく、既存不具合です。PRの新規regressionとしては数えません。 ただし、#2521はparserだけでなくstructured結果の正規化と有用な返却までを対象としているため、同じ限定的な修正範囲で解消する価値があります。
3. 検証上の不足:実出力のreplayと、通常経路のend-to-end検証は分ける
PR本文の実行報告は、次のように読むのが正確です。
| 確認対象 | PR本文から確認できる範囲 |
|---|---|
| 5profileの代表作業 | 実行したと報告されている |
grounded_researchの通常呼び出し |
capability probeがtimeoutし、legacy経路へfallback |
| 実機で取得したNDJSONの回答抽出 | _normalize_agy_result()へ直接投入して確認 |
| builder→wrapper→実AGYのstructured経路 | 今回のlive呼び出しでは未確認 |
この区別自体は本文に書かれており、未選択を隠しているわけではありません。ただし、_normalize_agy_result()への直接投入を「end-to-end検証」と呼ぶのは範囲が広すぎます。 「実出力replayによるparser/normalizer検証」と書き分けることを推奨します。
また、grounding_backend == "agy_native_websearch_structured"だけでは、調査結果の成功を確認できません。実装上、attempted_no_citationsでも同じbackend名になります。 回答抽出の成功、引用候補の保持、grounding状態はそれぞれ確認する必要があります。
大きなハーネスではなく、既存テストを接続すればよい
現在のroute-levelテストには、run_delegation()を通す資産があります。しかし、除外されているstructured E2Eテストは、backendや引用を確認する一方で、今回の中心である response_textとresult_surface.summaryをassertしていません。 新しい回答抽出テストはnormalizerへの直接入力です。
推奨は、既存route-levelテストのsubprocess mockとbwrap child-start通知の整合を取るか、その実行境界だけをテストダブルへ置換し、次の少数ケースを追加することです。
| ケース | 確認内容 |
|---|---|
| 改行・引用符を含む正常な回答 | wrapperまで通して本文とsummaryが回答から作られる |
terminalのresult/response欠損・型不正 |
正常な回答抽出と成功扱いをしない |
| tool outputにsourceなし、terminalにURLあり | 本文とcitation候補を保持し、候補だけでgroundedへ昇格させない |
正常な検索語にRESOURCE_EXHAUSTEDあり |
quota失敗と誤認せず候補を保持する |
fixtureの生成も、回答を"%s"でJSON文字列へ直接埋め込む現在のhelperではなく、json.dumps()を使う方が適切です。現helperでは、改行や引用符を含む普通の回答を渡すだけでfixture自体が不正JSONになります。
既知の2件の失敗は、変更前にも再現したと作者・既存reviewerが報告しています。これを根拠なく今回のregressionとして扱うべきではありません。 一方で、今回の修正が通る接続テストを一つ確保することと、環境依存の既知失敗をすべて解消することは別です。
liveの5profile検証を通常CIの必須条件へ追加する必要もありません。#2521自身が、live未確認と静的・mock検証の完了を区別する契約になっています。
4. マージを止めない改善事項
step_indexにはイベントの行番号ではなく、providerの値を使う
現在はenumerate(..., start=1)のindexを、tool recordとsource recordのstep_indexへ格納しています。公式のstep_indexはpayload内のゼロ始まりのstep番号なので、同じ値ではありません。ACTIVEイベントが挟まると、さらにずれます。([Google Antigravity]2)
また、今回の実装は厳密には「step IDによる重複排除」ではなく「ACTIVEイベントの除外」です。観測したACTIVE→DONEには有効ですが、その説明は実装の保証範囲に合わせるべきです。取得できたproviderのstep番号を保持し、取得できないものを行番号で代用しない修正を推奨します。diagnosticの改善であり、欠損時に作業を止める条件は不要です。
SKILL.mdの「tool-callトレース必須」は適用範囲を明確にする
SKILL.mdの早見表には、AGY側は「machine-verifiable tool-call トレース必須」と残っています。一方、#2059とweb-researcher.mdは、provider traceやcounterを最終的な調査成功の条件にしない契約です。
低レベルadapterの診断条件を説明しているのであれば、その旨を明示し、trace不足でも引用候補を保持し、source contentの評価・native fallbackを続けると補足するのがよいです。「トレース必須」を親エージェントが最終停止条件として読める状態は避けたいところです。
AGY 1.1.27のdenied_actionsは、追加ゲートではなく診断へ活用する
公式配布元の最新リリースAPIでも、確認時点の最新版は2026年9月5日公開の1.1.27でした。この版には、headless実行で拒否されたtool操作を通知し、JSON出力へdenied_actionsとして報告する変更が含まれています。PRの実機検証で使用した版と一致します。
公式仕様では、承認できない操作がsoft-deniedされても実行が続き、exit 0になる場合があります。したがって、委譲作業全般の動作確認では、exit 0だけで「必要な操作まで実施できた」と判断しないことが重要です。([Google Antigravity]2)
将来この情報を扱う場合も、既存のwarnings等へ必要な診断を残す程度で十分です。拒否された操作があっても代替手段で目的を達成したケースまで、一律失敗にする必要はありません。
効率面の次候補は、parserの二重解析よりcapability probe
PR報告では、grounded_researchは追加のprovider invocationを1回行い、20秒のprobe timeout後にlegacyへfallbackし、合計86.3秒かかっています。実際の作業効率への影響としては、既存レビューが挙げた軽微な二重parseより、この経路選択のコストを先に調べる価値があります。 ただし、これは報告された測定値に基づく優先順位の判断であり、今回私が測定したものではありません。
CLI invocation自体の変更は#2521のOut of Scopeなので、今回のparser修正を大きく広げず、別の小さな改善として扱うのが妥当です。
維持すべき点と、推奨する着地点
event判別キー・ネストしたpayload・result.responseへの修正は公式のone-shot形式に合っています。実在を確認できない旧形式をテストの都合だけで残さない判断、terminal URLを未検証候補として保持する判断も妥当です。候補を保持することと、その内容がclaimを裏付けると判断することは別なので、ここを再び厳しいprovider trace要件へ戻すべきではありません。([Google Antigravity]1)
また、PR #2517で修正済みのsource ID重複問題とbuilderの出力ファイル指定は、今回の未解決事項として再計上していません。
マージ前の必須修正は、terminal payloadの最小検証と、それを含む既存wrapper経路の回帰テストです。 quota文字列の誤判定も同じ局所的な範囲で修正することを推奨します。実機未確認の部分は未確認として残し、replayをend-to-endと呼ばないよう報告を整えればよく、新しい証跡基盤や常設のlive検証ゲートは不要です。
今回優先すべきなのは、壊れた回答を成功にしないこと、正常な調査結果を誤って捨てないこと、親エージェントにNDJSONの再解析をさせないことです。
Verdict: APPROVESecond consecutive re-review after another automatic
BlockersNone. verdict: APPROVE
reviewed_head_sha: "81e91d3dc96142b7d97075414b06ed846655c662"
blockers: []
warnings:
- "Carried forward from prior approved passes (code unchanged): dual-lens clean-room review performed in a single pass rather than two separate reviewer instances."
- "Carried forward from prior approved passes (code unchanged): minor redundant reparse call in _normalize_agy_result() for the grounded_research profile — non-blocking style note." |
|
推奨は、コメント #5558046284 をそのまま今回の 特に重要なのは、対象コメントが 修正範囲もかなり明確です。マージ前必須なのは、成功 terminal の また、レビューコメントが評価した head は Claude の現行 prompting guidance でも、実際に変更してほしい場合は「提案ではなく実装する」と明示し、独立した作業やレビューは SubAgent に明確に委譲する方が安定します。 ([Claude Platform Docs]1) 以下を auto mode の対話 Claude Code にそのまま貼る想定です。 PR #2527 / Issue #2521 について、以下の OWNER review comment を最新の fix_delta として 対象: このセッションでは、実装・検証・レビュー・branch update・CI確認・PR hygiene・再レビューを、merge を実行する直前まで人間の追加承認なしで自律的に進めてください。 今回のユーザー指示は、上記 OWNER ただし、repository の normative contract が定める genuine hard stop、実 Git conflict、secret/protected-path gate、解決不能な権限エラー、または merge 操作そのものは勝手に迂回しないでください。 1. Orchestration
実装は SubAgent を起動したら、その SubAgent が terminal state になるまで必ず待ってください。 SubAgent が実行中なのに、その結果を推測して次の Step へ進んではいけません。並列に起動した SubAgent がある場合も、必要な全 SubAgent の完了結果を回収してから判定してください。最終報告時にも background / pending の SubAgent を残さないでください。 通常の実装判断、テスト追加、局所的な refactor、commit、push、PR body 更新、current-head re-review、CI 再確認について私へ確認を求めないでください。repository / Issue / PR / code / test から解決可能な曖昧さは自分で調査して決めてください。 2. Current state を live に再取得する作業開始時に PR #2527、Issue #2521、対象 review comment、現在の PR head SHA、base SHA、Draft 状態、mergeability、review/comments、required CI を live に再取得してください。 過去の review は reviewed head に束縛してください。 対象コメントは main drift だけが入っている場合も、repository の 3. 今回のマージ前必須 fix_deltaまず review comment の Finding 1 と Finding 2 を実装対象としてください。 Finding 1 は 成功 terminal event について、terminal の個数・位置だけでなく、親へ回答を返すために必要な最小 payload を検証してください。 少なくとも成功 terminal では、nested
一方、AGY 自体が failure を返した terminal については、単に answer がないことだけで stream syntax malformed と決めつけないでください。process execution status、provider terminal status、stream parser validity、answer availability は可能な限り独立した diagnostics として扱い、Issue #2521 の AC7 を壊さないでください。 structured answer を正常に抽出できないのに raw NDJSON 全体が 既存 fallback policy 全体を大きく再設計する必要はありません。今回塞ぐべきなのは、「壊れた structured terminal を正常 structured answer と認識し、その結果 NDJSON が成功回答になる」経路です。 Finding 2 は structured stream 全体の raw stdout に対する structured route では quota failure 判定を、実際に失敗した execution / terminal error の構造化情報など、failure として意味を持つ場所へ限定してください。 途中の tool error があっても、provider が別手段で最終回答に成功している場合まで一律 failure にしないでください。 既存 legacy route の互換性を不用意に変更せず、structured route の false positive を局所的に直すことを優先してください。 4. Regression tests新しい大規模 harness や persistent evidence infrastructure は作らず、既存テスト資産へ最小限追加してください。 正常 answer fixture の生成では JSON 文字列を手組みで 少なくとも wrapper / route まで意味のある境界で、次を検証してください。 正常な terminal tool-derived source がなく terminal answer に URL だけある場合、citation candidate は保持されるが candidate だけで 正常な検索 query や回答本文に 実際の quota failure を表す既存の正当なケースがあるなら、それは引き続き quota failure と判定されることも確認してください。 5. Scope discipline今回の REQUEST_CHANGES を解消するために必要な局所修正を優先してください。 review comment の non-blocking 項目である 特に capability probe / CLI invocation logic は Issue #2521 の Out of Scope を維持してください。 新しい persistent ledger、receipt、provenance harness、live-E2E framework、CI mandatory live-provider gate は追加しないでください。 PR #2517 ですでに解消済みの source ID 重複問題や builder output-file 問題を再度この PR の blocker として計上しないでください。 6. VerificationIssue #2521 の live body を canonical contract として再取得し、Allowed Paths と literal Verification Commands を使用してください。 変更後は少なくとも Issue に記載された 既知の ただし「pre-existing」という過去コメントだけを盲信せず、今回の変更によって failure signature が変化した場合は調査してください。 live AGY が利用可能なら Issue contract に従って read-only representative verification を実行して構いませんが、外部条件で structured live route を通せなかった場合は real AGY NDJSON を 7. Review loop実装 SubAgent 完了後に test-runner を起動し、完了を待って current-head verification result を取得してください。 verification が blocking なら findings を implementation-worker へ fix_delta として返し、再実装してください。 verification が通ったら current-head gate を再評価してから
reviewer の head SHA が変わったら、それ以前の test/review verdict を stale として current head で取り直してください。 branch が BEHIND なら canonical SubAgent discovery が一時的に失敗した場合も、impl-review-loop が定義する bounded live-reload / fresh runtime recovery を先に試し、即座に私へ確認を返さないでください。 8. PR body と報告の整合修正後、PR body の Summary、Checks、AC table、verification evidence を actual current implementation と current-head verification に合わせて更新してください。 特に structured live route が選択されなかった実行を structured E2E PASS と表現しないでください。 今回追加した terminal payload validation と quota false-positive regression test を、対応する AC / review-fix evidence として記載してください。 過去 head の test 数・SHA・CI 状態を current-head result として残さないでください。 9. 終了地点目的は「コードを書いた」で終了することではありません。 current head について implementation complete、Issue Verification Commands pass または contract 上許容された明示的 unverified、Allowed Paths OK、required CI green、fresh pr-reviewer PR が Draft であることだけが merge の残障害になり、repository workflow 上 ただし PR を merge してはいけません。auto-merge も enable してはいけません。 最終的に「次に人間が行う実質的な操作が merge 判断だけ」の状態で停止してください。 最終報告では、current head SHA、実施した fix、実行した verification と結果、fresh reviewer verdict、required CI 状態、mergeability、残 warnings、未検証事項、そして「merge は未実行」であることを簡潔に示してください。 途中で routine confirmation を求めず、可能な作業は現在のセッション内で最後まで実行してください。 このプロンプトなら、今回の |
OWNER REQUEST_CHANGES(PR #2527 レビュー head 88eff0e)の blocking Finding 1・2 を解消する。 - parse_agy_stream_json_stream(): terminal `result` が非objectの場合と、 status:"SUCCESS" なのに response が欠落/非stringの場合を invalid として fail-closeする(terminal_result_payload_not_an_object / terminal_result_success_missing_response)。ERROR等の非SUCCESS terminalは 引き続きresponse無しでvalid(AC7: execution statusとparser-validityは独立)。 - _build_agy_structured_stream_json_grounded_research_metadata(): quota判定を raw stdout全体への無条件regexから、parse済みterminalの失敗フィールドのみへ scopeし直した。検索クエリや成功回答本文にRESOURCE_EXHAUSTED等の文字列が 含まれるだけでquota failureに誤分類しないようにする。 - テストfixture生成helperを"%s"文字列埋め込みからjson.dumps()ベースへ置換し、 改行・引用符・バックスラッシュを含む回答でも正しいNDJSONになるようにした。 - 上記2件のFindingおよびfixture改善に対する回帰テストを追加した。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Summary
preflight_agy.py::parse_agy_stream_json_stream()が現行公式 AGY stream-json 形式(event判別キー、step_update/resultペイロードのネスト、terminal answer はresult.response)を解析できない不整合を修正した。旧来のtype直下キー形式は実在バージョンで確認できなかったため互換 shim として残さず(AC4)、旧形式が守っていた malformed/missing-terminal/duplicate-terminal 検査の意味は現行形式の fixture へ移植した。run_gemini_headless.py::_normalize_agy_result()が、structured parsing 成功時(agy_structured_output_usedtrue かつ parserstatus: "valid")にresponse_text/result_surface.summaryを raw stdout(NDJSON 全体)ではなく terminalresult.responseから構築するよう修正した(AC5/AC6)。structured output が利用できない/解析失敗した場合の fallback は変更していない。_build_agy_structured_stream_json_grounded_research_metadata()に、tool_info.outputに構造化 source がない場合の terminal answer 内 URL の citation-candidate 抽出を追加した。候補抽出はgrounded/supportedへの自動昇格をせず、citation_candidates_unverified(legacy route と同じ既存の値)として扱う(AC8/AC9)。agy1.1.27、認証済み)で取得した real stream-json サンプルから、RECOGNIZED_WEB_TOOL_NAMESに実際に観測された tool 名(search_web/read_url_content/open_browser_url)を追加した(既存名は互換のため保持)。preflight_agy.pyの parser に、同一step_indexがstate: "ACTIVE"→"DONE"の順で複数回報告される実機挙動を二重カウントしないガードを追加した。Review Fix(OWNER REQUEST_CHANGES 対応。issuecomment-5558046284、レビュー対象 head
88eff0ec79e25a90a1571b63c5eac44b9dce3e17。今回のコミットは head59a3e76b99e2d21205e359ac2470c6af70f6db94)blocking の Finding 1・Finding 2 のみを対応した(
step_indexdiagnostics、SKILL.md trace 文言、AGY 1.1.27denied_actionsdiagnostics、capability probe 効率化の non-blocking 指摘はスコープ外として未着手)。Finding 1(P2・マージ前必須): 壊れた terminal を
validと判定し、回答抽出失敗でも成功扱いになり得るparse_agy_stream_json_stream()の terminal 検証を強化した(result["status"] = "valid"を設定する直前、exactly-one-terminal 検査の後):resultフィールドが dict でない場合 →status: "invalid"、reason_code: "terminal_result_payload_not_an_object"。result.status == "SUCCESS"かつresponseが欠落/非string の場合 →status: "invalid"、reason_code: "terminal_result_success_missing_response"。result.statusが"SUCCESS"以外("ERROR"や status フィールド自体が無い場合を含む)はresponseの存在を要求しない(AC7: execution status と parser-validity の独立性は維持)。この修正により、
_build_agy_structured_stream_json_grounded_research_metadata()の既存分岐(stream_parse.get("status") != "valid"→grounding_status: "attempted_no_web_tool_call"/grounding_failure_class: "agy_web_grounding_stream_json_malformed")が自動的に発火し、_normalize_agy_result()側のtop_level_okもgrounded_research_evidence.grounding_failure_classが non-null になることでFalseになる。追加調査(Finding 1 の指示に基づく):
--output-format stream-jsonが実際にプロダクションで付与されるのは_run_agy()内でtool_profile == GROUNDED_RESEARCH_PROFILEの場合のみであることをコードを読んで確認した(run_gemini_headless.pyの_run_agy()内、output_format変数の唯一の代入元)。したがって「壊れた structured terminal が non-grounded_research profile でtop_level_ok: trueのまま raw NDJSON を成功回答として返す」という経路は、実際の_run_agy()呼び出し経路には存在しない(direct/mocked caller がagy_structured_output_used=Trueを自己申告するテスト経路でのみ理論上到達可能)。よってrun_gemini_headless.py側にこれ以上の追加修正は行っていない。この結論はtest_normalize_agy_result_broken_success_terminal_never_reported_ok(grounded_research profile でのok: Falseを確認)で裏付けている。Finding 2(P2・既存不具合の局所修正): quota 判定が raw stdout 全体への正規表現一発判定で誤検知する
_build_agy_structured_stream_json_grounded_research_metadata()内の quota 判定を、_preflight_agy.parse_agy_stream_json_stream()によるパース処理の後に移動し、terminal event のresultオブジェクトのうちstatusが"SUCCESS"でない場合の、status以外の文字列フィールド(error/message等の失敗理由に相当するフィールド)に対してのみ_QUOTA_EXHAUSTED_REを適用するよう変更した。legacy route(_build_agy_grounded_research_metadata())は変更していない。既存の関数シグネチャ(stdoutとhook_eventsのみ)は変更していない。Regression Tests(既存テスト資産への追加。新規 harness は作成していない)
_make_stream_json_stdout()(test_agy_structured_output.py)/_live_format_stream_json_stdout()(test_preflight_agy.py)を"%s"文字列埋め込みからjson.dumps()ベースへ置換した。test_preflight_agy.pyに追加:test_parse_agy_stream_json_stream_rejects_non_object_terminal_result_payload/..._rejects_missing_terminal_result_field/..._rejects_success_status_without_response/..._rejects_success_status_with_non_string_response/..._non_success_status_stays_valid_without_response。test_agy_structured_output.pyに追加:test_structured_grounded_metadata_broken_success_terminal_fails_closed_not_grounded(OWNER repro の end-to-end 再現)/test_normalize_agy_result_broken_success_terminal_never_reported_ok(ok: False確認)/test_normalize_agy_result_response_text_with_newlines_and_quotes_round_trips/test_normalize_agy_result_response_text_with_multiline_answer_preserved_in_full/test_structured_grounded_metadata_quota_string_in_successful_query_not_misclassified(Finding 2 誤検知回帰)/test_structured_grounded_metadata_genuine_quota_failure_terminal_still_classified(genuine quota failure の非退行確認)。test_structured_grounded_metadata_extracts_terminal_answer_url_as_candidate_only(URL-only candidate は昇格しないこと)は Regression Test 5 の要件を既に満たしていたため重複追加していない。Checks
uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_preflight_agy.py -q— head59a3e76b99e2d21205e359ac2470c6af70f6db94で 52 passeduv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_structured_output.py -q -k "not test_run_agy_supported_capability_end_to_end_uses_structured_parser and not test_run_agy_legacy_citations_without_provenance_are_candidates_for_native_quality_check"— head59a3e76b99e2d21205e359ac2470c6af70f6db94で 50 passed, 2 deselecteduv run ruff check(変更 4 ファイル:preflight_agy.py/run_gemini_headless.py/test_preflight_agy.py/test_agy_structured_output.py。全て[]=checks passed)pnpm typecheck/pnpm lint/pnpm test/pnpm build— 本 Issue の Allowed Paths は Python スクリプト・テストのみで TypeScript/フロントエンド変更を含まないため、Issue 本文 Verification Commands は pytest コマンドを正本とするSchema Consumer Inventory
N/A —
Schema Change Applicability: not_schema_change(詳細は下記セクション参照)。既存delegation_result/v1/grounded_research_evidenceのフィールド集合・型を変更していない。新しいreason_code文字列値(terminal_result_payload_not_an_object/terminal_result_success_missing_response)を追加しているが、既存reason_codeフィールドのバリエーション追加であり、フィールド自体の追加・削除・型変更ではない。AC 充足状況まとめ(AC1からAC16まで。★は今回の fix_delta で更新した AC)
eventキーによるイベント種別判別preflight_agy.py::parse_agy_stream_json_stream()、test_preflight_agy.py::test_parse_agy_stream_json_stream_accepts_current_event_key_envelopestep_update/step_update.tool_infoの正しいネスト読み取りtest_parse_agy_stream_json_stream_reads_tool_info_under_step_update_nestingtest_parse_agy_stream_json_stream_missing_terminal_result_current_format/..._duplicate_terminal_result_current_format/..._rejects_non_object_terminal_result_payload/..._rejects_missing_terminal_result_fieldtype-key 形式を互換 shim にしない・意味を移植(+ terminal 成功判定の意味を厳密化)test_parse_agy_stream_json_stream_rejects_legacy_type_key_top_level、test_parse_agy_stream_json_stream_never_accepts_legacy_type_key_envelope、..._rejects_success_status_without_response、..._rejects_success_status_with_non_string_responseresponse_textが terminalresult.responseから構築されるrun_gemini_headless.py::_normalize_agy_result()、test_normalize_agy_result_response_text_terminal_result_not_raw_stdout、test_normalize_agy_result_response_text_with_newlines_and_quotes_round_tripsresult_surface.summaryが answer text から導出されるsummaryも検証)test_parse_agy_stream_json_stream_non_success_status_stays_valid_without_response(terminalstatus: "ERROR"はresponse無しでもvalid)、test_normalize_agy_result_response_text_terminal_result_not_raw_stdoutでexit_code不変を確認test_structured_grounded_metadata_tool_correlated_source_still_promotes_to_groundedtest_structured_grounded_metadata_extracts_terminal_answer_url_as_candidate_only、test_structured_grounded_metadata_no_citations_anywhere_stays_no_citationsweb_tool_call_count等は diagnostics のみ)_run_agy()はtool_profile == grounded_researchかつ capabilitysupportedの場合のみ--output-format stream-jsonを付与(Out of Scope: CLI invocation ロジック自体は変更していない)。他 4 profile は常に非 structured(legacy テキスト)経路test_normalize_agy_result_response_text_terminal_result_not_raw_stdout、test_normalize_agy_result_broken_success_terminal_never_reported_ok、test_structured_grounded_metadata_quota_string_in_successful_query_not_misclassified、test_structured_grounded_metadata_genuine_quota_failure_terminal_still_classified.github/ci/python-test-plan.jsonに変更なし。手動記録のみPre-existing Test Failure Baseline(現行 head
59a3e76b99e2d21205e359ac2470c6af70f6db94で独自再確認)test_agy_structured_output.pyの以下 2 件は、本 fix_delta 適用前(git stashで本コミットの変更を退避)でも同一のエラーで失敗することを現行 worktree で再確認した(bwrap がこの環境に存在するため、_run_agy()の bwrap-sandboxing 分岐がテストの mockedsubprocess.run()を「未確認の bwrap child start」とみなしcompleted.returncode=1の合成結果へフォールバックする。AGY stream-json のevent/typeキー形式とは無関係):test_run_agy_supported_capability_end_to_end_uses_structured_parser(assert result["ok"] is Trueで失敗。exit_code: 1,agy_invocation_attempted: false)test_run_agy_legacy_citations_without_provenance_are_candidates_for_native_quality_check(KeyError: 'grounded_research_evidence')今回の Finding 1/2 修正の前後でこの 2 件の failure signature(アサーション失敗箇所・例外種別)に変化がないことを確認済み。AC12 の VC どおり
-kで明示的に除外して実行し、上記「Checks」節のとおり残り全件 PASS を確認した。PR body に記載されている以下 2 件の既存 pre-existing failure baseline も、現行 head で再確認した(いずれも今回変更したファイルとは無関係な既知の環境依存 failure。failure signature に変化なし):
test_agy_provider.py::test_ac7_agy_github_research_dispatches_to_e2e_route—GH_TOKEN不在環境でのexit_code分岐(assert result["exit_code"] in (0, 77)で1により失敗)。git stashによる変更前後の同一再現を確認済み。test_run_gemini_headless_live_trial.py::test_ac8_local_asset_research_full_route_fixed_live_trial_plan—codex_cliruntime がrun_agent_provider_route_smoke.py --runtimeの choice に無い(invalid choice: 'codex_cli')ことに起因するproducer_nonzero_exit、およびclaude_coderuntime 側のvalidation_failedによる live trial 失敗。現行 head で実行し、同一の failure signature を確認済み。過去の live 検証記録(前回レビューサイクル、head
88eff0ec79e25a90a1571b63c5eac44b9dce3e17時点。今回の fix_delta では再実行していない — 参考情報として残す)以下は前回のレビューサイクル(PR #2527 初回実装、head
88eff0ec)で実施した認証済みagy1.1.27 による 5-profile 代表検証の記録であり、現行 head (59a3e76b) の結果ではない。今回の fix_delta は Finding 1/2 の局所修正のみで、grounded_research の structured route 選択条件自体(_run_agy()の capability probe / CLI invocation ロジック)は変更していないため、下記の live 挙動自体に変化は生じていないと考えられるが、再実行による現行 head での再検証は行っていない点に留意すること。no_toolsproposal_onlylocal_asset_researchSKILL.mdfrontmatter のname値を正しく読み取ったgithub_research--gh-issueフラグは使えず、プロンプト文中に issue 番号を含めた)grounded_researchinconclusiveに留まったため legacy テキスト経路(agy_native_websearch)にフォールバックした。pre-existing な probe timeout 値のチューニング不足であり、本 Issue の stream-json 形式修正とは無関係(別 Follow-up 候補)15.2.0と citation URL を返したgrounded_researchの structured route自体は、当時実機で取得した実際の NDJSON ストリーム(search_web呼び出し2回を含む、state: "ACTIVE"→"DONE"の重複あり)を_normalize_agy_result()に直接投入する形で end-to-end 検証していた(fixture ではなく実機出力そのもの):response_textが raw NDJSON ではなく terminalresult.response("15.2.0\n")になることを確認(AC5/AC6)。tool_call_recordsが 2 件(実際の検索回数と一致、ACTIVE/DONE の二重カウントなし)であることを確認。grounding_backendがagy_native_websearch_structuredになることを確認。Safety Claim Matrix
test_structured_grounded_metadata_extracts_terminal_answer_url_as_candidate_only/test_structured_grounded_metadata_tool_correlated_source_still_promotes_to_grounded/test_structured_grounded_metadata_no_citations_anywhere_stays_no_citationsstatus: "SUCCESS"の実回答が無い)は成功回答として parent へ渡らないtest_structured_grounded_metadata_broken_success_terminal_fails_closed_not_grounded/test_normalize_agy_result_broken_success_terminal_never_reported_ok。検証は grounded_research profile 経由(_run_agy()が structured output を付与する唯一の profile)で実施test_structured_grounded_metadata_quota_string_in_successful_query_not_misclassified/test_structured_grounded_metadata_genuine_quota_failure_terminal_still_classifiedSchema Change Applicability
not_schema_changedelegation_result/v1/grounded_research_evidenceのフィールド集合・型は変更していない。parse_agy_stream_json_stream()の戻り値スキーマ(reason_codeフィールド)に新しい値バリエーション(terminal_result_payload_not_an_object/terminal_result_success_missing_response)が追加されたが、フィールド自体の追加・削除・型変更ではない。grounding_statusが structured route でも既存 legacy route と同じcitation_candidates_unverified値を取り得る点も同様に既存の値バリエーションの範囲内。consumer(.claude/agents/web-researcher.md)は個別のgrounding_status/reason_code値ではなく一般カテゴリ(citation extraction failure / evidence quality 不足)で判断する設計であることを確認済み。Notes
preflight_agy.py/run_gemini_headless.py/tests//SKILL.md)内で完結。SKILL.mdは今回の fix_delta でも具体的な不整合が確認されなかったため変更していない。agyCLI での追加実機検証は実施していない(Finding 1/2 は構造化データのハンドリングロジックの修正であり、実機出力形式自体への依存を追加していないため、既存の live 検証記録が引き続き有効と判断した)。RECOGNIZED_WEB_TOOL_NAMESへのsearch_web/read_url_content/open_browser_urlの追加は Current Validated Scope(_build_agy_structured_stream_json_grounded_research_metadata()が消費する定数)内の修正であり、Allowed Paths 外への変更は発生していない。