Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: research
parent_issue: "#14"
goal_ref: "gemini-cli-headless-delegation の preflight / run wrapper に failure_class taxonomy と retry policy を schema 化し、transient error の誤分類を解消する"
change_kind: research-onlyParent Issue
Outcome
gemini-cli-headless-delegation の preflight / run wrapper の result JSON に failure_class(retry 可否付き)、retryable、attempts、last_stderr_summary フィールドが追加され、config error は retry せず quota/transient error のみ backoff retry する方針が SKILL.md または references/ 配下のドキュメントに記録された状態となり、後続の実装 Issue が起票可能になる。
Background
Issue #71 の refinement-loop で判明した問題として、auth.ok:false が transient エラー(quota / 一時的 API エラー)と真の認証失効を同一フィールドに丸めているため、retry 可否の判断ができず、config error でも quota error でも同じ fail-close になっている。
Issue #40 の観測では:
- codebase-investigator が
auth.ok:falseで fail-close - 同時刻に web-researcher が quota retry で成功
- 数分後に codebase-investigator が再試行で成功
これは auth.ok:false が transient error の誤分類である証拠であり、retry policy が非対称になっている。
現行の result JSON には failure_class / retryable / attempts / last_stderr_summary フィールドが存在せず、caller 側で retry 可否を判断する根拠が得られない。
In Scope
failure_classの分類体系(taxonomy)の定義と文書化(最低限:config_invalid、cli_missing、auth_missing_or_expired、quota_or_rate_limited、transient_api_error、network_error、output_parse_error)- preflight result JSON への
retryable: true|false、attempts: int、last_stderr_summary: stringフィールド仕様の策定 - retry policy の方針確定(
config_invalid/cli_missing/cli_incompatibleは retry 不可、quota_or_rate_limited/transient_api_error/network_errorは backoff retry 可)と SKILL.md またはreferences/への記録 - 後続の実装 Issue 起票
Out of Scope
- preflight の per-profile 化(実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 で扱う)
- codebase-investigator の Bash/Read hard guard(別 Issue で扱う)
- ACP transport 実装(実装: gemini-cli-headless-delegation に ACP (Agent Client Protocol) transport を完全実装する #26)
- 実装コード変更(
src/改修 /tests/追加)
Acceptance Criteria
- AC1:
failure_classの分類体系が定義され SKILL.md またはreferences/配下のドキュメントに記録されている(最低限:config_invalid、cli_missing、auth_missing_or_expired、quota_or_rate_limited、transient_api_error、network_error、output_parse_error) - AC2: preflight の result JSON 仕様に
retryable: true|false、attempts: int、last_stderr_summary: stringが追加されている - AC3:
config_invalid/cli_missing/cli_incompatibleは retry 不可(fail-close)、quota_or_rate_limited/transient_api_error/network_errorは backoff retry 可という方針が SKILL.md またはreferences/に記録されている - AC4: 本 Issue を受けた後続の実装 Issue が起票されており、本 Issue がそれを link している
Verification Commands
# AC1: failure_class taxonomy の記述確認
$ rg "failure_class|config_invalid|quota_or_rate_limited|transient_api_error" .claude/skills/gemini-cli-headless-delegation/ && echo "PASS: AC1" || echo "FAIL: AC1"
# AC2: retryable / attempts / last_stderr_summary フィールドの記述確認
$ rg "retryable|last_stderr_summary" .claude/skills/gemini-cli-headless-delegation/ && echo "PASS: AC2" || echo "FAIL: AC2"
# AC3: retry 不可 / retry 可方針の記述確認
$ rg "retry.*config_invalid|cli_missing.*retry|fail-close|backoff retry" .claude/skills/gemini-cli-headless-delegation/ && echo "PASS: AC3" || echo "FAIL: AC3"
# AC4: 後続実装 Issue が起票されているか確認(本 Issue クローズ前に番号を差し替える)
$ gh issue list --search "実装: gemini-cli-headless-delegation failure_class" --state open --json number,title,urlAllowed Paths
- 読み取り専用。リポジトリ変更なし(既定)
- 調査成果物として failure_class taxonomy を文書化する場合のみ:
.claude/skills/gemini-cli-headless-delegation/
Stop Conditions
- Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
- Allowed Paths 外への書き込みを試みた場合は即停止
- 権限不足(permission denied)により操作が完了できない場合は即停止
- 成果物の書き込みに失敗した場合(I/O エラー等)は即停止
Runtime Verification Applicability
decision: not_applicable
reason: research-only Issue。調査レポートの存在確認と grep による記述確認のみ。実装変更なし。
Handoff Contract
Current Objective:failure_classtaxonomy の確定と result JSON フィールド仕様の策定Bounded Current Context:.claude/skills/gemini-cli-headless-delegation/の preflight / run wrapper 周辺Open Questions: 既存 stderr 出力からfailure_classを判別するロジックの実現可能性Next Action: taxonomy と retry policy 確定後、後続の実装 Issue(result JSON フィールド追加・preflight wrapper 改修)を起票するArtifact Refs:.claude/skills/gemini-cli-headless-delegation/SKILL.md、references/配下の新規文書
Source
dedupe_key: transient-quota-auth-failure-taxonomy-retry-policy
source_issue: #71
source_url: #71
Activity
squne121 commentedon May 23, 2026
issue-refinement-loop: C4(VC コマンド行に
$プレフィックス追加)、C9 warn 解消(Runtime Verification Applicability 追加)。squne121 commentedon May 23, 2026
敵対的レビュー結論
判定: needs-fix before implementation issue.
Issue #268 の問題意識は正しいです。#71 は未解決項目として「transient / quota / API failure の auth 誤分類」を明示しており、#268 はその follow-up として妥当です。
ただし、現状の #268 は taxonomy を定義するには粒度が粗く、後続実装 Issue に渡すと再び
auth.ok:false的な過剰集約スキーマを作る危険が高いです。重大指摘
1. 「Issue #40 の観測」根拠が弱い
#268 は「Issue #40 の観測」として、codebase-investigator が
auth.ok:falsefail-close、web-researcher が quota retry 成功、数分後に codebase-investigator が成功した、という事象を根拠にしています。しかし #40 本文は DoR / state label / Plan Mode を束ねる parent tracker であり、少なくとも取得できた本文だけではその具体的 runtime 観測の一次証跡には見えません。
修正: #268 の Background に、実際の
auth.ok:false/ quota retry / later success が記録された 正確な issuecomment URL または runtime log artifact を追加すべきです。根拠が曖昧なまま taxonomy 化すると、「現象の再現性」ではなく「推測」をスキーマに固定します。2. #101 と衝突している
#268 は preflight / run wrapper の failure classification を扱いますが、Out of Scope で #101 の per-profile preflight を外しています。
一方、#101 は現行
preflight_gemini_headless.pyが profile に関係なくlocal_asset_researchの Serena 設定を検証し、無関係なgithub_research/grounded_research/no_toolsまで top-levelok:falseにする問題を扱っています。現行 preflight 実装でも
local_asset_errorsがあればfailure_reasonに設定して即 return しており、smoke test へ進みません。修正: #268 は #101 を単に Out of Scope にするのではなく、次のどちらかを明示すべきです。
Blocked by #101: preflight top-levelfailure_classは 実装: preflight_gemini_headless.py を per-profile 検証化し local_asset_research 不備で preflight 全体を fail させない #101 完了後に定義するsection-local classification:local_asset_research.ok:falseは section-local failure とし、top-level preflight failure とは別扱いにするこの区別なしに
config_invalidを導入すると、#101 の誤 fail-close を「仕様」として固定するリスクがあります。3.
retryable: true|falseは情報量が不足しているGemini API 公式の troubleshooting では、400 は malformed request、403 は権限・認証、429 は rate limit、500/503 は一時的な Google 側障害や過負荷、504 は deadline 超過として整理されています。特に 500/503 は待機・モデル切替・再試行が候補ですが、504 は timeout 拡大や context 削減が必要になる場合があります。([Google AI for Developers]1)
また rate limit は RPM / TPM / RPD など複数軸で発生します。([Google AI for Developers]2)
したがって
retryable: booleanだけでは足りません。必要なのは少なくとも以下です。Google Cloud の retry guidance でも、retry 可否は「レスポンス」と「操作の冪等性」の両方で決まるとされ、408/429/5xx や socket timeout は一般に retryable だが、永続的エラーは authorization/config 変更が必要と整理されています。([Google Cloud]3)
4. 現行 wrapper には retry があるが、caller に見えない
run_gemini_headless.pyはRETRY_LIMIT = 2を持ち、capacity / 429 系を_is_retryable_capacity_failure()で検出して同一 model を retry し、さらに model downgrade も行います。しかし result JSON には
attempts、attempts_by_model、retry_budget_exhausted、last_stderr_summaryが出ていません。最終的にmodel_chain_exhaustedのreason_codeは出るものの、どの model で何回失敗したかは caller が安定して読めません。修正:
attemptsは単なる int ではなく、最低限こう定義すべきです。5. ACP transport の既存知見を taxonomy に反映していない
ACP 側には既に
failure_classの先行実装があります。auth_requiredは fallback で隠さず hard failure として surface する設計になっており、authMethodsが存在するだけでは auth_required と判定しない、というコメントも実装に残っています。さらに ACP fallback は
gemini_not_found/launch_failed/initialize_failed/session_new_failedのような early failure class に限定され、auth_requiredは明示的に除外されています。#268 は ACP transport を Out of Scope にしていますが、taxonomy 設計の prior art としては必ず参照すべきです。ここを無視すると、headless_json 側でまた「auth っぽい文字列があったら auth_missing_or_expired」型の誤分類を再発させます。
推奨 taxonomy
#268 の最低限 taxonomy は以下に置き換えるべきです。
failure_class は最低限これくらい必要です。
output_parse_errorは常時 retryable にしない方がよいです。CLI の JSON 出力契約破壊、prompt leakage、stderr/stdout 混線、CLI version incompatibility の可能性があるため、最大 1 回の retry か、classification_confidence: lowで human escalation が妥当です。#268 本文への具体的パッチ方針
追加すべき AC
Verification Commandsは grep だけでは弱い現行 AC は
rgで文字列があることしか見ません。docs-only research でも、次のような fixture table 検査を入れるべきです。
後続実装 Issue の切り方
#268 の AC4 は「後続実装 Issue 起票」ですが、1 Issue に preflight と run wrapper を両方入れるとまた大きすぎます。分割推奨です。
Issue A: run wrapper の result schema 拡張
対象:
内容:
failure_classfailure_originretryableretry_scopeattemptsattempts_by_modellast_stderr_summaryIssue B: preflight result schema 拡張
#101 と依存関係を明示。#101 完了前なら top-level
okは触らず、section-local classification のみ。対象:
内容:
cli_missingcli_incompatibletrusted_workspace_requiredmcp_config_invalidgh_auth_requiredoutput_parse_errorretryable/retry_scope最終提案
#268 は close せず、まず本文を修正してください。特に次の 4 点は必須です。
retryableboolean ではなくretry_scopeとattempts_by_modelを入れるauth_required/ fallback 除外の知見を taxonomy 設計に反映するこの修正後なら、#268 は「調査 Issue」として有効です。現状のまま後続実装に進むと、
auth.ok:falseをfailure_classに名前だけ変えたような、caller が正しく判断できない schema になる可能性が高いです。squne121 commentedon May 23, 2026
Contract Snapshot (2026-05-23T07:00:00Z)
CONTRACT_REVIEW_RESULT_V1
実装詳細
failure_classtaxonomy 確定 + retry policy 文書化 + 後続実装 Issue 起票.claude/worktrees/issue-268-gemini-cli-headless-delegation-failure-cworktree-issue-268-gemini-cli-headless-delegation-failure-csqune121 commentedon May 23, 2026
implement-issue: AC4 後続実装 Issue 起票
後続の実装 Issue を起票しました:
実装: gemini-cli-headless-delegation failure_class taxonomy を result JSON に追加し retry policy を実装する #277
この Issue の taxonomy と retry policy 文書(
references/failure-class-taxonomy.md)を仕様の正本として #277 で実装を進めます。squne121 commentedon May 23, 2026
implement-issue: 実装完了 (2026-05-23T06:58:45Z)
.claude/worktrees/issue-268-gemini-cli-headless-delegation-failure-cworktree-issue-268-gemini-cli-headless-delegation-failure-cdocs(#268): failure-class-taxonomy v2 - PR #278 レビュー指摘を全反映
docs(#268): failure_class taxonomy と retry policy を references/ に追加 (#…
squne121 commentedon May 23, 2026
post-merge-cleanup: 完了 (2026-05-23T07:35:00Z)