Repository navigation
Closed
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "なし(単独改善)"
goal_ref: "Claude Code の非同期起動 SubAgent でも identity evidence を失わないように、run_worktree_agent_runtime_smoke.py の child identity 抽出経路を hook channel 対応にする"
change_kind: implementationParent Issue
なし(単独改善)
Outcome
scripts/agent-ops/run_worktree_agent_runtime_smoke.py の child identity 抽出経路が、
Claude Code の Agent tool が返す 非同期起動エンベロープ(status: "async_launched"、
agentType フィールドを含まない)でも runtime 提供の identity evidence を取りこぼさない状態。
native_spawn_event_observed が、spawn が実際に成立している run で False に落ちなくなる。
evidence の出所(provenance)が記録され、evidence が皆無の場合は従来どおり fail-closed で None を返す。
背景(Issue #2013 の evidence)
Issue #2013 の research(artifacts/claude-code-spawn-observability-research/、
Claude Code 2.1.225、tested SHA 9eca2f0074552a3e0687b0c81ee94b62122890a0、control 15 trial + production 15 trial)で
次が決定論的に確認された。
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になり、
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 を含む。 tool_use_result.agentTypeが欠落した 17 trial すべてで、hook channel は
正しいagent_typeを返し、agentIdは両 channel で完全一致した。
wall-clock timeout とsystem/api_retryは 0 件であり、transient failure ではない。
すなわち runtime は identity evidence を提供しており、欠落しているのは repo 側の抽出経路のみである。
Issue #2013 の結論カテゴリは repo_observability_defect である。
In Scope
extract_claude_child_agent_type()を、tool_use_result.agentTypeに加えて
hook channel(SubagentStart/SubagentStophook event の payload、および
hook_nameの<HookEvent>:<agent_type>接尾辞)からも agent type を抽出できるようにする。
優先順位は既存のtool_use_result経路を先に評価し、そこで得られない場合のみ hook channel を見る。- identity evidence の provenance を
child_agent_type_sourceとして
summary.mdの schema summary に記録する。 extract_claude_child_session_id()のparent_session_id欠落時の短絡
(run_worktree_agent_runtime_smoke.py内if not parent_session_id: return None)を解消し、
stdout に childagentIdが存在すればそれを返す。Agenttool の launch mode(同期完了 / 非同期起動 / 不明)を
child_spawn_launch_modeとして記録する。- 上記すべてに対する fixture ベースの回帰テストを追加する。
Out of Scope
native_spawn_event_observedの合成条件そのものの緩和(禁止)。
evidence が皆無なら従来どおりFalseに fail-close する。- expected agent type の代入、caller self-report の identity evidence 化(禁止)。
scripts/agent-ops/run_agent_provider_route_smoke.pyの failure ladder /_is_transient_infrastructure_candidate()の変更。
Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 のretry-policy-assessment.mdは現行設計の維持を結論している。- 非同期起動時に親セッションが子の完了を待たないことで marker / delegation evidence が
materialize しない問題(完了待ち semantics の課題であり、別途 scope 判断が必要)。 - repo-tracked
.claude/settings.json/.claude/hooks/**の変更。
本 Issue は既に stream-json に現れる hook event を読むだけで、hook 登録を要求しない。 - Codex CLI lane の identity 抽出経路の変更。
Acceptance Criteria
- AC1: 非同期起動エンベロープ(
tool_use_resultにagentIdはあるがagentTypeが無い)と
SubagentStarthook payload(agent_typeを含む)を含む stdout に対して、
extract_claude_child_agent_type()が hook payload のagent_typeを返す。 - AC2:
tool_use_result.agentTypeが存在する stdout では、hook channel より
tool_use_resultの値が優先される(既存挙動の非退行)。 - AC3: hook payload が無く
hook_nameが"SubagentStart:<agent_type>"形式の場合、
その接尾辞から agent type を抽出する。 - AC4: identity evidence が一切存在しない stdout では
extract_claude_child_agent_type()が
Noneを返す(fail-closed の非退行)。 - AC5:
extract_claude_child_session_id()がparent_session_idをNoneで呼ばれても、
stdout に childagentIdがあればそれを返す。 - AC6: schema summary に
child_agent_type_sourceが記録され、値が
tool_use_result/hook_payload/hook_name/Noneのいずれかである。 - AC7: schema summary に
child_spawn_launch_modeが記録され、
非同期起動エンベロープではasync_launchedになる。 - AC8: 既存の
scripts/agent-ops/tests/test_worktree_agent_runtime_smoke.pyと
scripts/agent-ops/tests/test_agent_provider_route_smoke.pyが引き続き全 pass する。
Verification Commands
# AC1-AC7
# baseline-expect: fail
$ uv run pytest scripts/agent-ops/tests/test_claude_spawn_identity_evidence.py# AC8
# baseline-expect: pass
$ uv run pytest scripts/agent-ops/tests/Allowed Paths
- scripts/agent-ops/run_worktree_agent_runtime_smoke.py
- scripts/agent-ops/tests/
Stop Conditions
- Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
- Allowed Paths 外への書き込みを試みた場合は即停止
- 権限不足(permission denied)により操作が完了できない場合は即停止
native_spawn_event_observedの evidence 水準を下げる変更が必要になった場合は即停止
Handoff Contract
Current ObjectiveBounded Current ContextOpen QuestionsNext ActionArtifact Refs
Notes for Reviewer
- 起票元: Issue 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013 の research 結論(
repo_observability_defect)。
raw evidence はartifacts/claude-code-spawn-observability-research/reproduction-log.jsonl。 - hook を identity evidence の唯一の正本にはしない。
tool_use_result経路を優先し、
hook channel はそれが得られない場合の追加チャネルとして扱う。
upstream のhttps://github.com/anthropics/claude-code/issues/27755
(SubagentStart/SubagentStopの未発火を報告する community bug report、"Closed as not planned")は
公式契約ではなく、hook 単独依存を避ける設計判断の補助資料である。 - 関連: 調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する #2013(本 Issue の起票元 research)、実装: codebase-investigator / web-researcher の delegation request で AGY provider をメインルートにする #1886 / PR 実装: codebase-investigator/web-researcher を AGY-only provider route へ固定する #2005(
extract_claude_child_agent_type()の導入元)。
Metadata
Metadata
Assignees
Labels
No labels
Activity
調査: Claude Code custom SubAgent の spawn observability 非決定性を診断する (#2013)…