Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent-retrospective run_retrospective.py の prepare() 完了後に、caller-supplied な非空 observer prompt を authoritative な run_id/base_sha/source_set_digest/observer_id と結合する identity-binding helper を追加し、custom prompt 経路でも observer_run_id_mismatch 系の identity mismatch が構造的に発生する gap を解消する"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: なし(単独 Issue)
- Desired Destination: なし(単独 Issue)
Current Validated Scope
.claude/skills/agent-retrospective/scripts/run_retrospective.pyのprepare()/build_observer_requests()/run_observer_wave()における、caller-supplied prompt への authoritative identity(run_id/base_sha/source_set_digest/observer_id)結合ロジックの追加
Remaining Parent Gaps
なし(単独改善 Issue のため)
Outcome
run_retrospective.py の run_cli() が prepare() を完了し ctx / plan の実際の値(run_id / base_sha / source_set_digest)が確定した後に、caller-supplied prompt(--prompts-file 経由)を authoritative context と結合する identity-binding helper(例: bind_observer_prompt(task_prompt, spec, ctx, plan))を追加する。default prompt 経路(PR #2347 の _default_observer_prompt())と caller-supplied prompt 経路の両方をこの同一 helper に通す。--run-id のような CLI から identity を事前指定させる公開 surface は追加しない(run_id は引き続き run_cli() 内部で uuid.uuid4() により新規生成される)。実装後、非空・実質的な調査 prompt を渡した observer 呼び出しが observer_run_id_mismatch / observer_source_set_digest_mismatch / observer_base_sha_mismatch のいずれも発生させずに完走することを regression test で確認できている状態を完了とする。
Runtime Verification Applicability
decision: immediate
reason: 本 Issue は run_retrospective.py の prepare() 後 prompt 結合ロジックという実行時契約の変更を扱うため、docs/dev/runtime-verification-policy.md の適用判定スキーマ上 immediate に該当する。
applicable_acs:
- AC4
execution_environment: 現在インストール済みの claude CLI バイナリ(実装時点の最新 main HEAD、認証済みサブスクリプションログイン環境)による手動実行環境。デフォルト CI 実行環境(claude CLI 非搭載)とは区別する。
skip_conditions: claude binary が PATH に存在しない、または claude auth status が非ゼロ exit で終了する場合は SKIP とし、実装完了報告に SKIP 種別を明記する。
fallback_policy: SKIP は PASS に昇格しない。SKIP が発生した場合は fail-closed のまま維持し、実装完了報告には「実行できなかった」ことと skip_condition の種別を明記する。
artifact_requirements: verify_run_retrospective_live_cli.sh --select による custom prompt identity-binding focused test の実行結果(reason_code, status 等の sanitized bounded classification。raw stdout 全文・credential・絶対パスは含めない)を実装完了時に PR 本文または PR コメントへ証跡として残す。Background
.claude/skills/agent-retrospective/scripts/run_retrospective.py を、--prompts-file に非空・実質的な調査タスク prompt(3 observer 全てに具体的な調査指示を記載、空文字列ではない)を指定して実行したところ、reason_code=observer_run_id_mismatch(exit_code: null)で fail-closed した。
これは Issue #2345/PR #2347 が扱う「--prompts-file 未指定時にデフォルトで observer 向け prompt が空文字列になり claude -p が起動段階で拒否する(exit_code=1, reason_code=nonzero_exit)」ケースとは異なる failure shape(exit_code=null)であり、caller が明示的に非空 prompt を渡した場合に発生している。
独立 read-only SubAgent によるコード追跡(run_retrospective.py 内の run_observer_wave() / build_observer_requests() / run_cli() / main())により、以下の構造的原因が判明した:
run_observer_wave()は observer からの応答 JSON をparse_agent_output_with_repair()でEvidenceBundle(OBSERVER_RESULT_V1)へ parse し、bundle.run_id != ctx.run_idの場合にobserver_run_id_mismatchを raise する。同様にbundle.source_set_digest != plan.source_set_digestでobserver_source_set_digest_mismatch、bundle.base_sha != ctx.base_shaでobserver_base_sha_mismatchを raise する(検証: agent-retrospective のsecurity boundary・evaluation・dual-runtime smokeを統合検証する #2239 の success oracle は 3 つ全ての一致を要求する)。bundle.run_id/bundle.source_set_digest/bundle.base_shaは observer(LLM)の応答 JSON をそのままfrom_wire()した値であり、production code は observer 応答へこれらを事後注入していない。build_observer_requests()はprompts.get(spec.observer_id, "")をAgentInvocationRequest.promptへそのまま渡すのみで、identity 情報を prompt へ埋め込む処理は行わない。source_set_digestはprepare()が collector 結果から構築するSourcePlanの値であり、run_cli()呼び出し前に caller が正確に知る構造的手段は存在しない(base_shaはgit rev-parse main等で caller が推測可能だが、source_set_digestは不可能)。
この gap の存在自体は Issue #2239(CLOSED)の過程で .claude/skills/agent-retrospective/scripts/tests/verify_agent_retrospective_live_smoke.py の docstring 上に "known, independently-confirmed production architecture gap" として文書化され、observer_run_id_mismatch は同 verifier の allowlist(既知の benign 失敗)に追加済みである。しかし同 docstring は「run_retrospective.py is not editable here(当時の Allowed Paths 外)」と明記しており、production code(run_retrospective.py)側でこの gap を解消する機構自体の実装は #2239 の scope に含まれていない。
設計方針(reframe、2026-08-26 レビューコメント反映)
当初案(--run-id を CLI から事前指定させる)は、run_id だけを caller に解決させても source_set_digest / base_sha を含む authoritative identity tuple 全体を caller が組み立てることはできず、observer_run_id_mismatch を消した直後に observer_source_set_digest_mismatch 等へ移るだけの不完全な解決策であると判明した(コメント)。また run_id は DelegatedAgentPermissionPolicy / run-scoped temp directory / observer identity に使われる run-scoped nonce であり、CLI から任意指定可能にすると nonce としての性質(一意性・衝突防止保証)が崩れる懸念がある。
そのため、caller に identity 値を事前生成・prompt へ書き戻させる往復を作るのではなく、PR #2347 の _default_observer_prompt() と同じ設計方針(prepare() 完了後に実際の ctx / plan から値を取得して prompt を構築する)を caller-supplied prompt にも適用する。identity の SSOT は引き続き orchestrator(run_cli() 内部の uuid.uuid4() 生成、および prepare() が返す ctx / plan)に一元化し、caller は task/evidence 部分のみを prompt に書く。
In Scope
prepare()が返すctx/planからrun_id/base_sha/source_set_digest/observer_idを取得し、caller-supplied prompt(--prompts-file経由)または default prompt のいずれに対しても、これらの authoritative context を結合した最終 prompt を構築する identity-binding helper(例:bind_observer_prompt())を追加する。build_observer_requests()(またはその呼び出し元)を、default prompt 経路・caller-supplied prompt 経路の両方が同一の identity-binding helper を通るように変更する。既存の_default_observer_prompt()(PR fix: agent-retrospective live smoke の空 prompt 拒否 regression を解消 (#2345) #2347)の呼び出し箇所を、新しい identity-binding helper と整合する形に統合する。- fake runner(既存 hermetic test 基盤)を用いた regression test を、新規テストファイル
test_run_retrospective_identity_binding.pyに追加し、caller-supplied な非空・実質的 prompt を渡した場合に 3 observer 全件がrun_id/base_sha/source_set_digestの identity validation を通過し、hermetic production call graph がPublishRequestまで到達することを確認する。 - 既存の
verify_run_retrospective_live_cli.sh(PR fix: fence 前後の地の文でも structured_output を抽出できるようにする #2353 で確立された--select <focused-test>呼び出し形式)に、実claudeCLI 経由で custom な非空 substantive prompt を渡した場合に observer identity validation を通過することを確認する focused test を 1 件追加する。新しい runtime harness は追加しない。
Out of Scope
- Issue 実装: claude -p の空文字列 prompt 拒否 regression に対する agent-retrospective live smoke 検知経路の修正 #2345/PR fix: agent-retrospective live smoke の空 prompt 拒否 regression を解消 (#2345) #2347 が扱う「
--prompts-file未指定時のデフォルト空文字列 prompt 拒否」対応の再実装 - Issue 実装: agent-retrospective canonical run が retrospective-runtime-observer の missing_structured_output で fail-closed する回帰を解消する #2341/PR fix: agent-retrospective の observer wave 失敗を診断可能にし regression coverage gap を解消する #2342 が扱う
missing_structured_outputの診断可能化・allowlist 化 - fence-anchor 正規表現による
missing_structured_output根本原因修正(別 Issue 実装: agent-retrospective の structured output compatibility recovery が fence 前後の地の文で decode failure する missing_structured_output を解消する #2348 が扱う) run_observer_wave()のbundle.run_id != ctx.run_id等の mismatch 検証ロジック自体の緩和・撤廃(fail-closed 設計は維持する)verify_agent_retrospective_live_smoke.pyの allowlist 変更(本 Issue は production code 側の機構追加のみ)- CLI から
run_idを事前指定できる公開 flag(例:--run-id)の追加。run-scoped nonce としての一意性・衝突防止保証を崩すため、当初案から撤回した設計判断であり、本 Issue の scope に含めない run_idの意味論拡張(同一run_idでの replay/resume 等の新規ユースケース)
Acceptance Criteria
- AC1:
prepare()完了後のctx/planからrun_id/base_sha/source_set_digest/observer_idを取得し、caller-supplied prompt へ結合する identity-binding helper(bind_observer_prompt()相当)がrun_retrospective.pyに追加されている - AC2: default prompt 経路(
_default_observer_prompt())と caller-supplied prompt 経路の両方が同一の identity-binding helper を通るように統合されている - AC3: 新規テストファイル
test_run_retrospective_identity_binding.pyの fake runner を用いた regression test で、caller-supplied な非空・実質的 prompt を渡した 3 observer 全件がobserver_run_id_mismatch/observer_source_set_digest_mismatch/observer_base_sha_mismatchのいずれも発生させず、hermetic production call graph がPublishRequestまで到達することを確認できている - AC4 : 実
claudeCLI 経由で、verify_run_retrospective_live_cli.sh --select <focused-test>により custom な非空 substantive prompt を渡した呼び出しが observer identity validation(run_id/base_sha/source_set_digest 全て一致)を通過することを確認する(Runtime Verification Applicability 参照) - AC5: 既存の hermetic suite
test_run_retrospective.pyが回帰なく PASS する
Verification Commands
# AC1
# baseline-expect: fail
$ grep -n "def bind_observer_prompt" .claude/skills/agent-retrospective/scripts/run_retrospective.py
# AC2
# baseline-expect: fail
$ grep -n "bind_observer_prompt" .claude/skills/agent-retrospective/scripts/run_retrospective.py
# AC3
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_identity_binding.py::test_caller_supplied_prompt_identity_binding_no_mismatch
# AC4
# preflight-scope: runtime_only
$ .claude/skills/agent-retrospective/scripts/tests/verify_run_retrospective_live_cli.sh --select test_real_claude_cli_custom_prompt_identity_binding
# AC5
$ 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.py
- .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_identity_binding.py
- .claude/skills/agent-retrospective/scripts/tests/test_run_retrospective_live_cli.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- identity-binding helper の導入により
run_idの run-scoped nonce としての一意性・衝突防止保証が損なわれると判明した場合は停止し設計を見直す - 修正により既存の
test_real_claude_cli_production_policy_round_trip(test_run_retrospective_live_cli.py)が fail するようになった場合は停止
Required Skills
なし
Required Design References
- .claude/skills/agent-retrospective/SKILL.md
- docs/dev/runtime-verification-policy.md
Scope Delta(任意)
N/A
Activity
squne121 commentedon Aug 26, 2026
結論
判定:
REQUEST_CHANGESRecommended disposition:
reframe_in_placeIssue 分割: 不要
#2350 が捉えている「caller-supplied prompt では正本 identity を事前に知れない」という問題自体は実在します。ただし、
Priority | Finding | 判定 -- | -- | -- P0 | --run-id だけでは authoritative identity tuple を完成できない | blocker P0 | AC4 は「実 Claude CLI 検証」を要求するのに VC が test -x だけ | blocker P1 | identity を内部生成→callerへ露出→promptに戻させる API 境界が逆向き | reframe 必須 P1 | meaningful live regression を追加するための Allowed Paths が不足 | contract 修正 P1 | caller 指定可能 run_id と「run-scoped nonce」という既存意味論が衝突 | 要整理 P2 | 新しい harness は不要。既存 live CLI wrapper を再利用すべき | simplification--run-idを追加する解決策は不完全です。現行 observer boundary はrun_idだけでなく、source_set_digestとbase_shaも完全一致を要求しているためです。#2350 のまま実装すると、observer_run_id_mismatchを消した直後にobserver_source_set_digest_mismatchへ移るだけでも AC3/AC4 を green にできます。P0 —
run_idだけ直しても構造的問題は解消しない#2350 自身が、caller prompt には
run_id / base_sha / source_set_digestが自動注入されないと正しく認識しています。にもかかわらず Outcome はrun_idだけを caller が先に指定可能にする設計です。現在の
run_observer_wave()は概念的に、という順で検証します。
base_shaは caller が別途git rev-parse mainすれば推測できます。しかしsource_set_digestはprepare()が collector 結果から作るSourcePlanの値です。run 起動前に固定済みでなければならない--prompts-fileから、これを正確に知る構造はありません。つまり、例えば
でも AC3 の「
observer_run_id_mismatchが発生しない」は満たせます。その直後に別 mismatch で死ぬだけです。これは #2239 で定義した success oracle とも矛盾します。そこでは
run_id / base_sha / source_set_digest3つすべての一致を要求しています。AC3 は現在のままだと false-green です。
P0 — AC4 の Verification Command が AC4 を一切検証していない
AC4 は、
と定義されています。
ところが VC は、
だけです。
これはファイルが executable か確認しているだけです。
Claude を起動しない
custom prompt を使わない
run_idを指定しないobserver を起動しない
mismatch を検出しない
ので、実装前から PASS し得ます。
既存の PR #2353 は、同じ wrapper を正しく、
という形で使っています。PR #2353 はすでに merge 済みです。
新しい runtime harness は不要です。既存 wrapper に focused test を1件載せれば十分です。
推奨する設計
--run-idを追加するのではなく、caller-supplied prompt をprepare()後に authoritative context と結合するのが適切です。これはすでに PR #2347 の default prompt が採用した設計と同じです。現在の default path は
prepare()後に、を作っています。
caller prompt にも同じ原則を適用します。例えば概念的には、
とします。
この方が、
run_idは従来通り内部でuuid4()生成base_shaは実際に固定された値source_set_digestは実 collector から算出した値caller は調査内容・evidence だけを書く
identity の SSOT は orchestrator に一元化
となります。
特に重要なのは、内部状態を caller に露出し、それを prompt file に書き戻させる往復が消えることです。
PR #2347 の OWNER review でも、「
prepare()後に actualctx/planから prompt を構築し、harness を増やさず production path 自体を単純化する」方針が採用され、その後の fix_delta で実装されています。--run-idを公開しない方がよいもう一つの理由現在の Skill は
run_idを run-scoped nonce と説明しています。また実装では同じ
run_idが、DelegatedAgentPermissionPolicyrun-scoped temp directory
observer identity
に使われています。
run_cli()内では現在run_id or uuid.uuid4()で解決されています。CLI から任意指定可能にすると、
を複数回使えるため、「nonce」という意味が崩れます。
重大なセキュリティ問題として大げさに扱う必要はありません。ただ、今回の defect を直すためだけに、run identity の意味論まで広げるのは余計な設計負債です。
将来「同一 run_id で replay/resume したい」という具体的用途が出た時に、その semantics と一緒に追加する方がよいです。
Allowed Paths も修正が必要
現行 Allowed Paths は、
だけです。
一方、実 Claude CLI の既存テストは
test_run_retrospective_live_cli.pyに分離され、verify_run_retrospective_live_cli.sh --select ...で実行する構成です。PR #2353 もこの構成を使っています。したがって以下を1行追加するのが自然です。
shell wrapper 自体は変更不要です。
test_run_retrospective.pyに live test を混ぜるより、既存レーンを維持する方が簡単です。外部実装との整合
Anthropic 側でも structured output 周辺は「常に期待どおり wrapper に入る」と仮定できる状態ではありません。
Agent SDK の公開 Issue #277 は、
subtype: successなのにstructured_outputが存在せず、正しい JSON が Markdown 化されたresultに残るケースを報告しており、2026年4月時点でも open です。Claude Code 本体でも #18536 が同系統の
--json-schema/structured_output欠落を報告しています。そのため、今回の修正でさらに「モデルが caller の identity 指示を正確に組み立てる」責務を増やすより、
identity binding は deterministic Python
model は分析
output は既存 schema validation
structured_outputの揺れは PR fix: fence 前後の地の文でも structured_output を抽出できるようにする #2353 の schema-validated compat recoveryという分業が妥当です。
PR #2353 は既に merge されているので、#2350 で新しい formatting/security harness を追加する必要はありません。
#2350 をどう直すか
Issue は削除・分割せず、目的だけ次のように変更するのを勧めます。
Goal
Implementation scope
--run-idCLI 追加は削除uuid.uuid4()の既存生成は維持default/custom の両 prompt を同じ identity-binding helper に通す
caller prompt は task/evidence 部分のみ所有
wire schema、permission policy、security harness は変更しない
AC は最低限こうするべきです。
AC1: caller-supplied prompt が
prepare()後に actualrun_id/base_sha/source_set_digest/observer_idと結合されるAC2: fake runner で3 observer 全件が identity validation を通過する
AC3:
observer_run_id_mismatchだけでなくobserver_source_set_digest_mismatch/observer_base_sha_mismatchも発生せず、hermetic production call graph がPublishRequestまで到達するAC4: 既存
verify_run_retrospective_live_cli.sh --select <focused-test>を1回実行し、実 Claude CLI でも custom substantive prompt が observer identity validation を通過するAC5: 既存 hermetic suite 全 PASS
この形なら、#2350 が狙った実運用 gap は解消しつつ、CLI surface、preflight phase、二段階 prepare、追加ハーネス、追加 security gate は全部不要です。
現状の #2350 は「問題の発見は正しいが、解決単位を
run_idに狭めすぎた」という評価です。実装開始前にrun identity pre-specificationからcustom prompt authoritative-context bindingへ reframe するのが最も有用です。squne121 commentedon Aug 26, 2026
issue-refinement-loop 完了報告
結果:
approved(human approval なしで自律完了、2 iteration)経緯
preflight.run.with_human_context(anchor comment: #2350 (comment))でSTATUS: pass/NEXT_ACTION: proceed。VERDICT: needs-fix(10 blockers)。主因は Runtime Verification Applicability セクションの箇条書きフォーマットがフィールド検出正規表現と衝突し必須5フィールドが「欠落」と誤検知され、加えてdecision: immediateに対応する<!-- runtime-verification: true -->タグが AC 側に付与されていなかったこと。あわせて、anchor comment(OWNER レビュー、判定:REQUEST_CHANGES、推奨 disposition:reframe_in_place)が、当初の--run-idCLI 追加案ではsource_set_digest/base_shamismatch が解消しない不完全な設計であると指摘し、prepare()完了後の identity-binding helper 方式への reframe を推奨。→ Outcome / In Scope / Out of Scope / AC1-5 / VC / Allowed Paths / Stop Conditions を全面的に書き換え、RVA セクションをフィールド検出可能な形式(fenced yaml、bullet dash 除去)へ修正し、AC4 に runtime-verification タグを付与。
→ AC3 の regression test を新規ファイル
test_run_retrospective_identity_binding.pyに置く形へ修正(VC・Allowed Paths・In Scope を追随更新)。VERDICT: approve(0 blockers)。semantic_review_applicable: trueと判定し、issue-design-reviewerを起動。全 P0/P1/P2 finding の技術的実質が新本文に反映されていることを独立コード読解で確認した上で、low severity の finding 1 件(_default_observer_prompt()とbind_observer_prompt()の instruction 重複可能性)を報告。join_review_results.pyのroute_high_open_to_rewritepolicy 上、low severity は rewrite を要求せず warning として記録され、effective_verdict: approve。実装時の申し送り事項(warning、blocking ではない)
Semantic review が指摘した低優先度の設計明確化ポイント:
_default_observer_prompt()(PR #2347)は既にrun_id/base_sha/source_set_digestを含む JSON envelope を自前で構築している。今回追加するbind_observer_prompt()へこれをそのまま二重に通すと identity echo 指示が重複記述される可能性がある。実装時に、_default_observer_prompt()を task-content のみを返す形へ縮小し、identity 埋め込みはbind_observer_prompt()側へ一元化するかどうかを設計判断すること(.claude/skills/agent-retrospective/scripts/run_retrospective.pyの_default_observer_prompt()定義箇所を参照)。最終本文
body_sha256:
sha256:b12d21c831ec29d22d37d6f8f5b1161bfc60e80df0327d11926258e6deb05cd2squne121 commentedon Aug 26, 2026
implement-issue: 実装完了 (2026-08-27)
.claude/worktrees/issue-2350-agent-retrospective-run-retrospective-pyworktree-issue-2350-agent-retrospective-run-retrospective-py0134e1bee192e691c426bb7413b8bcc8de46cdceVerification Commands 結果
grep -n "def bind_observer_prompt" run_retrospective.py→ PASS(bind_observer_prompt()を追加)grep -n "bind_observer_prompt" run_retrospective.py→ PASS(default prompt 経路・caller-supplied prompt 経路の両方から参照)uv run --locked pytest .../test_run_retrospective_identity_binding.py::test_caller_supplied_prompt_identity_binding_no_mismatch→ PASSverify_run_retrospective_live_cli.sh --select test_real_claude_cli_custom_prompt_identity_bindingを実 claude CLI(Claude Code 2.1.246、認証済みサブスクリプションログイン環境、claude auth statusexit 0)で実行 → PASS(SKIP ではない。1 passed, 4 deselected/PASS: live CLI verification succeeded)uv run --locked pytest .../test_run_retrospective.py→ PASS(137 → 138 件、無回帰)Stop Condition 確認:
test_real_claude_cli_production_policy_round_tripを同一環境で再実行し PASS を確認(fail していない)。標準検証:
pnpm typecheck/pnpm lint/pnpm test(112 files, 1876 tests)/pnpm buildすべて PASS。uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.pyも PASS。fix: bind_observer_prompt の identity 順序と caller-supplied path の完成例を修正 (…
fix: run_retrospective.py に identity-binding helper を追加し caller-suppl…