Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "local_asset_research route (Claude Code / Codex CLI / Antigravity CLI native) の live Serena MCP 起動・応答待ちを、正しく特定された stage/tool 単位の failure classification と自己誘発 stall 排除のもとで安定させ、AGY-native MCP discovery と full route の genuine live PASS を固定 trial plan で証明する"
change_kind: code-and-testParent Issue
なし(単独改善)
Parent Goal Ref
該当なし(parent Issue を持たない単独改善)。起票元は #1886 の human-escalation resolution:「AC6 の未達は PR #2005 のコード欠陥ではなく acceptance を完了するための runtime prerequisite / reliability gap として分離する」。
Current Validated Scope
.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.pyの_collect_live_serena_read_only_evidence()(L2000-2141)および呼び出し元except Exception as exc:ブロック(L5065-5111)に閉じる。.claude/skills/gemini-cli-headless-delegation/tests/test_agy_provider.pyは_collect_live_serena_read_only_evidence()をpatch.objectでモックしており(L502 付近)、transport-level failure(stderr backpressure・process cleanup・failure classification 分岐)を検証していない。本 Issue はこのファイルにも hermetic な transport-level test を追加する。- Serena package の pinning は既に
references/serena-tool-manifest.jsonのpinned_ref(commit3c241bab0d07d8adba8ef4f6c49676c954559dee)で実施済みであることを確認済み。本 Issue で新規にpinning機構を追加する必要はない(pinned_ref の更新是非は 調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 の関心事)。 - 2026-08-09 OWNER directive による scope reframe: PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 head
8a5b2f68時点で AC8 full-route trial が 2/6 のみ genuine PASS(4件はrun_agent_provider_route_smoke.py/run_worktree_agent_runtime_smoke.py(旧 Allowed Paths 外)の async child spawn/completion semantics の欠陥に起因)だったことを受け、OWNER が対話プロンプトで明示的に scope を拡張した。旧 Stop Condition「Serena MCP 以外の原因による AC8 failure は停止」を解除し、full-route harness・AGY-native MCP discovery・Serena install/cache 戦略・関連 CI/test contract を本 Issue・本 PR のスコープ内に統合する(別 Issue・別 PR への切り出しを禁止)。詳細は本文末尾の「OWNER Scope Reframe(2026-08-09)」節および PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 のコメントを参照。
Remaining Parent Gaps
- 調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 が扱う「serena CLI コマンド形式の moving target リスク」自体の解決は本 Issue の範囲外。
- 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 が扱う
preflight_gemini_headless.pyの per-profile 検証化は別関心事(本 Issue はrun_gemini_headless.py側の live 呼び出しパスを扱う)。 - 改善: SERENA_DANGEROUS_TOOLS のツール名と Serena upstream 公式ツール名の乖離を定期検証・更新する仕組みを整備する #256 が扱う
SERENA_DANGEROUS_TOOLSのツール名乖離検証は別関心事。 - 実装: codebase-investigator に pinned Graphify CLI advisory pilot を追加する #2009 の Graphify CLI advisory pilot は Serena の代替/補助ツールに関する別提案であり、本 Issue が扱う timeout reliability 修正の代替として使わない。
- 実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277(OPEN,
failure_classtaxonomy 全般実装)はrun_gemini_headless.py/preflight_gemini_headless.pyの result JSON にfailure_class/retryable/retry_scope等を横断的に実装する Issue だが、その AC1 の failure_class 一覧にlive_serena_mcp_failedまたはその細分化 class は含まれない。本 Issue はこの gap を先行して埋める。実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277 実装時に本 Issue が新設する stage-specific failure class を taxonomy へ統合できるようreferences/failure-class-taxonomy.mdを更新する。 - retry ledger の所有権: 実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277 は同じ
run_gemini_headless.pyを対象に横断的なretryable/retry_scope/attemptsフィールドを設計する OPEN Issue である。本 Issue は既存のlocal_asset_retrieval_metadata(コード上既に存在するキー)配下の nested フィールドとしてのみ retry ledger を追加し、trunk-level(top-level)のretryable/attemptsフィールドは追加しない。実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277 実装時に統合可否を判断する。
Background
Issue #1886 の impl-review-loop iteration 3 で、PR #2005 の AC6 のうち codex_cli / codebase-investigator / local_asset_research route を live 実行したところ live_serena_mcp_failed: timed out waiting for Serena MCP response id 4 で fail した。OWNER はこれを PR #2005 のコード欠陥ではなく runtime prerequisite / reliability gap と判定し、別 Issue として分離することを決定した。
本 Issue の contract は敵対的レビュー(OWNER, REQUEST_CHANGES)を複数回受けて改訂されてきた。P0-1〜P1-3(id マッピング・stderr pipe deadlock・CLI 引数・failure class 粒度・timeout 階層・process-tree cleanup)は control-plane が現行コードを直接読み事実確認済みで、iteration 1-2 で対応した。
PR #2044 は一度 bot pr-reviewer の APPROVE により draft_pr_ready に到達したが、OWNER が PR #2044 へ非常に詳細なコード行レベルの技術的 REQUEST_CHANGES(P1: AC8 full-route test が producer の exit code のみで PASS 判定・cleanup が process group の grandchild を回収しない・server_tool_timeout が実際には Serena 起動 command に渡っていない・retry が route-level deadline を破り初回証跡を破棄する)を投稿し、bot APPROVE を明示的に撤回した。iteration 3 でこのうち3件を修正・独立検証済みだが、AC8 full-route test の意味論的欠陥を修正した結果、genuine live 実行で collector-only は 12/12 PASS(Serena MCP 自体は安定)である一方、full-route は 2/6 のみ PASS(4件は本 Issue が変更していない run_agent_provider_route_smoke.py / run_worktree_agent_runtime_smoke.py の async child spawn/completion 欠陥起因)と判明し、旧 Stop Condition に基づき一度 human escalation した。
これを受けて OWNER は 2026-08-09、対話プロンプトで本 Issue のスコープを明示的に拡張した(詳細は「OWNER Scope Reframe(2026-08-09)」節)。
Outcome
run_gemini_headless.py の _collect_live_serena_read_only_evidence() とその呼び出し元、および local_asset_research route の full-route 実行経路(async child spawn/completion semantics を含む)が、Serena MCP の startup・protocol negotiation・tool execution・manifest validation・cleanup を段階別に観測し、stderr backpressure による自己誘発 stall を起こさず、monotonic な session deadline 内で終了する状態になる。
Antigravity CLI(AGY)自身が workspace の .agents/mcp_config.json から Serena MCP を native に discovery・接続・invoke できることが、モデルの自己申告ではなく MCP tool event / server log で証明される。
Serena は user-local に exact-pinned で persistent install され、cold/warm/offline のいずれでも安定して起動する。
固定済み trial plan に基づき、collector 単体(12/12)・AGY-native probe(3/3)・full route(Claude Code / Codex CLI、6/6 + no-change repeat 6/6)が genuine live PASS することが本 Issue の PR マージ前に確認され、証跡として記録される。
In Scope
_collect_live_serena_read_only_evidence()の各 JSON-RPC request を machine-readable な request ledger として記録する(local_asset_retrieval_metadata配下)。- Serena subprocess の stderr を専用 thread で継続的に drain し、bounded ring buffer へ保存する。stdout と stderr を merge しない。
search_for_patternの探索範囲を context file が属するディレクトリ等に限定し、repo-wide search を避ける。- stage 別 failure class を
references/failure-class-taxonomy.mdに追加し、retryable 判定を明記する。 - transient failure class(timeout 系)に対してのみ、route 単位の単一 absolute monotonic deadline を共有する bounded single retry を実装する(初回証跡を破棄しない)。
- cleanup を
start_new_session=Trueによる process group 単位の管理へ堅牢化し、grandchild process の残存を防ぐ(primary failure がない cleanup 失敗は fail-close、primary failure がある場合はcleanup_failureを secondary failure として記録)。 SERENA_SERVER_TOOL_TIMEOUT_SECを実際に Serena 起動 command(--tool-timeout)へ配線する。- (2026-08-09 追加) full-route test(
test_ac8_local_asset_research_full_route_fixed_live_trial_plan)を、producer exit code のみでなく canonical validator(scripts/agent-ops/validate_agent_provider_route_smoke.py)と route artifact のstatus/failure_class/retrieval_status/retrieval_mode/evidence_record_count/head_shaを直接 assert する実装に修正する。 - (2026-08-09 追加)
scripts/agent-ops/run_agent_provider_route_smoke.pyおよびscripts/agent-ops/run_worktree_agent_runtime_smoke.pyの async child spawn と completion の観測を分離し、child terminal event(SubagentStop 等)と artifact materialization を bounded polling で待つ実装へ修正する。producer の exit code 0 を route PASS として扱わない(--require-route-pass相当の fail-on-route-failure flag を追加し AC で有効化する)。 - (2026-08-09 追加) Antigravity CLI(AGY)自身が
.agents/mcp_config.jsonから Serena MCP を native discovery・接続・invoke することを、MCP tool event / server log を必要条件として証明する専用 live probe を追加する(least-privilege な read-only Serena tool のみ allow)。 - (2026-08-09 追加) Serena の resolver/launcher を
scripts/agent-ops/resolve_serena_mcp.pyに集約し、明示 override → PATH → user-local managed install → exact-pinned uvx fallback の優先順位で解決する。user-local へ latest compatible stable を persistent install する(machine-specific absolute path は repo に commit しない)。 - (2026-08-09 追加) CI の
test_ac13_minimal_agy_env_allowlistで検出されたUV_CACHE_DIRenv leak を修正する(_minimal_agy_env()と Serena 専用 env builder を分離する)。 - (2026-08-09 追加) 上記の hermetic regression test 群(spawn/completion 分離・env leak・process group cleanup・cache cold/warm/offline 等)を追加する。
- (2026-08-09 追加) root cause と再発防止策を PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 のコメントまたは canonical artifact として machine-readable に報告する。
Out of Scope
- serena package(oraios/serena)本体への機能追加・upstream への PR。
- 調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 が扱う「serena CLI コマンド形式の moving target リスク」自体の解決。
- 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 が扱う
preflight_gemini_headless.pyの per-profile 検証化。 - 改善: SERENA_DANGEROUS_TOOLS のツール名と Serena upstream 公式ツール名の乖離を定期検証・更新する仕組みを整備する #256 が扱う
SERENA_DANGEROUS_TOOLSのツール名乖離検証。 - 実装: codebase-investigator に pinned Graphify CLI advisory pilot を追加する #2009 の Graphify advisory 等、代替ツールへの切り替え。
- 実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277 が扱う
failure_class/retryable/attempts等のフィールドをrun_gemini_headless.pyの result JSON top-level へ横断的に実装すること。 - Issue 実装: codebase-investigator / web-researcher の delegation request で AGY provider をメインルートにする #1886 / PR 実装: codebase-investigator/web-researcher を AGY-only provider route へ固定する #2005 の Allowed Paths 拡張、または 実装: codebase-investigator / web-researcher の delegation request で AGY provider をメインルートにする #1886 本文の直接編集。
- 無関係な repo-wide wildcard や、本 Issue の目的に causally 不要な追加権限。
Acceptance Criteria
- AC1:
_collect_live_serena_read_only_evidence()の各 request が、request_id・method・tool_name・arguments のハッシュ・elapsed time・response 受信有無を含む machine-readable な request ledger(local_asset_retrieval_metadata配下)として記録されるテストが追加され PASS している。id=4 に対応する fixture はsearch_for_patternを示す。 - AC2: 大量の stderr を出力してから正常な JSON-RPC response を返す fake MCP server に対し、collector が timeout せず完了することを検証する hermetic test が追加され PASS している。
- AC3:
search_for_patternの探索範囲がリポジトリ全体ではなく context file のディレクトリ等に限定されることを検証するテストが追加され PASS している。 - AC4: stage 別 failure class が
references/failure-class-taxonomy.mdに記録され、retryable 判定が明記されている。manifest drift 以外のケースでmanifest_drift_failedがtrueにならないことをテストで検証する。 - AC5: retryable と判定された timeout class のみ、route 単位の単一 absolute deadline を共有する bounded single retry のテストが追加され PASS している。retry で first attempt の evidence(request ledger・stderr・cleanup)が失われないことを検証する。
- AC6:
recv()の deadline 計算がtime.monotonic()ベースの absolute session deadline に変更され、server_tool_timeout < client_request_timeout < collector_session_deadline < route_harness_timeout - cleanup_graceの関係(retry を含めた worst case)がテストと本文の両方に記録されている。 - AC7: 正常終了・SIGTERM 終了・SIGKILL fallback・grandchild process 存在(親が先に終了し grandchild が SIGTERM を無視するケースを含む)の各ケースで、process group 単位の残存確認により direct child と descendant process が回収されることを検証するテストが追加され PASS している。primary failure がない cleanup 失敗は fail-close される。
- AC8:
SERENA_SERVER_TOOL_TIMEOUT_SECが実際に Serena 起動 command(--tool-timeout)へ配線され、preflight で検証されるテストが追加され PASS している。 - AC9:
.claude/skills/gemini-cli-headless-delegation/tests/およびscripts/agent-ops/tests/配下の全 pytest が引き続き PASS している。 - AC10(旧AC8を改訂・2026-08-09): full-route test が canonical validator と route artifact の意味論フィールド(
status/failure_class/retrieval_status/retrieval_mode/evidence_record_count/head_sha)を直接 assert し、producer exit code のみでは PASS できないことを検証するテストが追加され PASS している。 - AC11(新設・2026-08-09):
run_agent_provider_route_smoke.py/run_worktree_agent_runtime_smoke.pyが child spawn 観測と completion 観測を分離し、child terminal event と artifact materialization を bounded polling で待つことを検証する hermetic regression test(fixture: async_launched child、spawn ありcompletion なし、agent_id 不一致等)が追加され PASS している。 - AC12(新設・2026-08-09): Antigravity CLI 自身が workspace
.agents/mcp_config.jsonから Serena MCP を native discovery・接続・invoke したことを、MCP tool event / server log を必要条件として証明する live probe が、3 回連続実行で 3/3 PASS している。 - AC13(新設・2026-08-09):
resolve_serena_mcp.pyresolver が明示 override → PATH → user-local managed install → exact-pinned uvx fallback の優先順位で解決し、cold/warm/offline-warm の各 cache モードで正しく動作することを検証するテストが追加され PASS している。CI のtest_ac13_minimal_agy_env_allowlist(UV_CACHE_DIRunexpected env key)が解消されている。 - AC14(新設・2026-08-09): 固定 live trial plan(collector-only 12/12、AGY-native probe 3/3、full route Claude Code 3 + Codex CLI 3 の 6/6、さらにコード変更なしでの no-change repeat 6/6、計 full-route 12/12)が genuine live 実行で全て PASS し、PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 に証跡として記録されている。環境 unavailable による skip は AC14 の達成に数えない。
- AC15(新設・2026-08-09): root cause(元の Serena timeout の直接原因、2/6 failure の trial 別原因、AGY が実際に Serena MCP を使用できていたか、cache/download の実態、async completion 欠落の詳細、旧 AC8 が 18/18 false PASS を出した理由、CI の
UV_CACHE_DIRregression を見逃した理由、再発防止策)が PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 のコメントまたは canonical artifact に machine-readable に記録されている。
Verification Commands
# AC1
# preflight-scope: pr_review_only
$ rg -n "request_ledger" .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py# AC2
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_agy_provider.py -k stderr_backpressure -q# AC3
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ -k search_for_pattern_scope -q# AC4
# preflight-scope: pr_review_only
$ rg -n "startup_timeout" .claude/skills/gemini-cli-headless-delegation/references/failure-class-taxonomy.md# AC5
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless.py -k serena_retry -q# AC6
# preflight-scope: pr_review_only
$ rg -n "time.monotonic" .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py# AC7
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless.py -k serena_cleanup -q# AC8
# preflight-scope: pr_review_only
$ rg -n "tool-timeout" .claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py# AC9
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/ scripts/agent-ops/tests/ -q# AC10
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless_live_trial.py -k full_route -q --collect-only# AC11
# preflight-scope: pr_review_only
$ uv run --locked pytest scripts/agent-ops/tests/ -k spawn_completion -q# AC12
# preflight-scope: runtime_only
$ uv run --locked pytest scripts/agent-ops/tests/ -k agy_native_serena_probe -q# AC13
# preflight-scope: pr_review_only
$ rg -n "def resolve" scripts/agent-ops/resolve_serena_mcp.py# AC14
# preflight-scope: runtime_only
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless_live_trial.py -q# AC15
# preflight-scope: pr_review_only
$ gh pr view 2044 --repo squne121/loop-protocol --json comments --jq '.comments[].body' --template '{{range .}}{{.}}{{"\n"}}{{end}}'Allowed Paths
.claude/skills/gemini-cli-headless-delegation/scripts/run_gemini_headless.py.claude/skills/gemini-cli-headless-delegation/references/failure-class-taxonomy.md.claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless.py.claude/skills/gemini-cli-headless-delegation/tests/test_agy_provider.py.claude/skills/gemini-cli-headless-delegation/tests/test_run_gemini_headless_live_trial.py.claude/skills/gemini-cli-headless-delegation/references/serena-tool-manifest.json.claude/skills/gemini-cli-headless-delegation/references/scripts/agent-ops/run_agent_provider_route_smoke.pyscripts/agent-ops/run_worktree_agent_runtime_smoke.pyscripts/agent-ops/validate_agent_provider_route_smoke.pyscripts/agent-ops/resolve_serena_mcp.pyscripts/agent-ops/tests/.agents/mcp_config.json.gemini/settings.json.github/workflows/ci.ymlscripts/ci/
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合。
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合。特に
local_asset_retrieval_metadata以外の場所へ top-levelretryable/attempts等を追加する必要が生じた場合。 - 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)。
- 後続 Phase / 別スコープへの波及が判明した場合。
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合。
- nested SubAgent delegation が必要になった場合。
(2026-08-09 OWNER directive による本 Issue 限定の例外・優先ルール。上記6項目の一般原則は他 Issue への標準テンプレートとして維持するが、本 Issue #2015 の継続作業においては以下を優先し、単独では停止条件にしない):
- 上記6項目のうち「Allowed Paths 外の変更が必要と判明した場合」は、本文「Allowed Paths」節に列挙された OWNER 承認済みの拡張パス(
scripts/agent-ops/*、.agents/mcp_config.json、.gemini/settings.json、.github/workflows/ci.yml、scripts/ci/等)の範囲内である限り該当しない(それら以外の path が必要になった場合のみ該当)。 - 「後続 Phase / 別スコープへの波及」「新規 Issue の起票が必要」は、full-route harness・async child completion・AGY MCP discovery・Serena install/cache・関連 CI/test contract に関する限り該当しない(OWNER directive によりこれらは本 Issue の明示スコープ内であり、別 Issue・別 PR へ切り出さない)。
- 旧 Stop Condition「Serena MCP timeout の根本原因が本 Issue のコード変更では解決不能な外部 infra 問題と判明した場合」「AC8 の live 実行で Serena MCP 以外の原因(AGY provider・GH_TOKEN 等)による failure が判明した場合」は解除された。
- 一時的なネットワーク障害、test failure、CI failure、runtime harness の不具合は、それ単体では停止条件にしない。原因を特定して修正を継続する。
本 Issue #2015 の継続作業における実効的な停止条件(human 承認不要で継続、以下のみ停止):
- データ喪失を伴う破壊的操作が不可避と判明した場合。
- secret の開示・生成・コミットが必要と判明した場合。
- 明示されていない外部課金が必要と判明した場合。
- GitHub または実行環境の権限が回復不能に不足し、push / comment / check 取得が実行不能になった場合。
Required Skills
- Python
- pytest
- subprocess/process-group management
- MCP (Model Context Protocol) client/server semantics
Required Design References
.claude/skills/gemini-cli-headless-delegation/references/failure-class-taxonomy.md.claude/skills/gemini-cli-headless-delegation/references/serena-tool-manifest.json
Runtime Verification Applicability
本 Issue の変更対象はワークフロー文書・スクリプト・CI 設定のみです。ゲームの実行時動作には影響しません。
decision: not_applicable
reason: "Workflow documentation, script, and CI config changes only. No runtime game behavior changed."Delivery Rule
1 Issue = 1 PR。既存 worktree・既存 branch・既存 PR #2044 を継続して使用する。新規 PR は作らない。
OWNER Scope Reframe(2026-08-09)
OWNER が PR #2044(issuecomment-5229836428)で対話プロンプトにより本 Issue のスコープを明示的に拡張した。
schema_version: ANCHOR_SCOPE_REFRAME_V1
target:
repo: squne121/loop-protocol
issue_number: 2015
decision: approve_scope_delta
allowed_path_deltas:
- "scripts/agent-ops/run_agent_provider_route_smoke.py"
- "scripts/agent-ops/run_worktree_agent_runtime_smoke.py"
- "scripts/agent-ops/validate_agent_provider_route_smoke.py"
- "scripts/agent-ops/resolve_serena_mcp.py"
- "scripts/agent-ops/tests/"
- ".agents/mcp_config.json"
- ".gemini/settings.json"
- ".claude/skills/gemini-cli-headless-delegation/references/serena-tool-manifest.json"
- ".claude/skills/gemini-cli-headless-delegation/references/"
- ".claude/skills/gemini-cli-headless-delegation/scripts/"
- ".claude/skills/gemini-cli-headless-delegation/tests/"
- ".github/workflows/ci.yml"
- "scripts/ci/"
rationale: "OWNER directive: AC8 genuine full-route PASS is the outcome boundary. Runtime spawn/completion harness、AGY-native MCP discovery、Serena launch/cache strategy、関連CI/test contractを同一Issue #2015・PR #2044で修正する。least privilege、非破壊、secretなし、外部課金なし、無関係な権限拡張なし。"
required_rerun:
- contract_review
- refinement_preflight
- allowed_paths_gate停止条件は本文「Stop Conditions」節に置き換えられた(データ喪失不可避 / secret / 未承認課金 / 権限の回復不能な不足のみ)。旧 Stop Condition(AC8 の Serena 以外原因による failure、Allowed Paths 不足)は解除。
Notes for Reviewer
- 関連 Issue: 実装: codebase-investigator / web-researcher の delegation request で AGY provider をメインルートにする #1886(起票元)、調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 / 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 / 改善: SERENA_DANGEROUS_TOOLS のツール名と Serena upstream 公式ツール名の乖離を定期検証・更新する仕組みを整備する #256 / 実装: codebase-investigator に pinned Graphify CLI advisory pilot を追加する #2009 / 実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277(別関心事、上記参照)。
- 2026-08-09: OWNER の PR 実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する #2044 コメント(issuecomment-5229719867)が iteration 3 の bot APPROVE を撤回し4件の P1 blocker を提示、control-plane が3件を修正・独立検証(残り AC8 は当時の Stop Condition により human escalation)。続けて OWNER が対話プロンプトで Stop Condition を解除しスコープを拡張した(本節「OWNER Scope Reframe」参照)。
- dedupe_key 候補:
follow-up:squne121/loop-protocol:issue/1886:serena-mcp-runtime-timeout-reliability - overlap preflight(
ISSUE_OVERLAP_PREFLIGHT_RESULT_V1): decision=overlap_requires_comment(C1, allowed_paths_overlap)。関連候補 実装: gemini route の gh_commands 実行に環境変数 scrub / GH_CONFIG_DIR isolation / streaming byte cap / process-group kill を追加する #2002 / 実装: failure-class-taxonomy.md の mcp_tool_policy_invalid に「security boundary ではなく configuration hygiene check」の注記を追加する #290 / 調査/実装: failure-class-taxonomy の preflight_checks 構造体と attempts カウント方式を実装可能レベルに詳細化する #289 / 調査/実装: failure-class-taxonomy の last_error_summary を canonical フィールドに格上げし source 区分を追加する #288 / 実装: gemini-cli-headless-delegation に gh_commands + timeout_sec < 300 時の runtime warning を追加する #258 / 実装: delegation_request_v1 に context_policy / permission_policy のネスト構造を導入する #29 / 実装: gemini-cli-headless-delegation に依存関係グラフによる動的コンテキストツリー化を導入する #28 / 実装: gemini-cli-headless-delegation にマルチモデル並列実行と自動敵対的レビュー調停を導入する #27 / gemini-cli-headless-delegation の導入と改善 #14 は編集意図が異なる独立 PR(non_conflict_reason)。マージ順序の依存はない。
Activity
squne121 commentedon Aug 8, 2026
[create-issue] post-create ready tuple validation FAILED: phase/implementation label missing. Manual fix required.
squne121 commentedon Aug 8, 2026
[create-issue] post-create ready tuple validation now PASSES after adding label 'phase/implementation' via create_issue_txn.py reconcile. all_passed: true.
squne121 commentedon Aug 8, 2026
Issue #2015 敵対的レビュー
判定
REQUEST_CHANGES — 現状の Issue 契約は implementation-ready ではありません。
最も重大なのは、起票根拠となった timeout の発生箇所が誤認されていることです。その状態で timeout 延長や bounded retry を実装すると、実際には wrapper 自身が作っている stall を「transient infra」として隠蔽する可能性があります。
現時点で #2015 に直接対応する実装 PR は確認できず、Issue コメントもラベル修復記録に留まっています。したがって、以下は現行
mainの実装、起票元 PR #2005、関連調査 PR #2022、pin 済み Serena 実装を対象にした契約レビューです。Issue は_collect_live_serena_read_only_evidence()、timeout、failure taxonomy、retry、cleanup に範囲を限定しています。P0-1: timeout した request ID の対応付けが事実と異なる
Issue 本文は、
id=4を3番目のtools/call、すなわちget_symbols_overviewと説明しています。しかし現行コードの ID 発行順は次のとおりです。initialize: ID 1tools/list: ID 2find_file: ID 3search_for_pattern: ID 4get_symbols_overview: ID 5したがって観測された失敗は、少なくとも記録上は
get_symbols_overviewではなくsearch_for_patternの応答待ちです。しかも PR #2005 の route smoke は
local_asset_researchの context file にREADME.mdを渡します。wrapper はその親ディレクトリ"."をsearch_for_patternの探索範囲にし、固定パターンlocal_asset_researchをリポジトリ全体から検索します。上流 Serena の実装も、このツールが指定範囲内のプロジェクトファイルを走査することを示しています。影響
現在の Background、Outcome、AC1 は、誤った tool/stage を前提にしています。
が区別されていません。原因を特定しないまま timeout を増やすべきではありません。
必須修正
各 request について最低限、以下を機械可読で残す必要があります。
Issue 本文の
id=4 = get_symbols_overviewは修正し、AC1 は単なる調査記録ではなく、この ledger から tool/stage を再計算できることを要求すべきです。P0-2: wrapper 自身が stderr pipe deadlock を発生させ得る
現行 wrapper は Serena subprocess を次の構成で起動しています。
しかし、待機ループが読むのは stdout だけで、stderr はプロセス終了時を含めて一度も drain されません。
一方、pin 済み Serena は stdout を MCP 専用にし、起動ログ・tool call・tool result を stderr へ出します。さらに
Tool.apply_ex()は tool result 全体をINFOログへ書いた後に結果を返します。この組み合わせでは、
search_for_patternの大きな検索結果を stderr に記録して pipe が満杯になると、Serena は tool result を MCP stdout へ返す前に停止できます。親は stdout を待ち続け、180秒後に timeout します。これは当該実行で実際に pipe が満杯になったことの証明ではありません。しかし、現行コードに自己誘発 deadlock 経路が存在することはコード上成立しています。Python の公式ドキュメントも、PIPE を使用しながら適切に読み出さない場合の deadlock を明示的に警告しています。MCP stdio 仕様は stderr へのログ出力を許可し、stdout はプロトコルメッセージ専用としています。([Model Context Protocol]1)
必須修正
retry より先に、以下を実装してください。
例えば次のケースが timeout せず成功しなければなりません。
単に
180 → 300秒へ変更するだけでは、この deadlock を300秒待つようになるだけです。P0-3: AC5 の Verification Command は実行不能
Issue の AC5 は次の形です。
run_gemini_headless.py \ --tool-profile local_asset_research \ --provider agy \ --prompt "..."しかし現行 CLI にこれらの option は存在しません。通常実行では
--request-fileと--output-fileが必須です。したがって、この Verification Command は argparse の usage error で終了します。さらに、仮に direct wrapper invocation を正しく直しても、それは Claude Code / Codex CLI の custom-agent spawn を検証しません。両 runtime の正規経路は既存の producer です。
scripts/agent-ops/run_agent_provider_route_smoke.py \ --runtime claude_code|codex_cli \ --agent codebase-investigator \ --profile local_asset_research修正版
wrapper 単体の live probe は、まず request を正規 builder で生成します。
runtime integration は別に実行します。
既存 aggregate validator の assertion flags は required six-route 全件を close gate にするため、#2015 の2 routeだけにそのまま適用すると必ず missing-route になります。2 route 専用の assertion を inline Python または新しい verifier で実施するか、既存 validator に subset mode を追加するなら Allowed Paths を明示的に拡張する必要があります。
P0-4: failure class が粗すぎ、retry 判定に使用できない
現在は live Serena 経路内のすべての例外を broad
except Exceptionで捕捉し、同じ値へ丸めています。さらに、例外の種類に関係なく
manifest_drift_failed: trueが設定されます。timeout、process exit、JSON parse error、JSON-RPC error、credential-like result 検出、tool manifest drift がすべて同じ状態です。この generic class を taxonomy に追加して
retryable: trueにすると、次まで再試行されます。これらは transient timeout ではありません。
必要な分類
少なくとも次へ分割すべきです。
追加で次のフィールドが必要です。
manifest_drift_failedは実際にtools/listと manifest が不一致だった場合だけtrueにし、それ以外はfalseまたはnullにしてください。また failure class は既存 taxonomy と同様の
snake_casetoken とし、空白を含む表示文を class に使用すべきではありません。現行 taxonomy はclient_subprocess_timeout等を retryable としていますが、Serena の startup・request・tool failure を区別していません。P0-5: timeout の階層が互いに矛盾している
現在確認できる timeout は次の構造です。
tool_timeout: 240秒initialize、tools/list、tools/call× 3上流 Serena の tool は、設定された
tool_timeoutまで task result を待機します。デフォルト設定は240秒です。現在の client は180秒なので、server が正常に処理中でも60秒先に諦める可能性があります。一方、outer route の既定値も180秒です。wrapper の1 requestだけでouter budgetを使い切るため、inner timeout、agent startup、AGY 実行、artifact materialization を同じ budget に収められません。
さらに現行
recv()は request ごとに新しい180秒 deadlineを作ります。すべての応答が期限直前まで掛かれば、1 attempt が最大約900秒、whole-collector retry で最大約1800秒になり得ます。必須設計
次の不等式を明示的に満たす必要があります。
実装は
time.time()ではなく、時計補正の影響を受けないtime.monotonic()による absolute session deadline を使うべきです。([Python documentation]2)推奨構造は次です。
timeout 数値を先に決めるのではなく、実測した warm/cold distribution から決定してください。実際に Serenaへ渡された effective
tool_timeoutも evidence に記録する必要があります。P0-6: 「stable」の証明条件が存在しない
AC5 は Claude Code / Codex CLI で各1回成功すれば満たせる構造ですが、1回の成功は安定性の証明ではありません。特に retry を追加すると、初回失敗を隠した「最終成功」だけを記録しやすくなります。
関連する #2013 / PR #2022 では、再試行すると成功する非決定的事象を、事前固定した control 15 trial / production 15 trial で調査しました。その結果、transient infrastructure ではなくリポジトリ側の observability defect と判定され、retry は対象外のまま維持されています。#2015 も同じ因果判定水準を採用すべきです。
必須の trial plan
結果を見てから条件を変えない、次のような plan を Issue に固定してください。
少なくとも以下を全 trial に記録します。
commit pin は source identity を固定しますが、
uvxの cold start、Git取得、環境構築、cache hit/miss の時間差までは消しません。uv は解決済み Git commit を cache key として利用するため、warm/cold lane を区別する必要があります。([Astral Docs]3)P1-1: cleanup は subprocess tree を回収していない
現行 cleanup は次の処理です。
process.terminate()wait(timeout=5)process.kill()ただし
kill()後に再度wait()していません。また kill 対象は直接起動したuvxprocess だけで、Serena本体や language server などの descendant が残る可能性があります。MCP の lifecycle 仕様では、stdio server の終了は input close、graceful wait、SIGTERM、最後に SIGKILL という段階的処理が想定されています。request timeout 時には cancellation を送り、response 待機を停止することも定義されています。([Model Context Protocol]4)
推奨処理
POSIX を正式な対象にするなら、次の順序が妥当です。
テストは fake server が grandchild を起動し、SIGTERM を無視するケースまで含めるべきです。cleanup failure が発生しても、元の request timeout を上書きせず、primary failure と cleanup failure の両方を保持してください。
P1-2: retry ledger の保存先が契約上未定義
AC3 は
initial_resultを保持するよう要求していますが、#2015 は同時に固定キー集合・schema変更を Stop Condition とし、横断的なattempts/retryable/retry_scopeは #277 の範囲外としています。現行 wrapper result には、#2015 用の
initial_resultの保存場所が定義されていません。一方、route smoke は独自にretry.initial_result等を持っていますが、これは collector 内部 retry の証跡ではありません。#277 はまさに同じ
run_gemini_headless.py、taxonomy、tests を対象に、failure_origin、retryable、retry_scope、attempts等を追加する OPEN Issue です。必須決定
次のいずれかを Issue 本文に明記してください。
local_asset_retrieval_metadata.attemptsという nested schema のみを所有し、実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277 が後でtop-levelへ統合する現状の「schema変更禁止だが initial_result を保存する」は矛盾しています。
P1-3: 根本原因が query shape でも修正できない Scope になっている
誤った ID 対応を直すと、timeout 対象は repo-wide
search_for_patternです。しかし In Scope は timeout値、taxonomy、retry、cleanup に限定され、tool query の縮小は含まれていません。測定の結果、repo全体検索が原因だった場合に必要なのは、例えば次です。
relative_pathを context file 自体へ限定paths_include_globで対象を限定multiline=Falselocal_asset_researchではなく、context file に確実に存在する bounded query を使用max_answer_charsを明示現状の Scope では、原因を発見しても timeout延長か別Issue化しかできません。query-shape reliability を In Scope に追加するか、Outcome を「原因調査・分類」へ縮小してください。
推奨する修正版 Outcome
以下の形へ置き換えるのが妥当です。
推奨 Acceptance Criteria
AC1: 正しい request attribution
timeout/error artifact から
request_id、method、tool name、arguments digest、elapsed time を再計算できる。ID 4 の fixture はsearch_for_patternを示す。AC2: stderr backpressure 耐性
大量の stderr を出力してから正常な JSON-RPC response を返す fake MCP server に対し、collector が timeoutせず完了する。stderr は bounded・redacted であり、stdout JSON-RPC は汚染されない。
AC3: failure classification
startup timeout、request timeout、process exit、protocol error、JSON-RPC error、manifest drift、redaction failure、cleanup failure が別 class になる。manifest drift 以外で
manifest_drift_failed=trueにならない。AC4: bounded retry
retryable predicate を満たす timeout のみ fresh process で最大1回 retryする。初回 attempt、cleanup、retry attempt、final result がすべて保持される。manifest drift、protocol error、tool error、redaction failureは retry回数0。
AC5: deadline hierarchy
monotonic session deadline を使用し、server tool timeout、request timeout、collector timeout、route timeout の大小関係がテストと文書で固定される。
AC6: process-tree cleanup
正常終了、SIGTERM終了、SIGKILL fallback、grandchild存在の各ケースで direct child と descendant が回収される。kill後には必ず waitする。
AC7: fixed live trials
事前固定した collector-only trial と Claude/Codex integration trial を実行し、first-attempt pass と retry-recovered pass を別々に報告する。trial の事後除外は禁止。
AC8: regression
単一ファイルだけでなく、delegation skill の全 pytest が通る。
Allowed Paths の修正
最低でも次を追加すべきです。
現行の live Serena success tests は
_collect_live_serena_read_only_evidence()を mock しているtest_agy_provider.py側にあり、transport-level failure を直接検証していません。#2015 の対象をtest_run_gemini_headless.pyだけに限定すると、既存の AGY local-asset integration seam と分断されます。run_agent_provider_route_smoke.pyや validator 自体を変更しないなら、scripts/agent-ops/を Allowed Paths に加える必要はありません。既存 producer を verification-only で利用できます。最終結論
#2015 の方向性自体は妥当です。ただし、現行契約は次の危険な順序になっています。
採用すべき順序は逆です。
現状のまま実装を開始すると、timeout の根本原因を隠す retry patch になる可能性が高いため、Issue 本文・AC・Verification Commands・Allowed Paths の再定義がマージ前提です。
squne121 commentedon Aug 8, 2026
Issue Refinement Loop 終了報告(承認・approved)
OWNER の anchor comment(issuecomment-5226174852、敵対的レビュー、REQUEST_CHANGES、P0-1〜P1-3)を反映し、2 iteration で本文を改訂しました。
1f15ef85)で直接検証し、すべて事実と確認。Outcome/In Scope/Out of Scope/AC1-AC9/Verification Commands/Allowed Paths を全面改訂。issue-reviewer →VERDICT: needs-fix(AC8 の VC がuv run python3 <script>直接呼び出しで VC preflight allowlist 違反)。test_run_gemini_headless_live_trial.py)へ修正し、Allowed Paths に追加。issue-reviewer →VERDICT: approve(control-plane がcheck_issue_contract.py --issue 2015を直接実行し独立に再確認、C1-C11 全 PASS、blockers 0)。Final Gate: not applicable at this stage(
issue-contract-reviewskill の CONTRACT_REVIEW_RESULT_V1 snapshot は本 refinement loop の範囲外であり未実行。次段階として実装着手直前に別途実行が必要)。Next Action: 実装着手前に
issue-contract-reviewskill を実行してCONTRACT_REVIEW_RESULT_V1: status: goの fresh snapshot を得た上でimpl-review-loopへ handoff してください。squne121 commentedon Aug 8, 2026
implement-issue: 実装完了 (2026-08-08T14:38:27Z)
.claude/worktrees/issue-2015-local-asset-research-route-live-serena-mworktree-issue-2015-local-asset-research-route-live-serena-mfix: E501 (line too long) を3箇所解消し ruff check を green にする (#2015)
docs: failure-class-taxonomy に日本語説明を補い PR Body Japanese Check を通す (#2015
squne121 commentedon Aug 8, 2026
impl-review-loop: 完了 (2026-08-08T16:00:00Z)
fix: Serena MCP cleanup/timeout/retry/AC8検証の4件のP1指摘に対応する (#2015)
squne121 commentedon Aug 9, 2026
Issue #2015 scope reframe(OWNER directive materialization)
OWNER が PR #2044 のコメント(issuecomment-5229836428)で本 impl-review-loop の対話セッションへ直接指示した内容を、Issue #2015 の canonical contract update として materialize する。
エスカレーション時 head:
8a5b2f68ca9165b3ace8b3c4d6fe98b86f3da979対話プロンプトの要旨:
Issue 本文(In Scope / Allowed Paths / Acceptance Criteria / Verification Commands / Stop Conditions)を本 directive に合わせて同一 transaction で更新した。
fix: AGY subprocess env allowlist から UV_CACHE_DIR を除去し Serena 専用 env …
実装: AC11 async child spawn/completion 分離・AC13 Serena resolver・env lea…
修正: full-route trial の diagnostics companion ファイルが validator を偽陽性で fa…
fix(agent-ops): async Task 完了と証跡未生成の genuine race を bounded retry 対象に…
fix(agent-ops): full-route retry が genuine な artifact-materialization…
fix(agent-ops): materialized-but-failed AGY 結果を artifact 未材料化と誤分類しない (#…
修正: full-route live trial の残存2種の断続的失敗を live 再現で特定・修正する (#2015)
修正: codex_cli spawn_not_observed が genuine な Serena retrieval 成功を偽 fa…
修正: codex_cli の genuine な artifact 未materialization race が provider_m…
修正: codex_cli full-route trial の agy_rate_limited を retry 対象にし残存断続的失敗…
実装: AGY-native Serena MCP discovery を独立に証明する live probe (AC12) を追加する (#…
修正: run_agent_provider_route_smoke.py の実装拡張で drift した code-analysis.m…
chore: 誤って commit された __pycache__ の .pyc 2件を除去する (#2015)
squne121 commentedon Aug 10, 2026
impl-review-loop: 完了 (2026-08-11T02:15:00Z)
mergeStateStatus: UNSTABLEは required set 外の無関係なvisual-impact-policy-trusted起因、CI evaluator に委ね human escalation にはしない)実装: local_asset_research route の live Serena MCP 応答待ちタイムアウトの信頼性を改善する (#…