Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "codebase-investigator が gemini-cli-headless-delegation 経由で調査できない原因を特定し、修正方針または許容ルールを文書化する"
change_kind: research-onlyParent Issue
なし(単独改善)
Outcome
delegation_request_v1 テンプレートおよび gemini-cli-headless-delegation wrapper が local_asset_research タスクで Serena MCP を要求する条件が path:line レベルで特定され、codebase-investigator の agent 定義と wrapper 実装の乖離点が一覧化され、fall back を許可するか修正するかの推奨方針が調査レポートとして docs/dev/ 配下または該当 skill ドキュメントに記録された状態。
Background
2026-05-20 の Issue #25 refinement-loop 実行中、codebase-investigator SubAgent が gemini-cli-headless-delegation 経由で調査を実行する設計(agent 定義の description に「実調査は必ず gemini-cli-headless-delegation skill 経由で Gemini に委譲」と明記)であるにもかかわらず、wrapper status が failed となり fall back が発生し、SubAgent 自体が直接 Read/Bash で代替調査を実行した。
SubAgent の failure reason 報告:
local_asset_research実行時に "requires WSL-local Serena MCP command"
この報告は codebase-investigator の delegation 設計と矛盾する(Serena MCP は agent 定義に登場しない)。少なくとも以下のいずれかの問題が存在する:
delegation_request_v1のテンプレートが Serena MCP を必須前提にしているgemini-cli-headless-delegationwrapper が Serena MCP 不在で fail-close する条件分岐になっているcodebase-investigatorのリクエスト構築コードが誤って Serena ルートを選択している
参照:
- Issue 実装: issue-body-authoring / edit-issue に必須セクション/VC形式チェックリストを追加し review-issue と整合させる #25 refinement-loop 実行ログ
.claude/agents/codebase-investigator.md.claude/skills/gemini-cli-headless-delegation/
Current Finding Summary(2026-05-23 更新)
本事象は単一原因ではなく、以下に分解された。
| # | 状態 | 問題 | 対応 |
|---|---|---|---|
| 1 | Resolved | codebase-investigator.md の Gemini API key 誤記 |
PR #102 / #143 |
| 2 | Resolved | .gemini/settings.json の Serena excludeTools denylist 不備 |
#140 |
| 3 | Unresolved | preflight が profile 非依存で local_asset_research を検証する | #101 (open) |
| 4 | Unresolved | transient / quota / API failure の auth 誤分類 | 新規 Issue 必要 |
| 5 | Unresolved | fail-close の技術的 enforcement(Bash/Read hard guard) | 新規 Issue 必要 |
In Scope
delegation_request_v1テンプレートとgemini-cli-headless-delegationwrapper における Serena MCP 依存箇所の調査・特定(path:lineレベル)codebase-investigatorの agent 定義と wrapper 実装の乖離点の一覧化local_asset_researchタスクが Serena MCP を要求するようになった条件分岐の追跡- fall back(直接 Read/Bash 実行)を許可するか修正するかの推奨方針の提示
- 調査レポートを
docs/dev/配下または.claude/skills/gemini-cli-headless-delegation/内ドキュメントとして記録
Out of Scope
- 実装修正(本 Issue の AC は調査・文書化のみ。修正は別 implementation Issue で扱う)
- Serena MCP の導入・セットアップ
codebase-investigator以外の SubAgent の fall back 挙動調査
Acceptance Criteria
- AC1: Serena MCP 要求箇所と現在の settings 修正状態が path:line / PR link 付きで記録されている
- AC2: preflight と run wrapper の profile 判定非対称性が path:line 付きで記録され、実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 に反映されている
- AC3:
GEMINI_API_KEY誤診が resolved として PR feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む #102 / docs: codebase-investigator gemini 委譲フロー修正 — context_files 規約・fail-close・Serena MCP 切り分け手順 (#100) #143 に link されている - AC4: transient/quota/auth 誤分類を扱う follow-up Issue が起票されている
- AC5: silent fallback を技術的に封じる follow-up Issue が起票されている
Verification Commands
AC1: 調査レポートの存在確認と Serena MCP の path:line 特定の記載確認
test -f docs/dev/codebase-investigator-delegation-fallback.md && echo "PASS: レポート存在" || echo "FAIL: レポート未作成"rg "path:line|Serena" docs/dev/ .claude/skills/gemini-cli-headless-delegation/ 2>/dev/null | grep -v ".pyc" | head -10
AC2: 乖離点一覧の記載確認
rg "乖離|discrepancy|mismatch" docs/dev/ .claude/skills/gemini-cli-headless-delegation/ 2>/dev/null | head -5
AC3: GEMINI_API_KEY 誤診の resolved 記録確認
rg "GEMINI_API_KEY|PR #102|PR #143" docs/dev/codebase-investigator-delegation-fallback.md 2>/dev/null | head -5
AC4: transient/quota/auth follow-up Issue の存在確認
gh issue list --repo squne121/loop-protocol --state open --search "transient quota auth failure taxonomy" --json number,title | head -5
AC5: silent fallback hard guard follow-up Issue の存在確認
gh issue list --repo squne121/loop-protocol --state open --search "codebase-investigator Bash Read hard guard" --json number,title | head -5
Runtime Verification Applicability
decision: not_applicable
reason: research-only Issue。調査レポートの存在確認のみで十分。実装変更なし。
Allowed Paths
docs/dev/(調査レポート書き出し用).claude/skills/gemini-cli-headless-delegation/(skill 内ドキュメント更新が必要な場合のみ)- 上記以外は読み取り専用
Stop Conditions
- Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
- Allowed Paths 外への書き込みを試みた場合は即停止
- 権限不足(permission denied)により操作が完了できない場合は即停止
- 成果物の書き込みに失敗した場合(I/O エラー等)は即停止
- 調査中に
codebase-investigator.mdや wrapper スクリプトの実装修正が必要と判断した場合は、本 Issue の Scope 外として停止し、follow-up implementation Issue 起票を推奨する
Handoff Contract
Current Objective:codebase-investigatorのgemini-cli-headless-delegation経由調査が Serena MCP 不在で fail する根本原因の特定と方針文書化Bounded Current Context:.claude/agents/codebase-investigator.md,.claude/skills/gemini-cli-headless-delegation/SKILL.md,delegation_request_v1テンプレート, Issue 実装: issue-body-authoring / edit-issue に必須セクション/VC形式チェックリストを追加し review-issue と整合させる #25 実行ログOpen Questions: Serena MCP を要求するコードパスがdelegation_request_v1テンプレート側か wrapper 側かは調査前未確定Next Action: 調査レポート完成後、推奨方針に応じて実装修正 implementation Issue を起票するArtifact Refs: 調査レポートはdocs/dev/codebase-investigator-delegation-fallback.md(または同等のパス)に出力
Activity
squne121 commentedon May 20, 2026
追加観測データ: Issue #79 refinement loop 中に同事象が再現 (2026-05-20T11:30:32Z)
issue-refinement-loop(対象 Issue #79)の Step 1 で
codebase-investigatorSubAgent を起動し、明示的にgemini-cli-headless-delegation経由での委譲を指示したが、SubAgent は Gemini に委譲できず直接 Read / Grep / Bash にフォールバックした。SubAgent 自身が報告した委譲メタ:
切り分けに有用な点
GEMINI_API_KEY環境変数の未設定 と SubAgent が自己申告している。この Issue への示唆(#71 のスコープ内で検討候補)
GEMINI_API_KEY未設定で確定なら、切り分けの主眼は「鍵未設定時の期待挙動」の定義。codebase-investigatorの出力契約に「delegation_status: delegated | fallback」を必須化し、silent fallback を構造的に検知可能にする案を検討対象に追加したい。(出典: Issue #79 issue-refinement-loop, 2026-05-20)
squne121 commentedon May 20, 2026
原因切り分け完了: GEMINI_API_KEY は無関係、真因は2点 (2026-05-20T11:49:23Z)
Issue #79 の後続作業で本事象を実環境で切り分けた。結論として
GEMINI_API_KEY未設定は本事象と無関係 であり、codebase-investigator が報告した「GEMINI_API_KEY 未設定のため Gemini 委譲不可」は 誤診 だった。実環境での確認結果
geminiCLI 存在geminiheadless smoke 実行gemini --model gemini-3-flash-preview --approval-mode plan --skip-trust --prompt ... --output-format jsonが{"response": "OK"}を返す)SKILL.mdL148,usage-contract.mdL77)も OAuth 前提と明記。GEMINI_API_KEYは認証経路ではないpreflight_gemini_headless.py実行ok:false真因 1: preflight が profile 非依存で local_asset_research を検証する
run_gemini_headless.pyはtool_profile == local_asset_researchの時のみ_validate_local_asset_research_settings()を呼ぶ(L758-761)。github_research/grounded_researchは Serena 検証を通らない。preflight_gemini_headless.pyのrun_preflight()は profile に関係なく 常に_validate_local_asset_research_settings()を実行(L279)し、失敗するとreturn result(ok:false)。smoke test にも到達しない。github_researchだけ使いたい呼び出し元も、無関係な.gemini/settings.jsonの Serena 設定不備で preflight 全体が fail する。今回
.gemini/settings.jsonで出た具体エラー:local_asset_research requires WSL-local Serena MCP command: uvx ... serena ... --project-from-cwd— preflight はargsに リテラルserena要素を要求するが('serena' not in args)、実際の settings はserena-mcp-serverを使用。これは 調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54(serena CLI コマンド形式の moving target)と同根。local_asset_research dangerous tool denylist is incomplete— settings にexcludeToolsdenylist が無い。真因 2: codebase-investigator.md の fail-close 条件に誤記
.claude/agents/codebase-investigator.mdL119:skill は OAuth 前提で
GEMINI_API_KEYを使わないため「Gemini API key の不在」は fail-close 条件として誤り。haiku モデルの SubAgent がこの記述に引きずられGEMINI_API_KEYをチェックし、(a) 誤った理由で「委譲不可」と判断、(b) 契約上は fail-close すべきところを直接 Read/Bash 調査へ silent fallback、という二重の契約違反を起こした。推奨フォローアップ
実装フォローアップ Issue を別途起票する(本コメント後にリンク追記):
preflight_gemini_headless.pyを per-profile 検証化(またはlocal_asset_research検証失敗をgh_cliと同様 warning 扱いにして top-levelokを落とさない)codebase-investigator.mdL119 から「Gemini API key」を削除し OAuth/preflight 基準へ修正(web-researcher 追加 PR に同梱予定).gemini/settings.jsonの Serena コマンド形式正準化(調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 と統合検討)(出典: Issue #79 後続作業, 2026-05-20)
squne121 commentedon May 20, 2026
フォローアップ実装 Issue を起票: #101(preflight per-profile 検証化)。codebase-investigator.md L119 の「Gemini API key」誤記修正は web-researcher 追加 PR に同梱予定。
feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む (#102)
squne121 commentedon May 21, 2026
再現証跡(issue-refinement-loop #40 セッション, 2026-05-21)
本 Issue の事象が再現したので原因切り分けの材料として記録する。
観測
同一セッション内で 2 つの SubAgent が
gemini-cli-headless-delegation経由委譲を実行した:auth.ok: false(Error when talking to Gemini API/ MCP issues detected)。retry せず即 fail-close環境:
gemini --version= 0.42.0、~/.gemini/にconfig/history/google_accounts.json存在(認証情報は物理的に存在)。切り分け仮説
auth.ok: falseは 真の認証失効ではなく transient エラー(quota スロットリング / 一時的 API エラー)の誤分類の可能性が高い。直後に web-researcher が同じ Gemini API に対し quota retry で成功し、数分後に codebase-investigator 自身も retry で成功しているため。推奨調査ポイント
auth.ok: falseに丸めていないか(failure_class の粒度)squne121 commentedon May 23, 2026
派生観察 (from Issue #254 refinement loop, 2026-05-23)
Issue #254 の issue-refinement-loop iter 1 で本 Issue の事象を実観測しました。
codebase-investigatorSubAgent がgemini-cli-headless-delegationで fail-close し、main thread からの直接調査(gh/ls)で fallback 完了。具体的な失敗内容は #140 にも記録しましたが、本 Issue (#71) の調査スコープに直接対応する観察として:
local_asset_researchprofile の denylist 不備 +auth.ok: falsememory feedback
feedback_gemini_delegation_retryの「retry で成功」は auth transient のみ に限定すべきで、profile denylist 等の config エラーには適用不可と確認できました。本切り分け Issue の結論材料の一部として記録します。SubAgent agentId:
a23211fe8f86f9cbf/abc3f763a8f8c39ca関連: #140(denylist 直接修正), #101(per-profile preflight 分割)
squne121 commentedon May 23, 2026
結論
Issue #71 は まだ close すべきではありません。初期仮説だった「Serena MCP 不在で codebase-investigator が fall back する」は、その後の観測で 少なくとも 4 系統の問題に分解されています。
未解決の runtime 問題:
preflight_gemini_headless.pyが profile 非依存でlocal_asset_researchを検証し、無関係な profile まで落とす。これは 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 が open のままです。契約違反の silent fallback: 実装: codebase-investigator の gemini 委譲フローを定義通りに修正する — context_files 規約明確化・fail-close 徹底・Serena MCP 切り分け手順追記 #100 / PR docs: codebase-investigator gemini 委譲フロー修正 — context_files 規約・fail-close・Serena MCP 切り分け手順 (#100) #143 で文書上は強化済みですが、
codebase-investigatorはまだBash/Readを持つため、技術的には完全封止されていません。誤診問題:
GEMINI_API_KEY未設定を原因扱いした件は feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む #102 / PR docs: codebase-investigator gemini 委譲フロー修正 — context_files 規約・fail-close・Serena MCP 切り分け手順 (#100) #143 で修正済み。ただし公式 Gemini CLI docs では headless 環境に API key / Vertex を推奨する記述もあるため、「API key 不要」と断定せず「このプロジェクトの既定経路では必須ではない。委譲可否は smoke/preflight で判定する」が正しいです。 (Gemini CLI)transient / quota / auth 誤分類: Issue 導入: Issue contract / DoR / dependency 判定による AI 実装前提基盤の整備 (parent) #40 の再現観測にある
auth.ok:falseが真の認証失効ではなく一時的 API / quota エラーだった可能性は、実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 の scope だけでは十分に扱えていません。Issue 調査: codebase-investigator が gemini-cli-headless-delegation 経由で調査できず直接 Read/Bash に fall back する事象の原因切り分け #71 コメントにもこの非対称 retry 問題が記録されています。したがって、#71 は「Serena MCP 依存の調査 Issue」として閉じるより、delegation failure taxonomy / profile-aware preflight / fallback enforcement の親調査ログとして再整理した方が品質が上がります。
関連 Issue / PR の状態整理
対象 | 状態 | 評価 -- | -- | -- #71 | open | 元 Issue。AC は「Serena MCP 要求箇所特定・乖離点一覧・fallback 方針」だが、後続観測に対して本文が古い。 #101 | open | 最重要未解決。preflight_gemini_headless.py の per-profile 化または warning 降格。現 main でも preflight は local_asset 検証失敗時に即 return します。 #100 / PR #143 | closed / merged | context_files 規約、fail-close、GEMINI_API_KEY 誤診防止は文書上かなり改善済み。ただし Bash hard guard は未実装と PR 本文自身が認めています。 #102 | merged | web-researcher 追加と codebase-investigator の「Gemini API key」誤記修正。良い修正ですが、runtime preflight は未解決。 #140 | closed | .gemini/settings.json に excludeTools denylist を追加済み。現 main の settings は trust:false、read-only includeTools、dangerous excludeTools を持つ。 #54 | open | Serena CLI コマンド形式の moving target 対策。現状の静的検証は upstream drift に弱いので、#71 の残リスクと直結します。 #14 | open | gemini-cli-headless-delegation 全体改善の親。429/quota/fallback 統一や preflight 統合の文脈はここにもあります。敵対的指摘
1. #101 の方針は「warning 降格」だけでは甘い
現 main の
preflight_gemini_headless.pyは、run_preflight()内で常に_validate_local_asset_research_settings()を実行し、エラーがあるとfailure_reasonを設定して即 return します。つまりgithub_research/grounded_research/no_toolsの利用者まで、Serena 設定不備で止まります。一方
run_gemini_headless.pyのvalidate_request()はtool_profile == local_asset_researchの場合だけ Serena 設定を検証します。ここに実装上の非対称性があります。ただし #101 の「local_asset_research 不備を warning 降格」という方向だけだと、今度は local_asset_research を本当に使う呼び出しでも preflight が成功に見える危険があります。より正しい修正はこれです。
profile ごとの top-level
ok判定を分けるべきです。no_tools: Gemini CLI version/help/smoke が通れば okproposal_only: 同上 + proposal_only schema 検証grounded_research: 同上 + grounding 利用可能性の smokegithub_research: 同上 +gh/gh authが fail なら top-level faillocal_asset_research: 同上 + Serena MCP settings / MCP discovery / tool filter が fail なら top-level fail現状の「全 profile を同時に検証して、不要なものは warning」は、観測性は高いですが gate として曖昧です。
2. fail-close はまだ「文書契約」であり、技術的制御ではない
PR #143 により、
codebase-investigator.mdは wrapper failure 後の直接 Read / Grep / Glob / Bash 代替を MUST NOT レベルで禁止しています。これは前進です。しかし現 main の frontmatter では、
codebase-investigatorは依然としてBashとReadを持っています。Grep/Globは disallowed ですが、Bash経由ならgrep,rg,gh,cat,sedなどを呼べます。つまり、今回の silent fallback 再発防止は モデルが指示を守ることに依存しています。敵対的に見ると、これは不十分です。
必要な follow-up は以下です。
許可すべき Bash は、原則この 3 種だけです。
Readも/tmp/codebase-investigator-result-*.jsonと request JSON 程度に限定し、workspace ファイルの直接 Read は禁止する設計が望ましいです。3.
GEMINI_API_KEY問題は「不要」ではなく「判定根拠にしてはいけない」Issue #71 のコメントで、実環境では OAuth / Google アカウント経路で Gemini CLI headless smoke が成功しており、
GEMINI_API_KEY未設定は本件の真因ではないと切り分けられています。ただし公式 Gemini CLI docs は、通常のローカル利用では Google アカウントログインを簡便な経路として説明しつつ、headless / 自動化では API key や Vertex AI を使う選択肢も示しています。したがって、Issue / agent 文言は次が正確です。(Gemini CLI)
PR #102 / #143 はこの方向に寄せており、ここは概ね妥当です。
4. transient failure を
auth.ok:falseに丸める設計は危険Gemini CLI headless docs では
-p/--promptによる非対話実行、JSON output、exit code が定義されています。特に exit code1は general / API failure を含むため、認証失効・quota・一時的 API failure を雑に同じ扱いにすると誤判定します。(Gemini CLI)Issue #40 の観測では、同一セッション内で codebase-investigator は
auth.ok:falseとされて fail-close、web-researcher は quota retry で成功、数分後に codebase-investigator も成功しています。これはauthではなく retryable transient failure の可能性が高いです。追加すべき
failure_classは最低限これです。そして
retryable: true|false、attempts、last_stderr_summaryを result に入れるべきです。config_invalidとquota_or_rate_limitedを同じauth.ok:falseに丸めると、今回と同じ運用判断ミスが再発します。5. Serena 設定は現 main で改善済みだが、静的 shape 検証はまだ脆い
現 main の
.gemini/settings.jsonはuvx --from git+https://github.com/oraios/serena serena --project-from-cwd、trust:false、read-onlyincludeTools、dangerousexcludeToolsを持ち、#140 の denylist gap は塞がっています。Gemini CLI の MCP 設定では
includeTools/excludeTools/trustが公式にサポートされ、excludeToolsが優先されます。この方向性自体は妥当です。(Gemini CLI) (Gemini CLI)ただし Serena 公式 docs は MCP 接続例として
serena start-mcp-server --context ... --project-from-cwdなどを示しており、Serena 側は active に変化しうる配布物です。静的に「args に literalserenaがあるか」だけを見る検証は、本質的な MCP 起動成功を保証しません。(OraiOS)#54 の採用方針は、単なる文字列検証ではなく次のどちらかにすべきです。
Option A+B 推奨: Serena の commit / version を pin しつつ、
serena --help/serena start-mcp-server --help/ MCP tool discovery smoke を複数候補で検証する。includeToolsは allowlist を正とし、未知 tool が見えた場合は warning ではなく profile 次第で fail。denylist は defense-in-depth として残すが、upstream tool 名 drift の唯一の安全策にしない。
#71 本文への具体的な改訂案
#71 は、現在のコメント列に重要情報が散っているため、本文に「最終整理」を追記した方がよいです。
AC も次のように更新するべきです。
GEMINI_API_KEY誤診が resolved として PR #102 / #143 に link されている[ ] AC5: silent fallback を技術的に封じる follow-up Issue が起票されている
推奨する次アクション
実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 を profile-aware preflight に修正する
単なる warning 降格ではなく
--profileを追加し、profile ごとに top-levelokを決める。新規 Issue: transient / quota / auth failure taxonomy + retry policy
failure_class,retryable,attemptsを schema 化し、config error は retry せず、quota / transient のみ backoff retry する。新規 Issue: codebase-investigator hard guard
Bashを wrapper 実行だけに制限し、Readを result JSON 読み取りだけに制限する hook / policy を入れる。調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 を先に結論化する
Serena command shape は moving target なので、静的文字列検証ではなく MCP discovery smoke を正にする。
調査: codebase-investigator が gemini-cli-headless-delegation 経由で調査できず直接 Read/Bash に fall back する事象の原因切り分け #71 は調査ログとして本文を更新してから close
実装: codebase-investigator の gemini 委譲フローを定義通りに修正する — context_files 規約明確化・fail-close 徹底・Serena MCP 切り分け手順追記 #100/feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む #102/実装: .gemini/settings.json に Serena MCP excludeTools denylist を追加し local_asset_research preflight を通過させる #140 は完了扱い、実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101/調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54/新規2件は未解決 dependency として明記する。
最終判定は Needs revision。#71 の調査方向は正しいですが、現時点では「原因切り分け完了」として閉じるには、runtime preflight、retry taxonomy、fallback enforcement の 3 点が不足しています。
## 結論Issue #71 は まだ close すべきではありません。初期仮説だった「Serena MCP 不在で codebase-investigator が fall back する」は、その後の観測で 少なくとも 4 系統の問題に分解されています。
preflight_gemini_headless.pyが profile 非依存でlocal_asset_researchを検証し、無関係な profile まで落とす。これは 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 が open のままです。codebase-investigatorはまだBash/Readを持つため、技術的には完全封止されていません。GEMINI_API_KEY未設定を原因扱いした件は feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む #102 / PR docs: codebase-investigator gemini 委譲フロー修正 — context_files 規約・fail-close・Serena MCP 切り分け手順 (#100) #143 で修正済み。ただし公式 Gemini CLI docs では headless 環境に API key / Vertex を推奨する記述もあるため、「API key 不要」と断定せず「このプロジェクトの既定経路では必須ではない。委譲可否は smoke/preflight で判定する」が正しいです。 ([Gemini CLI]1)auth.ok:falseが真の認証失効ではなく一時的 API / quota エラーだった可能性は、実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 の scope だけでは十分に扱えていません。Issue 調査: codebase-investigator が gemini-cli-headless-delegation 経由で調査できず直接 Read/Bash に fall back する事象の原因切り分け #71 コメントにもこの非対称 retry 問題が記録されています。したがって、#71 は「Serena MCP 依存の調査 Issue」として閉じるより、delegation failure taxonomy / profile-aware preflight / fallback enforcement の親調査ログとして再整理した方が品質が上がります。
関連 Issue / PR の状態整理
preflight_gemini_headless.pyの per-profile 化または warning 降格。現 main でも preflight は local_asset 検証失敗時に即 return します。context_files規約、fail-close、GEMINI_API_KEY 誤診防止は文書上かなり改善済み。ただし Bash hard guard は未実装と PR 本文自身が認めています。.gemini/settings.jsonにexcludeToolsdenylist を追加済み。現 main の settings はtrust:false、read-onlyincludeTools、dangerousexcludeToolsを持つ。敵対的指摘
1. #101 の方針は「warning 降格」だけでは甘い
現 main の
preflight_gemini_headless.pyは、run_preflight()内で常に_validate_local_asset_research_settings()を実行し、エラーがあるとfailure_reasonを設定して即 return します。つまりgithub_research/grounded_research/no_toolsの利用者まで、Serena 設定不備で止まります。一方
run_gemini_headless.pyのvalidate_request()はtool_profile == local_asset_researchの場合だけ Serena 設定を検証します。ここに実装上の非対称性があります。ただし #101 の「local_asset_research 不備を warning 降格」という方向だけだと、今度は local_asset_research を本当に使う呼び出しでも preflight が成功に見える危険があります。より正しい修正はこれです。
profile ごとの top-level
ok判定を分けるべきです。no_tools: Gemini CLI version/help/smoke が通れば okproposal_only: 同上 + proposal_only schema 検証grounded_research: 同上 + grounding 利用可能性の smokegithub_research: 同上 +gh/gh authが fail なら top-level faillocal_asset_research: 同上 + Serena MCP settings / MCP discovery / tool filter が fail なら top-level fail現状の「全 profile を同時に検証して、不要なものは warning」は、観測性は高いですが gate として曖昧です。
2. fail-close はまだ「文書契約」であり、技術的制御ではない
PR #143 により、
codebase-investigator.mdは wrapper failure 後の直接 Read / Grep / Glob / Bash 代替を MUST NOT レベルで禁止しています。これは前進です。しかし現 main の frontmatter では、
codebase-investigatorは依然としてBashとReadを持っています。Grep/Globは disallowed ですが、Bash経由ならgrep,rg,gh,cat,sedなどを呼べます。つまり、今回の silent fallback 再発防止は モデルが指示を守ることに依存しています。敵対的に見ると、これは不十分です。
必要な follow-up は以下です。
許可すべき Bash は、原則この 3 種だけです。
Readも/tmp/codebase-investigator-result-*.jsonと request JSON 程度に限定し、workspace ファイルの直接 Read は禁止する設計が望ましいです。3.
GEMINI_API_KEY問題は「不要」ではなく「判定根拠にしてはいけない」Issue #71 のコメントで、実環境では OAuth / Google アカウント経路で Gemini CLI headless smoke が成功しており、
GEMINI_API_KEY未設定は本件の真因ではないと切り分けられています。ただし公式 Gemini CLI docs は、通常のローカル利用では Google アカウントログインを簡便な経路として説明しつつ、headless / 自動化では API key や Vertex AI を使う選択肢も示しています。したがって、Issue / agent 文言は次が正確です。(Gemini CLI)
PR #102 / #143 はこの方向に寄せており、ここは概ね妥当です。
4. transient failure を
auth.ok:falseに丸める設計は危険Gemini CLI headless docs では
-p/--promptによる非対話実行、JSON output、exit code が定義されています。特に exit code1は general / API failure を含むため、認証失効・quota・一時的 API failure を雑に同じ扱いにすると誤判定します。(Gemini CLI)Issue #40 の観測では、同一セッション内で codebase-investigator は
auth.ok:falseとされて fail-close、web-researcher は quota retry で成功、数分後に codebase-investigator も成功しています。これはauthではなく retryable transient failure の可能性が高いです。追加すべき
failure_classは最低限これです。そして
retryable: true|false、attempts、last_stderr_summaryを result に入れるべきです。config_invalidとquota_or_rate_limitedを同じauth.ok:falseに丸めると、今回と同じ運用判断ミスが再発します。5. Serena 設定は現 main で改善済みだが、静的 shape 検証はまだ脆い
現 main の
.gemini/settings.jsonはuvx --from git+https://github.com/oraios/serena serena --project-from-cwd、trust:false、read-onlyincludeTools、dangerousexcludeToolsを持ち、#140 の denylist gap は塞がっています。Gemini CLI の MCP 設定では
includeTools/excludeTools/trustが公式にサポートされ、excludeToolsが優先されます。この方向性自体は妥当です。([Gemini CLI]3) (Gemini CLI)ただし Serena 公式 docs は MCP 接続例として
serena start-mcp-server --context ... --project-from-cwdなどを示しており、Serena 側は active に変化しうる配布物です。静的に「args に literalserenaがあるか」だけを見る検証は、本質的な MCP 起動成功を保証しません。([OraiOS]4)#54 の採用方針は、単なる文字列検証ではなく次のどちらかにすべきです。
serena --help/serena start-mcp-server --help/ MCP tool discovery smoke を複数候補で検証する。includeToolsは allowlist を正とし、未知 tool が見えた場合は warning ではなく profile 次第で fail。#71 本文への具体的な改訂案
#71 は、現在のコメント列に重要情報が散っているため、本文に「最終整理」を追記した方がよいです。
AC も次のように更新するべきです。
推奨する次アクション
実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 を profile-aware preflight に修正する
単なる warning 降格ではなく
--profileを追加し、profile ごとに top-levelokを決める。新規 Issue: transient / quota / auth failure taxonomy + retry policy
failure_class,retryable,attemptsを schema 化し、config error は retry せず、quota / transient のみ backoff retry する。新規 Issue: codebase-investigator hard guard
Bashを wrapper 実行だけに制限し、Readを result JSON 読み取りだけに制限する hook / policy を入れる。調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54 を先に結論化する
Serena command shape は moving target なので、静的文字列検証ではなく MCP discovery smoke を正にする。
調査: codebase-investigator が gemini-cli-headless-delegation 経由で調査できず直接 Read/Bash に fall back する事象の原因切り分け #71 は調査ログとして本文を更新してから close
実装: codebase-investigator の gemini 委譲フローを定義通りに修正する — context_files 規約明確化・fail-close 徹底・Serena MCP 切り分け手順追記 #100/feat: web-researcher SubAgent を追加し issue-refinement-loop に組み込む #102/実装: .gemini/settings.json に Serena MCP excludeTools denylist を追加し local_asset_research preflight を通過させる #140 は完了扱い、実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101/調査: serena CLI コマンド形式の moving target リスクへの対策方針を決定する (PR #49 follow-up) #54/新規2件は未解決 dependency として明記する。
最終判定は Needs revision。#71 の調査方向は正しいですが、現時点では「原因切り分け完了」として閉じるには、runtime preflight、retry taxonomy、fallback enforcement の 3 点が不足しています。
squne121 commentedon May 23, 2026
issue-refinement-loop iter 1: C4(VC コードフェンス→バレット形式)、C5(
# AC1-AC3範囲表記修正)、NB2(AC 3件→5件・4系統分解反映)、NB3(Current Finding Summary 追加)、NB1(Runtime Verification Applicability 追加)を反映。squne121 commentedon May 23, 2026
issue-refinement-loop iter 2: C5(
# AC1タグ重複→単一タグ化)のみ修正。squne121 commentedon May 23, 2026
issue-refinement-loop: 完了 (2026-05-23T06:10:16Z)
# AC1-AC3範囲表記修正)、NB2(AC 3件→5件・4系統分解反映)、NB3(Current Finding Summary 追加)、NB1(Runtime Verification Applicability 追加)# AC1タグ重複)# AC1タグ単一化)→ approvesqune121 commentedon May 23, 2026
issue-refinement-loop: 最終完了報告 (2026-05-23T06:18:09Z)
改善履歴
# AC1-AC3範囲表記修正)、NB2(AC 3件→5件・4系統分解反映)、NB3(Current Finding Summary 追加)、NB1(Runtime Verification Applicability 追加)# AC1タグ重複)→ 修正派生 Issue の対応
次アクション
issue-contract-reviewを起動して実装着手 preflight を実施squne121 commentedon May 23, 2026
クローズ (2026-05-23T06:29:29Z)
issue-refinement-loop 完了・後続 Issue 準備完了に伴いクローズします。
達成内容
後続 Issue