Repository navigation
実装: agent-retrospective の run 永続化と agent_retro_index/v1 統合を実装する - #2304
Conversation
persist_retrospective_run.py を新規実装し、run_retrospective.py の main() から persistence-backed PreviousStateProvider(IssueCommentPreviousStateProvider)を --state-backend issue-comments で実接続する。idempotency guard・best-effort な optimistic concurrency guard・fail-closed な human authorization gate (TTY確認 or human_authorization_receipt/v1)・post-write readback・ambiguous POST failure recovery・public-safety validator を実装し、agent_retro_index/v1 にトップレベル optional な retrospective_runs[] を additive に追加する。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #2304 closed). |
pr-reviewer の REQUEST_CHANGES を受け、python-test-core CI で persist_retrospective_run.py と test_persist_retrospective_run.py の E501 (120文字超過) 58件を行分割のみで解消する。ロジック変更なし。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
.claude/skills/agent-retrospective/SKILL.md と references/wire-contract.md の 「永続化」節見出しが per-block 日本語比率検査で threshold 0.1 未満だったため、 説明文を追加して比率を引き上げる(ロジック・契約内容の変更なし)。
敵対的レビュー結果Verdict: 対象は current head 主要CIが通っていても、現行テストは helper 単体へ完成済み envelope、固定 P0-1: 承認対象の repository と実際の POST 先が分離している
例えば、request が 最小修正
これはセキュリティ強化ではなく、承認対象とmutation対象を一致させる基本的な正しさです。 P0-2: non-interactive receipt 経路は通常のCLIから生成できないreceipt は
CLIには envelope preview、 さらに、Issue契約が要求している「別コマンドが発行する短命receipt」は実装されておらず、 推奨修正 現在のIssue契約を維持するなら、次の2段階にします。
個人開発では署名・PKI・GitHub Appは不要です。mode P0-3: |
| ケース | 期待結果 |
|---|---|
同一requestを publish_run() で2回実行、clockを進める |
POSTは1回、2回目はno_op |
expected_previous_digest=None で既存headあり、新しいkey |
stale_expected_previous_digest |
| 同一parentを持つ2 commentをseed後にprovider read | status=stale |
| marker付きcommentのdigestを改変 | provider/idempotency双方が拒否 |
| 非許可loginから完全な偽recordを投稿 | stateとして採用しない |
request repositoryとCLI --repoが不一致 |
transport呼び出しゼロ |
| prepare→authorize→publish間でheadが変化 | POSTせず再準備要求 |
| 2回目のPOSTが着地後timeout | 再検索で回収し、3回目POSTなし |
| readback schema/digest不一致 | published_unverified、index更新なし |
| CLIからindex updaterが失敗 | published_index_stale |
これらはすべてfake transportで検証可能です。毎PRでlive GitHub mutationを行う必要はなく、live smokeは予定通りChild 6の #2239 に1本置けば十分です。
過剰実装しない範囲
この修正に、データベース、分散ロック、署名基盤、GitHub App、毎PRのlive mutation、投稿済みcommentのrollback/deleteは不要です。
必要なのは次の範囲だけです。
- canonical source dataを捨てない
- stable request digestでduplicateを判定する
Noneを含む正確なOCC- GitHubが既に返すlogin情報による軽量なwriter確認
- schema+digestの再検証
- 実際のCLI経路へindex updaterを接続する
現状は防御不足というより、追加したガード同士が矛盾して通常ワークフローを成立させていない状態です。P0を解消するまではmergeを保留するのが妥当です。
repository_id/--repo cross-check、two-stage prepare/authorize/publish flow、idempotency の stable digest 化、provider の read-time fork 検出、 実 source_observations の永続化、verified-comment 検証の一元化、 agent-retro-index への run_digest 直結wiring を実装。10件の regression test を追加し、既存 test_run_retrospective.py(Allowed Paths外)122件は 無傷のまま全 pytest/vitest/typecheck/lint/build を通過させた。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
impl-review-loop PR Review (iteration continuation after OWNER adversarial review)Reviewed head: This is a follow-up automated review after the OWNER's adversarial Mergeability / Evidence Check
P0 / P1 verification table
All 10 required regression tests (OWNER's table) are present and semantically match what was asked, independently re-run and passing. BlockersNone. Non-blockers (warnings)
verdict: APPROVE
reviewed_head_sha: "d36f8728a3a4a6ff07756b0cc6eccd3447640431"
blockers: []
warnings:
- "retro-index-builder.mjs silently drops malformed/unverifiable run comments instead of surfacing via generation_verdict/blockedReasons (non-blocking follow-up candidate)"
- "resolve_previous_state_provider() docstring default description is stale (cosmetic)" |
* fix: retrospective-run marker malformed comment を discard せず記録する (#2308) buildRetroIndex() が normalizeRetrospectiveRunComment() の kind: 'blocked' 判定(構造的に無効な agent_retrospective_run_publication/v1 envelope、および marker prefix はあるが strict marker parse に失敗するケース)を黙って discard せず、retrospective_runs_blocked[](run_comment_url + reason)へ記録するよう 変更する。retrospective_runs_blocked が非空の場合、既存 blockedReasons が空 である限り generation_verdict を partial に反映し、index 生成・upsert 自体は 継続する。extractRetrospectiveRunPayload() は marker prefix はあるが strict parse に失敗する first line を kind: 'blocked' / reason: 'retrospective_run_marker_malformed' として返すよう拡張する。 detectSchemaMigrationRequirement() の allowedKeys と docs/schemas/agent-retro-index.schema.json へ optional additive property として retrospective_runs_blocked を追加する。既存 blockedReasons 由来の blocked semantics と publication_digest の暗号学的検証は変更しない (PR #2304 の pr-reviewer 非ブロッキング指摘 P0-7 関連の解消)。 Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix: retrospective-run marker prefix の \b 誤マッチを負の先読みで修正する (#2308) PR #2366 への human REQUEST_CHANGES fix_delta。RETROSPECTIVE_RUN_MARKER_PREFIX の ECMAScript \b は両側が word 文字だと発火しないため、 `v1repository_id=...` や `v1_repository_id=...` のような区切り文字を欠いた malformed マーカーが prefix 判定をすり抜け ignored のまま kind: 'blocked' に 昇格しなかった(AC3 違反)。`(?![0-9])` の負の先読みに置き換え、v10 等の 将来バージョンとの区別を保ったまま該当パターンを blocked に分類する回帰 テストを追加する。 --------- Co-authored-by: Test <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
Summary
Issue #2238(#2192 Child 5)を実装しました。
.claude/skills/agent-retrospective/scripts/persist_retrospective_run.pyを新規実装し、run_retrospective.pyのmain()を--state-backend issue-comments経由で persistence-backedPreviousStateProvider(IssueCommentPreviousStateProvider)に実接続しました。docs/schemas/agent-retro-index.schema.jsonにはトップレベル optional なretrospective_runs[]セクションを additive に追加し、既存entries[]契約は変更していません。Checks
uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_persist_retrospective_run.py -v(AC1〜AC12、全 32 テスト PASS)uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/ -q(既存 358 テストも含め全 PASS、regression なし)pnpm typecheckpnpm lintpnpm test(tests/agent-logs/retro-index-update.test.ts/retro-index-builder.test.ts/retro-index-schema.test.tsを含む)pnpm builduv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py受け入れ条件の達成状況
run_retrospective.py main()が fixture ではなく persistence-backed provider を実際に構築・使用することを確認 —test_production_provider_used(--state-backend issue-comments時にIssueCommentPreviousStateProviderが生成されることを検証)、test_production_provider_used_fixture_backend_is_still_fixture(既定fixturebackend は変わらないことを対照確認)read_versionがPUBLISH_REQUEST_V1.expected_previous_digestへ伝播することを確認 —test_read_version_propagates_to_expected_previous_digest、test_read_version_propagates_to_expected_previous_digest_none_when_no_historypersist_retrospective_run.pyがPUBLISH_REQUEST_V1を消費しpublication_digestを生成することを確認 —test_publish_request_produces_publication_digesthuman_authorization_receipt/v1も無い場合は POST を実行しない fail-closed gate を確認 —test_authorization_gate_blocks_without_receipt_or_confirmation、test_authorization_gate_blocks_when_tty_confirm_present_but_not_a_tty、test_authorization_gate_blocks_when_tty_confirm_declines、test_authorization_gate_has_no_bare_authorized_flag_field、test_authorization_gate_succeeds_with_valid_receipt、test_authorization_gate_rejects_expired_receipttest_idempotency_key_noop_vs_conflict、test_idempotency_key_recomputed_not_trusted_from_caller(publisher 側で key を再計算し caller 値を信用しないことを検証)test_optimistic_concurrency_best_effort_conflict_detection(AC5 の idempotency guard とは独立した検証パス)sha256-jcs-v1canonical digest readback の一致を確認 —test_canonical_get_readback_digest_matchfinding_contract.identity/claim_class/evaluations[]・delta_resultsの round-trip と 1:1 cardinality を確認 —test_candidate_finding_delta_full_roundtrip、test_candidate_finding_delta_full_roundtrip_legacy_candidate_has_no_identityavailable/no_history/legacy_unavailable/partial/staleを実データ形状から分類することを確認 —test_previous_state_status_classification_no_history、_legacy_unavailable、_available、_partial、_stalerequest_id/idempotency key で既存投稿を回収することを確認 —test_ambiguous_post_failure_recovery_by_request_id_recovers_when_already_created、_conflict_on_digest_mismatch、_bounded_retry_when_not_foundpublished_index_staleとなり一次記録をロールバックしないことを確認 —test_index_update_failure_does_not_rollback_primary_record、test_index_update_success_reports_published。entries[]等既存フィールド不変はtests/agent-logs/retro-index-update.test.ts等をpnpm testで確認test_public_safety_validator_runs_before_post_rejects_token_pattern、_rejects_absolute_path、_rejects_smuggled_authority_field、_rejects_disallowed_top_level_fieldSchema Change Applicability
docs/schemas/agent-retro-index.schema.jsonにトップレベル optional なretrospective_runs[]($defs/retrospectiveRunEntry)を追加しました。既存entries[]/orphan_reports[]/ambiguous_links[]の型・必須性は変更していません(additive only)。Schema Consumer Inventory
Before(変更前)
agent_retro_index/v1の top-level required key はschema/generation_verdict/entries/orphan_reports/ambiguous_linksの 5 個で、additionalProperties: falseにより未知キーは拒否されていました。After(変更後)
トップレベルに optional
retrospective_runs[](各要素はrun_comment_url/run_digest/base_sha/source_set_digest/candidate_count/delta_summaryを持つretrospectiveRunEntry)を追加しました。既存 5 キーの型・required 性は不変です。scripts/agent-logs/lib/retro-index-builder.mjsbuildRetroIndex()がagent_retrospective_run_publication/v1marker comment を検出しretrospective_runs[]を additive に生成するロジックを追加。detectSchemaMigrationRequirement()の allowlist にretrospective_runsを追加。scripts/agent-logs/update-retro-index.mjsbuildRetroIndex()の戻り値indexをそのまま透過するため、コード変更は不要(retrospective_runsを含む index を自動的に artifact / comment へ伝播)。docs/dev/agent-retro-index.md.claude/skills/agent-retrospective/scripts/persist_retrospective_run.pyretrospective_runs[]の元データとなるagent_retrospective_run_publication/v1Issue comment を生成する新規 consumer/producer。Safety Claim Matrix
human_authorization_receipt/v1のいずれかによる人間承認なしには実行されない(fail-closed)test_authorization_gate_blocks_without_receipt_or_confirmationほか AC4 系 5 テスト(test_persist_retrospective_run.py)test_public_safety_validator_runs_before_post_*(AC12、5 テスト)docs/schemas/agent-retro-index.schema.jsonのentries[]等既存フィールドは削除・型変更されていない(additive only)tests/agent-logs/retro-index-update.test.ts/retro-index-builder.test.ts/retro-index-schema.test.ts全 PASS(既存 25 テスト + 新規 3 テスト)Notes
docs/adr/0007-agent-retrospective-boundaries.mdの mutation boundary(artifact-publication mutation は事前人間承認必須)、optimistic concurrency(best-effort)/idempotency(duplicate suppression)の区別に整合させています。agent_retrospective_run_publication/v1envelope は Child 2 のagent_retrospective_run/v1schema(per-sourcesource_observations[]の acquisition window を要求)とは別の schema_version です。PUBLISH_REQUEST_V1が per-source detail を保持しないため、repository source のみの最小source_observations単一項目で代替しています(Child 2 側の run identity 拡張は ADR 0007 の別途フォローアップとして記載済み・本 PR のスコープ外)。candidate_statusのaccepted等への変更)は Issue Stop Condition により本 PR のスコープ外です。docs/schemas/agent-retro-index.schema.json変更)を確認しました。lane classification:contract_artifact(schema/contract 変更、Node vitest で検証)。既存 CI lane 構成(python-test/node-backed-hook-tests等)への変更は行っていません。