Skip to content

fix: unify percentile estimator paths to nearest_rank_v1 (#2180) - #2490

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-2180-percentile-nearest-rank-v1-unify
Sep 4, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-2180-percentile-nearest-rank-v1-unify

Conversation

@squne121

@squne121 squne121 commented Sep 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

tests/ci/test_ci_performance_gate.py の全 decision-producing percentile path(provider critical-path / legacy e2e(before)baseline / gate-ready before / gate-ready after)を、versioned nearest_rank_v1 semantics に統一する(PR #2172 OWNER adversarial review の deferred finding P1-2 の是正)。統一前は provider critical-path と validator の assessment builder のみが nearest_rank_v1 を使い、legacy e2e(before)baseline P50 と gate-ready before/after P50 は Python 標準ライブラリの偶数件平均型 statistics.median() を使っていた。偶数サンプルサイズ(n=20)では両者が異なりうり、AC9a の 35% relative-shortening gate の判定を反転させ得る不整合だった。

tests/ci/test_ci_performance_gate_percentile_consistency.py(新規)に、実際の decision-producing path(_job_duration_seconds() / _gate_ready_latency_seconds() / _pair_by_workflow_run_id() + _provider_critical_path_paired_p50_p95())を経由する決定論的 golden vector regression test を追加し、この一致(および 35% gate 判定反転の re-regression)を固定した。同ファイルで gate 側 / validator 側の _nearest_rank_percentile() 実装の semantic parity も固定している。

docs/dev/e2e-performance-benchmark.md と schemas/ci_runtime_delta_v2.schema.json の run_details 関連記述を、現行 validate_ci_performance_assessment_v2.py の status == "complete" && claim.kind != "none" required-when-claim 契約に同期した(schema は description のみ変更、key/type/required set は不変)。加えて _job_duration_seconds() が phase_id.startswith("test_e2e") の test-execution phase sum のみを意図的に維持し、install/build/container-startup/artifact-processing 等の wall-clock へ broaden していないことを docs に明記した。

Closes #2180(本 PR のマージで close する)。

fix_delta(OWNER REQUEST_CHANGES issuecomment-5532831822 対応)

  • P1 (merge blocker): golden regression test(test_ci_performance_gate_percentile_consistency.py)が、fixture を実 decision-producing path(_job_duration_seconds() 等)へ通した後の legacy e2e P50・gate-ready P50・35% relative-shortening 判定を、テスト自身が _nearest_rank_percentile() を直接呼んで再構成していた(実 gate の decision call site が将来別 estimator に変更されても golden test がその変更を検知できない構造)。_legacy_e2e_vs_provider_relative_shortening() と _gate_ready_before_after_non_regression() の 2 つの pure calculation helper を test_ci_performance_gate.py に抽出し、(1) 実 gate のテスト関数(test_p50_provider_meets_absolute_and_relative_shortening_threshold / test_p50_gate_ready_latency_not_regressed)と (2) golden vector regression test(AC3 + gate-ready 側新規テスト)の両方が同一 helper を直接呼ぶ構成に変更した。gate-ready 側には AC3 と対称な decision-reversal regression test(test_gate_ready_non_regression_decision_reversal_uses_nearest_rank_v1)を新規追加し、legacy old P50 / provider P50 からの relative shortening、および gate-ready before/after P50 / non-regression 判定の両方が共通 helper を消費する構造にした。nearest_rank_v1 の実装自体(数行の nearest-rank ロジック)は変更していない。
  • P2 (merge前に同時修正): docs/dev/e2e-performance-benchmark.md と schemas/ci_runtime_delta_v2.schema.json(RunDetail.description)の run_details 文言を、validate_ci_performance_assessment_v2.py::_check_percentile_recomputed_from_raw_samples の正確な predicate(status == "complete" and claim_kind != "none")に厳密同期した。従来の「後方互換で omission が可能なのは claim.kind == "none" のみ」という過度に強い文言を修正し、predicate の外側(例: status が incomparable_cohort / insufficient_samples / unavailable 等で claim.kind != "none" のまま)では、この percentile-recomputation 要件自体は run_details の省略を拒否しないが、他の意味検証・承認ルールが assessment を却下しないことを意味しない旨を明記した。schema の key / type / required set は変更していない(description のみ 1 行差分)。

Checks

  • ! rg -n -e 'statistics\.median' -e '^import statistics$' tests/ci/test_ci_performance_gate.py → PASS(マッチなし、exit 0)
  • uv run --locked pytest tests/ci/test_ci_performance_gate_percentile_consistency.py -q → PASS(7 passed — fix_delta で gate-ready decision-reversal test 1 件追加)
  • uv run --locked pytest tests/ci/test_ci_performance_gate_paired_critical_path.py -q → PASS(3 passed)
  • uv run --locked pytest tests/ci/test_ci_performance_gate*.py -q → PASS(65 passed, 3 skipped — 既存の cohort-dependent 統合テストで、live GitHub Actions history 不在によるものであり Runtime Verification Applicability の SKIP 規約通り)
  • rg -n -F 'phase_id.startswith("test_e2e")' docs/dev/e2e-performance-benchmark.md → PASS(1 match)
  • rg -n -F 'status == "complete"' docs/dev/e2e-performance-benchmark.md → PASS(1 match)
  • rg -n -F 'claim.kind != "none"' docs/dev/e2e-performance-benchmark.md → PASS(1 match)
  • ! rg -n 'does not read run_details' schemas/ci_runtime_delta_v2.schema.json → PASS(マッチなし、exit 0)
  • ! rg -n 'このチェックをスキップする' docs/dev/e2e-performance-benchmark.md → PASS(マッチなし、exit 0)
  • uv run --locked pytest schemas/tests/test_catalog.py -q(focused regression)→ PASS(51 passed)
  • uv run --locked pytest .claude/skills/ci-test-performance/scripts/tests/ -q(validator consumer suite, schema description 変更の影響確認)→ PASS(150 passed)
  • uv run --locked ruff check tests/ci/test_ci_performance_gate.py tests/ci/test_ci_performance_gate_percentile_consistency.py → PASS(All checks passed!)
  • uv run --locked python3 .claude/skills/create-issue/scripts/validate_japanese_content.py --file docs/dev/e2e-performance-benchmark.md --verbose → PASS(51 prose blocks, 0 failed)
  • uv run --locked python3 -c "import json; json.load(open('schemas/ci_runtime_delta_v2.schema.json'))" → PASS(JSON 構文健全性確認)

AC-by-AC 達成状況

  • AC1: tests/ci/test_ci_performance_gate.py から statistics.median の呼び出しおよび import statistics を除去し、旧 e2e(before)baseline P50 と gate-ready before/after P50 を既存の _nearest_rank_percentile()(nearest_rank_v1)へ置き換えた。provider critical-path / validator と合わせて全 4 decision-producing path が同一セマンティクスに適合している。達成(上記 rg negated check + 全 gate テスト PASS で証明)。
  • AC2: samples = [100.0] * 10 + [200.0] * 10(n=20)の golden vector fixture を、legacy e2e job-duration path と gate-ready latency path の両方に対して materialize し、実際の decision-producing path(_job_duration_seconds() / _gate_ready_latency_seconds() → _nearest_rank_percentile())が P50 = 100.0 を返すこと(statistics.median の 150.0 ではない)を test_ac2_legacy_e2e_p50_even_n_divergence_uses_nearest_rank_v1 / test_ac2_gate_ready_p50_even_n_divergence_uses_nearest_rank_v1 で証明。達成。
  • AC3: old_samples = [100.0] * 10 + [200.0] * 10(legacy e2e job-duration fixture)、provider_samples = [90.0] * 20(paired critical-path fixture)に対し、統一後の relative shortening が (100 - 90) / 100 == 10% と判定され、35% shortening gate を誤って PASS しないことを test_ac3_unified_estimator_does_not_incorrectly_pass_35_percent_gate で証明。同テストは pre-fix の混在計算(statistics.median(old_samples) == 150 → shortening 40% → gate を誤って PASS)を regression guard として明示的に再現し、統一後との対比を固定している。fix_delta により、このテストは実 gate と同一の pure helper(gate._legacy_e2e_vs_provider_relative_shortening)を直接呼ぶ構成に変更されている。達成。
  • AC4: samples = [100.0] * 19 + [500.0] の golden vector fixture を legacy e2e job-duration path と provider paired critical-path の両方に対して materialize し、nearest_rank_v1 P95 = 100.0 であること、estimator version が percentile_method: "nearest_rank_v1" として decision-producing result payload に明示されることを test_ac4_p95_boundary_nearest_rank_v1_legacy_e2e_path / test_ac4_p95_boundary_nearest_rank_v1_provider_critical_path_declares_estimator_version で証明。達成。
  • AC5: _job_duration_seconds() が phase_id.startswith("test_e2e") の test-execution phase sum のみを維持しており、install/build/container-startup/artifact-processing 等への broaden が行われていないことを、docs/dev/e2e-performance-benchmark.md の新規セクション「_job_duration_seconds() の計測スコープ」に明記した。達成。
  • AC6: docs/dev/e2e-performance-benchmark.md(AC8 セクション)と schemas/ci_runtime_delta_v2.schema.json(RunDetail.description)の run_details 関連記述を、現行 validate_ci_performance_assessment_v2.py の status == "complete" && claim.kind != "none" required-when-claim 実装契約と一致するよう同期した。fix_delta(P2)で predicate の外側での挙動(percentile-recomputation 要件自体は省略を拒否しないが他ルールは拒否しうる)まで明記し、validate_ci_performance_assessment_v2.py::_check_percentile_recomputed_from_raw_samples の実装と文言を完全一致させた。schema の key / type / required set は不変(description フィールドのみ 1 行差分)。達成。

検証コマンドと実行結果(Verification Commands and actual results)

上記「Checks」セクション参照。全 Issue #2180 本文記載の Verification Commands を実行し、すべて PASS した。追加で focused regression(schemas/tests/test_catalog.py、validator consumer suite)、ruff check、validate_japanese_content.py、schema JSON 構文健全性も実行し、すべて PASS した。

Schema Change Applicability

- decision: not_schema_change

schemas/ci_runtime_delta_v2.schema.json の変更は RunDetail.description フィールド 1 行のみであり、キー名・型・required 配列は一切変更していない(git diff で確認可能、1 insertion + 1 deletion の description 文字列差分のみ)。fix_delta(P2)でも同フィールドの文言をさらに predicate 一致に精緻化したのみで、対象は同じく description のみ。consumer 境界をまたぐ contract(key/type/required set)に変更がないため docs/dev/schema-governance.md の not_schema_change 判定基準(「Allowed Paths 内の変更がすべて内部ロジック・コメント・説明文のみで、consumer 境界をまたぐ contract に変更がない」)に該当する。

Schema Consumer Inventory

N/A(not_schema_change — description のみの変更であり、consumer 側のパース/読み取りロジックへの影響がないため、consumer 一覧・before/after key diff は不要)。

参考までに ci_runtime_delta_v2 schema の既知 consumer は rg -l "ci_runtime_delta_v2" .(.claude/worktrees 除外)で以下:

  • schemas/ci_test_performance_assessment_v2.schema.json($ref 参照)
  • schemas/tests/test_catalog.py(catalog test — 本 PR で再実行し PASS 確認済み)
  • schemas/catalog.yaml(catalog エントリ)
  • .claude/skills/ci-test-performance/scripts/validate_ci_performance_assessment_v2.py(validator consumer suite を本 fix_delta で追加再実行し PASS 確認済み)

いずれも description 文字列の変更では影響を受けない(構造・型・required set 非依存のため)。

Safety Claim Matrix

N/A — reason: 変更対象パス(tests/ci/*.py、docs/dev/e2e-performance-benchmark.md、schemas/ci_runtime_delta_v2.schema.json)は docs/dev/schema-governance.md の safety-sensitive パスパターン(transport / permission / sandbox / auth / mcp / .claude/skills/ / .github/workflows/)のいずれにも一致しない。テストコード・ドキュメント・schema description の変更のみで、実行時の権限・sandbox・auth・transport 境界への影響はない。

Scope Delta

Issue #2423(canonical cohort materialization、duplicate / run-attempt / fingerprint / timestamp canonicalization、approval eligibility binding、close-grade CLI の fail-closed exit contract)の owner scope は、本 PR では意図的に実装していない。OWNER の 2026-09-04 敵対的レビュー確定(anchor: https://github.com/squne121/loop-protocol/issues/2180#issuecomment-5530904888)に基づき、正しい依存順序は #2180 -> #2423 -> #2155 close-grade verification であり、#2180 は percentile estimator contract の owner のまま、#2423 が consumer として #2180 完了後に着手する。新しい「canonical cohort P0 Issue」の起票も行っていない(既存 #2423 がその責務を保持しているため)。

また production _cli_main() の approval_eligible 未チェックによる false-green(#2423 AC4 の責務)も本 PR のスコープ外として残している。

Notes

PR #2172's OWNER adversarial review deferred finding P1-2: the legacy
e2e (before) baseline P50 and gate-ready before/after P50 in
tests/ci/test_ci_performance_gate.py used Python's statistics.median()
while the provider critical-path P50/P95 and the validator's assessment
builder already used nearest_rank_v1. On even-n samples the two
estimators disagree, which could flip the AC9a 35% relative-shortening
gate decision depending on which code path computed "before" P50.

- Remove `import statistics` and both statistics.median() call sites;
  replace with the existing _nearest_rank_percentile() (nearest_rank_v1)
  helper already used by the provider critical-path calculation.
- Add tests/ci/test_ci_performance_gate_percentile_consistency.py with
  deterministic golden-vector regression tests exercising the actual
  decision-producing paths (job-duration / gate-ready-latency /
  paired-critical-path conversions, not a bare direct helper call) for
  the even-n P50 divergence, the 35% gate decision reversal regression,
  and the P95 boundary -- plus gate/validator semantic parity.
- docs/dev/e2e-performance-benchmark.md: document the intentional
  test_e2e*-only scope of _job_duration_seconds() (no wall-clock
  broadening), sync the run_details description with the validator's
  current required-when-claim contract, and note the estimator
  unification across all four decision-producing paths.
- schemas/ci_runtime_delta_v2.schema.json: sync the RunDetail
  description with the current required-when-claim validator contract
  (description only; keys/types/required unchanged).

Issue #2423 (canonical cohort materialization, duplicate/run-attempt/
fingerprint/timestamp canonicalization, approval eligibility binding,
close-grade CLI fail-closed contract) is intentionally NOT implemented
here -- it remains #2423's owner scope per the OWNER-confirmed
dependency ordering #2180 -> #2423 -> #2155.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2490 closed).

@squne121

squne121 commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES が妥当です。

PR #2490 の中核修正、つまり statistics.median() を除去して nearest_rank_v1 に統一する変更自体は正しいです。Python の statistics.median() は偶数件で中央2値を平均するため、n=20 の P50 ではこのリポジトリの nearest-rank 実装と実際に値が変わります。また percentile には複数の正当な定義があるため、「nearest-rank が絶対的に正しい」のではなく、採用する estimator を versioned contract として固定し、全 decision path で統一するという設計も適切です。NumPy も複数の percentile method を明示的に区別しています。(docs.python.org)

PR は head 69e26cf5... で CI 成功しており、変更範囲も Issue #2180 の現在の owner scope に沿っています。 ただし、今回追加された「将来の再混在を防ぐ regression test」が、肝心の変更 call site を固定できていません。ここを直してから merge した方がよいです。

優先度 | 所見 | 判定 -- | -- | -- P1 / blocker | 新規 golden-vector test が変更対象の実 decision call site を実行していない | 修正必須 P2 | run_details の docs/schema description が validator の条件より狭く書かれている | merge前修正推奨 P3 | 新規332行テストは目的に対してかなり重く、P1修正と同時に簡略化できる | 任意

P1 — regression test が「実 call site」を固定できていない

PR 本文と新規テストの説明は、fixture を「実際の decision-producing path」に通していると主張しています。Issue #2180 も AC2/AC3 で「関連する decision-producing path」から P50 と35%判定を証明する契約になっています。

しかし実装を見ると、legacy e2e の AC2 は _job_duration_seconds() で vector を作ったあと、テスト自身が直接 gate._nearest_rank_percentile(durations, 50) を呼びます。gate-ready も同様に _gate_ready_latency_seconds() の結果へテスト側から estimator を適用しています。AC3 の35%判定も、provider 側は実関数を通す一方、old 側 P50 と relative shortening はテスト自身で再実装しています。

一方、今回本当に変更された箇所は test_ci_performance_gate.py 内の

old_p50 = _nearest_rank_percentile(old_durations, 50)

および gate-ready の

new_p50 = _nearest_rank_percentile(...)
old_p50 = _nearest_rank_percentile(...)

です。

つまり、将来この3箇所のどれかを別 estimator に戻しても、新規 consistency test は _nearest_rank_percentile() 自体が残っている限り PASS できます。たとえば gate-ready call site を独自の補間 percentile に変更しても、新規 AC2 test は変更箇所を呼ばないため検知しません。

これは特に問題です。既存の artifact-dependent gate テストは live cohort がなければ SKIP し得るため、今回 artifact-independent golden test を追加した理由そのものが「常時 regression を検出すること」だからです。以前の #2180 OWNER review でも、artifact-independent test を主検証にすべきと明記されています。

推奨修正は harness を増やすことではありません。 AST 検査や live GitHub Actions harness は不要です。test_ci_performance_gate.py 内に小さな pure calculation helper を切り出し、実 gate と golden test の両方がそれを呼ぶ構成が最も軽量です。例えば legacy/provider の P50+shortening 計算と、gate-ready before/after P50 比較をそれぞれ小さな関数にし、現在の artifact-dependent test function はデータ取得後にその関数を呼ぶだけにします。これなら estimator を call site で変更すると golden test も必ず壊れます。

なお ! rg statistics.median は現在の修正確認には有用ですが、長期 regression contract としては弱いです。median_low、別 helper、手書き補間などは検出しません。

P2 — run_details の「optional は claim:none のみ」は現行 validator と一致しない

変更後 docs は、

status == complete && claim.kind != none の場合 required

という条件を正しく書いた直後に、**「後方互換が残るのは claim.kind == none の no-op artifact のみ」**としています。schema description も同じ主張です。

前半は正しいですが、後半の「のみ」は強すぎます。現行契約では performance_evidence.status に insufficient_samples や incomparable_cohort などがあり、active claim と証拠充足状態は独立しています。 現行 validator も run_details を必須にする predicate を status == complete and claim_kind != none としているため、claim.kind != none でも status が incomplete なら、この particular rule は run_details 欠落を要求しません。

したがって AC6 の「現行 validator と同期」という観点では、

run_details is conditionally required for complete, non-none claims. Outside that predicate, omission is not blocked by percentile recomputation itself; other semantic/approval rules may still block the assessment.

程度にする方が正確です。

これは runtime bug ではありません。JSON Schema の description は validation assertion ではなく annotation なので、今回の description-only 変更が構造 contract を変えないという PR の判断は正しいです。(JSON Schema) むしろ conditional JSON Schema を追加して仕組みを二重化する必要はなく、文章だけ直せば十分です。

スコープについて

以前の敵対的レビューで出ていた canonical cohort、duplicate/run-attempt、fingerprint、approval_eligible false-green を この PR の blocker に戻すべきではありません。その後の OWNER anchor で責務は #2423 に明確に分離され、現在の正しい依存順序は #2180 → #2423 → #2155 と確定しています。 Issue #2180 本文にも同じ dependency ordering が反映されています。 #2423 自体も canonical materialization と close-grade CLI を自分の owner scope とし、#2180 の percentile estimator を consumer として使う契約です。

したがって、ここで canonicalization や approval harness を #2490 に追加すると、品質向上ではなく scope 再膨張です。避けるべきです。

merge 前の最小修正

P1だけなら merge blocker、P2は同じ修正ラウンドで直すのが合理的です。P1 を直す際には、新しい framework や dependency を増やさず、actual gate calculation を数十行以下の pure helper に抽出して golden test と共有するのが最も費用対効果が高いです。

また、nearest_rank_v1 の8行程度の実装を NumPy に置き換えることも勧めません。NumPy 自身が percentile method を多数持っていることからも method の明示は重要ですが、このプロジェクトでは50/95の固定値しか使っておらず、現在の小さな versioned helper+golden vectorsの方が依存・理解コストとも低いです。(NumPy)

最終 verdict: REQUEST_CHANGES。P1 修正後は、P2 の文言同期を確認したうえで APPROVE 寄りです。 現在レビュー thread は付いておらず、PR はまだ Draft です。

## 判定

REQUEST_CHANGES が妥当です。

PR #2490 の中核修正、つまり statistics.median() を除去して nearest_rank_v1 に統一する変更自体は正しいです。Python の statistics.median() は偶数件で中央2値を平均するため、n=20 の P50 ではこのリポジトリの nearest-rank 実装と実際に値が変わります。また percentile には複数の正当な定義があるため、「nearest-rank が絶対的に正しい」のではなく、採用する estimator を versioned contract として固定し、全 decision path で統一するという設計も適切です。NumPy も複数の percentile method を明示的に区別しています。([docs.python.org]1)

PR は head 69e26cf5... で CI 成功しており、変更範囲も Issue #2180 の現在の owner scope に沿っています。 ただし、今回追加された「将来の再混在を防ぐ regression test」が、肝心の変更 call site を固定できていません。ここを直してから merge した方がよいです。

優先度 所見 判定
P1 / blocker 新規 golden-vector test が変更対象の実 decision call site を実行していない 修正必須
P2 run_details の docs/schema description が validator の条件より狭く書かれている merge前修正推奨
P3 新規332行テストは目的に対してかなり重く、P1修正と同時に簡略化できる 任意

P1 — regression test が「実 call site」を固定できていない

PR 本文と新規テストの説明は、fixture を「実際の decision-producing path」に通していると主張しています。Issue #2180 も AC2/AC3 で「関連する decision-producing path」から P50 と35%判定を証明する契約になっています。

しかし実装を見ると、legacy e2e の AC2 は _job_duration_seconds() で vector を作ったあと、テスト自身が直接 gate._nearest_rank_percentile(durations, 50) を呼びます。gate-ready も同様に _gate_ready_latency_seconds() の結果へテスト側から estimator を適用しています。AC3 の35%判定も、provider 側は実関数を通す一方、old 側 P50 と relative shortening はテスト自身で再実装しています。

一方、今回本当に変更された箇所は test_ci_performance_gate.py 内の

old_p50 = _nearest_rank_percentile(old_durations, 50)

および gate-ready の

new_p50 = _nearest_rank_percentile(...)
old_p50 = _nearest_rank_percentile(...)

です。

つまり、将来この3箇所のどれかを別 estimator に戻しても、新規 consistency test は _nearest_rank_percentile() 自体が残っている限り PASS できます。たとえば gate-ready call site を独自の補間 percentile に変更しても、新規 AC2 test は変更箇所を呼ばないため検知しません。

これは特に問題です。既存の artifact-dependent gate テストは live cohort がなければ SKIP し得るため、今回 artifact-independent golden test を追加した理由そのものが「常時 regression を検出すること」だからです。以前の #2180 OWNER review でも、artifact-independent test を主検証にすべきと明記されています。

推奨修正は harness を増やすことではありません。 AST 検査や live GitHub Actions harness は不要です。test_ci_performance_gate.py 内に小さな pure calculation helper を切り出し、実 gate と golden test の両方がそれを呼ぶ構成が最も軽量です。例えば legacy/provider の P50+shortening 計算と、gate-ready before/after P50 比較をそれぞれ小さな関数にし、現在の artifact-dependent test function はデータ取得後にその関数を呼ぶだけにします。これなら estimator を call site で変更すると golden test も必ず壊れます。

なお ! rg statistics.median は現在の修正確認には有用ですが、長期 regression contract としては弱いです。median_low、別 helper、手書き補間などは検出しません。

P2 — run_details の「optional は claim:none のみ」は現行 validator と一致しない

変更後 docs は、

status == complete && claim.kind != none の場合 required

という条件を正しく書いた直後に、**「後方互換が残るのは claim.kind == none の no-op artifact のみ」**としています。schema description も同じ主張です。

前半は正しいですが、後半の「のみ」は強すぎます。現行契約では performance_evidence.status に insufficient_samples や incomparable_cohort などがあり、active claim と証拠充足状態は独立しています。 現行 validator も run_details を必須にする predicate を status == complete and claim_kind != none としているため、claim.kind != none でも status が incomplete なら、この particular rule は run_details 欠落を要求しません。

したがって AC6 の「現行 validator と同期」という観点では、

run_details is conditionally required for complete, non-none claims. Outside that predicate, omission is not blocked by percentile recomputation itself; other semantic/approval rules may still block the assessment.

程度にする方が正確です。

これは runtime bug ではありません。JSON Schema の description は validation assertion ではなく annotation なので、今回の description-only 変更が構造 contract を変えないという PR の判断は正しいです。(JSON Schema) むしろ conditional JSON Schema を追加して仕組みを二重化する必要はなく、文章だけ直せば十分です。

スコープについて

以前の敵対的レビューで出ていた canonical cohort、duplicate/run-attempt、fingerprint、approval_eligible false-green を この PR の blocker に戻すべきではありません。その後の OWNER anchor で責務は #2423 に明確に分離され、現在の正しい依存順序は #2180 → #2423 → #2155 と確定しています。 Issue #2180 本文にも同じ dependency ordering が反映されています。 #2423 自体も canonical materialization と close-grade CLI を自分の owner scope とし、#2180 の percentile estimator を consumer として使う契約です。

したがって、ここで canonicalization や approval harness を #2490 に追加すると、品質向上ではなく scope 再膨張です。避けるべきです。

merge 前の最小修正

P1だけなら merge blocker、P2は同じ修正ラウンドで直すのが合理的です。P1 を直す際には、新しい framework や dependency を増やさず、actual gate calculation を数十行以下の pure helper に抽出して golden test と共有するのが最も費用対効果が高いです。

また、nearest_rank_v1 の8行程度の実装を NumPy に置き換えることも勧めません。NumPy 自身が percentile method を多数持っていることからも method の明示は重要ですが、このプロジェクトでは50/95の固定値しか使っておらず、現在の小さな versioned helper+golden vectorsの方が依存・理解コストとも低いです。(NumPy)

最終 verdict: REQUEST_CHANGES。P1 修正後は、P2 の文言同期を確認したうえで APPROVE 寄りです。 現在レビュー thread は付いておらず、PR はまだ Draft です。

@squne121

squne121 commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

確認した限り、今回は 既存 PR #2490 をそのまま使い、#2180 の impl-review-loop を再開して target comment の P1/P2 を fix-delta として処理するのが最小です。新しい Issue / PR は不要です。

PR #2490 は現在 open / Draft、head は 69e26cf5...、変更は4ファイルです。main は PR の base SHA 0b0d8f8c... のままで、確認時点では base drift もありません。CI workflow もその head で success です。

対象コメントの判断はかなり明確です。P1 は blockerで、現在の golden-vector test は fixture の変換部分こそ実関数を通すものの、肝心の legacy P50・gate-ready P50・relative-shortening をテスト側で直接計算しているため、変更された decision call site 自体を固定できていません。P2 は同じ修正ラウンドで直すべき文言不整合です。P3 の332行テスト簡略化は、P1修正に伴って自然に小さくできる範囲だけで十分です。

また、canonical cohort、duplicate/run-attempt、fingerprint、approval_eligible、close-grade CLI は #2423 の owner scope で、#2180 が取り戻すべきではありません。#2423 自身も #2180 の estimator contract を consumer とする契約です。

impl-review-loop 自体も implementation-worker → test-runner → pr-reviewer を SubAgent として回し、REQUEST_CHANGES なら fix-delta を Step 1 に戻す設計です。APPROVE 単独では終了せず、live mergeability と blocker 空を合わせて判断します。 現行 Claude Code では対話セッションを claude --permission-mode auto で開始できます。([GitHub]1)

その前提で、以下をそのまま貼るのがよいです。

GitHub repository squne121/loop-protocol で、既存 PR #2490 / Issue #2180 に対する impl-review-loop を実行してください。

Target PR:
#2490

Linked implementation Issue:
#2180

今回の trusted human-context / fix-delta anchor:
#2490 (comment)

このセッションは claude --permission-mode auto で起動した対話的 Claude Code を想定しています。

Goal

PR #2490 の上記レビューコメントを canonical fix-delta として扱い、既存 PR / 既存 branch / 既存 worktree を継続利用して、

実装修正
→ 独立検証
→ PR review
→ REQUEST_CHANGES があれば再修正
→ 再検証
→ 再review
→ current-head CI確認
→ merge直前の状態

まで、人間の途中承認を要求せず自律的に完了してください。

gh pr merge、auto-merge、有効化済み merge queue への投入など、実際の merge 操作だけは行わないでください。

最終状態は「人間が merge 操作だけを行えばよい状態」を目標にしてください。

最新の人間指示の解釈

target comment 内の REQUEST_CHANGES は今回の作業を停止せよという veto ではありません。

このプロンプトが、その REQUEST_CHANGES を実際に修正して impl-review-loop を続行するという最新の明示的指示です。

したがって target comment を human_context_comment_urls に渡す trusted human-context / fix-delta として扱い、P1/P2 を解消してください。

過去コメント内の REQUEST_CHANGES という文字列だけを理由に human escalation / terminal stop しないでください。

現在把握している主要 fix-delta

まず live GitHub state と現在の branch/HEAD/diff を再取得して確認し、この記述を盲目的に信用しないでください。

P1 / merge blocker

現在追加されている tests/ci/test_ci_performance_gate_percentile_consistency.py は、fixture を

  • _job_duration_seconds()
  • _gate_ready_latency_seconds()
  • _pair_by_workflow_run_id()
  • _provider_critical_path_paired_p50_p95()

へ通してはいますが、その後の legacy e2e P50、gate-ready P50、relative-shortening decision をテスト自身が _nearest_rank_percentile() 等で再構成しています。

このため、実際に PR #2490 で変更した

  • legacy e2e old_p50
  • gate-ready new_p50
  • gate-ready old_p50
  • 35% relative-shortening decision

の production decision call site が将来別 estimator に戻っても、golden test が通る余地があります。

これを修正してください。

推奨する最小設計は、tests/ci/test_ci_performance_gate.py 内に小さな pure calculation helper を抽出し、

  1. artifact-dependent な実 gate
  2. artifact-independent な golden-vector regression test

の両方が同じ helper を呼ぶ構成にすることです。

例えば概念的には、

  • legacy old P50 と provider P50 から relative shortening を算出する helper
  • gate-ready before/after の P50 と non-regression decision を算出する helper

程度です。

正確な関数名・return type は現行コードとの整合性を見て決めて構いません。

重要なのは、golden test が estimator primitive を直接呼んで production logic を再実装するのではなく、実 gate が使う decision-producing pure helper を直接検証することです。

AST inspection、新しい harness、新しい dependency、live GitHub Actions fixture は追加しないでください。

nearest_rank_v1 の数行の実装を NumPy 等へ置き換える必要もありません。

AC2/AC3 の regression が次を直接証明する状態にしてください。

  • even-n old samples [100]*10 + [200]*10 → old P50 = 100
  • provider P50 = 90
  • relative shortening = 10%
  • 35% gate は PASS しない
  • pre-fix の mixed estimator なら 40% になり誤 PASS することとの対比

gate-readyについても、実 gate と golden test が共通 calculation helper を消費する構造にしてください。

P2 / merge前に同時修正

docs/dev/e2e-performance-benchmark.md と
schemas/ci_runtime_delta_v2.schema.json
の run_details 説明を validator の正確な predicate に同期してください。

正しい中心契約は、

performance_evidence.status == "complete" && claim.kind != "none"

の場合に run_details が required である、です。

現在の

「後方互換で omission が可能なのは claim.kind == "none" のみ」

という意味の文言は強すぎます。

active claim でも status が complete でなければ、この particular run_details required rule 自体は成立しません。

趣旨は例えば、

run_details is conditionally required for complete, non-none claims. Outside that predicate, omission is not rejected by this percentile-recomputation requirement itself; other semantic or approval rules may still reject the assessment.

程度にしてください。

JSON Schema の key / type / required set は変更せず、description-only のままにしてください。

P3 / optional

新規 consistency test が現在かなり大きいため、P1 の pure helper 抽出に伴い明らかな重複を削れるなら簡略化して構いません。

ただし、行数削減そのものを目的にしないでください。

AC2/AC3/AC4、gate/validator semantic parity、pre-fix decision reversal の regression value を落とさないことを優先してください。

Scope boundary

Issue #2180 の live body / Allowed Paths を authority としてください。

特に以下を #2490 に戻さないでください。

これらは Issue #2423 の owner scope です。

dependency ordering は現在、

#2180 -> #2423 -> #2155 close-grade verification

です。

新しい canonical-cohort Issue も作成しないでください。

Existing PR reuse

新しい PR を作らないでください。

PR #2490 の linked worktree / branch を特定し、その current head から継続してください。

既存 branch:
worktree-issue-2180-percentile-nearest-rank-v1-unify

ただし live GitHub / git state を再取得して identity を確認してください。

root checkout で直接変更しないでください。

通常の fast-forward push は必要に応じて自律実行して構いません。

force push、history rewrite、published commit の destructive amend/reset は禁止です。

impl-review-loop execution

.claude/skills/impl-review-loop/SKILL.md と参照される step files を読み、現行 implementation に従ってください。

root/main thread は control-plane に徹してください。

以下の SubAgent を実際に起動してください。

  • implementation-worker
  • test-runner
  • pr-reviewer

必要なら同じ役割を iteration ごとに fresh に再起動してください。

各 SubAgent に役割を明確に限定し、同一 agent が「実装したので自分で APPROVE」のような自己承認をしないようにしてください。

SubAgent 自身からさらに nested SubAgent を増殖させないでください。delegation は root orchestrator が管理してください。

SubAgent completion barrier

これは必須です。

起動した SubAgent は必ず terminal state まで待ってください。

SubAgent の作業が走っている途中で root/main thread が最終回答を返してはいけません。

並列に起動した場合も、全 relevant SubAgent の completion を join してから次の routing decision をしてください。

各 iteration で、

implementation-worker 完了
→ test-runner 完了
→ pr-reviewer 完了
→ live state 再取得
→ route 判定

の causal ordering を保持してください。

stale head に対する review result を current head の verdict として再利用しないでください。

最終報告には、起動した全 SubAgent を列挙し、それぞれの terminal status と担当内容を示してください。

No-human-approval operating policy

通常の実装判断では人間に質問しないでください。

以下は自律処理してください。

  • repository / Issue / PR / comment の調査
  • allowed-path 内の編集
  • pure helper の設計選択
  • regression test の追加・修正
  • docs description の修正
  • lint / pytest / verification commands
  • formatter
  • commit
  • normal fast-forward push
  • CI待機
  • CI failure のログ調査
  • CI failure が今回の差分起因なら修正
  • reviewer REQUEST_CHANGES への対応
  • PR body の Checks / AC-by-AC / Scope Delta 更新
  • target review comment への対応結果コメント
  • stale-head re-review
  • main が進んだ場合の non-destructive branch update
  • mergeability / branch protection / required checks の再確認
  • 必要であれば final state で Draft → Ready for Review への遷移

「どうしますか」「修正してよいですか」「テストを実行しますか」「pushしてよいですか」等の routine confirmation は不要です。

reviewer の human_review_required: true 自己申告だけでも停止しないでください。まず root が evidence を検証し、機械的・技術的に解消できるものは解消してループを続けてください。

iteration 上限は routine human approval を発生させないよう十分大きく設定してください。3回で足りない場合に単に「max_iterationsなので人間へ」とするのではなく、同一の明確な技術的 blocker に進展なく反復しているかを確認してください。

Hard stop

人間へ停止して確認してよいのは、原則として次の場合だけです。

  1. destructive / irreversible operation が不可避

    • force push
    • git reset --hard
    • published history rewrite
    • branch deletion
    • 意図不明な既存作業の破棄
    • scope外データを失わせる conflict resolution
    • その他、容易に元へ戻せない共有状態の変更
  2. secret / credential / protected secret-policy decision が必要

    • token、credential、secret の閲覧・貼り付け・更新
    • secret-policy の Decision Gate を越える必要がある
    • 権限昇格のため秘密情報を人間から受け取る必要がある

それ以外の技術的失敗は、まず安全な代替手段、再試行、ログ調査、fix iteration で解消してください。

permission classifier があるコマンドを拒否した場合、--dangerously-skip-permissions、hook bypass、--no-verify 等へ逃げないでください。安全な代替経路を探してください。

実 Git conflict も、意味が一意で通常の merge で安全に解消できるなら自律解消して構いません。双方の意図のどちらかを捨てる必要があり正解が repository evidence から決められない場合だけ hard stop としてください。

Verification

Issue #2180 の Verification Commands を current live body から取得し、すべて実行してください。

少なくとも今回の fix に対し focused に、

tests/ci/test_ci_performance_gate_percentile_consistency.py

と関連 gate tests を実行してください。

P1 の regression test については、修正前の設計では検出できなかった decision-call-site drift が修正後に検出可能になったことをレビューしてください。

docs/schema の P2 については validator implementation も読み、predicate と説明文が完全に一致していることを確認してください。

その後、PR head を push し、current-head の GitHub Actions / required checks を待ってください。

過去 head の green CI を最終証拠にしないでください。

required CI は branch protection の live state から取得してください。

failure があれば current-head の failed job/log を取得し、今回の差分起因なら同じループ内で修正してください。

flaky と決めつけず原因を確認してください。

PR review loop

verification が通った current head に対して fresh pr-reviewer を実行してください。

reviewer には少なくとも以下を確認させてください。

  • target comment P1 が本当に解消されたか
  • golden-vector test が production decision helper を共有しているか
  • AC2 / AC3 の 35% decision reversal が production calculation path を検証しているか
  • gate-ready P50 が同様に production calculation path を検証しているか
  • P2 docs/schema wording が validator predicate と一致したか
  • 実装: 性能ゲートの canonical cohort materialization と close-grade CLI を fail-closed 化する #2423 scope を侵食していないか
  • Allowed Paths 違反がないか
  • unnecessary framework / dependency / harness を増やしていないか
  • current-head verification / CI が有効か

REQUEST_CHANGES の場合は blockers を concrete fix_delta として implementation-worker に戻し、人間へ質問せず次 iteration を続けてください。

reviewer が APPROVE を返しても、その reviewed_head_sha が current PR head と一致することを確認してください。

PR hygiene

修正完了後、PR #2490 の body を current implementation に同期してください。

特に、

  • Summary
  • Checks
  • AC-by-AC
  • Scope Delta
  • Closes #2180

を current head の実態と一致させてください。

target comment の指摘に対応したことが分かる簡潔な PR conversation comment も投稿してください。

P1:
production decision calculation を pure helper に抽出し golden regression と共有したこと

P2:
run_details 文言を exact validator predicate に同期したこと

を記載してください。

対象コメントは top-level PR conversation comment なので、存在しない review thread を無理に resolve しないでください。

Final merge-readiness gate

終了前に live state を再取得してください。

以下がすべて成立するまで完了扱いにしないでください。

  • Issue 実装: e2e performance benchmark の percentile estimator を before/after/provider/gate-ready 全経路で統一する #2180 scope/AC を満たす
  • target comment の P1 blocker 解消
  • P2 解消
  • Allowed Paths clean
  • current-head focused tests PASS
  • Issue Verification Commands PASS
  • current-head required CI PASS
  • fresh pr-reviewer verdict == APPROVE
  • reviewer blockers == []
  • reviewed_head_sha == current PR head SHA
  • PR mergeable
  • base drift が残っていない、または安全に branch update 済み
  • PR body が current implementation と一致
  • Closes #2180 が保持されている
  • unresolved actionable review feedback がない

PR がまだ Draft であり、repository workflow 上 Ready for Review にすることが merge直前 handoff として適切なら、最後に Ready for Review へ変更してください。

ただし実際の merge は絶対に実行しないでください。

gh pr merge
auto-merge enable
merge queue submit

は禁止です。

Final report

最終回答は途中経過ではなく、全 SubAgent が terminal state になった後だけ返してください。

以下を簡潔に報告してください。

  • final PR URL
  • final head SHA
  • 実装した P1/P2 fix
  • 変更ファイル
  • verification results
  • current-head CI results
  • final pr-reviewer verdict
  • mergeability / draft-or-ready status
  • unresolved blockers の有無
  • 起動した全 SubAgent と terminal status
  • merge を実行していないこと
  • 人間が次に行う必要がある操作

成功時、人間の次アクションは原則 PR #2490 を確認して merge する の1つだけにしてください。

このプロンプトでは、コメント中の REQUEST_CHANGES を「停止命令」ではなく「今回直す fix-delta」だと明示した点と、SubAgent completion barrier を明文化した点が重要です。さらに max_iterations=3 の機械的 escalation が今回の目的と衝突しやすいので、routine な反復では人間に戻さない方針も入れています。

squne121 and others added 3 commits September 4, 2026 07:20
PR #2490 OWNER REQUEST_CHANGES (issuecomment-5532831822) の fix_delta。

P1 (merge blocker): golden regression test
(test_ci_performance_gate_percentile_consistency.py) が
legacy e2e P50・gate-ready P50・35% relative-shortening 判定を
`_nearest_rank_percentile()` の直接呼び出しでテスト自身が再構成しており、
実 gate (test_ci_performance_gate.py) の decision call site が将来別
estimator に変更されても golden test がその変更を検知できない構造だった。

`_legacy_e2e_vs_provider_relative_shortening()` と
`_gate_ready_before_after_non_regression()` の2つの pure decision helper
を test_ci_performance_gate.py に抽出し、実 gate のテスト関数
(test_p50_provider_meets_absolute_and_relative_shortening_threshold /
test_p50_gate_ready_latency_not_regressed) と golden test
(AC3 + 新規 gate-ready 版) の両方が同じ helper を直接呼ぶ構成に変更した。
gate-ready 側には AC3 と対称な decision-reversal regression test
(test_gate_ready_non_regression_decision_reversal_uses_nearest_rank_v1) を
新規追加した。

P2 (merge前に同時修正): docs/dev/e2e-performance-benchmark.md と
schemas/ci_runtime_delta_v2.schema.json の run_details 記述を、
validate_ci_performance_assessment_v2.py の実装 predicate
(`status == "complete" and claim_kind != "none"`) に厳密同期し、
「後方互換が残るのは claim.kind == none のみ」という過度に強い文言を
修正した(schema の key/type/required set は不変、description のみ変更)。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

squne121 commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

fix_delta 対応完了(OWNER REQUEST_CHANGES issuecomment-5532831822)

head SHA b82acb1212c4a29c8423b2e6d98234ef1e62e7b2(commit fdbc4409...、その後 remote 分岐を merge)で以下を対応しました。

P1 (merge blocker) — 対応済み

test_ci_performance_gate_percentile_consistency.py が fixture を _job_duration_seconds() 等の実 decision-producing 関数に通した後、legacy e2e P50・gate-ready P50・35% relative-shortening 判定をテスト自身が _nearest_rank_percentile() を直接呼んで再構成していた問題を修正しました。

tests/ci/test_ci_performance_gate.py に以下 2 つの pure calculation helper を新規抽出しました:

  • _legacy_e2e_vs_provider_relative_shortening(old_durations, provider_p50_seconds) -> dict(old_p50_seconds / provider_p50_seconds / relative_shortening / meets_relative_shortening_threshold を返す)
  • _gate_ready_before_after_non_regression(old_latencies, new_latencies) -> dict(old_p50_seconds / new_p50_seconds / non_regressed を返す)

実 gate 側のテスト関数(test_p50_provider_meets_absolute_and_relative_shortening_threshold / test_p50_gate_ready_latency_not_regressed)と golden regression test(AC3 test_ac3_unified_estimator_does_not_incorrectly_pass_35_percent_gate および新規追加した test_gate_ready_non_regression_decision_reversal_uses_nearest_rank_v1)は、両方ともこの同一 helper を直接呼び出す構成になりました。これにより、将来 estimator/ratio/threshold の計算方式が実 gate 側で変更された場合、golden test は自動的にその変更を検知します。

gate-ready 側には AC3 と対称な decision-reversal regression test を新規追加し(old_latencies=[100]*10+[200]*10, new_latencies=[120]*20 → nearest_rank_v1 では regression 検出、statistics.median ベースの混在計算では regression を誤って見逃す、という regression guard)、legacy/provider 側だけでなく gate-ready 側でも実 gate と golden test が共通 helper を消費する構造にしました。

nearest_rank_v1 の実装自体(数行の nearest-rank ロジック)は変更していません。AST inspection・新規 harness・新規 dependency・live GitHub Actions fixture の追加もありません。

P2 (merge前に同時修正) — 対応済み

docs/dev/e2e-performance-benchmark.md と schemas/ci_runtime_delta_v2.schema.json(RunDetail.description)の run_details 文言を、validate_ci_performance_assessment_v2.py::_check_percentile_recomputed_from_raw_samples の正確な predicate(status == "complete" and claim_kind != "none")に厳密同期しました。

従来の「後方互換が残るのは claim.kind == "none" のみ」という過度に強い文言を修正し、predicate の外側(例: status が incomparable_cohort / insufficient_samples / unavailable 等で claim.kind != "none" のまま)では、この percentile-recomputation 要件自体は run_details の省略を拒否しないが、それは他の意味検証・承認ルールが assessment を却下しないことを意味しない旨を明記しました。

schema の key / type / required set は変更していません(RunDetail.description の 1 フィールドのみ)。編集前に _check_percentile_recomputed_from_raw_samples の実装を読み、predicate と文言が完全一致することを確認しています。

検証

  • uv run --locked pytest tests/ci/test_ci_performance_gate_percentile_consistency.py -q → 7 passed
  • uv run --locked pytest tests/ci/test_ci_performance_gate*.py -q → 65 passed, 3 skipped
  • ! rg -n -e 'statistics\.median' -e '^import statistics$' tests/ci/test_ci_performance_gate.py → exit 0
  • uv run --locked pytest .claude/skills/ci-test-performance/scripts/tests/ -q(validator consumer suite)→ 150 passed
  • uv run --locked ruff check tests/ci/test_ci_performance_gate.py tests/ci/test_ci_performance_gate_percentile_consistency.py → All checks passed
  • Issue 実装: e2e performance benchmark の percentile estimator を before/after/provider/gate-ready 全経路で統一する #2180 本文記載の全 Verification Commands → すべて PASS

詳細は更新済みの PR body(Summary / fix_delta セクション / Checks / AC-by-AC)を参照してください。

verdict 判定は別途 pr-reviewer が行います。

@squne121
squne121 marked this pull request as ready for review September 4, 2026 10:24
@squne121
squne121 merged commit 08ea195 into main Sep 4, 2026
40 checks passed
@squne121
squne121 deleted the worktree-issue-2180-percentile-nearest-rank-v1-unify branch September 4, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: e2e performance benchmark の percentile estimator を before/after/provider/gate-ready 全経路で統一する

1 participant