Skip to content

実装: AGY PreToolUse hook eventsをisolated workspace削除前にdelegation_result/v1へ配線し、grounded_researchのtool呼び出し不発を再調査する #1752

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1265"
goal_ref: "AntigravityCLI (agy) provider が fan-out orchestrator の並列実行先として実運用可能であることを実機検証する(#1494)"
change_kind: code

Parent Issue

#1265

Parent Goal Ref

Current Validated Scope

  • .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py 内の _normalize_agy_result() が delegation_result/v1 へ agy_provenance_hook_events / agy_provenance_hook_load_error を含めるよう修正する
  • isolated workspace 内で grounded_research の search_web / read_url_content 呼び出しが発生しない原因を再調査し、対処または references/ への文書化を行う
  • 上記の hermetic 回帰テストと redaction テストを追加する

Remaining Parent Gaps

Source

#1494(Antigravity CLI (agy) provider 実機 fan-out E2E 検証、research issue)の最終 live E2E fan-out 実行 6 回目の試行中に control-plane が独立確認した実装 gap。以下は 2026-07-25 時点で git grep -n により実ファイル・実行番号・実関数名を確認済み。

Background

.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py の _run_agy()(2445 行目、docstring 2469-2480 行目参照)は、tool_profile が agy_permission_policy.ALLOWED_PROFILES に含まれる場合(isolated workspace 分岐)と含まれない場合(tempfile.TemporaryDirectory フォールバック分岐)の両方で、_agy_provenance.load_hook_events(hook_log_path)(2536 行目 / 2594 行目)を呼び出し <workspace>/_provenance/hook_events.jsonl から PreToolUse hook events を読み取り、completed.agy_provenance_hook_events(2543 行目 / 2601 行目)として subprocess.CompletedProcess オブジェクトへ動的属性として付与している。この読み取り自体はワークスペース削除(isolated workspace 分岐: finally: shutil.rmtree(workspace.workspace_dir, ...) 2547 行目 / フォールバック分岐: with tempfile.TemporaryDirectory(...) の context manager 終了)より前に発生しているため、メモリ上の値としては破棄されていない。

しかし、_run_agy() の呼び出し元である _run_delegation_core()(4402 行目で _run_agy(prompt_text, timeout_sec_agy) を呼び出し)はこの戻り値を _normalize_agy_result()(2881 行目、4525 行目で呼び出し)へ渡すが、_normalize_agy_result() の 3 つの return 分岐(exit != 0: 2908 行目 / stdout 空: 2937 行目 / 成功: 2980 行目)はいずれも completed.agy_provenance_hook_events / completed.agy_provenance_hook_load_error を読み取らず、delegation_result/v1 の返り値へ一切含めない。加えて _run_agy() はワークスペース自体(_provenance/hook_events.jsonl を含む)を削除するため、run_delegation() の戻り値以外に事後的にディスクから hook events を回収する手段もない。

結果として、.claude/skills/gemini-cli-headless-delegation/scripts/build_fanout_evidence_bundle.py の --hook-events-file(348 行目 hook_events_files 引数、371 行目 _load_evidence_map(hook_events_files, jsonl=True))へ渡す JSONL ファイルを、run_delegation() の呼び出し元が組み立てる手段が構造的に存在しない。.claude/skills/gemini-cli-headless-delegation/scripts/validate_agy_fanout_e2e_evidence.py の _predicate_hook_provenance()(562 行目)が読む child.get("hook_events", []) はこの bundle 由来のフィールドであるため、predicate_07(594 行目 grounded_research_has_canonical_hook_event)・predicate_08(608 行目 grounded_research_executes_search_web)・predicate_10(641 行目 hook_conversation_transcript_child_result_correlate)は、grounded_research が実際に成功していても常に FAIL する。

さらに #1494 の 6 回目試行では、_run_agy() が --model claude-sonnet-4-6(#1749/#1751 で実装済み)を正しく付与していることを確認済みの状態でも、grounded_research subtask の search_web 呼び出しが 5 回連続(本日実施分)で発生しなかった(web_tool_call_count: 0)。#1749 の PR #1751 では「live 再テストで実際に search_web 呼び出しと正当な引用 URL を確認済み」とされていたが、この再テストが isolated workspace(agy_permission_policy.materialize_isolated_agy_workspace() 経由)ではなく非隔離環境で行われていた可能性があり、isolated workspace 固有の要因(PreToolUse hook wrapper 自体が headless tool 実行を阻害している可能性、または .agents/hooks.json / workspace-scoped permission 設定と実際の tool 呼び出し許可の相互作用の不整合)を切り分けて再調査する必要がある。

Outcome

agy_provenance_hook_events / agy_provenance_hook_load_error が delegation_result/v1 の返り値へ正しく含まれるようになり、run_delegation() の呼び出し元が hook events を bundle 化できる状態になる。また、isolated workspace 内で grounded_research の search_web / read_url_content 呼び出しが実際に発生しない原因について、再調査の結果(対処、または対処不能と判明した場合の具体的原因・再現条件・次のアクション)が references/ 配下に記録された状態になる。

In Scope

  1. _normalize_agy_result()(2881 行目)の 3 つの return 分岐すべてに agy_provenance_hook_events(completed から取得した list、存在しない場合は空 list)と agy_provenance_hook_load_error(completed から取得した str|None)を追加する。
  2. _run_agy() 自体(ワークスペース削除タイミング)には変更を加えない(hook events は既に削除前にメモリへロード済みのため)。ただし _normalize_agy_result() が getattr(completed, "agy_provenance_hook_events", []) のように安全にフィールドへアクセスすることを保証する(_run_agy を経由しないテスト用 CompletedProcess に属性が存在しない場合でも例外を送出しない)。
  3. isolated workspace 内で grounded_research の tool 呼び出しが発生しない原因を再調査する。以下を確認する:
    • workspace-scoped .agents/hooks.json / .antigravity/settings.json の生成内容が search_web / read_url_content を実際に許可しているか(agy_permission_policy.py の GROUNDED_RESEARCH_ALLOWLIST との整合)を静的に確認する
    • PreToolUse hook wrapper スクリプト自体が agy CLI の tool 実行を待機・ブロックしていないかを静的に確認する
    • 上記静的確認で原因が特定できない場合は、対処不能・追加の live 再現検証が必要である旨と再現条件を references/ へ明記する(本 Issue のスコープでは live 実行は行わない。Runtime Verification Applicability 参照)
  4. 上記 1-3 の hermetic 回帰テストを .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py(新規)に追加する。_run_agy の呼び出しはモック化し、実 agy バイナリ・実ネットワークアクセスを必要としない。
  5. hook events の内容(toolCall.args 等)に認証情報・transcript 生データが含まれず、_normalize_agy_result() を経由しても redaction 状態が変わらないことを検証する回帰テストを同ファイルに追加する。

Out of Scope

Acceptance Criteria

  • AC1: _normalize_agy_result() の成功分岐(exit_code=0, stdout 非空)が返す delegation_result/v1 dict に、completed.agy_provenance_hook_events の値がそのまま agy_provenance_hook_events キーとして含まれる。
  • AC2: _normalize_agy_result() の exit_code != 0 分岐が返す dict にも agy_provenance_hook_events / agy_provenance_hook_load_error キーが含まれる(fail-closed 診断のため、失敗時も hook 証跡を捨てない)。
  • AC3: _normalize_agy_result() の stdout 空分岐が返す dict にも agy_provenance_hook_events / agy_provenance_hook_load_error キーが含まれる。
  • AC4: completed オブジェクトに agy_provenance_hook_events 属性が存在しない場合(既存の直接呼び出し・モックテスト互換)でも _normalize_agy_result() が例外を送出せず、agy_provenance_hook_events: [] を返す。
  • AC5: isolated workspace 内 grounded_research tool 呼び出し不発の再調査結果が .claude/skills/gemini-cli-headless-delegation/references/grounded-research-isolated-workspace-investigation.md(新規)に、## Findings と ## Next Action の見出しを含めて記録されている。
  • AC6: hook events の redaction テストが、toolCall.args に sk- や ya29. のような資格情報様パターンを含むダミー event を投入した場合に _normalize_agy_result() の返り値からその値がそのまま漏出しないこと(もしくは redaction 済みであること)を確認する。

Verification Commands

# _normalize_agy_result() 成功分岐が hook events を伝播する
# AC1
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_success_propagates_hook_events -v

# exit_code != 0 分岐でも hook events を伝播する
# AC2
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_nonzero_exit_propagates_hook_events -v

# stdout 空分岐でも hook events を伝播する
# AC3
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_empty_stdout_propagates_hook_events -v

# agy_provenance_hook_events 属性欠落時に例外を送出せず空 list を返す
# AC4
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_missing_attribute_defaults_to_empty_list -v

# 再調査結果ドキュメントが存在する
# AC5
# baseline-expect: fail
$ test -f .claude/skills/gemini-cli-headless-delegation/references/grounded-research-isolated-workspace-investigation.md

# hook events の redaction テスト
# AC6
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_hook_events_redaction_no_credential_leak -v

Allowed Paths

  • .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py
  • .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py(新規)
  • .claude/skills/gemini-cli-headless-delegation/references/grounded-research-isolated-workspace-investigation.md(新規)
  • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md(Result Contract セクションへの追記のみ)

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • (追加)isolated workspace 内 tool 呼び出し不発の原因調査に実 agy CLI の live 実行が必須と判明した場合、または _run_agy() のワークスペース削除タイミング自体の変更が必要と判明した場合

Required Skills

なし

Required Design References

  • .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md
  • .claude/skills/gemini-cli-headless-delegation/references/result-surface.md
  • docs/dev/agent-skill-boundaries.md

Scope Delta(該当時のみ記載)

N/A

Runtime Verification Applicability

本 Issue の変更対象はワークフロー文書・スクリプトのみです。ゲームの実行時動作には影響しません。

decision: not_applicable
reason: "Workflow documentation and script changes only. No runtime game behavior changed."

Delivery Rule

Notes for Reviewer

Scope Collision (C1) Preflight

check_issue_overlap.py の結果: decision: overlap_requires_comment / policy_class: C1 / reason_code: allowed_paths_overlap。

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jul 25, 2026
  2. squne121 commented on Jul 25, 2026

    @squne121
    OwnerAuthor

    Scope Collision (C1): related_issue=#1736, #1692, #258, #29, #28, #27, #14; overlapping_paths=.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py. non_conflict_reason: 各候補は run_gemini_headless.py 内の異なる関数・異なる関心事を扱っており、本 Issue が対象とする _run_agy()/_normalize_agy_result() の hook events 伝播とは非衝突(詳細は Issue 本文 ## Scope Collision (C1) Preflight 参照)。

  3. squne121 commented on Jul 25, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-25T13:44:59Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1752
      body_sha256: "sha256:15202d04f141fb9423b132cf971c3fc460e17a054f79cdf6941e50d8064a76c9"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        product_spec_check: {"schema":"product_spec_check/v1","applicability":"applicable","decision":"pass","triggers":{"docs_product_allowed_paths":false,"tasks_md_mentioned":false,"specify_artifact_mentioned":false,"generated_task_mentioned":false,"product_spec_context_present":false,"machine_readable_contract_present":true},"conditions":{"docs_product_requires_spec_evidence":{"status":"pass","evidence":[]},"tasks_md_not_direct_source":{"status":"pass","evidence":[]},"specify_not_canonical":{"status":"pass","evidence":[]},"diff_first_rationale_present":{"status":"pass","evidence":[]},"generated_task_trace_present":{"status":"pass","evidence":[]},"task_dependencies_materialized":{"status":"pass","evidence":[]}},"blocked_reasons":[],"body_sha256":"sha256:15202d04f141fb9423b132cf971c3fc460e17a054f79cdf6941e50d8064a76c9","source_provenance":{"source_type":"github_api","body_file":null}}
        vc_preflight:
          decision: pass
          classifications: [{"ac":"AC1","line":3,"raw_command":"uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_success_propagates_hook_events -v","command_hash":"sha256:c93c25a26219bf63dd375de53bd92aad9c70de9bcbcc983bfb2fbdfe53e98834","execution_key_hash":"sha256:5b3027e8413eeffddabfda2bcac758af75730511201d9e1a3fcf95476e3b8f27","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["============================= test session starts ==============================","platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /home/squne/projects/LOOP_PROTOCOL/.venv/bin/python","cachedir: .pytest_cache","rootdir: /home/squne/projects/LOOP_PROTOCOL","configfile: pyproject.toml","plugins: xdist-3.8.0","collecting ... collected 0 items","============================ no tests ran in 0.01s ============================="],"stdout_truncated":false,"stdout_original_line_count":10,"stderr_head":["ERROR: file or directory not found: .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":191,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC2","line":7,"raw_command":"uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_nonzero_exit_propagates_hook_events -v","command_hash":"sha256:0f65d1b5073c30015f99e4d0bd3a8ab126cb3b82d77536b82c1fa5fe51b7556e","execution_key_hash":"sha256:6a27bff7abe0c4c1398d25d50b9c30fe795a141ebc31a2164d50676e7ec52619","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["============================= test session starts ==============================","platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /home/squne/projects/LOOP_PROTOCOL/.venv/bin/python","cachedir: .pytest_cache","rootdir: /home/squne/projects/LOOP_PROTOCOL","configfile: pyproject.toml","plugins: xdist-3.8.0","collecting ... collected 0 items","============================ no tests ran in 0.01s ============================="],"stdout_truncated":false,"stdout_original_line_count":10,"stderr_head":["ERROR: file or directory not found: .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":181,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC3","line":11,"raw_command":"uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_empty_stdout_propagates_hook_events -v","command_hash":"sha256:a2dcaf8b7c251e7c2dd3945bfa047a59bbcc912f7cb6e12d8a4f06f1599f93f6","execution_key_hash":"sha256:7f1e56b8dabfab19c48c668d932434ea106c93c901b596be1f3510912004d280","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["============================= test session starts ==============================","platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /home/squne/projects/LOOP_PROTOCOL/.venv/bin/python","cachedir: .pytest_cache","rootdir: /home/squne/projects/LOOP_PROTOCOL","configfile: pyproject.toml","plugins: xdist-3.8.0","collecting ... collected 0 items","============================ no tests ran in 0.01s ============================="],"stdout_truncated":false,"stdout_original_line_count":10,"stderr_head":["ERROR: file or directory not found: .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":207,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC4","line":15,"raw_command":"uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_normalize_agy_result_missing_attribute_defaults_to_empty_list -v","command_hash":"sha256:af5244129cd7dc55837b2cb5ea70595d80b031e606af0e299702a4a3991d2a22","execution_key_hash":"sha256:29b8066eb969eb2bd11fccb89a316abd636f33feac9b7eb1cf8eefa11206bec7","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["============================= test session starts ==============================","platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /home/squne/projects/LOOP_PROTOCOL/.venv/bin/python","cachedir: .pytest_cache","rootdir: /home/squne/projects/LOOP_PROTOCOL","configfile: pyproject.toml","plugins: xdist-3.8.0","collecting ... collected 0 items","============================ no tests ran in 0.01s ============================="],"stdout_truncated":false,"stdout_original_line_count":10,"stderr_head":["ERROR: file or directory not found: .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":184,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC5","line":20,"raw_command":"test -f .claude/skills/gemini-cli-headless-delegation/references/grounded-research-isolated-workspace-investigation.md","command_hash":"sha256:66697930efd9c18102e8122c29d0755f34d7e0897f5159e2ed3c80ca61400539","execution_key_hash":"sha256:eec7f38ca281a87e548b44aed9d4bab9b766b8cdbc4f1b939dac5385803a8a14","runner":"exec","exit_code":1,"classification":"expected_fail","category":"file_not_found_expected","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":[],"stdout_truncated":false,"stdout_original_line_count":1,"stderr_head":[],"stderr_truncated":false,"stderr_original_line_count":1,"runner_env_delta":{},"duration_ms":1,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":"fail","vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":19,"raw":"# baseline-expect: fail"},"strict":null,"repair":null},{"ac":"AC6","line":24,"raw_command":"uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py -k test_hook_events_redaction_no_credential_leak -v","command_hash":"sha256:5b554cdc40020c6ef261036d8f7cf876b997b9349f4a0e5af63590ee92bfc419","execution_key_hash":"sha256:b230037d9af8ea7d1b0186a9de48da17b98f9a4f448eb0aa032031b77a33c631","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["============================= test session starts ==============================","platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0 -- /home/squne/projects/LOOP_PROTOCOL/.venv/bin/python","cachedir: .pytest_cache","rootdir: /home/squne/projects/LOOP_PROTOCOL","configfile: pyproject.toml","plugins: xdist-3.8.0","collecting ... collected 0 items","============================ no tests ran in 0.01s ============================="],"stdout_truncated":false,"stdout_original_line_count":10,"stderr_head":["ERROR: file or directory not found: .claude/skills/gemini-cli-headless-delegation/tests/test_agy_hook_events_propagation.py"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":182,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null}]
      source: ensure_contract_snapshot_auto
      expected_contract_fingerprint: {"issue_number":1752,"contract_source_kind":"issue_comment","contract_source_id":"5078711882","contract_body_sha256":"sha256:15202d04f141fb9423b132cf971c3fc460e17a054f79cdf6941e50d8064a76c9","allowed_paths_normalized_sha256":"f6c5277497ae6cd87ffbd38c0ed0a2ca6540d341c6327695648cc2cb08ca2eae","base_ref":"main","base_sha_at_snapshot":"b2352e973e637d7954aea73408a0fb530f5ab484"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions