Skip to content

実装: agent-retrospective canonical run が retrospective-runtime-observer の missing_structured_output で fail-closed する回帰を解消する #2341

Closed

Description

@squne121

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: mixed

Parent 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: 現在インストール済みの claude CLI バイナリ(実装時点の最新 main HEAD、認証済みサブスクリプションログイン環境)+ uv run --locked pytest(-m claude_live 選択実行)による実行環境。ローカル開発機または人間/agent が直接操作できる環境を前提とし、デフォルト CI 実行環境(claude CLI 非搭載)とは区別する。
    skip_conditions: verify_run_retrospective_live_cli.sh 既存実装の skip_condition(1: claude binary が 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_live regression 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(独立した敵対的監査より)

  1. .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_id binding 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 では検知できない設計になっている。
  2. 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 に混ぜない:

In Scope

  1. 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 を維持する)。
  2. verify_agent_retrospective_live_smoke.py および test_security_boundary.py::test_live_smoke_claude_code_operator_run の「ObserverWaveFailed の reason_code を無区別に許容 fail 扱いする」ロジックを、既知の想定失敗(run_id binding 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 等その他の ObserverWaveFailed reason_code は verifier 自体を FAIL(exit != 0 / assert failure)させる。この修正では missing_structured_output を明示的に allowlist 対象外(拒否対象)として verifier のソース上で識別可能な形(allowlist 定義・コメント・テストケース等いずれでもよい)に残すこと(regression coverage を静的にも確認できるようにするため)。
  3. test_run_retrospective_live_cli.py に、本 Issue で観測した実際の failure shape(retrospective-runtime-observer に対する、trivial echo ではない実質的な分析 prompt)を再現する claude_live regression test を追加する(今回のような欠落を今後 CI 経路で検知できるようにする、hermetic mock ではなく実 CLI round-trip であること)。
  4. verify_run_retrospective_live_cli.sh(claude_live マーカー suite)を、何らかの CI 経路(scheduled workflow 等)で定期的に実行する仕組みを追加する、または現実的に不可能な場合はその理由と代替の compensating control を明示する。
  5. 調査の結果、本 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

Acceptance Criteria

  • AC1: run_retrospective.py の失敗時トップレベル出力(main() の except 節)が reason_code と exit_code を含む
  • AC2: verify_agent_retrospective_live_smoke.py が既知の allowlist 対象以外の ObserverWaveFailed reason_code(missing_structured_output を含む)を検知した場合に非ゼロ exit で FAIL する
  • AC3: test_security_boundary.py::test_live_smoke_claude_code_operator_run が既知の allowlist 対象以外の ObserverWaveFailed reason_code に対して assertion failure する
  • AC4: test_run_retrospective_live_cli.py に、実質的な分析 prompt を用いた claude_live regression 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_live suite)を 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.py

Allowed 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

Delivery Rule

  • 1 Issue = 1 PR を原則とする
  • 実装は .claude/worktrees/ 配下の専用 worktree で行い、Draft PR を既定とする

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 25, 2026
  2. squne121 commented on Aug 25, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告 (#2341)

    • VERDICT: approve(0 blockers、deterministic checks 13/13 pass or n/a)
    • iteration: 1(初回 review で needs-fix 10件 → rewrite → 再review approve)
    • rewrite内容: ## Runtime Verification Applicability の5必須フィールド追加、AC4/AC5/AC6への <!-- runtime-verification: true --> 付与、VC preflight allowlist違反2件を許可コマンドへ置換、# baseline-expect: pass 追加、claude_live marker欠落によるexit5解消
    • semantic design review (Step 2.5): semantic_review_applicable: false(checker_gap_count=0, heuristic_concern_count=0, owner_decision_conflict=false, cross_contract_change=false)のためスキップ
    • body_sha256 (final): sha256:696fe7355cd6aea0e18fffae5654e7f877beaf3f3bac2dc50ccce0efadb93efa
    • follow-up candidate(非materialize、Issue本文のStop Conditionsとして既に記録済み): upstream CLI原因が特定できない場合、compatibility対応(In Scope 5)は見送り、診断可能性向上とregression coverage gap解消のみで完了してよい旨をIssue自体が明記済みのため、追加Issueの即時起票は不要

    NEXT_ACTION: proceed(implementation-ready)

  3. squne121 commented on Aug 25, 2026

    @squne121
    OwnerAuthor

    root-owned entry router audit

    route: invoke_impl_review_loop
    reason: fresh_review_go_live_equality

  4. squne121 commented on Aug 25, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-25)

    AC 別サマリ

    • AC1: run_retrospective.py の main() 失敗時出力に reason_code/exit_code を additive に追加し、ObserverWaveFailed/EvaluatorInvocationFailed に AgentInvocationResult の詳細を伝播。
    • AC2: verify_agent_retrospective_live_smoke.py の reason_code 無差別許容を allowlist 化(missing_structured_output は明示的に非allowlist)。
    • AC3: test_security_boundary.py::test_live_smoke_claude_code_operator_run に独立 assertion を追加。
    • AC4: test_run_retrospective_live_cli.py に実質的な分析 prompt を用いた claude_live regression test test_real_claude_cli_analytical_prompt_structured_output_shape を追加(collect-only で確認済み)。
    • AC5: verify_run_retrospective_live_cli.sh --select test_real_claude_cli_production_policy_round_trip を実行し 1 passed(exit 0)を確認。既存の trivial round-trip test は回帰なし。
    • AC6: retro-live-verification.yml に compensating control(claude CLI subscription 認証を CI secret 化しない理由と代替運用)を明記。
    • AC7: 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 をどう扱うかの設計判断が必要)。

    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  5. squne121 commented on Aug 25, 2026

    @squne121
    OwnerAuthor

    impl-review-loop 終了報告 (#2341 / PR #2342)

    IMPL_REVIEW_LOOP_RESULT_V1:
      status: draft_pr_ready
      issue_number: 2341
      pr_number: 2342
      final_head_sha: e7fe373a7d47b8eeb0af7d19df61e0f044664a71
      mergeable: MERGEABLE
      merge_state_status: CLEAN
      loop_verdict: APPROVE
    
    • iteration: 1(Step1実装→Step2検証→Step4レビューでBEHIND×2回検出、update_branchで解消。コード内容自体の修正往復は無し)
    • Step2 (test-runner): AC1-AC7 全PASS(hermetic suite 135 passed、test_run_retrospective_live_cli.py claude_live 4件 collect済み)
    • Step4 (pr-reviewer): 最終head e7fe373a7d で APPROVE(blockers: [])。Allowed Paths gate ok、Schema Consumer Inventory / Safety Claim Matrix 確認済み
    • route_loop_verdict_v2: route: approved(mergeable=MERGEABLE, merge_state_status=CLEAN, blockers=[])
    • 副次的発見(本PRスコープ外、Stop Conditions通り未修正): claude -p が空文字列prompt を拒否する既存の別 regression(test_live_smoke_claude_code_operator_run が稀に reason_code=nonzero_exit を報告する原因)を実装中に発見。PR本文で follow-up Issue化を提案済み

    PR は Draft のまま、人間のマージ判断待ちで終了します。

  6. squne121 commented on Aug 25, 2026

    @squne121
    OwnerAuthor

    impl-review-loop 終了報告 (#2341 / PR #2342, fix_delta後)

    IMPL_REVIEW_LOOP_RESULT_V1:
      status: draft_pr_ready
      issue_number: 2341
      pr_number: 2342
      final_head_sha: fda6091f0609f8a5f15915b241e68f77e928772f
      mergeable: MERGEABLE
      merge_state_status: CLEAN
      loop_verdict: APPROVE
    

    OWNER REQUEST_CHANGES(#2342 (comment) )を受け fix_delta 1周で解消:

    Step2/Step4をfix_delta後headで再実行し、pr-reviewer最終APPROVE(blockers: [])、全required CI green、mergeStateStatus: CLEANを確認。route_loop_verdict_v2 は route: approved。

    PRはDraftのまま、人間のマージ判断待ちで終了します。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions