Repository navigation
feat: agent-retrospective の agent_retrospective_run/v1・agent_improvement_candidate/v1 schema と validator を追加 - #2266
Conversation
…ent_candidate/v1 schema と validator を追加 (#2235) ADR 0007 の bounded observation モデル・claim-class source authority・idempotency と optimistic concurrency の区別を前提に、run identity/source_observations の JSON Schema 2 件・fixtures・candidate_status の state transition validator・ compute_source_set_digest() を新規実装する。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
…する (#2235) .claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.py が .github/ci/python-test-plan.json(python-test-core の pytest target SSOT)に未登録で、 ci_test_selection/v1 の uncovered_changed_test_files gate が CI を FAIL させていた (PR #2266 REQUEST_CHANGES Blocker 1)。既存の #1303 directory-target convention に 倣い、ディレクトリ target として登録した。
結論Verdict: 敵対的レビュー findings
追加の hardeningP2 として、schema は Draft-07 を宣言しながら また merge 前の最小修正セットは、#2235 の契約を ADR/Child3 と再同期して PRが更新された後、このblocker群が解消されたかを再チェックする運用もできます。 |
…を ADR 0007 に同期する PR #2266 の OWNER レビュー(issuecomment-5348975280)を受けた fix_delta。 Issue #2235 の改訂契約(AC7〜AC9)に対応する。 - source_observation に source_id(Child 3 #2236 の5アダプタ識別)と source_status(fail-independent status)を追加 - ADR 0007 Decision 1 に基づき acquisition window(fetch_started_at/ fetch_completed_at)と resource-event window を分離し、旧 observed_from/observed_until は非 required の deprecated フィールドとする - validate_run() が run_identity.source_set_digest を source_observations から再計算した値と照合し、stale/fabricated な digest を拒否する - validate_run()/validate_candidate() に明示的な jsonschema.FormatChecker を渡し date-time format を実際に強制する(jsonschema[format] extra を pyproject.toml に追加、uv.lock 再生成) - allOf/if/then で partial_reason・implementation_issue_ref・ rejection_reason・superseded_by の相互条件を schema レベルで enforce - ALLOWED_TRANSITIONS を修正し rejected/superseded がすべての 非終端状態から直接到達可能にする(docstring の主張と整合) - compute_source_set_digest() を source_observations の安定ソート後に canonicalize するよう修正し、配列順序に非依存にする - $schema を draft-07 から 2020-12 に更新($defs との整合) 47/47 pytest pass、ruff check pass。
Preview URLPreview removed (PR #2266 closed). |
CI の python-test-core が本ブランチの直前 fix_delta(`pyproject.toml` の `jsonschema>=4.0` を `jsonschema[format]>=4.0` に変更)で2件回帰した: - `scripts/ci/tests/test_runtime_dependency_smoke.py::test_project_dependencies_partition` は `[project].dependencies` に完全一致の `jsonschema` キー(specifier `>=4.0`)を 要求しており、`[format]` extra でキーが `jsonschema[format]` に変わり破壊された (Issue #2235 の Allowed Paths 外の既存契約テスト)。 - `.claude/skills/issue-refinement-loop/tests/test_issue_execution_decision_schema_parity.py::test_format_checker_date_time_support_is_documented_honestly` は「date-time format checking はリポジトリ全体で機能していない」ことを正直に 記録する canary テストで、`jsonschema[format]` が transitive に導入する `rfc3339-validator` により jsonschema のグローバル default FormatChecker が date-time チェッカーを自動登録してしまい canary が反転した(Issue #2235 スコープ外の 別 follow-up を要求する)。 `pyproject.toml` / `uv.lock` を revert し、代わりに `validate_retrospective_schema.py` にモジュールローカルな `jsonschema.FormatChecker()` インスタンス(`_FORMAT_CHECKER`)を定義して stdlib-only の `date-time` チェッカー(`_check_date_time_stdlib`, `datetime.fromisoformat` ベース)を登録する。`FormatChecker.__init__` は `checkers` をインスタンスごとにコピーするため、このローカル登録は他ファイルが 使うグローバル/クラスレベルの default FormatChecker を汚染しない。 Verification (clean venv, uv 0.11.29): - `.claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.py` 47/47 pass - `scripts/ci/tests/test_runtime_dependency_smoke.py` 10/10 pass - `.claude/skills/issue-refinement-loop/tests/test_issue_execution_decision_schema_parity.py` 5/5 pass - `uv run --isolated --locked --no-default-groups python scripts/ci/runtime_dependency_smoke.py` OK - `uv run --locked ruff check .claude/scripts scripts schemas .claude/skills` clean - `uv run --locked python scripts/ci/verify_lane_union.py` ok:true Co-Authored-By: Claude Sonnet 5 <[email protected]>
…b の deterministic source adapter を実装する (#2269) * 実装: agent-retrospective に Claude Code・Claude-GPT・repository・GitHub・Web の deterministic source adapter を実装する (#2236) ADR 0007 と agent_retrospective_run/v1 schema(PR #2266)に整合する CollectorResult (observation/private_evidence の dual-channel)契約で5 source の collector 関数を 実装した。各 collector は source_status/reason_code を独立に返し、typed operational failure のみを fail-independent に吸収する(プログラマバグは run-level fatal として 伝播)。repository adapter は base_sha のみを anchor とし main を再解決しない。 Claude-GPT adapter は PR #2222 の hook-event sink を authority とする。GitHub adapter は Link header pagination + endpoint/page 単位 provenance を持つ。Web adapter は https-only・credential-bearing URL 拒否・private/metadata address 拒否・redirect 再検証の SSRF 防御境界を実装する。private_evidence/observation は secret・raw local path を _scrub() で一律除去する(AC9)。 Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix: PR #2269 REQUEST_CHANGES 対応 (DNS rebinding/TOCTOU, transport_log 動的import, resolver programmer bug, GitHub 403/429分類, secret/pathスクラブ強化) 人間 REQUEST_CHANGES (issuecomment-5355112663, reviewed_head_sha 9f2f599) の fix_delta を反映する。 - Web adapter: resolve→validate→connect を単一の `_resolve_pinned_ip` に一体化し、 検証済み IP を `fetch`/`default_https_fetch` まで貫通させることで DNS rebinding/TOCTOU を解消。`default_https_fetch` は urllib opener chain を経由 しない直接ソケット実装へ変更し、`https_proxy`/`http_proxy` 環境変数を一切 参照しない。redirect は hop ごとに同じ境界検証+resolve を再適用する。 - `_load_transport_log_module()`: `exec_module()` 前に `sys.modules` へ登録する 標準 recipe に修正し、Python 3.12 の dataclass 文字列アノテーション解決に 伴う `AttributeError` を解消。real transport_log.py を通す回帰テストを追加。 - `_resolve_pinned_ip`: resolver 呼び出しの catch を `socket.gaierror`/`OSError` のみに限定し、resolver のプログラマバグ(KeyError 等)が `dns_resolution_failed` に誤変換されず run-level fatal として伝播するよう 修正。poison test を追加。 - GitHub adapter: `_classify_github_status()` で 403/429 を status/Retry-After/X-RateLimit-Remaining/エラーボディで分類し `rate_limited` と `permission_denied` を分離。`default_github_fetch_page()` ( `gh api --include` + `X-GitHub-Api-Version` pin) を production 実装として 追加。 - AC9: `_ABS_PATH_RE` を `/tmp/`・`/mnt/`・`/var/`・`/workspace/` と埋め込み 出現にも対応させ、`_safe_diagnostic_text()` の fail-closed allowlist validator を通さない限り diagnostics に自由形式テキスト(str(exc)/stderr 全文)を保持しない設計に変更。 - 推奨 hardening: Claude Code / Claude-GPT adapter は malformed 行が valid evidence と共存する場合 `complete` でなく `partial` (`malformed_response`) を返すよう修正。 regression matrix: DNS rebinding + proxy-env, real transport_log.py dynamic load on Python 3.12, resolver programmer-error propagation, 403/429/rate-header matrix, /tmp・/mnt・embedded path/Authorization leak 検出, valid+malformed runtime evidence の非対称解消 -- すべて追加テストで確認済み(54 tests pass)。 Issue #2236, PR #2269 追加コミット。 Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Summary
.claude/skills/agent-retrospective/にagent_retrospective_run/v1とagent_improvement_candidate/v1の JSON Schema、fixtures、validator(validate_retrospective_schema.py)、pytest を新規追加します。docs/adr/0007-agent-retrospective-boundaries.md(Child 1・#2234・マージ済み)が確定した bounded observation モデル・claim-class source authority・idempotency と optimistic concurrency の区別を前提にしています。agent_retrospective_run_v1.schema.json:run_identity(base_sha/generated_at/runtime_version/source_set_digest必須)とsource_observations(配列。各要素はsource_type/source_id/source_status/pagination_completenessを required、source_typeがrepository以外の場合はfetch_started_at/fetch_completed_atも required とする allOf/if/then 制約付き。observed_from/observed_untilは非推奨・任意で後方互換用に残置、resource_updated_at_min/resource_updated_at_maxは任意)を定義。agent_improvement_candidate_v1.schema.json:candidate_statusを 8 状態の closed enum(proposed/accepted/implementation_issue_created/implemented/validating/validated/rejected/superseded)として定義。validate_retrospective_schema.py: JSON Schema バリデーション(validate_run/validate_candidate)、candidate_statusの許可された state transition のみを許可するvalidate_transition()(例:rejected -> implementedを拒否。ALLOWED_TRANSITIONSは非終端状態すべてからrejectedへの遷移を許可)、決定論的かつ配列順序非依存なcompute_source_set_digest()(idempotency 用途限定。optimistic concurrency とは別概念であることを docstring に明記)を実装。schemas/fixtures/に各 schema 1 valid + 1 invalid fixture を追加。scripts/tests/test_validate_retrospective_schema.pyに 47 件の pytest を追加。fix_delta(PR #2266 レビュー対応)で以下を追加実装しました:
validate_run()がrun_identity.source_set_digestをsource_observationsから再計算し不一致を拒否する digest consistency enforcement、compute_source_set_digest()の配列順序非依存化(stable key によるソート)、date-timeformat を新規依存追加なしの module-local stdlib-only checker で enforcement、partial_reason/rejection_reason/superseded_by/implementation_issue_refの 4 つの status 固有フィールドをallOf/if/thenで schema-enforced 化。受け入れ条件の達成状況
agent_retrospective_run_v1.schema.jsonが存在し$schemaを持つ有効な JSON Schema であるtest_run_schema_has_schema_keywordPASS(uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.py -v実行、47/47 PASS。うち本テストは$schemaフィールド存在を assert)agent_improvement_candidate_v1.schema.jsonのcandidate_statusenum が 8 状態すべてを含むtest_candidate_status_enum_contains_all_eight_statesPASSvalidate_retrospective_schema.pyが valid fixture を pass、invalid fixture を fail として判定するtest_run_valid_fixture_passes_schema_validation/test_run_invalid_fixture_fails_schema_validation/test_candidate_valid_fixture_passes_schema_validation/test_candidate_invalid_fixture_fails_schema_validation4件 PASScandidate_status遷移(例:rejected -> implemented)を拒否するtest_invalid_transition_rejected5 パラメータケース(rejected-implemented含む)+test_invalid_transition_unknown_status_raisesPASS。正常遷移側はtest_valid_transition_accepted12 ケース PASScompute_source_set_digest()が同一入力に対して同一 digest を返す(決定論性)test_digest_deterministic_same_input_same_digest/test_digest_deterministic_differs_for_different_input/test_digest_deterministic_key_order_independent/test_digest_deterministic_array_order_independent4件 PASSrun_identityがbase_sha/generated_at/runtime_version/source_set_digestを required に持つtest_run_schema_run_identity_required_fieldsPASSagent_retrospective_run_v1.schema.jsonがsource_observationsを required フィールドとして持ち、その配列要素がsource_type/source_id/source_status/ (source_typeがrepository以外の場合)fetch_started_at/fetch_completed_atを持つ(ADR 0007 の bounded observation モデルおよび Child 3(#2236)の 5 アダプタ契約との整合)test_run_schema_source_observations_required_and_shapedPASS(source_type/observed_from/observed_until/fetch_started_at/fetch_completed_atの各プロパティ存在を assert)。fetch_started_at/fetch_completed_atの non-repository 必須制約(allOf/if/then)はtest_run_invalid_fixture_fails_schema_validation(欠落 fixture が reject されることを確認)とtest_run_valid_fixture_distinguishes_claude_code_and_claude_gpt_source_ids(両フィールドを持つ valid fixture が accept されることを確認)で PASSagent_retrospective_run_v1.schema.jsonのsource_observations要素がsource_id/source_statusを持つtest_run_schema_source_observation_requires_source_id_and_source_statusPASS(source_idenum がclaude_code/claude_gpt/repository/github/web、source_statusenum がcomplete/partial/unavailable/blockedであることを assert)validate_run()がrun_identity.source_set_digestとsource_observationsから再計算した digest の不一致を拒否する(digest consistency の enforcement)test_validate_run_rejects_stale_source_set_digest/test_validate_run_accepts_digest_recomputed_after_mutation2件 PASS実行コマンドと結果(2026-08-20 再実行、fix_delta 後の head
cbdff3a96e492e3df06298bc76efa81b6c6a3157で再確認済み):Checks
uv run --locked pytest .claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.py -v— 47/47 PASSuv run --locked ruff check .claude/skills/agent-retrospective/— All checks passed.github/ci/python-test-plan.jsonは下記 Scope Delta で拡張登録した機械的追加)Scope Delta
pr-reviewer REQUEST_CHANGES(CI
node-backed-hook-testsチェック FAIL:ci_test_selection_v1gate が新規追加 pytest を uncovered と検出)への fix_delta として、以下の Allowed Paths 拡張を行いました。.github/ci/python-test-plan.json.claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.pyが CI のpython-test-plan.json(pytest target set の SSOT。scripts/ci/python_test_plan.pyloader とci_test_selection/v1artifact 生成の双方が参照)に未登録だったため、ci_test_selection_v1のuncovered_changed_test_filesgate が CI を FAIL させていた。Issue 実装: agent-retrospective の agent_retrospective_run/v1・agent_improvement_candidate/v1 schema と validator を実装する #2235 の Current Validated Scope・In Scope(固定契約)自体は変更せず、CI が新規 pytest を正しく実行対象として認識するための機械的登録のみを行う(同種の前例: 実装: hooks: publish_termination_report 用 controlled mutation policy を分離する #1166、実装: python-test-plan に edit-issue tests directory coverage を追加する #1303 directory-target convention)。targets配列に.claude/skills/agent-retrospective/scripts/tests/をディレクトリ target として追加(1行差分)。.github/workflows/ci.ymlは変更していない。scripts/ci/python_test_plan.py --emit scope-argvの出力に新規 target が含まれることを確認。pytest .claude/skills/agent-retrospective/scripts/tests/ --collect-onlyで当時 24 tests が collect されることを確認(fix_delta 追加分を含む現行 head では 47 tests)。node-backed-hook-testsjob の固定 2 nodeid(tests/session_recording/codex/配下)とのディスジョイント性は維持(本 PR の新規テストはそのパス配下にないため重複なし)。CI_TEST_PERFORMANCE_DECISION_V1
Schema Change Applicability
新規 JSON Schema 2 件(
agent_retrospective_run_v1/agent_improvement_candidate_v1)を追加するため以下の通り判定します。Schema Consumer Inventory
本 PR で 2 schema を新規追加するため、既存 consumer は存在しません。
before
(N/A — schema 自体が本 PR で新規追加のため既存 consumer は存在しない)
after
.claude/skills/agent-retrospective/scripts/validate_retrospective_schema.pyvalidate_run/validate_candidate/validate_transition/compute_source_set_digestを実装.claude/skills/agent-retrospective/scripts/tests/test_validate_retrospective_schema.pyChild 3〜6(#2192 の未着手 child)が今後この schema の実 consumer(source adapter・Skill/SubAgent・永続化・自動検証)として追加される予定です。
Safety Claim Matrix
.github/ci/python-test-plan.jsonの CI target 登録も同様に純粋な設定ファイル変更)candidate_statusの遷移はvalidate_transition()の allowlist state machine でのみ許可され、schema の enum だけではrejected -> implementedのような不正遷移を防げないことをテストで確認済みtest_invalid_transition_rejected5 ケース PASSsource_set_digestは idempotency(重複抑止)専用であり optimistic concurrency(stale-write protection)の代替ではないことを docstring・schema description に明記した(ADR 0007 Decision 5 との整合)agent_retrospective_run_v1.schema.json/validate_retrospective_schema.pyの該当 description 参照Notes
not_applicable(本 Issue 本文の記載通り。JSON Schema・fixtures・validator はすべて純粋な静的検証ロジックであり、pytest 単体テストで完結するため)。.github/ci/python-test-plan.jsonへの target 登録は上記 Scope Delta の通り fix_delta で対応済みです(元 Allowed Paths 5 パスには含まれていませんでしたが、CI test selection SSOT への機械的登録として拡張しました)。本 PR は以下の Issue をクローズします。
Closes #2235