Skip to content

feat: structural repair actionをcontrolled consumerへ接続する - #2400

Merged
squne121 merged 2 commits into
mainfrom
worktree-issue-2396-structural-repair-consumer
Aug 29, 2026
Merged

squne121 merged 2 commits into
mainfrom
worktree-issue-2396-structural-repair-consumer

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

template-derived structural_repair_action/v1(Issue #995 の mutation-free producer)の auto_apply_safe bundle を、既存の edit_issue_txn.py controlled transaction core(Issue #2039 / PR #2202 が確立したパターン)へ接続する。command_registry.py に structural_repair_action.apply を新規登録し、run_refinement_preflight.py に per-item digest 再検証・行シフト安全な body 合成・共有 mutation dispatch core・fresh validation を備えた新規 consumer 関数 run_structural_repair_action_apply() を追加した。あわせて severity arbitration に限定条件付きの deadlock override を追加し、全件 auto_apply_safe かつ過不足なく missing_required_section を coverage する structural candidate が structural_repair_action_deferred によって永続的に抑制される #2180 実インシデントの blocked precedence deadlock を解消した。

Checks

  • pnpm typecheck: PASS(TypeScript エラーなし。本 PR は Python 専用スキルコード変更のため影響なし)
  • pnpm lint: PASS(ESLint: No issues found)
  • pnpm test: PASS(Test Files 112 passed / Tests 1887 passed)
  • pnpm build: PASS(vite build 成功)
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: PASS(24 passed)
  • git diff --check: PASS(whitespace エラーなし)

Schema Change Applicability

  • decision: not_schema_change
  • refinement_preflight_result_v1.schema.json の structural_repair_action / repair_action フィールド定義は一切変更していない(Out of Scope)。既存フィールド定義をそのまま再利用し、run_structural_repair_action_apply() の戻り値(structural_repair_apply_result/v1)は preflight result schema の一部ではない、この consumer 独自の stdout 形状(Allowed Paths が schemas/ を含まないため新規 schema ファイルも追加していない)。

Schema Consumer Inventory

schema 変更を伴わないため(not_schema_change)、consumer inventory の詳細記入は対象外。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
GitHub Issue body への mutation は 1 回のみ(single mutation) yes - test_consumer_reuses_edit_issue_txn_core / test_multi_item_synthesis_reverifies_digests_before_dispatch(dispatch 呼び出し回数 1 を assert) -
mutation 前に stale guard(whole-body sha 比較 + per-item digest 再検証)を通す yes - test_whole_body_drift_without_replay_rejected / test_stale_anchor_heading_removed_from_live_body_rejected / test_tampered_candidate_section_digest_rejected -
mutation 後に authoritative readback を実施する yes - test_consumer_reuses_edit_issue_txn_core の _repair_receipt_from_txn_result 経由 readback 呼び出し(generic lane と共有) -
unknown outcome を blind retry しない(post_dispatch_retry_budget は常に 0) yes - test_receipt_projection_matches_generic_lane_semantics(mutation_outcome_unknown でも dispatch 呼び出しは 1 回のまま) -
GitHub mutation は raw gh issue edit を経由しない(edit_issue_txn.py --input-file のみ) yes - _dispatch_candidate_body_via_edit_txn() の実装(generic lane から抽出した共有コア。新規 subprocess 呼び出しを追加していない) -
冪等リプレイ(同一 bundle の再適用)は GitHub mutation を発生させず no_change に解決する yes - test_replay_against_already_applied_body_is_idempotent_no_change -

Notes

AC 別ステータス

  • AC1: PASS — structural_repair_action.apply の execution_class は exact_structural_repair_action_apply で repair_action.apply(exact_repair_action_apply)と別値。
  • AC2: PASS — 全件 auto_apply_safe かつ missing_required_section を過不足なく coverage する structural candidate に対し、severity arbitration が structural_repair_action_deferred を追加せず needs_fix / apply_deterministic_structural_repair を採用する。
  • AC3: PASS — (a) ambiguous insertion を含む、(b) coverage 不完全、(c) 無関係な blocker namespace が同時存在、のいずれでも従来どおり deferred を維持する回帰を確認。
  • AC4: PASS — argv は固定 list、issue_number / repo / preflight_result_path のプレースホルダー命名は repair_action.apply と同一。
  • AC5: PASS — mutation dispatch は generic lane の run_repair_action_apply() から抽出した共有ヘルパー _dispatch_candidate_body_via_edit_txn() / _dispatch_candidate_body_default_transaction() を両 lane が呼び出す。2 件以上の同時 auto_apply_safe item を行シフトを考慮した順序で単一 body へ合成し、合成前に各 item の digest を再検証する。
  • AC6: PASS — 2 件以上の同時 auto_apply_safe item を含む fixture に適用後、fresh な structural 検出(build_structural_repair_bundle() 再実行)で対象 blocker が解消し、合成後 body が意図した内容と byte-exact に一致することを確認。
  • AC7: PASS — 既存 9 ファイル(test_repair_action_apply_consumer.py 等)が全件変更なく PASS(137 passed)。

Verification Commands(実行結果)

$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py -k test_command_registry_entry_distinct_execution_class -v
# => 1 passed
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_deadlock_arbitration.py -k test_full_coverage_auto_apply_safe_not_deferred -v
# => 1 passed
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_deadlock_arbitration.py -k "test_ambiguous_item_still_deferred or test_incomplete_coverage_still_deferred or test_unrelated_blocker_still_deferred" -v
# => 3 passed
$ rg -n "structural_repair_action.apply" .claude/skills/issue-refinement-loop/scripts/command_registry.py
# => 638, 647, 648, 658 (execution_class: exact_structural_repair_action_apply)
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py -k test_consumer_reuses_edit_issue_txn_core -v
# => 1 passed
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py -k test_fresh_preflight_after_apply_clears_blocker -v
# => 1 passed
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_repair_action_apply_consumer.py .claude/skills/issue-refinement-loop/tests/test_repair_action_apply_stale_guard.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_dual_intent.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_fresh_validation.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_production_provenance.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_provenance.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_result_schema.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_secure_open.py .claude/skills/issue-refinement-loop/tests/test_repair_apply_unknown_outcome.py -v
# => 137 passed
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q
# => 1829 passed, 4 failed(下記「既知の pre-existing 失敗」参照。origin/main の clean checkout でも同一 3 件が再現する uv バージョンピン不一致、および 1 件の flaky な live smoke。いずれも本 PR の変更とは無関係)

既知の pre-existing 失敗(本 PR の変更と無関係)

  • test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch の 3 件: skill_runtime_exec.py 内の uv_version_mismatch によるサンドボックス環境依存の失敗。origin/main の clean worktree checkout で同一 3 件を再実行し、同じ失敗が再現することを確認済み(本 PR の変更前から存在)。
  • test_codebase_investigator_agy_fallback_smoke.py::test_live_smoke_consumer_agy_timeout_native_fallback_when_allowed: 単独実行では PASS(flaky な live smoke、タイミング依存)。

Scope Delta

N/A(Allowed Paths の 4 ファイルのみ変更。追加のスコープ拡張なし)。

関連 Issue(参照のみ、closing keyword は使用しない)

実装ノート

  • command_registry.py: structural_repair_action.apply エントリを新規登録(execution_class: exact_structural_repair_action_apply、argv は固定 list)。
  • run_refinement_preflight.py:
    • run_repair_action_apply() 内の transaction dispatch ロジックを _dispatch_candidate_body_via_edit_txn() / _dispatch_candidate_body_default_transaction() として top-level 抽出し、両 lane が同一コアを再利用する形に整理(既存 9 テストは無改変で PASS)。
    • run_structural_repair_action_apply() を新規追加。artifact 読込 → disposition/insertion 検証 → live body に対する stale guard(whole-body sha 比較 + AC10 類似の idempotent replay 検出)→ per-item digest 再検証 → 行シフト安全な body 合成 → 共有 dispatch core 呼び出し → fresh validation、という流れ。
    • severity arbitration(既存の structural_repair_action_deferred ブロック)に _structural_deadlock_override_eligible() を追加。全 item が auto_apply_safe かつ insertion.disposition != "ambiguous"、かつ required_sections/required_contract_keys の union と bundle の coverage が完全一致し、かつ blockers が missing_required_section[:*] / structural_repair_action_deferred:* / PLANNER_FAIL_CLOSED(実装: e2e performance benchmark の percentile estimator を before/after/provider/gate-ready 全経路で統一する #2180 実インシデントで同時発生することが確認済みの companion marker)のみで構成される場合に限り、deferred を発生させず needs_fix / apply_deterministic_structural_repair を採用し、該当 blocker を clear する。
  • 新規テスト 2 ファイル(test_structural_repair_action_apply_consumer.py 15 件、test_structural_repair_deadlock_arbitration.py 8 件)を追加。producer 由来の production-shaped fixture(build_structural_repair_bundle() を実際に呼び出す)を優先し、手書き digest は使用していない。

本 Issue を解決するための実装 PR である。
Closes #2396

template-derived structural_repair_action/v1 の auto_apply_safe bundle を
既存 edit_issue_txn.py controlled transaction core へ接続し、修復可能な
missing_required_section が severity precedence によって永続的に
deferred される blocked precedence deadlock(#2180 の実インシデント)を
解消する。

- command_registry.py に structural_repair_action.apply エントリを追加
  (execution_class は repair_action.apply と別値)
- run_refinement_preflight.py に run_structural_repair_action_apply() を
  追加。per-item digest 再検証 → 行シフト安全な合成 → 既存 GitHub
  mutation dispatch core(_dispatch_candidate_body_via_edit_txn /
  _dispatch_candidate_body_default_transaction、run_repair_action_apply()
  から抽出した共有ヘルパー)経由で single mutation・stale guard・
  authoritative readback・fresh validation まで実行
- severity arbitration に _structural_deadlock_override_eligible() を
  追加し、全件 auto_apply_safe かつ過不足なく missing_required_section
  を coverage する場合のみ structural_repair_action_deferred を出さず
  needs_fix/apply_deterministic_structural_repair を採用

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

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2400 closed).

@squne121
squne121 marked this pull request as ready for review August 29, 2026 11:59
@squne121
squne121 merged commit 12806d8 into main Aug 29, 2026
42 checks passed
@squne121
squne121 deleted the worktree-issue-2396-structural-repair-consumer branch August 29, 2026 12:08
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.

実装: template-derived structural_repair_action を controlled consumer へ接続し、blocked precedence deadlock を解消する

1 participant