Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent-retrospective の production Agent invocation が現行 Claude Code CLI 上で実質的な分析タスクに対して fail-closed する regression を解消し、CI 上で継続検知できる状態にする"
change_kind: mixedParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: なし(単独 Issue)
- Desired Destination: なし(単独 Issue)
Current Validated Scope
.claude/skills/agent-retrospective/scripts/run_retrospective.pyの失敗時トップレベル出力の診断可能性向上.claude/skills/agent-retrospective/scripts/tests/verify_agent_retrospective_live_smoke.py/test_security_boundary.pyのObserverWaveFailed許容ロジックの allowlist 化.claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_live_cli.pyへの regression test 追加verify_run_retrospective_live_cli.shの CI 定期実行経路の追加検討
Remaining Parent Gaps
- なし
Outcome
canonical agent-retrospective の run_retrospective.py が、実質的な分析タスクの prompt に対して現行 Claude Code CLI 上で observer wave (retrospective-runtime-observer) の structured output 欠落により fail-closed する regression について、(1) run_retrospective.py の失敗出力に reason_code/exit_code を含めて診断可能にし、(2) verify_agent_retrospective_live_smoke.py / test_security_boundary.py が missing_structured_output 等の未知 ObserverWaveFailed reason_code を無区別に許容してしまう regression coverage gap を allowlist 化で解消し、(3) test_run_retrospective_live_cli.py に本 Issue の failure shape を再現する claude_live regression test を追加し、(4) verify_run_retrospective_live_cli.sh を定期実行する CI 経路(または代替の compensating control の明示)を追加した状態を完了とする。上記変更後も既存の test_real_claude_cli_production_policy_round_trip が PASS し続けることを確認する。
Runtime Verification Applicability
- decision: immediate
- reason: 本 Issue は
claude_liveマーカー付きの実 Claude Code CLI round-trip テスト(verify_run_retrospective_live_cli.sh/test_run_retrospective_live_cli.py)の追加・修正を扱うため、docs/dev/runtime-verification-policy.mdの適用判定スキーマ上 immediate に該当する。実装完了時にverify_run_retrospective_live_cli.shを実 CLI で実行し証跡を残すこと。
applicable_acs: AC4, AC5, AC6
execution_environment: 現在インストール済みのclaudeCLI バイナリ(実装時点の最新 main HEAD、認証済みサブスクリプションログイン環境)+uv run --locked pytest(-m claude_live選択実行)による実行環境。ローカル開発機または人間/agent が直接操作できる環境を前提とし、デフォルト CI 実行環境(claudeCLI 非搭載)とは区別する。
skip_conditions:verify_run_retrospective_live_cli.sh既存実装の skip_condition(1:claudebinary が PATH に存在しない、2:claude auth statusの事前呼び出しが非ゼロ exit で終了する=認証未確立)を踏襲する。SKIP は exit 77 として明示的に区別し、FAIL や PASS と混同しない。
fallback_policy: SKIP は PASS に昇格しない。SKIP が発生した場合は fail-closed のまま維持し、実装完了報告には「実行できなかった」ことと skip_condition の種別を明記する。AC5/AC6 の完了判断は、実際に PASS した実行証跡(stdout の1 passed相当の出力)またはAC6の代替 compensating control の明示のいずれかを必須とする。
artifact_requirements:verify_run_retrospective_live_cli.sh --select test_real_claude_cli_production_policy_round_tripの実行 stdout(exit code 込み)、および AC4 で追加するclaude_liveregression test を含むuv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_live_cli.py -m claude_liveの実行結果を、実装完了時に PR 本文または PR コメントへ証跡として残す。raw stdout 全文・credential・絶対パスは含めない(bounded classification のみ、Background節の既存の sanitize 方針を踏襲する)。
Background
canonical agent-retrospective Skill の production entrypoint .claude/skills/agent-retrospective/scripts/run_retrospective.py を、現在インストール済みの claude CLI(バージョン 2.1.245、current main HEAD a1d9a1c78a6f624a8e7a6d5e231997573e0711c2)から、--prompts-file に実質的な調査タスクを記述した prompt を渡して実行すると、observer wave の1体目 retrospective-runtime-observer の呼び出しで毎回(2/2回)以下のエラーで fail-closed する。
{"reason": "observer_failed:retrospective-runtime-observer:malformed_output", "reason_code": "ObserverWaveFailed", "status": "failed"}
fail-closed 設計(partial_agent_output: reject)により codebase-investigator / web-researcher / retrospective-evaluator は一度も起動されない。
独立再現(production adapter を直接呼び出した診断結果、sanitized)
run_retrospective.build_agent_invocation_argv() / invoke_agent()(production の subprocess 呼び出しパス、DelegatedAgentPermissionPolicy 込み)を、実際の retrospective-runtime-observer agent・現行 observer_result_v1.schema.json・実質的な調査 prompt に対して直接呼び出し、以下を確認した(credential/token・raw stdout 全文は含めない、bounded classification のみ):
{"status": "malformed_output", "reason_code": "missing_structured_output", "exit_code": 0, "raw_stdout_excerpt_len": 200, "raw_stdout_excerpt_bounded_120": "{\"is_error\":false,\"duration_api_ms\":32329,\"num_turns\":1,\"stop_reason\":\"end_turn\",\"session_id\":\"d2847932-2601-4653-95b8-3", "structured_output_present": false, "structured_output_keys": null}exit_code: 0 かつ wrapper の is_error:false であることから、これは permission/auth/environment failure ではない(bucket E を排除)。invoke_agent() のコード上、この分類(reason_code: missing_structured_output)は wrapper の subtype が "success" と判定されたにもかかわらず structured_output フィールドが欠落/非object だった場合にのみ到達する分岐であり、result テキストからの compatibility recovery(_structured_output_from_result_compat)も失敗している。
対照実験: 既存の canonical live verifier は同一コード・同一CLIバージョンで PASS する
.claude/skills/agent-retrospective/scripts/tests/verify_run_retrospective_live_cli.sh --select test_real_claude_cli_production_policy_round_trip を同一 HEAD・同一 claude CLI (2.1.245) で実行したところ 1 passed(exit 0)。このテスト(test_run_retrospective_live_cli.py::test_real_claude_cli_production_policy_round_trip)は同じ retrospective-runtime-observer agent・同じ observer_result_v1.schema.json・同じ production DelegatedAgentPermissionPolicy(--disallowedTools の現行 unpacking 実装含む)を使うが、prompt は「与えられたフィールド値をそのまま echo する」という自明で短い内容である。
この対照から、--disallowedTools の argv 構成(",".join(...) から *sorted(...) への変更、commit e1f70dd, PR #2301)自体は今回の regression の原因ではないと判断できる(同一コードで trivial prompt は成功しているため)。差分は prompt の実質的な複雑さ・分析タスクとしての性質にある。
有力仮説(証拠に基づくが完全に確証はしていない)
Web調査(一次資料: https://code.claude.com/docs/en/agent-sdk/structured-outputs 、https://code.claude.com/docs/en/headless )により、--output-format json + --json-schema の公式contractでは subtype: "success" は「structured output was generated and validated successfully」を意味し、structured_output フィールドが伴うことが期待されている。しかし公開されている Anthropic 公式リポジトリの Issue(anthropics/claude-agent-sdk-typescript#277 )は、nested schema(配列内オブジェクト等)に対して subtype: success が返されているにもかかわらず structured_output が undefined になるという、まさに同型の不具合を報告している。observer_result_v1.schema.json の findings フィールドは array-of-objects(nested schema)である。
このため、今回の regression は「モデルが実質的な分析タスクに対して自由記述の応答を生成し、CLI 側の structured-output 検証/リトライ機構が nested schema に対して success を誤って報告しつつ structured_output を欠落させる」という、upstream の Claude Code CLI / structured-output 挙動に起因する可能性が高い(確証度: 中〜高。CLI自体のソースやリリースノートでの直接確認はできていない)。
ただし、これを upstream の確定バグと断定はしない。本 Issue の作業ではこの仮説の検証(例: nested schema を持たない代替 schema 表現での再現有無、prompt 長・turn数依存性の追加確認)を含めてよい。
追加で判明した regression coverage gap(独立した敵対的監査より)
.claude/skills/agent-retrospective/scripts/tests/verify_agent_retrospective_live_smoke.py(PR test: agent-retrospective のsecurity boundary・evaluation・dual-runtime smokeを統合検証する #2331, Issue 検証: agent-retrospective のsecurity boundary・evaluation・dual-runtime smokeを統合検証する #2239 由来)は、inner_payload.get("status") == "failed"かつreason_codeが存在すれば reason_code の値を一切区別せず exit 0(許容された fail)として扱う(472-474行目付近)。これは元々ObserverWaveFailedの「run_idbinding gap」という特定の想定失敗のためのものだが、今回のようなmissing_structured_output由来のObserverWaveFailedも無差別に同じ分岐で「許容」されてしまう。test_security_boundary.py::test_live_smoke_claude_code_operator_runもpayload["status"] in ("pass","fail")(456行目)とreason_codeが truthy であること(458行目)しか assert しない。つまりこの regression は既存の live smoke / security boundary test では検知できない設計になっている。test_run_retrospective_live_cli.pyはpytest.mark.claude_liveでマークされ、pyproject.tomlのaddopts(-m 'not github_live and not claude_live')と.github/ci/python-test-plan.jsonのruntime_verification_only_markersにより、デフォルトのpytest実行・通常CIから常時除外されている。.github/workflows/配下を確認したが(retro-live-verification.ymlは別機能=retro_live_verification/v2/v3の pnpm ベース post/verify であり、本 regression とは無関係)、verify_run_retrospective_live_cli.shやclaude_liveマーカーテストを実行する GitHub Actions ワークフローは存在しない。つまり CI上でこの regression は継続的に検知される仕組みが現状ない。
Ownership の分離(重要)
この Issue は agent-retrospective の production Agent invocation / canonical live execution regression のみを扱う。以下は別 ownership であり、この Issue に混ぜない:
- Issue 実装: Claude-GPT workflow の actor-scoped capability handoff を導入し issue-refinement-loop の auth/delegation parity を安定化する #2340(Claude-GPT workflow の actor-scoped capability handoff)— 別の defect
- Issue 実装: fake_gh.py の GitHub CLI互換性ギャップ(gh repo view --jq / gh api refs/heads)を解消する #2330 / 実装: claude-gpt launcher の Herdr Agents session 認識 hint を条件付きで適用する #2332 — read-only 参照のみ、本文変更しない
- Issue 実装: Claude-GPT の GitHub access を compatibility-first に切り替え既存 workflow を安定化する #2299(root credential sharing)、実装: Spark delegation の per-invocation model pin 回帰を解消し final-diff live E2E を必須化する #2274(Spark model pin)、実装: capability_preflight_result() の nested timeout 構造を単一 deadline 共有方式へ改善する #2322(timeout)
In Scope
run_cli()の失敗時トップレベル出力(run_retrospective.pyのmain()の except 節、現在observer_failed:<agent>:<status>のみ)を、AgentInvocationResultが既に保持しているreason_codeとexit_codeを含む形に additive に拡張する。raw stdout/stderr の全文・credential・絶対パスは一切含めない(bounded classification のみ、既存の_stdout_excerptの200文字境界方針を踏襲するか、それも含めないかは実装判断で良いが、含める場合も sanitize/bound を維持する)。verify_agent_retrospective_live_smoke.pyおよびtest_security_boundary.py::test_live_smoke_claude_code_operator_runの「ObserverWaveFailedの reason_code を無区別に許容 fail 扱いする」ロジックを、既知の想定失敗(run_idbinding gap、Issue 検証: agent-retrospective のsecurity boundary・evaluation・dual-runtime smokeを統合検証する #2239 AC6/AC7 由来のbundle.run_id != ctx.run_idチェック起因のもの等、正確な reason_code 文字列は現在のコードを確認して特定する)のみを allowlist する形に修正し、missing_structured_output等その他のObserverWaveFailedreason_code は verifier 自体を FAIL(exit != 0 / assert failure)させる。この修正ではmissing_structured_outputを明示的に allowlist 対象外(拒否対象)として verifier のソース上で識別可能な形(allowlist 定義・コメント・テストケース等いずれでもよい)に残すこと(regression coverage を静的にも確認できるようにするため)。test_run_retrospective_live_cli.pyに、本 Issue で観測した実際の failure shape(retrospective-runtime-observerに対する、trivial echo ではない実質的な分析 prompt)を再現するclaude_liveregression test を追加する(今回のような欠落を今後 CI 経路で検知できるようにする、hermetic mock ではなく実 CLI round-trip であること)。verify_run_retrospective_live_cli.sh(claude_liveマーカー suite)を、何らかの CI 経路(scheduled workflow 等)で定期的に実行する仕組みを追加する、または現実的に不可能な場合はその理由と代替の compensating control を明示する。- 調査の結果、本 regression が upstream Claude Code CLI の structured-output 挙動(nested schema + subtype:success + structured_output欠落)に起因すると確認できた場合、その observed shape に対する限定的な compatibility 対応(例: 該当パターンを検知して明確な reason_code に分類する、等)を追加する。ただし schema validation を弱めない・
subtype != successを成功扱いにしない・present-but-wrong-type のstructured_outputを安易に fallback しない・malformed/partial output の fail-closed を維持することを厳守する。
Out of Scope
- Issue 実装: Claude-GPT workflow の actor-scoped capability handoff を導入し issue-refinement-loop の auth/delegation parity を安定化する #2340 の actor-scoped capability handoff の実装
- Issue 実装: fake_gh.py の GitHub CLI互換性ギャップ(gh repo view --jq / gh api refs/heads)を解消する #2330 / 実装: claude-gpt launcher の Herdr Agents session 認識 hint を条件付きで適用する #2332 の本文編集
--dangerously-skip-permissions等の permission bypass- Claude-GPT actor capability 問題全般
- upstream Claude Code CLI 自体のソースコード修正(このリポジトリの管理外)
Acceptance Criteria
- AC1:
run_retrospective.pyの失敗時トップレベル出力(main()の except 節)がreason_codeとexit_codeを含む - AC2:
verify_agent_retrospective_live_smoke.pyが既知の allowlist 対象以外のObserverWaveFailedreason_code(missing_structured_outputを含む)を検知した場合に非ゼロ exit で FAIL する - AC3:
test_security_boundary.py::test_live_smoke_claude_code_operator_runが既知の allowlist 対象以外のObserverWaveFailedreason_code に対して assertion failure する - AC4:
test_run_retrospective_live_cli.pyに、実質的な分析 prompt を用いたclaude_liveregression test が追加されている - AC5:
verify_run_retrospective_live_cli.sh --select test_real_claude_cli_production_policy_round_tripが本変更後も PASS する - AC6:
verify_run_retrospective_live_cli.sh(claude_livesuite)を CI 上で定期実行する仕組み、または代替の compensating control の説明が repo に追加されている - AC7: 既存 hermetic suite
test_run_retrospective.pyが回帰なく PASS する
Verification Commands
VC 補足:
- AC2 は静的確認とする。
missing_structured_outputが既知 allowlist 対象外として verifier ソース上に識別可能な形(allowlist 定義・コメント・テストケース等)で存在することを確認する。baseline(未実装)では grep 不一致(exit 1)が期待値。 - AC3 は
claude_liveマーカーがpyproject.tomlのaddoptsでデフォルト除外されるため、-m claude_liveを明示指定する。 - AC5 の baseline VC は実行権限確認のみとする。実 CLI round-trip の実行証跡は
## Runtime Verification Applicabilityのartifact_requirementsに従い実装完了時に別途残す。
# AC1
# baseline-expect: pass
$ grep -n "reason_code" .claude/skills/agent-retrospective/scripts/run_retrospective.py
# AC2
$ rg -n "missing_structured_output" .claude/skills/agent-retrospective/scripts/tests/verify_agent_retrospective_live_smoke.py
# AC3
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_security_boundary.py -k test_live_smoke_claude_code_operator_run -m claude_live
# AC4
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_live_cli.py --collect-only -m claude_live
# AC5
# baseline-expect: pass
$ test -x .claude/skills/agent-retrospective/scripts/tests/verify_run_retrospective_live_cli.sh
# AC6
$ grep -n "claude_live" .github/workflows/retro-live-verification.yml
# AC7
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective.pyAllowed Paths
- .claude/skills/agent-retrospective/scripts/run_retrospective.py
- .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_live_cli.py
- .claude/skills/agent-retrospective/scripts/tests/verify_run_retrospective_live_cli.sh
- .claude/skills/agent-retrospective/scripts/tests/verify_agent_retrospective_live_smoke.py
- .claude/skills/agent-retrospective/scripts/tests/test_security_boundary.py
- .github/ci/python-test-plan.json
- .github/workflows/retro-live-verification.yml(新規 scheduled job を追加する場合のみ既存ファイルへの追記、または新規 workflow ファイル追加)
Scope Delta(該当時のみ記載)
N/A
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- raw stdout/stderr 全文や credential を public な Issue/PR/CI artifact に出力してしまう場合は即停止し設計を見直す
- 修正により既存の
test_real_claude_cli_production_policy_round_tripが fail するようになった場合は停止 - upstream CLI 挙動の確定原因が調査しても特定できない場合、compatibility 対応(In Scope 5)は見送り、診断可能性向上とregression coverage gapの解消のみで一旦 Issue を完了してよい(follow-up として別途起票)
Required Skills
なし
Required Design References
- docs/dev/runtime-verification-policy.md
- .claude/skills/agent-retrospective/SKILL.md
Notes for Reviewer
- Scope Collision (C1, advisory):
.github/ci/python-test-plan.jsonについて Issue 実装: CI: Playwright E2E の responsive matrix を専用 lane へ分離し critical path を短縮する #2119(Playwright E2E responsive matrix 分離)と Allowed Paths が重複するが、両者は独立した concern(本 Issue はruntime_verification_only_markers/claude_live関連の記載、実装: CI: Playwright E2E の responsive matrix を専用 lane へ分離し critical path を短縮する #2119 は E2E lane 分離)であり、同一 key を編集する場合は先着 merge を尊重し必要なら rebase する。 - 本 Issue は Issue 実装: Claude-GPT workflow の actor-scoped capability handoff を導入し issue-refinement-loop の auth/delegation parity を安定化する #2340 とは独立した defect である。
Delivery Rule
1 Issue = 1 PRを原則とする- 実装は
.claude/worktrees/配下の専用 worktree で行い、Draft PR を既定とする
Activity
squne121 commentedon Aug 25, 2026
issue-refinement-loop 終了報告 (#2341)
## Runtime Verification Applicabilityの5必須フィールド追加、AC4/AC5/AC6への<!-- runtime-verification: true -->付与、VC preflight allowlist違反2件を許可コマンドへ置換、# baseline-expect: pass追加、claude_livemarker欠落によるexit5解消semantic_review_applicable: false(checker_gap_count=0, heuristic_concern_count=0, owner_decision_conflict=false, cross_contract_change=false)のためスキップNEXT_ACTION: proceed(implementation-ready)
squne121 commentedon Aug 25, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
squne121 commentedon Aug 25, 2026
implement-issue: 実装完了 (2026-08-25)
.claude/worktrees/issue-2341-agent-retrospective-canonical-run-retrosworktree-issue-2341-agent-retrospective-canonical-run-retrosclaudeCLI(2.1.245)で実行済みAC 別サマリ
run_retrospective.pyのmain()失敗時出力にreason_code/exit_codeを additive に追加し、ObserverWaveFailed/EvaluatorInvocationFailedにAgentInvocationResultの詳細を伝播。verify_agent_retrospective_live_smoke.pyの reason_code 無差別許容を allowlist 化(missing_structured_outputは明示的に非allowlist)。test_security_boundary.py::test_live_smoke_claude_code_operator_runに独立 assertion を追加。test_run_retrospective_live_cli.pyに実質的な分析 prompt を用いたclaude_liveregression testtest_real_claude_cli_analytical_prompt_structured_output_shapeを追加(collect-only で確認済み)。verify_run_retrospective_live_cli.sh --select test_real_claude_cli_production_policy_round_tripを実行し1 passed(exit 0)を確認。既存の trivial round-trip test は回帰なし。retro-live-verification.ymlに compensating control(claudeCLI subscription 認証を CI secret 化しない理由と代替運用)を明記。test_run_retrospective.pyは 135 passed(回帰なし)。実装中に発見した副次的な finding(本 PR のスコープ外)
AC2/AC3 の allowlist ロジックを実環境に適用したところ、
test_live_smoke_claude_code_operator_run(Issue #2239 由来)が、これまで想定されていた「run_id binding gap」ではなく 別の隠れていた regression を実際に検知した:claude -pに空文字列 prompt を渡すとError: Input must be provided either through stdin or as a prompt argument when using --printでexit_code=1になりinvoke_agent()がreason_code="nonzero_exit"を返す。旧コードはこれを無差別にreason_code: "ObserverWaveFailed"(class-name fallback)として静かに許容していたため、今まで検知不能だった。本 Issue の Stop Conditions(「後続 Phase / 別スコープへの波及が判明した場合」)に従い、この空 prompt 拒否自体の修正は本 PR のスコープ外とした。followup Issue の起票を推奨する(
verify_agent_retrospective_live_smoke.pyが--prompts-fileなしで観測 Agent を呼び出す設計の re-check、またはrun_retrospective.py側で空 prompt をどう扱うかの設計判断が必要)。squne121 commentedon Aug 25, 2026
impl-review-loop 終了報告 (#2341 / PR #2342)
test_run_retrospective_live_cli.pyclaude_live 4件 collect済み)e7fe373a7dで APPROVE(blockers: [])。Allowed Paths gate ok、Schema Consumer Inventory / Safety Claim Matrix 確認済みroute: approved(mergeable=MERGEABLE, merge_state_status=CLEAN, blockers=[])claude -pが空文字列prompt を拒否する既存の別 regression(test_live_smoke_claude_code_operator_runが稀にreason_code=nonzero_exitを報告する原因)を実装中に発見。PR本文で follow-up Issue化を提案済みPR は Draft のまま、人間のマージ判断待ちで終了します。
squne121 commentedon Aug 25, 2026
impl-review-loop 終了報告 (#2341 / PR #2342, fix_delta後)
OWNER REQUEST_CHANGES(#2342 (comment) )を受け fix_delta 1周で解消:
ObserverWaveFailedの全raise siteに粒度あるreason_code付与、allowlistをobserver_run_id_mismatchのみへnarrowingpytest.xfail()をpytest.fail()(hard fail)へ変更test_security_boundary.pyの非独立assertionを削除し、独立hermetic parametrizedテストへ置換verify_agent_retrospective_live_smoke.pydocstringの誤記述訂正 + follow-up Issue 実装: claude -p の空文字列 prompt 拒否 regression に対する agent-retrospective live smoke 検知経路の修正 #2345(claude -p空prompt拒否regression)起票Step2/Step4をfix_delta後headで再実行し、pr-reviewer最終APPROVE(blockers: [])、全required CI green、mergeStateStatus: CLEANを確認。
route_loop_verdict_v2はroute: approved。PRはDraftのまま、人間のマージ判断待ちで終了します。
fix: agent-retrospective の observer wave 失敗を診断可能にし regression coverag…