Skip to content

feat(#550): generalize scope collision detection with scope_context - #554

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-550-scope-collision
Jun 1, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-550-scope-collision

Conversation

@squne121

@squne121 squne121 commented Jun 1, 2026 •

Copy link
Copy Markdown
Owner

概要

Closes #550

scope rollup の衝突判定を、語彙一致(security keyword 等)による即時 escalation から、
構造化コンテキスト(scope_context / domain_flags / ordering_constraint)ベースの判定へ汎用化する。
同一スキーマファイルを対象とするが目的・anchor が独立した変更(#547/#549 パターン)が
human_review_required に誤分類される問題を解消する。


Contract transition(旧 security_assessment → scope_context)

本 PR の正本契約は、reframe 後の 現 Issue #550 本文(scope_context / domain_flags / ordering_constraint)である。

Assumption correction(secret_policy 前提の訂正)

  • 現 SECURITY_RE は secret_policy を keyword secret として 検出しない(_ が word
    character のため \bsecret\b 不成立)。実証: secret_policy → []、"secret policy"(空白)→ ['secret']。
  • したがって「secret_policy フィールド名一致が false-positive の直接原因だった」という旧前提は 誤り。
  • 実際の false-positive トリガーは本文中の standalone keyword(secret / permission 等)。
  • この訂正は test_secret_policy_property_name_is_not_detected_as_secret_keyword で回帰固定。

Fixture rationale(テスト設計根拠)


変更内容

  • scope_context(additive): anchor_paths / conflicting_anchors / domain_flags /
    conflict_type / escalation_required
  • domain_flags: security / schema / metadata / workflow / runtime / docs の audit 専用分類
  • ordering_constraint: suggested_action とは別の時間順序フィールド
  • escalation ロジック: keyword 一致 → scope_context.escalation_required == true /
    conflict_type == uncertain のみで停止
  • sub-file anchor 抽出: JSON Pointer 風トークン + バックティック付きプロパティ名の軽量抽出。
    同一ファイルでも anchor disjoint なら escalate しない
  • prefix overlap: prefix_overlap_uncertain を追加し anchor_paths に parent -> child を記録(B4)
  • 既存 ISSUE_SCOPE_ROLLUP_DECISION_V2 フィールドは非削除(additive)

conflict_type 判定

conflict_type 条件 escalation
none パス重複なし false
same_anchor_conflicting_operation 同一ファイル + 共有 sub-file anchor true
same_file_disjoint_anchor 同一ファイルだが anchor disjoint(#547/#549) false
prefix_overlap_uncertain prefix(親子)重複のみ。anchor_paths に記録。共有 anchor で escalate 条件付き
uncertain 完全同一ファイルだが anchor 抽出不能 true(fail-safe)

sub-file anchor 抽出の限界(RFC 6901 非準拠)

軽量テキスト抽出であり厳密な RFC 6901 実装ではない(~0/~1 unescape なし・array index 非対応・構文検証なし)。
precise な AST / tree-sitter anchoring は follow-up。限界は scope-rollup-policy.md に明記。

Acceptance Criteria 検証

AC 内容 結果
AC1 scope_context が出力に含まれる ✅
AC2 domain_flags が出力に含まれる ✅
AC3 ordering_constraint が別フィールド ✅
AC4 property/metadata 名一致だけでは escalate しない ✅ test_scope_rollup_treats_schema_property_keyword_as_metadata_not_domain_specific_risk
AC5 genuine conflict は escalate ✅ test_scope_rollup_escalates_uncertain_or_boundary_affecting_changes
AC6 既存テスト(B4 含む)が pass ✅ 38 passed
AC7 既存フィールド非削除(additive) ✅

検証コマンド結果

uv run pytest .../test_plan_issue_scope_rollup.py -q  → 38 passed
uv run pytest .../gemini-cli-headless-delegation/tests/test_model_routing.py -q  → 21 passed

Out of Scope / follow-up

🤖 Generated with Claude Code

語彙一致による誤エスカレーションを抑止するため、scope rollup の衝突判定を
構造化コンテキスト(scope_context / domain_flags / ordering_constraint)ベースへ汎用化する。

- scope_context を追加(anchor_paths / conflicting_anchors / domain_flags /
  conflict_type / escalation_required)
- domain_flags を audit 専用分類として追加(security/schema/metadata/workflow/
  runtime/docs)— 判定の主因にしない
- ordering_constraint を suggested_action とは別の時間順序フィールドとして追加
- escalation を keyword 一致から scope_context.escalation_required /
  conflict_type==uncertain へ変更
- sub-file anchor(JSON Pointer / バックティック付きプロパティ名)を軽量抽出し、
  同一ファイルでも anchor が disjoint なら escalate しない(#547/#549 パターン)
- 既存 ISSUE_SCOPE_ROLLUP_DECISION_V2 フィールドは非削除(additive 拡張)
- AC4/AC5 回帰テスト追加、scope-rollup-policy.md を更新

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=UNSTABLE(e2e pending のみ。conflict/merge blocker ではない)

Evidence Check

  • AC coverage: ○ 全 AC1-AC7 を firsthand 検証(reviewer が PR head SHA 7aec2e5 で VC 実行)
    • AC1 scope_context / AC2 domain_flags / AC3 ordering_constraint: rg で出力フィールド確認
    • AC4 test_scope_rollup_treats_schema_property_keyword_as_metadata_not_domain_specific_risk: pass。escalation は語彙一致ではなく scope_context.conflict_type == same_file_disjoint_anchor で driven、security_match_evidence は audit 記録のみ(意味的に正しい)
    • AC5 test_scope_rollup_escalates_uncertain_or_boundary_affecting_changes: pass。same_anchor_conflicting_operation(escalation_required==true)と uncertain(fail-safe)の両経路で human_review_required を検証
    • AC6: test_plan_issue_scope_rollup.py 35 passed(B4: test_issue_author_does_not_trigger_security_auth_keyword / test_token_budget_does_not_trigger_security_token_keyword 存在・pass)
    • AC7: suggested_action / security_match_evidence 等の既存フィールド非削除(additive)
  • Allowed Paths: 遵守。diff は 3 ファイルのみ(plan_issue_scope_rollup.py / test_plan_issue_scope_rollup.py / scope-rollup-policy.md)で issue #550 Allowed Paths と完全一致
  • CI Verification: build/lint/test/typecheck/python-test/validate-generated-artifact = pass、e2e = pending
  • 検証コマンド結果(firsthand): scope rollup 35 passed / model_routing 回帰ゲート 21 passed

VC 証跡注記

  • PR に TEST_VERDICT_MACHINE コメントが存在せず、CI python-test job は test_plan_issue_scope_rollup.py を実行していない(CI_CHECK_RUN_SCOPED が対象 VC を被覆しない)。
  • このため PR body self-report 単独では APPROVE 不可だが、reviewer が PR head SHA で VC を firsthand 実行し PASS を直接確認したため、self-report より強い一次証跡として採用。

Schema / Safety Gate

  • Schema: ISSUE_SCOPE_ROLLUP_DECISION_V2 への additive 拡張(新規フィールドのみ、削除/rename なし)。consumer は同一 skill の orchestrator のみで additive により非破壊。schema-governance.md Initial Known Schemas 非該当 → not_schema_change として扱い consumer inventory 不要。
  • Safety: .claude/skills/** パスで safety-sensitive 判定だが、変更は security-keyword 即時停止を緩和する方向で、genuine conflict escalation(AC5)と uncertain fail-safe は保持。無限定の safe/read-only 主張なし → overclaim なし。

Blockers

  • なし

Non-blockers(任意改善)

  • なし(AST / tree-sitter anchor 解決, domain plugin は issue #550 Out of Scope として follow-up 明記済み)

LOOP_VERDICT

verdict: APPROVE
blockers: []
mergeable: MERGEABLE
mergeStateStatus: UNSTABLE
reviewed_head_sha: 7aec2e508f833d394b72614225707ad2ec6c4340
recommendations: []
follow_up_issue_requests: []

@squne121

squne121 commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #554 は方向性としては妥当です。secret_policy という単語だけで止めるのではなく、同一ファイル内の変更対象 anchor を見て scope collision を判定する、という設計は #550 の根本原因に近い。PR本文も scope_context / domain_flags / ordering_constraint を追加し、conflict_type == uncertain や escalation_required == true のときだけ停止する、と説明しています。([GitHub]1)

ただし、このまま approve は危険です。主に Issue契約とのズレ と テストが本来の失敗を固定できていない 点で止めるべきです。

Blocker 1: #550 の公開ACを満たしていない

公開されている Issue #550 は、出力に security_assessment.classification と reason を含めることを明示要求しています。さらに、security_match_evidence が存在するだけで止めず、security_assessment.escalation_required == true または classification == uncertain のときに止める、という契約です。([GitHub]2)

一方、PR #554 は security_assessment を実装せず、scope_context.domain_flags と security_match_evidence を監査用に残す設計へ置き換えています。これは「security特化ではなく普遍的なscope衝突検出へ寄せる」という設計判断としては理解できますが、公開Issue本文のACとは一致していません。PR本文側ではACが scope_context / domain_flags / ordering_constraint に差し替わっています。([GitHub]1)

修正要求: #550 側の契約を更新するか、該当コメントをPR本文の contract snapshot として明示してください。少なくとも「security_assessment は廃止し、scope_context に置換する」が仕様変更として追跡可能でないと、Closes #550 は不正確です。

Blocker 2: 回帰テストが「secret_policy による false positive」を直接固定していない

#550 の実例は、#547 が phase_instance_id の pattern 拡張、#549 が root required に secret_policy を追加するという、同一 schema ファイル内の別anchor変更です。Issueはこのケースで matched term: secret を想定しています。([GitHub]2)

しかし追加テストの fixture は、secret_policy そのものではなく "permission" を security keyword として使っています。テストコメントも「security-adjacent keyword ("permission")」と説明しており、secret_policy が secret として検出される本来の事故を再現していません。([GitHub]3)

修正要求: 実際の #547 / #549 相当の本文を fixture 化し、少なくとも次を assert してください。

candidate: "#549"
security_match_evidence: includes "secret"  # 本当に出る設計なら
scope_context.conflict_type: same_file_disjoint_anchor
scope_context.escalation_required: false
suggested_action: != human_review_required

逆に、現在の SECURITY_RE が Python の word-boundary 前提で secret_policy を secret として拾わない設計なら、#550 の「secret_policy が secret として検出された」という前提自体を再調査し、Issue本文を修正すべきです。PRはこの矛盾を放置しています。

Blocker 3: 「実セキュリティリスクは止める」保証が消えている

#550 は false positive 抑止と同時に、secret value の読み取り・ログ出力、GitHub Actions secrets、auth token、permission/access control などは引き続き human_review_required にする positive test を要求しています。([GitHub]2)

PR #554 の実装は、security keyword を security_match_evidence に残すだけで、停止条件からは外しています。停止条件は scope_context.escalation_required または conflict_type == uncertain に寄っています。([GitHub]4)

追加テストも「secretをログ出力する」「GitHub Actions secretsを扱う」「token/API key/credential validation」「permission/access control」を直接扱っていません。テストされている positive path は、同じ /required anchor を双方が変更する schema conflict と、同一ファイルだが anchor 抽出不能な uncertain case です。これは scope collision の positive test であって、security risk の positive test ではありません。([GitHub]3)

修正要求: 方針を二択で明示してください。

  1. scope rollup は security gate ではない、と明記し、security escalation は別ゲートに委譲する。その場合 実装: scope collision 判定を構造化コンテキストで汎用化し、単語一致による誤エスカレーションを抑止する #550 の security ACを別Issueへ分離。
  2. scope rollup 内で最低限の real-security-risk 判定を維持し、secret logging / Actions secrets / credential / permission の fixture を追加。

現状は「security keywordだけでは止めない」からさらに進んで、「real security risk でも構造衝突でなければ止めない」実装に見えます。

Blocker 4: prefix overlap が scope_context.conflict_type: none になり得る

_build_candidates は prefix overlap を signal として検出しますが、その場合 matched_paths は空のままです。_build_scope_context は matched_paths が空なら即 conflict_type: none / escalation_required: false を返します。([GitHub]4)

つまり、Allowed Paths が .claude/skills/foo と .claude/skills/foo/SKILL.md のように親子関係で重なるケースは、候補検出はされるが scope_context.anchor_paths に構造的重なりが記録されません。これは scope collision の説明責任として弱いです。

修正要求: prefix overlap 時も anchor_paths に正規化した overlap pair を入れるか、conflict_type: prefix_overlap_uncertain のような fail-safe 分類を追加してください。少なくとも none は不正確です。

技術調査ベースの指摘

PRは sub-file anchor を「JSON Pointer(RFC 6901 style)」として扱っていますが、実装は _JSON_POINTER_RE = re.compile(r"(?<![\w])/[A-Za-z_][\w./-]*")の軽量抽出です。RFC 6901 の JSON Pointer は/ で始まる reference token 列で、~は~0、/は~1` としてエスケープされます。また array index も構文上扱われます。([GitHub]4)

軽量抽出を採ること自体は許容できますが、これは厳密な JSON Pointer 実装ではありません。PR本文で AST / tree-sitter は follow-up とされていますが、Tree-sitter は構文木を作り、編集に応じて効率的に更新できるパーサ基盤なので、将来的な正確な anchor 解決の候補としては妥当です。([GitHub]1)

また、#547 の CI-native ID 文脈では、GitHub Actions の GITHUB_RUN_ID は workflow run ごとに一意で rerun では変わらず、GITHUB_RUN_ATTEMPT は rerun ごとに増えます。#547 の ci:<producer_slug>:<run_id>:<run_attempt> 形式はこの意味論に沿っています。([GitHub]5)

Non-blockers

PRの additive 方針は良いです。既存の suggested_action や security_match_evidence を消さず、scope_context と ordering_constraint を追加するため、downstream consumer 破壊の可能性は抑えられています。([GitHub]1)

ただし、PR上の既存レビューコメントは APPROVE で、e2e pending は merge blocker ではないとしていますが、そのレビューは PR head SHA で手元VCを実行した一次証跡を採用しているだけで、上記の contract drift と fixture不足を十分に見ていません。([GitHub]1)

具体的な修正案

  1. 実装: scope collision 判定を構造化コンテキストで汎用化し、単語一致による誤エスカレーションを抑止する #550 の契約を security_assessment から scope_context へ置換するなら、Issue本文またはコメントに明示し、PR本文からリンクする。
  2. 実装: agent_session_manifest schema の phase_instance_id を CI-native 形式(ci:<workflow>:<run_id>:<run_attempt>)に対応させる #547/実装: agent-session-manifest.schema.json の root required に secret_policy を追加する #549 の実本文に近い fixture を追加し、secret_policy / /required / phase_instance_id の disjoint anchor を直接検証する。
  3. real security risk の positive tests を追加するか、scope rollup から security gate を分離する follow-up Issue を作る。
  4. prefix overlap を none にしない。少なくとも anchor_paths に親子パス関係を記録する。
  5. 「JSON Pointer」と呼ぶなら RFC 6901 非準拠範囲を明記する。厳密化は follow-up でよいが、現在の抽出器の限界は policy に残す。

現時点では REQUEST_CHANGES。設計方向は良いが、現PRは「#550を閉じる実装」としては証跡が足りません。

…emise correction, RFC6901 limits

人間レビュー (PR #554 REQUEST_CHANGES) の Blocker 2/4/5 に対応する実装修正。
B1/B3(contract transition / security gate 責務)は PR body と follow-up Issue で扱う。

- B4: prefix overlap(親子パス関係)が conflict_type: none に collapse する問題を修正。
  新分類 prefix_overlap_uncertain を追加し anchor_paths に "parent -> child" を記録。
  共有 anchor があれば escalate、なければ fail-safe で非 escalate(false escalation 抑止)
- B2: secret_policy false-positive 前提の訂正。SECURITY_RE は secret_policy を secret
  として拾わない(_ が word char)ことを単体テストで固定。realistic fixture は
  standalone keyword(secret / permission)を実トリガーとして使用
- B5: sub-file anchor 抽出が RFC 6901 非準拠(~0/~1 unescape なし・array index 非対応)
  である限界を policy に明記。AST/tree-sitter は follow-up
- scope rollup は security gate ではない旨を policy / scope_context docstring に明記

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@squne121

squne121 commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

@squne121 REQUEST_CHANGES ありがとうございます。設計方針(B1/B3)と実装修正(B2/B4/B5)を分けて対応しました(commit 33124c5)。

B1/B3 — 設計方針(contract transition / security gate 責務)

人間指示 issuecomment-4592375157(「security 特化にしない。特定文脈は別エージェントスキルに」)に整合する Option 1 を採用します。

  • B1(contract drift): 「レビュアーの旧フレーミング参照」では片付けません。Issue 本文は再編集せず(reframe 済み契約を再度揺らさないため)、PR body に Contract transition 小節を追加して security_assessment.classification/reason → scope_context/domain_flags/ordering_constraint の置換経緯を reframe コメント参照つきで追跡可能にしました。scope rollup は security gate ではない も明記。
  • B3(security gate 責務): real-security-risk escalation(secret logging / Actions secrets / credential / permission / access-control)は 別 skill の責務として follow-up 設計: scope rollup から security escalation を分離した専用 security-risk gate skill を検討する #558 を起票しました。本 PR では scope rollup から分離します(policy / docstring に明記)。

B2/B4/B5 — 実装修正(レビュー指摘を正として受容)

  • B2(fixture 前提崩れ): ご指摘の通りです。SECURITY_RE は secret_policy を secret として 検出しません(_ が word char)。実証を test_secret_policy_property_name_is_not_detected_as_secret_keyword で固定し、「secret_policy が false-positive の直接原因」前提を 誤りとして訂正。realistic fixture は standalone keyword(secret / permission)を実トリガーとして使用し、実 keyword がマッチしても disjoint anchor なら escalate しないことを検証する test を追加。
  • B4(prefix overlap → none): ご指摘の通り none は不正確でした。新分類 prefix_overlap_uncertain を追加し、anchor_paths に parent -> child ペアを記録。共有 anchor があれば escalate、なければ fail-safe 非 escalate(false escalation 抑止)。test_prefix_overlap_records_anchor_paths_and_is_not_classified_none で固定。
  • B5(RFC 6901 非準拠): 軽量抽出が ~0/~1 unescape・array index 非対応である限界を scope-rollup-policy.md に明文化。precise な AST/tree-sitter anchoring は follow-up。

検証

uv run pytest .../test_plan_issue_scope_rollup.py -q  → 38 passed
uv run pytest .../test_model_routing.py -q             → 21 passed

再レビューをお願いします。

@squne121
squne121 marked this pull request as ready for review June 1, 2026 13:43
@squne121
squne121 merged commit 0714d8b into main Jun 1, 2026
7 checks passed
@squne121
squne121 deleted the worktree-issue-550-scope-collision branch June 1, 2026 13:43
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.

実装: scope collision 判定を構造化コンテキストで汎用化し、単語一致による誤エスカレーションを抑止する

1 participant