Repository navigation
調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する (#2013) - #2022
Merged
Merged
Conversation
control lane 15 trial / production lane 15 trial の固定試行で、 claude_code runtime の spawn_not_observed / validation_failed を lifecycle 12 checkpoint 単位で切り分けた research artifact を追加する。 結論カテゴリは repo_observability_defect。 Claude Code 2.1.225 の Agent tool は status: "async_launched" の 非同期起動エンベロープを返すことがあり、その形状には agentType が無い。 extract_claude_child_agent_type() は tool_use_result.agentType のみを読むため None を返し、native_spawn_event_observed が spawn 成立時にも False に落ちる。 同じ run の hook channel には runtime が返した agent_type が存在し、 agentId は両 channel で 30/30 trial 完全一致する。 timeout と system/api_retry は 0 件であり transient failure ではないため、 _is_transient_infrastructure_candidate() が claude_code + spawn_not_observed を bounded retry 対象外とする現行設計は維持する。 production code は一切変更していない。追従する修正は #2021 で扱う。 Closes #2013 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
Preview URLPreview removed (PR #2022 closed). |
markdownlint MD040 が retry-policy-assessment.md / conclusion.md の 言語指定なし fenced code block を検出したため、build_assessments.py が yaml 言語付きの fence を生成するようにする。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
ci_test_selection/v1 の uncovered_changed_test_files gate が、新規追加した 5 本の contract test を「plan に未登録」として検出し、required check の python-test(python-test-core 経由)を fail させていた。 Scope Delta: Issue #2013 の Allowed Paths は artifacts/claude-code-spawn-observability-research/ のみだが、 新規 pytest ディレクトリを .github/ci/python-test-plan.json の targets に 登録しないと required CI が通らないため、1 行の target 追加のみを行う。 Issue #2013 が変更を禁じている production code (run_worktree_agent_runtime_smoke.py / run_agent_provider_route_smoke.py / .claude/settings.json / .claude/hooks/**)には一切触れていない。 あわせて日本語比率ゲート(PR Body Japanese Check の changed Markdown 検査)で 不足していた prose block に日本語を追加する。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Owner
Author
CI / テストレーン判断の証跡
CI_TEST_PERFORMANCE_DECISION_V1:
schema: CI_TEST_PERFORMANCE_DECISION_V1
issue_number: 2013
pr_number: 2022
decision_scope: ci_change
changed_paths:
- .github/ci/python-test-plan.json
- artifacts/claude-code-spawn-observability-research/
lane_classification:
fast_static:
applicable: true
evidence:
- "markdownlint MD040 が生成 Markdown の fence 言語欠落を検出したため修正した"
required_commands:
- pnpm lint
- pnpm lint:docs
- uv run --locked ruff check .claude/scripts scripts schemas .claude/skills
python_unit:
applicable: true
evidence:
- "新規 contract test 5 本を artifacts/claude-code-spawn-observability-research/tests/ に追加した"
- "ci_test_selection/v1 の uncovered_changed_test_files gate が 5 件を未登録として検出した"
required_commands:
- uv run pytest artifacts/claude-code-spawn-observability-research/tests/
- uv run pytest scripts/ci/tests/test_python_test_plan.py
contract_artifact:
applicable: true
evidence:
- "python-test-plan SSOT に target を追加し、pytest 実行と ci_test_selection/v1 の対象を一致させた"
required_commands:
- uv run python3 scripts/ci/python_test_plan.py --emit scope-argv --check-paths --format json
integration:
applicable: false
evidence:
- "runtime 実行は research harness 内で完結し、CI integration lane を変更していない"
required_commands: []
baseline_inputs:
ci_runtime_baseline_v1_available: false
run_count: 0
p50_p95_ready: false
artifact_consistency:
ci_test_selection_v1_checked: true
missing_pytest_args: []
risk_flags:
- "追加した contract test は artifacts/ 配下にあるが、CI の pytest lane は plan の targets を正本とするため登録が必要である"
- "テストは decision/ledger の静的検証のみで、live runtime 起動を伴わないため lane 実行時間への影響は小さい"
reviewer_gate:
approve_allowed: true
required_evidence:
- CI_CHECK_RUN_SCOPED
follow_up_required: []Scope Delta の説明Issue #2013 の Allowed Paths は
|
This was referenced Aug 8, 2026
Merged
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Issue #2013(research-only)の成果物を
artifacts/claude-code-spawn-observability-research/に追加する。PR #2005 / Issue #1886 の impl-review-loop で観測された claude_code runtime の非決定的
spawn_not_observed/validation_failedについて、lifecycle checkpoint 単位で原因を切り分けた。production code(
scripts/agent-ops/run_worktree_agent_runtime_smoke.py、scripts/agent-ops/run_agent_provider_route_smoke.py、repo-tracked.claude/settings.json、.claude/hooks/**)は一切変更していない。差分は原則として Allowed Paths(
artifacts/claude-code-spawn-observability-research/)内だが、Scope Delta として
.github/ci/python-test-plan.jsonに 1 行だけ target を追加している。AC が要求する新規 pytest ディレクトリを required check である
python-testが拾えるようにするための最小限の登録であり、これを行わないと
ci_test_selection/v1のuncovered_changed_test_filesgate が required CI を fail させる。判断の詳細は本 PR の
CI_TEST_PERFORMANCE_DECISION_V1コメントに記録した。本 PR のマージをもって対象 Issue を完了として閉じる。Closes #2013
調査方法(research method)
事前に
trial-plan.jsonとして試行条件を凍結し、その SHA256 digest を全 record に刻んだ上で固定試行数を実行した。結果を見てから route 比率・prompt・timeout・max-turns・agent 定義を
変更していない。
--agentsで inline 定義した最小 customsubagent
spawn-probeを spawn する。外部 provider・Serena MCP・GitHub retrieval を一切必要としない。research artifact 内に生成した session-local
--settingsでSubagentStart/SubagentStophook を no-op logger として構成し、公式 hook payload を stream-json から回収した。
codebase-investigator/web-researcherを、実build_route_prompt()と実 gemini sentinel stub で駆動した。3 route を宣言順にラウンドロビンして各 5 trial。
分類は production コードを read-only import して算出しており、
failure_classは_run_route_once()の評価順序を忠実に複製している。diagnostic_causeはそれとは独立にraw lifecycle checkpoint のみから算出する。全 trial の raw stdout/stderr を
raw/に保存したので、派生値はすべて独立に再計算できる。
実行条件
2.1.225 (Claude Code)9eca2f0074552a3e0687b0c81ee94b62122890a028394e226533cd59cdfc0f55602ac65e389a6600baseline から tested SHA までの差分は #2010(Graphify CLI advisory pilot)の 1 commit のみで、
調査対象の 2 スクリプトは変更されていない。provenance は
code-analysis.mdに記録した。分布サマリ(distribution summary)
lane 別の status 分布は次のとおりである。
lane 別
diagnostic_cause(noneは pass):nonetool_result_identity_not_observednonetool_result_identity_not_observedrequest_validation_faileddelegation_wrapper_failedidentity evidence の channel 比較:
wall-clock timeout は 0 件、
system/api_retry観測も 0 件だった。診断結論(diagnostic conclusion)
結論カテゴリは
repo_observability_defectである。Claude Code 2.1.225 の
Agenttool が返すtool_use_resultには 2 形状がある。status: "completed"、agentTypeありisAsync: true,status: "async_launched"、agentIdはあるがagentTypeが無いextract_claude_child_agent_type()はtool_use_result.agentTypeとテキスト断片のみを読むため、非同期起動型では常に
Noneを返す。その結果agent_type_identity_verifiedがFalseとなり、spawn が実際に成立している run でも
native_spawn_event_observedがFalseに落ちる。一方、同じ run の hook channel には runtime 自身が返した identity evidence が存在する。
SubagentStart/SubagentStophook payload は公式スキーマどおりagent_id/agent_typeを持ち、SubagentStartのhook_nameは"SubagentStart:<agent_type>"形式で agent type を含む。agentTypeが欠落した 20 trial すべてで hook channel は要求どおりのagent_typeを返し、agentIdは全 30 trial で両 channel 完全一致した。すなわち runtime は identity evidence を提供しており、欠けているのは repo 側の抽出経路のみである。
upstream runtime の契約違反でも、infrastructure の transient failure でも、
model orchestration の問題でも、downstream route の失敗でもない。
spawn_not_observedとvalidation_failedに分かれるのは spawn の有無ではなく、_run_route_once()の順 4(harness 非ゼロ終了)が順 5(spawn evidence)より先に評価されるかで決まる。外側の
failure_classから spawn の有無を推測してはならない。なお Issue 本文が 8 段階として記載していた評価順序は current main では 9 段階
(
route_evidence_schema_mismatchを含む)であり、この drift もcode-analysis.mdに記録した。retry policy 結論
retry_policy_verdict: keep_excluded_is_transient_infrastructure_candidate()がclaude_code+spawn_not_observedをbounded single retry の対象外としている現行設計は、観測データと整合するため 維持する。
観測された
spawn_not_observedはすべて決定論的な抽出経路の欠落であり、timeout も
system/api_retryも 1 件も観測されていない。再実行するとエンベロープ形状の分岐に応じて成功することはあるが、それは根本原因の解消ではない。
「再実行したら通った」だけを transient 判定の根拠にはしていない。
ただし現行コードのコメントが述べる理由(Claude の spawn evidence は in-memory stdout にあるため
miss は transient ではない)は、実際に観測した機序とは異なる。結論は正しいが根拠は更新されるべきである。
既存契約テスト
test_claude_spawn_not_observed_is_not_transient_candidateは変更不要である。silent retry・2 回以上の追加 retry・成功するまでの反復 retry はいずれも提案していない。
追従実装 Issue(follow-up implementation issue)
#2021 を起票した。本 PR は research-only のため、#2021 を閉じる keyword は本文に含めていない。
run_worktree_agent_runtime_smoke.pyの identity evidence 抽出経路を hook channel 対応にすること、および
extract_claude_child_session_id()がparent_session_id欠落時に stdout 探索自体をスキップする短絡を解消することを扱う。#2013 は research-only のため本 PR では実装しない。
非同期起動時に親セッションが子の完了を待たず marker / delegation evidence が materialize しない
事象は、完了待ち semantics の別課題として
conclusion.mdに観測事実のみ記録し、#2021 のスコープには含めていない。
スコープ境界
failure_classschema(spawn_not_observed/validation_failed)は変更していない。diagnostic_causeのrequest_validation_failed/delegation_wrapper_failedとして spawn lifecycle とは別フィールドに保持しており、spawn failure へ再分類していない。
独立記録して突き合わせている。upstream の
[BUG] SubagentStart/SubagentStop unreliable for settings.json hooks — cascade failures break agent lifecycle management anthropics/claude-code#27755 は community bug report であり
公式契約ではないことを artifact 内に明記した。
検証結果(全 verification)
Issue #2013 の Verification Commands はすべて
baseline-expect: failである。origin/mainにはartifacts/claude-code-spawn-observability-research/が存在せず(
git ls-tree origin/main -- artifacts/claude-code-spawn-observability-research/が空)、5 コマンドすべてが baseline で fail することを確認した上で成果物を完成させた。
false-green のために assertion を弱めていない。
uv run pytest artifacts/claude-code-spawn-observability-research/tests/test_code_analysis_contract.pyuv run pytest artifacts/claude-code-spawn-observability-research/tests/test_reproduction_log_contract.pyuv run pytest artifacts/claude-code-spawn-observability-research/tests/test_reproduction_summary_contract.pyuv run pytest artifacts/claude-code-spawn-observability-research/tests/test_retry_policy_assessment_contract.pyuv run pytest artifacts/claude-code-spawn-observability-research/tests/test_conclusion_contract.pyuv run pytest artifacts/claude-code-spawn-observability-research/tests/リポジトリ必須検証:
pnpm typecheckpnpm lintpnpm testpnpm builduv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.pyuv run ruff check artifacts/claude-code-spawn-observability-research/uv run python3 scripts/ci/check_python_invocation_policy.pypnpm lint:docsuv run pytest scripts/ci/tests/test_python_test_plan.pyvalidate_japanese_content.pyGitHub Actions の required check(
typecheck/lint/test/build/python-test/validate-generated-artifact)はすべて green である。component-vrt-reportは required check ではなく、branch 分岐元のmain(9eca2f00)およびその前 2 commit でも同じ job が failure であることを確認した既存の failure であるため、
本 PR では対応しない(VRT を通すためのスコープ外変更を行わない)。
contract test は artifact の散文を読むだけでなく、引用した
file:lineが実際の production source の該当条件を指しているか、既存テスト名が実在するか、summary の各数値が raw JSONL から再計算した値と
一致するかまで相互検証している。
本 PR は Claude Code により生成された。
🤖 Generated with Claude Code