Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1265"
goal_ref: "GeminiCLI 委譲版 delegation platform を AntigravityCLI (agy) provider へ段階移行し、機能同等性を達成する"
change_kind: codeParent Issue
Parent Goal Ref
- Goal: GeminiCLI 依存を段階的に縮小しつつ、AGY provider が Gemini 版と同等の delegation platform として機能し、可観測性・テスト密度・認証堅牢性・クォータ制御を備えた状態にする。
- Desired Destination: 導入: Gemini CLI → Antigravity CLI (agy) provider migration: 機能同等性評価と改善計画 #1265 の並列実行評価観点、および 調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 の Acceptance Criteria が要求する「実 AGY プロセスの並列実行」の機械検証可能な証跡基盤が整い、調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 の最終 E2E 検証 PR がこの telemetry を前提に実行できる状態にする。
Current Validated Scope
.claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.py(make_subprocess_runner()/RunnerContext/_run_one()/_journal()closure)に限定した write-capable scope。.claude/skills/gemini-cli-headless-delegation/tests/配下に新規テストファイルを追加する write-capable scope。- 調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 自体は Allowed Paths が
docs/research/pr-1487-agy-fanout-e2e-evidence.mdのみの調査 Issue であり、code 変更は本 Issue で行う契約(#1494 コメント)。
Remaining Parent Gaps
- WebSearch 証跡を AGY stdout 自己申告から実 hook / transcript 由来へ切り替える対応(レビュー Blocker 1)は本 Issue の対象外。別 Issue で扱う。
- Serena live probe の subtask 対応付け(レビュー Blocker 3)、
no_tools/local_asset_researchのプロファイル別 tool deny(レビュー Blocker 4)も本 Issue の対象外。 - 調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 自体の実 AGY・実 Serena・実 WebSearch E2E 証拠収集(最終 closure)は、本 Issue を含む全 implementation Issue のマージ後に別 PR で行う。
Outcome
.claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.py の make_subprocess_runner() が、subprocess.Popen() 成功後にのみ process-start event を、process exit/reap 後に process-exit event を NDJSON journal へ記録するようになり、pid / pgid / started_monotonic_ns / exited_monotonic_ns を用いた overlap 判定関数が実装され、real subprocess integration test で「異なる AGY provider process が実際に区間重複して生存していた」ことを機械検証できる状態になる。既存の subtask_started イベント順序ベースの並列性主張(レビュー Blocker 2 が指摘した誤検証)は、この process lifecycle telemetry に置き換わる。
In Scope
make_subprocess_runner()内でsubprocess.Popen()成功直後に process-start event を journal へ書く(spawn 失敗時は started として記録しない)。proc.wait()完了(reap)直後に process-exit event を journal へ書く。- 各イベントに少なくとも次のフィールドを含める:
schema(journal event の version 識別子)、process_role(delegation_wrapper|provider_cliのいずれか。run_gemini_headless.pywrapper process 自体と、その配下で起動される実 AGY provider process を区別する)、provider(例:agy)、parent_run_id、subtask_id、attempt_id、artifact_stem、pid、pgid、executable(絶対パスではなく basename または public-safe identity)、started_monotonic_ns、exited_monotonic_ns、started_utc、exited_utc、returncode、termination_reason。 process_role: delegation_wrapperはmake_subprocess_runner()が起動するrun_gemini_headless.pywrapper subprocess 自体のイベントとし、process_role: provider_cliは wrapper 配下で実際に起動される AGY provider process(agyCLI 実行)を指すイベントとして区別する。本 Issue では、少なくとも wrapper process(process_role: delegation_wrapper)の lifecycle telemetry を実装し、wrapper がすでに保持している provider 実行情報(run_gemini_headless.py側の既存 AGY subprocess 起動箇所、または audit ログのattempt_id相関)を用いてprocess_role: provider_cliイベントも記録可能にする。wrapper 側に対応する既存 AGY 起動箇所が実装前確認で見当たらない場合は、Stop Conditions に従い、まずdelegation_wrapperprocess のみで overlap 判定基盤を完成させ、provider_clitelemetry を follow-up Issue に切り出す。- spawn failure(
subprocess.Popen()がOSErrorを送出するケース)を started 扱いにしない(child_spawn_failed経路で process-start event を書かない)。 - timeout(
overall_timeout_secによる cancel)、SIGTERM、SIGKILL escalation(_terminate_process_group())、late result discard(overall_timeout_late_result_discarded)のそれぞれでtermination_reasonを正確に記録する。 - PID reuse による誤相関を防ぐため、
pid単独ではなくpgidとstarted_monotonic_nsを併用した識別を overlap 判定関数の入力契約にする。 max(a.started_monotonic_ns, b.started_monotonic_ns) < min(a.exited_monotonic_ns, b.exited_monotonic_ns)で 2 つの process lifecycle event ペアの overlap を判定する純粋関数を実装する。- distinct
pidかつ distinctsubtask_idの少なくとも一組で overlap 判定が成立した場合にのみactual_provider_process_overlap=trueとする集約関数を実装する(同一subtask_id内の複数イベントや同一pidの再利用は overlap の根拠にしない)。 subtask_startedイベントが複数存在しても、actual_provider_process_overlapが true にならない場合は fan-out 並列性の検証結果を FAIL とする validator ロジックを実装する(既存のsubtask_started順序のみに基づく誤検証をこの validator が置き換える)。- fake executable(
sys.executableの代わりに、決定論的に sleep して終了する軽量 script)を使った real subprocess integration test を追加する(mockrunnerの代わりに実subprocess.Popen()を経由させる)。 - 少なくとも次の 8 ケースをテストする: (a) 2 つの subtask が実際に process overlap する成功ケース、(b) sequential 実行で overlap しないケース、(c) 一方の spawn のみ失敗するケース、(d) 全 spawn が失敗するケース、(e)
overall_timeout_secによる timeout 経由の termination、(f) SIGTERM 後も終了せず SIGKILL に escalation するケース、(g) malformed または欠落した exit event を安全に扱うケース、(h)subtask_startedの journal 順序だけでは overlap するように見えるが実 process overlap が起きていない(wrapper process 起動順序のみが重なる)ケース。 - event journal への書き込みは、既存の
_journal()closure(journal_lockによる single-writer 化と_write_ndjson_record()の書き込み量検証)と同じ排他制御方式を再利用または拡張し、破損しないことを複数 subprocess からの並行書き込みを想定したテストで確認する。 - process lifecycle event の public artifact(journal ファイルおよびテスト assertion 対象の出力)へ absolute executable path を出力しない(
executableフィールドは basename のみ、または public-safe identity に redaction する)。
Out of Scope
- WebSearch 証跡の hook / transcript 化(レビュー Blocker 1、Implementation A)。
no_tools/local_asset_researchのプロファイル別 tool deny 実装(レビュー Blocker 4、Implementation C)。- Serena live probe の subtask 対応付け(レビュー Blocker 3、Implementation D)。
- 調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 自体の E2E validator 統合・実 AGY/Serena/WebSearch を用いた最終証拠収集(Implementation E)。本 Issue は process lifecycle telemetry と overlap 判定関数の提供までとし、調査: fan-out orchestrator の実AGY/Serena MCP/WebSearch並列実行E2E検証を行う #1494 の証拠文書更新は行わない。
fan_out_orchestrator.pyのsubtask_started/subtask_finishedイベント自体の削除・rename(既存 audit 相関を壊さないため、新規 process lifecycle event を追加する形にとどめる)。delegation_fanout_request_v1/delegation_fanout_result_v1スキーマ自体の変更(journal 内部イベントの追加のみで、公開 request/result スキーマは変更しない)。
Acceptance Criteria
- AC1:
make_subprocess_runner()はsubprocess.Popen()成功後にのみ process-start event を journal へ書く。spawn 失敗時(OSError)は process-start event を書かない。 - AC2:
make_subprocess_runner()はproc.wait()完了後に process-exit event を journal へ書く。 - AC3: process-start / process-exit event はそれぞれ
schema,process_role,provider,parent_run_id,subtask_id,attempt_id,artifact_stem,pid,pgid,executable,started_monotonic_ns(start event)またはexited_monotonic_ns(exit event),started_utc(start event)またはexited_utc(exit event),returncode(exit event),termination_reason(exit event)を含む。 - AC4: overlap 判定関数が
max(a.started_monotonic_ns, b.started_monotonic_ns) < min(a.exited_monotonic_ns, b.exited_monotonic_ns)のロジックで実装され、単体テストで検証されている。 - AC5: distinct
pidかつ distinctsubtask_idの組み合わせで overlap が成立した場合にのみactual_provider_process_overlap=trueを返す集約関数が実装され、同一pid再利用や同一subtask_id内の複数イベントでは true にならないことがテストされている。 - AC6:
subtask_startedイベントが複数あっても process overlap が実際には成立しないケースで、validator ロジックが FAIL を返すことがテストされている。 - AC7: fake executable を使った real subprocess integration test(mock runner ではなく実
subprocess.Popen()経由)が追加されている。 - AC8: 8 ケース(成功 overlap / sequential no-overlap / one spawn failure / all spawn failure / timeout termination / SIGKILL escalation / malformed or missing exit event / wrapper-level overlap のみで provider process overlap なし)がそれぞれ独立したテストとして存在する。
- AC9: event journal への並行書き込みが single-writer またはそれと同等の atomic append で破損しないことを、複数 subprocess からの並行書き込みを想定したテストで確認している。
- AC10: process lifecycle event 内の
executableフィールドに absolute path が含まれず、basename または public-safe identity のみであることがテストで確認されている。 - AC11: 既存の
test_fan_out_orchestrator.pyの既存テストが全て PASS のまま壊れていない(後方互換性)。
Verification Commands
# AC1
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_process_start_event_only_after_popen_success
# AC2
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_process_exit_event_recorded_after_reap
# AC3
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_process_lifecycle_event_required_fields
# AC4
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_overlap_predicate_monotonic_window
# AC5
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_actual_provider_process_overlap_requires_distinct_pid_and_subtask
# AC6
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_validator_fails_when_subtask_started_without_process_overlap
# AC7
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_real_subprocess_integration_with_fake_executable
# AC8
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k "overlap_success_two_distinct_processes or sequential_no_overlap or one_spawn_failure_no_provider_overlap or all_spawn_failure_no_provider_overlap or timeout_termination_recorded or sigkill_escalation_recorded or malformed_or_missing_exit_event_handled or wrapper_overlap_without_provider_overlap"
# AC9
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_concurrent_journal_writes_do_not_corrupt
# AC10
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py -k test_executable_field_is_redacted_to_basename
# AC11
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_orchestrator.py -qAllowed Paths
.claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.py.claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py(新規).claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_orchestrator.py(既存テストとの後方互換性確認・必要最小限の調整のみ)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- (Issue 固有)
process_role: provider_clitelemetry の実装にrun_gemini_headless.py内の実 AGY 起動箇所そのものへの変更が必要と判明した場合は、その部分を follow-up Issue に切り出し、本 Issue はprocess_role: delegation_wrapperの telemetry と overlap 判定基盤の完成に留める - (Issue 固有)
fan_out_orchestrator.pyの journal event 定義に対して並行 Implementation Issue(A/C/D)との衝突が実装前確認で判明した場合
Required Skills
なし
Required Design References
- .claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.py(
make_subprocess_runner()/RunnerContext/_run_one()/_journal()の既存実装が本 Issue の直接の変更対象) - docs/dev/runtime-verification-policy.md(Runtime Verification Applicability: deferred の扱い)
Scope Delta(任意)
N/A
Scope Collision 判断(Implementation A/C/D との並行実装)
- 本 Issue(process lifecycle telemetry / overlap validator)は
fan_out_orchestrator.pyのmake_subprocess_runner()/ journal event 追加部分を変更する。 - Implementation A(WebSearch hook 化)は
run_gemini_headless.pyの AGY 実行部分・stdout parser を変更する見込みで、fan_out_orchestrator.py自体には触れない、または触れても journal event 定義とは独立した箇所(WebSearch grounding 判定)になる見込みのため disjoint。 - Implementation C(プロファイル別 tool deny)は AGY 起動時の引数・permission policy を変更する見込みで、
fan_out_orchestrator.pyの journal event 定義とは独立した箇所になる見込みのため disjoint。 - Implementation D(Serena evidence の subtask 対応付け)は Serena MCP 呼び出し・prompt 構成部分を変更する見込みで、
fan_out_orchestrator.pyの process lifecycle telemetry とは独立した箇所になる見込みのため disjoint。 - 上記はいずれも実装前時点で対象 Issue が未起票のため確定情報ではない。並行 Issue が
fan_out_orchestrator.pyのmake_subprocess_runner()近傍を変更する場合は、実装着手前にgit diffベースで overlap の有無を再確認し、衝突が判明した場合は Stop Conditions に従って停止する。 - overlap preflight helper(
check_issue_overlap.py)の実行結果はdecision: overlap_requires_comment(policy_class C1)で、既存 OPEN Issue gemini-cli-headless-delegation の導入と改善 #14「gemini-cli-headless-delegation の導入と改善」が.claude/skills/gemini-cli-headless-delegation/scriptsおよびtestsディレクトリ全体を Allowed Paths としているため path-prefix レベルで overlap している。gemini-cli-headless-delegation の導入と改善 #14 は当該スキル全体の導入・改善を包括する古い umbrella Issue であり、本 Issue が対象とするfan_out_orchestrator.pyの process lifecycle telemetry という具体的な concern は gemini-cli-headless-delegation の導入と改善 #14 の現行スコープに個別記載されていない。non_conflict_reason: gemini-cli-headless-delegation の導入と改善 #14 は directory 粒度の広域 tracking Issue であり、本 Issue は Blocker 2 に対応する特定コンポーネントの実装。edit_intent: 本 Issue のみがmake_subprocess_runner()を変更し、gemini-cli-headless-delegation の導入と改善 #14 側で並行する具体的な PR は現時点で存在しない。dependency ordering: gemini-cli-headless-delegation の導入と改善 #14 と本 Issue の間に blocking 関係はない(並行実装可能)。
Delivery Rule
1 Issue = 1 PRを原則とする。- worktree を新規作成して作業する(
.claude/worktrees/配下)。 - Draft PR を既定とし、レビュー通過後に人間が Ready 化・merge する。
Closes #<この Issue の番号>を PR 本文に含める。
Runtime Verification Applicability
decision: deferred
deferred_destination: "#1494"
deferred_verification_condition: "実 AGY provider を用いた live E2E fan-out 実行で #1494 の最終証拠収集 PR が作成される時点"hermetic subprocess tests(fake executable を使った real subprocess integration test)はローカルで実行し証跡を残す。実 AGY provider を使った live E2E 実行は本 Issue の対象外であり、#1494 の最終 E2E run で行う。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jul 24, 2026
Contract Review Result
fix: E501 line-too-long in test_fan_out_process_lifecycle.py
実装: fan-out AGY provider processのlifecycle telemetryと実overlap validat…
実装: AGY/Serena/WebSearch fan-out E2E artifact validatorとenvironment m…