Skip to content

fix: trusted owner anchor section spans - #2583

Merged
squne121 merged 9 commits into
mainfrom
worktree-issue-2582-trusted-anchor-section-source-span
Sep 9, 2026
Merged

squne121 merged 9 commits into
mainfrom
worktree-issue-2582-trusted-anchor-section-source-span

Conversation

@squne121

@squne121 squne121 commented Sep 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #2582 の Step 1 を更新します。structural_repair_action.apply は、OWNER anchor を使う item だけについて、実際の transaction dispatch の直前に source comment を再取得し、comment identity、対象 Issue、OWNER association、source revision を再検証します。取得不能・削除・revision 不一致は既存の fail-closed not_attempted 経路へ進み、transaction を呼びません。

owner-anchor の source candidate は、fence-aware な既存 section parser の境界計算を維持しつつ、列 0 の完全一致 ## Quality Decision Record、## Child Issues、## Remaining Parent Gaps のみを採用します。新しい schema、key、enum、registry、command profile は追加していません。

Checks

  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py -q(23 passed、anchor wiring 回帰は成功)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py -q(27 passed、consumer 回帰は成功)
  • 上記 2 suite の combined rerun(50 passed)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py -q(44 passed、anchor preflight 回帰は成功)
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py -q(39 passed、command policy guard は成功)
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py -q(17 passed、runtime exec guard は成功)
  • pnpm typecheck、pnpm lint、pnpm test(108 files / 1939 tests)、pnpm build(repository baseline は成功)
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(24 passed、model routing 回帰は成功)

受け入れ条件の達成状況

  • AC1: trusted OWNER anchor の三つの canonical section を owner_anchor / source_span_exact として組み立てる。
  • AC2: structural repair 後の fresh preflight が既存の修復完了判定を維持する。
  • AC3: stale source、fetch failure、identity・target・OWNER・revision 不一致は transaction 前に fail-closed となる。prose、YAML fence、fenced Markdown、list/container の偽 heading は source に採用しない。
  • AC4: current-issue same-body source span の既存回帰を保持する。
  • AC5: command registry と execution profile を変更しない。

Allowed Paths 遵守

git diff --name-only origin/main...HEAD で確認した実変更は、Issue #2582 の Allowed Paths 内の次の 4 ファイルだけです。

.claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
.claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py
.claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py

Runtime Verification Applicability

  • decision: not_applicable
  • reason: deterministic Python control-plane logic と fixture regression の変更だけであり、browser または external runtime behavior は変更しません。

Schema Change Applicability

  • decision: not_schema_change
  • reason: versioned schema、固定 key set、enum、型定義、command registry profile は変更していません。

Schema Consumer Inventory

N/A。schema change ではないため consumer inventory の更新は不要です。

Safety Claim Matrix

この表は実装済みの安全性境界、今回の変更だけでは制御できない事項、および継続確認の方法を明示します。各行の Follow-up は related Issue #2582 に紐付け、未制御事項を成功扱いにはしません。

Claim Implemented? Not controlled Evidence Follow-up
OWNER source の stale / deleted / mismatched comment を mutation 前に拒否する yes GitHub transport 自体の可用性 consumer regression 27 passed #2582: transport failure は fresh preflight を再実行する
同一 comment を共有する三 item の再取得を一回に束ねる yes 同時に行われる外部編集 consumer regression 27 passed #2582: concurrent edit 後は fresh preflight を再生成する
canonical source heading を列 0 の完全一致 H2 に限定する yes human が指定する section の意味判断 wiring regression 23 passed #2582: 意味判断が必要なら human review を要求する
schema、registry、command profile を変更しない yes 既存外部 consumer の運用状態 focused guard tests 39 + 17 passed #2582: existing CI と independent review で継続確認する

Notes

Bind exact parent-template sections from the explicit OWNER human-context lane to the existing structural repair provenance model.

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

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2583 closed).

@squne121
squne121 marked this pull request as ready for review September 8, 2026 13:48
Test and others added 3 commits September 8, 2026 22:55
Resolve Ruff E501 in the parent-contract fixture without changing behavior.

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

squne121 commented Sep 9, 2026

Copy link
Copy Markdown
Owner Author

結論

REQUEST_CHANGES を推奨します。
PR #2583 の基本設計は妥当です。Issue #2582 の scope に沿って既存の owner_anchor / source_span_exact を再利用し、変更も3ファイルに限定されています。PR #2469 で問題になった line-range の byte-exact reconstruction や generic producer boundary での provenance 再検証も踏襲できています。

ただし、P1が1件あります。これはマージ前に直した方がいいです。 加えて、低コストで潰せるP2/P3があります。

1. P1 — OWNER comment を preflight 後に編集すると、古い human decision を適用できる

今回のPRは「duplicate / empty / stale / wrong source は human_review_required に fail-closed」と明示しています。

producer 側では確かに、

  • comment ID / URL
  • target Issue / repo
  • OWNER
  • comment body digest
  • source_revision
  • source line range / exact text

までかなり丁寧に束縛されています。

しかし、structural_repair_action.apply の mutation 前 validation は fresh な target Issue body だけを再取得しています。structural consumer の interface も fetch_current / apply_transaction / fresh_validate で、OWNER source comment を fresh read する入口がありません。 target 側については _fetch_issue(repo, issue_number) を再実行しています。 また fresh validation も structural detector を現在の Issue body に対して再実行するものです。

したがって次が成立します。

  1. preflight が OWNER comment revision A を読み、candidate A を作る。
  2. 人間が同じ comment を revision B に編集する。
  3. target Issue body 自体は変わっていない。
  4. structural_repair_action.apply を実行する。
  5. candidate digest と target insertion anchor はまだ一致するので、revision A の古い内容が適用され得る。

source_revision は producer artifact 内では正しく作られていますが、structural apply が live comment と照合していないため、「artifact が自己矛盾していない」ことしか保証していません。

これはセキュリティ強化ではなく、最新の人間判断を mutation authority とするための correctness です。しかも GitHub REST API は comment ID から raw body・updated_at・issue_url・author_association を直接再取得できます。([GitHub Docs]1)

推奨修正は小さくて済みます。owner_anchor item が存在するときだけ、mutation直前に unique source_object_id ごとに 1回だけ _fetch_single_comment() し、少なくとも live body SHA が source_revision と一致することを確認してください。3 section が同じ comment 由来ならネットワークアクセスは1 GETだけです。新しい authority、schema、command profile、ハーネスは不要です。

回帰テストも「preflight後にsource commentを編集 → mutation not_attempted」「同一revision → 従来通りapply」の2本程度で十分です。

2. P2 — _parse_h2_sections() は「top-level H2」と言っているが、GFM container を理解していない

共通 _parse_h2_sections() は fence-aware なのは良いのですが、実装上は fenced code block しか状態管理せず、0〜3 spaces の ## をそのまま section heading と認識します。

GitHub Flavored Markdown では list item / block quote は container block であり、list item 内にも heading を置けます。公式GFM specでもその構造が明示されています。また通常のATX heading自体は0〜3 spaces indentationが許容されます。([GitHub Pages]2)

例えば、

- 説明
  ## Child Issues
ここから通常本文

では ## Child Issues はGFM上 list item 内の heading になり得ますが、現在の custom parser は top-level Child Issues として拾い、その後の通常本文を section content と解釈できます。

今回の用途は「canonical parent section を exact copy」なので、フルCommonMark parserを導入するのは過剰です。OWNER-anchor lane に限って source heading を column 0 の ## Quality Decision Record 等に限定するのが最小かつ堅いです。これなら依存追加もありません。

3. P3 — 実データ形状の regression fixture を1本追加したい

実際の #2572 OWNER decision comment #5584982649 は、単純な3 section commentではありません。長い説明、YAML fence、さらに canonical section のサンプルを含む fenced Markdown があり、その後に実際の ## Quality Decision Record / ## Child Issues / ## Remaining Parent Gaps が続きます。

現在追加された positive fixture は3つのH2だけのかなり単純化された形なので、PR本文の「#2572 shape」という表現より弱いです。

これはマージブロッカーにはしませんが、custom Markdown scannerを使い続けるなら、

prose → YAML fence → fenced Markdown内の偽 ## Child Issues → 実canonical H2

という #5584982649 相当 fixture を1本置く価値があります。特に上の container-block negative test とセットなら十分です。新しい巨大fixture/harnessは不要です。

それ以外の評価

owner_anchor_snapshot と span を repair_issue_contract.py 側でも再照合する構成、_section_line_bounds() の再利用、複数source候補を優先順位で選ばず conflict にする設計は良いです。親テンプレートでも今回の3フィールドは実際に required です。

また、#2431 / PR #2469 では source が same target Issue body だったため、structural consumer の既存 fresh target-body read が source freshness の確認も兼ねられました。今回初めて source が外部 Issue comment になったので、P1はその設計を拡張したことで新しく生じた境界です。この1点を埋めれば、設計の一貫性はかなり高くなります。

推奨マージ条件

修正必須は P1だけ と考えます。P2は小さいので同じfix deltaで潰すことを推奨、P3はできれば追加、という優先順位です。セキュリティ機構や新しいvalidation frameworkを増やす必要はありません。

なお、最新readbackでは head 05b11d8b... の GitHub Actions ci run #6707 はまだ in_progress です。 取得時点では主要jobはgreenで、python-test-core のserial laneが残っていました。CIとは別に、上記P1を理由に現状は REQUEST_CHANGES が適切です。

@squne121

squne121 commented Sep 9, 2026

Copy link
Copy Markdown
Owner Author

推奨は、PR #2583 を作り直さず、Issue #2582 の既存 impl-review-loop を対象コメントを fix_delta として再開し、P1/P2/P3を同じPRで処理することです。

対象コメントの優先順位は妥当です。P1は必須、P2は同じ修正で処理、P3も回帰コストが小さいため今回入れるのを推奨します。特にP1の修正対象となる run_refinement_preflight.py と consumer regression test は Issue #2582 の Allowed Paths に含まれるため、現時点ではscope拡張を必要としません。

一点、対象コメント末尾のCI情報はすでに古くなっています。HEADは引き続き 05b11d8b… ですが、ci run #6707 は completed / failure になっています。PR自体は open / mergeable のままです。 私が確認したjob内訳では通常の test / python-test / build / lint / typecheck 等は成功し、aggregate の ci-verdict-summary が overall_status='gh_error' で落ちています。したがって、コード修正後はfresh current-head CIを再取得し、この失敗もmerge前条件として処理させるべきです。

また、PR本文は現在「変更3ファイル」と記載していますが、P1のconsumer regressionを正しいテストファイルへ追加すれば変更ファイルが増える可能性があります。実際の最終diffに合わせてPR本文のAllowed Paths・Checks・AC evidenceも更新させます。現在の3ファイルはいずれもIssueのAllowed Paths内です。

そのまま既存の auto mode Claude Code に渡すなら、以下を推奨します。

PR #2583 / Issue #2582 の既存実装を対象に、.claude/skills/impl-review-loop を使って fix → verification → independent PR review のループを再開してください。

対象:

ゴールは PR #2583 を現在のIssue contractを満たす merge-ready 状態まで持っていき、実際の merge の直前で停止すること です。

人間への途中承認は不要です。
実装、テスト追加・修正、commit、push、CI確認、レビュー指摘対応、再レビューは自律的に継続してください。
PRのmergeだけは実行しないでください。

今回参照している #issuecomment-5602027646 の REQUEST_CHANGES は、ここで停止する命令ではありません。
このプロンプトがその指摘を修正してループを継続する明示的な現在の人間指示です。
コメント本文を authoritative fix_delta として処理してください。

0. canonical skill / live stateを最初に確認

最初に以下を読んでください。

過去の audit comment、artifact、古いHEAD、古いCI結果をauthorizationとして扱わないでください。

fresh live stateから、既存worktree / branch / PRを再利用できることを確認してください。
新規PRを作り直さないでください。

current-runの impl-review-loop が root-owned synchronous entry transition を要求する場合は、SKILL.mdの現行契約どおりその場で実行してください。
過去の root-owned entry router audit commentを再利用可能なauthorization packetとして扱わないでください。

1. SubAgent運用

impl-review-loop のオーケストレーターとして、実作業をSubAgentへ委譲してください。

最低限:

  1. implementation-worker
  2. independent test-runner / verification
  3. independent pr-reviewer

を使用してください。

必要なら実装前にread-only investigator SubAgentを使ってP1/P2/P3の根因と最小修正点を調査して構いません。

重要:

  • root/main Claude Codeがオーケストレーターであり続けること。
  • SubAgent自身にnested SubAgentを起動させないこと。
  • 各SubAgentを起動したら、必ずその作業完了を待って結果を回収すること。
  • SubAgentがまだ動作中なのに次Stepへ進んだり、最終回答を返したりしないこと。
  • 複数SubAgentを並列起動した場合も全員の完了を待つこと。
  • SubAgentの自己申告だけをmerge readinessの証拠にせず、rootがlive HEAD / tests / CI / PR stateを再取得すること。

2. 今回のfix_delta

#issuecomment-5602027646 を全文読んだうえで、最低限以下を解消してください。

P1 — 必須: owner_anchor source comment のfreshnessをmutation直前に再検証

現在の実装はpreflight時点では owner_anchor の:

  • repo
  • target Issue
  • comment id / URL
  • OWNER association
  • body digest / source_revision
  • heading
  • line range
  • exact text

をかなり厳密に束縛しています。

しかし structural_repair_action.apply のmutation前preconditionは主にtarget Issueのfresh bodyを再取得しており、外部sourceであるOWNER commentのlive revisionを再確認していません。

したがって、

preflight revision A
→ OWNERが同じcommentをrevision Bへ編集
→ target Issue bodyは不変
→ apply
→ revision Aの古いhuman decisionをmutation

というstale-source適用を防いでください。

最小修正を優先してください。

推奨方向:

  • structural_repair_action.apply が owner_anchor provenanceを含むitemをconsumeするときだけ追加検証する。
  • unique source_object_id 単位でfresh comment readを行う。
  • 同一comment由来の3 sectionならGitHub readは原則1回にdedupeする。
  • 既存 _fetch_single_comment() 等のread primitiveを再利用できるか最初に確認する。
  • fresh responseについて少なくともlive body SHAがartifactの source_revision と一致することを検証する。
  • 可能なら同じfresh readでcomment identity、target Issue binding、author_association == OWNER も再確認する。
  • source commentのfetch failure / deletion / revision mismatchでは mutationを一切dispatchしない。
  • 既存の not_attempted / fail-closed contractを使う。
  • 新しいauthority、persistent state、ledger、daemon、approval frameworkは作らない。
  • command registry/profileを増やさない。
  • versioned schemaや固定key setを変更しない。

新しいschema enum等がどうしても必要になると判明した場合は、Issue #2582 のStop Conditionsに従い勝手にscopeを広げず停止理由を明示してください。
ただし、まず既存result contractで表現できないか十分確認してください。

最低限 regression:

  1. preflight artifact作成後にowner source commentのbodyが変更されたケース

    • mutationは not_attempted
    • apply_transaction は呼ばれない
  2. source commentがartifactと同一revisionのケース

    • 従来どおりapply可能

3 sectionが同じcomment由来の場合、fresh source fetchが1回にdedupeされることも可能なら検証してください。

P1のconsumer regressionは、責務上適切なら
.claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py
へ追加してください。
これはIssue #2582のAllowed Paths内です。

P2 — 今回一緒に修正: OWNER-anchor laneではcanonical H2をcolumn 0に限定

generic _parse_h2_sections() をCommonMark/GFM完全parserへ作り替えないでください。

今回必要なのは owner_anchor laneのcanonical required sectionだけです。

例えば:

- 説明
  ## Child Issues
偽の内容

のようなlist container内部のheadingをtop-level canonical sourceとして採用しないようにしてください。

最小方針は、OWNER-anchorの3 headingについてraw source heading lineを確認し、

## Quality Decision Record
## Child Issues
## Remaining Parent Gaps

がcolumn 0から始まるcanonical headingである場合だけsource candidateにすることです。

shared Markdown parser全体の意味論を広げたり、CommonMark parser依存を追加したりしないでください。

positive regressionとcontainer-block negative regressionを追加してください。

P3 — 今回追加推奨: #5584982649相当の実データ形状 regression

以下のactual human anchorを確認してください。

#2572 (comment)

単純な「3 H2だけ」のfixtureだけではなく、少なくとも次のshapeを含むrepresentative regressionを1本追加してください。

  • 通常prose

  • YAML fenced block

  • fenced Markdown等の内部に偽の ## Child Issues 等

  • fence終了後の実canonical

    • ## Quality Decision Record
    • ## Child Issues
    • ## Remaining Parent Gaps

巨大な全文fixtureを複製する必要はありません。
今回壊れ得る構造を保持した最小representative fixtureにしてください。

3. Allowed Paths

Issue #2582 のlive bodyに書かれている Allowed Paths を正本にしてください。

現行contractでは少なくとも以下が許可されています。

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
  • .claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py
  • .claude/skills/issue-refinement-loop/tests/test_structural_repair_action_apply_consumer.py
  • .claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py
  • scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py

live Issueを再取得して変更がないことを確認してください。

Allowed Paths外のproduction changeが本当に必要になった場合はIssueのStop Conditionsに従って停止してください。
テストを雑に既存3 changed filesへ押し込めてAllowed Paths数を維持する必要はありません。
責務に合う許可済みtest fileを使ってください。

4. Verification

Issue #2582 のVerification Commandsを正本としてfocused testを実行してください。

少なくとも:

  • trusted anchor producer / provenance regressions
  • preflight-with-anchor regressions
  • structural_repair_action.apply consumer regressions
  • command-policy guard
  • runtime-exec guard

を実行してください。

さらにrepository baseline:

  • pnpm typecheck
  • pnpm lint
  • pnpm test
  • pnpm build
  • model-routing regression

もIssue contractどおり実行してください。

変更範囲に応じて必要な追加focused testを選択してください。

implementation-worker自身の「PASS」だけで終了せず、独立test-runner SubAgentにcurrent HEADを検証させ、その完了を待ってください。

5. PR本文をcurrent truthへ同期

現在のPR本文には過去のchanged-file count / test counts / checksが記載されています。

fix後に必ずcurrent diffを再取得し、

  • Summary
  • Checks
  • Acceptance Criteria
  • Allowed Paths
  • Runtime Verification Applicability
  • Schema Change Applicability
  • Safety Claim Matrix

の記述がcurrent HEADと一致しているか確認してください。

変更ファイルが3→4/5等へ増えた場合は、PR本文を実態に合わせて更新してください。
「3ファイルのまま」に見せるためにテスト配置を歪めないでください。

Closes #2582 は維持してください。

6. CI

current HEADに対するfresh GitHub Actionsを確認してください。

旧head / 旧runのgreen evidenceを再利用しないでください。

現在確認されているrun #6707はworkflow-levelではfailureなので、fix push後のcurrent HEADについてrequired CIをfreshに評価してください。

CI failureが発生した場合:

  1. failing job / step / logsを読む
  2. implementation起因か、environment / evaluator起因かを切り分ける
  3. implementation起因なら修正してloop継続
  4. transient/environmentalならbounded rerunしてcurrent-head resultを再取得
  5. unrelated workflow/harness改造へscopeを広げない

特にaggregate evaluatorだけが失敗し、そのunderlying required jobsがgreenの場合も、merge-readyと勝手に宣言せず、現行 impl-review-loop のCI / mergeability routingに従ってください。

7. Independent PR review

修正・verification・push完了後、current HEADに対してfreshな pr-reviewer SubAgentを起動してください。

必ずSubAgent完了を待ってください。

reviewerには:

を確認させてください。

review verdictが REQUEST_CHANGES の場合は、blockersを次iterationのfix_deltaとしてimplementation-workerへ渡して自律修正してください。

reviewed_head_shaがstaleなら、人間へ聞かずcurrent HEADでre-reviewしてください。

通常の REQUEST_CHANGES やテスト失敗で途中終了しないでください。
impl-review-loop のiteration budget内で修正→検証→reviewを継続してください。

8. 停止条件

人間判断なしで進めてよい範囲はmerge直前までです。

以下では停止してください。

逆に、以下だけを理由に途中で人間承認を求めないでください。

  • 通常のcode change
  • test追加
  • commit / normal push
  • PR本文更新
  • reviewerの通常REQUEST_CHANGESへの対応
  • current-head再レビュー
  • bounded CI rerun
  • stale reviewの再取得
  • ordinary mergeability/CI再評価

force push、history rewrite、secret操作、破壊的操作はしないでください。

9. 完了条件

以下をすべてlive readbackで確認した状態まで進めてください。

ここまで到達したら mergeは実行せず停止 してください。

最終報告には最低限:

  • current PR HEAD SHA
  • 修正したP1/P2/P3
  • changed files
  • focused tests結果
  • baseline結果
  • CI結果
  • independent review verdict / reviewed_head_sha
  • live mergeability
  • unresolved blockers
  • READY_FOR_HUMAN_MERGE: yes | no
  • STOP_REASON

を出してください。

READY_FOR_HUMAN_MERGE: yes の場合も gh pr merge 等は実行しないでください。

この形なら、既存の impl-review-loop の「実装→独立検証→fresh review」という責務を保ちつつ、今回のトップレベルコメントを明確なfix_deltaとして処理できます。Issue #2582では既に既存worktree/PRで実装済みという記録もあるため、同じPRを継続するのが自然です。

squne121 and others added 4 commits September 9, 2026 21:58
Re-fetch OWNER anchor comments immediately before structural repair dispatch and require source provenance to remain current. Restrict owner-anchor canonical section candidates to exact column-zero H2 headings.

Co-Authored-By: Claude Code <[email protected]>
Reject manually forged owner-anchor source spans whose trusted snapshot uses an indented H2, before source_span_exact can be auto-applied.

Co-Authored-By: Claude Code <[email protected]>
@squne121
squne121 merged commit 4f9c5a9 into main Sep 9, 2026
28 checks passed
@squne121
squne121 deleted the worktree-issue-2582-trusted-anchor-section-source-span branch September 9, 2026 14:18
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.

実装: issue-refinement-loop structural repair が trusted human-context anchor の section source_span を consume できるようにする

1 participant