Skip to content

fix: trusted OWNER directive を contract update へ正規化 - #2026

Merged
squne121 merged 22 commits into
mainfrom
worktree-issue-1951-trusted-directive
Aug 8, 2026
Merged

squne121 merged 22 commits into
mainfrom
worktree-issue-1951-trusted-directive

Conversation

@squne121

@squne121 squne121 commented Aug 8, 2026 •

Copy link
Copy Markdown
Owner

Summary(概要)

信頼済みの人間ディレクティブを、既存のスコープ差分権限と契約更新レーンへ正規化します。古い snapshot が A→B→A の本文循環によって権限を回復しないようにします。後続更新では、六つの判定ゲートと経路選択を補強し、危険な混在 Allowed Paths を fail-closed にしました。

Closes #1951。PR #2036 を current base に取り込んだ状態で、同じ Issue を分割せずに完了させる実装です。

Current Binding(現在の束縛)

reviewed_head_sha: 3ccba2127fa182484107cc930faf4c61abd441e7
base_sha: 04a79898af4ebe7c75a3e0389b361e444a38bd26
issue_1951:
  updated_at: 2026-08-08T12:27:27Z
  body_sha256: sha256:da76fd9992eef7f5be49a106f4f5220b5f178001681160e5ea4459cf21fcdde0
main_merge: PR #2036

受け入れ条件の達成状況

  • AC1: anchor payload のない信頼済み OWNER directive を source URL/comment/hash/evidence span とともに contract_update_required へ正規化する。
  • AC2: 役割分離と Issue 分割を分け、同一 Issue / 一つの PR 指示では requires_issue_split=false とする。
  • AC3: exact・必要・非破壊・secret/paid/unrelated widening なしの permission delta は、実装前の契約更新に限定する。
  • AC4: generated OWNER handoff を権限源から除外し、explicit origin lane を区別する。
  • AC5: untrusted/ambiguous/conflicting/destructive/secret/paid/technically unavailable 要求を fail-closed とする。
  • AC6: body/hash/updatedAt binding と公開直前の再読により、stale source / A→B→A を拒否する。
  • AC7: fresh rerun と validator 前には implementation route を許可しない。
  • AC8: presentation style と author_association=OWNER 単独で authorization を変えない。

検証コマンド結果

以下はすべて current head 3ccba2127fa182484107cc930faf4c61abd441e7 に束縛した結果です。

  • 修正: issue-refinement-loop で trusted OWNER directive を重複承認なしに contract update へ正規化する #1951 の Acceptance Criteria Verification Commands: 102 passed。
  • 実運用形状の origin + anchor consumer chain: 126 passed。
  • trusted-directive regression suite: 23 passed。
  • Ruff、py_compile、git diff --check: PASS。
  • GitHub Actions run 31258161749: terminal success。
  • artifact ci-verdict-summary-v2-31258161749-1: head 一致、overall_status: merge_ready。
  • 同一 head で受け入れ条件、実運用経路、信頼済み指示、静的検査、継続的統合を独立に確認した。

これらは同一 head で再実行し、受け入れ条件、実運用経路、信頼済み指示、静的検査、継続的統合をそれぞれ独立に確認した結果です。

Runtime Verification Evidence(実行時検証証跡)

fixture-only の結果を runtime PASS に昇格していません。実運用形状の origin + anchor chain により、explicit source lane、anchor binding、preflight/contract-update routing、fail-closed の終端判断を current head で検証しました(126 passed)。

Allowed Paths 遵守

current remote diff の 14 paths は、#1951 の current Allowed Paths にすべて含まれます。

.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
.claude/skills/issue-refinement-loop/SKILL.md
.claude/skills/issue-refinement-loop/references/scope-signal-guard.md
.claude/skills/issue-refinement-loop/scripts/command_registry.py
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
.claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py
.claude/skills/issue-refinement-loop/tests/test_issue_1952_trusted_directive_regression.py
.claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py
.claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py
.claude/skills/issue-refinement-loop/tests/test_trusted_anchor_iteration_zero.py
scripts/agent-guards/skill_runtime_command_policy.py
scripts/agent-guards/skill_runtime_exec.py
scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py

Schema Change Applicability(スキーマ変更適用性)

  • decision: schema_change
  • reason: 既存の厳密な入出力契約を保った実装変更であり、新規の公開スキーマやキー集合は追加しない。directive・anchor・provenance の識別子は既存 consumer 内でのみ扱う。

Schema Consumer Inventory(スキーマ consumer 一覧)

既存の閉じた入出力契約を保ったまま、明示的な人間/agent レーンと source binding を下流まで受け渡します。公開スキーマやキー集合は追加せず、既存の strict result schema と互換な範囲で処理します。

区分 担当ファイル 役割と互換性
producer command_registry.py 明示的な human / agent profile を生成し、曖昧な anchor を人間由来へ推測しない。
wrapper skill_runtime_command_policy.py 厳密な argv allowlist で profile 由来の引数だけを許可する。
実行境界 skill_runtime_exec.py command-id と target binding を照合し、別経路への混入を拒否する。
preflight consumer run_refinement_preflight.py provenance を保存し、contract-update handoff を fail-closed に整形する。
authority consumer scope_signal_delta.py path と authority を正規化し、unsafe な mixed paths を拒否する。

Safety Claim Matrix(安全性主張マトリクス)

主張 実装済み 未統制範囲 証跡 追跡先
origin の昇格 明示的な origin lane と source binding が一致する場合だけ扱い、generic・未指定・両 lane 重複を拒否する。 なし AC1–AC8: 102 passed、origin + anchor: 126 passed。 なし
契約更新への進行 後続更新で追加した六つの gate がすべて通る場合だけ進め、一つでも未達なら実装権限を与えない。 なし trusted-directive: 23 passed、CI run 31258161749。 なし
非冪等な操作 正の権限として扱わず、non-idempotent な要求を常に拒否する。 なし AC1–AC8: 102 passed。 なし
Allowed Paths exact かつ安全な単一の差分だけを扱い、unsafe または mixed paths を拒否する。 なし trusted-directive: 23 passed、CI run 31258161749。 なし
stale binding source/body hash と updatedAt が current binding と一致する場合だけ扱い、stale source、stale body、A→B→A 循環を拒否する。 なし AC1–AC8: 102 passed、origin + anchor: 126 passed。 なし

CI Test Performance Decision(CIテスト性能判定)

CI_TEST_PERFORMANCE_DECISION_V1:
  issue_number: 1951
  pr_number: 2026
  reviewed_head_sha: 3ccba2127fa182484107cc930faf4c61abd441e7
  changed_path_count: 14
  required_ci_run: 31258161749
  ci_verdict_artifact: ci-verdict-summary-v2-31258161749-1
  overall_status: merge_ready

Notes(注記)

  • merge、auto-merge、Issue close はこの PR では実行しません。

@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2026 closed).

@squne121

squne121 commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

結論

推奨アクションは block_on_ci の継続ではなく、expand_minimally_and_fix_current_pr です。 ただし、現時点で scripts/agent-guards を VIRTUAL_ENV 対応のために広げるのは勧めません。

確認時点の PR head は、提示された 94b2ca7 ではなく 6c370aeaa0410f1414d7cafba24c69aa17e502df まで進んでいます。現在の Actions run 31245835224 はこの head に束縛され、CI 全体は failure です。

敵対的レビュー結果

P0 — canonical runtime への provenance lane 配線が切れています。

PR の run_refinement_preflight.py は、anchor URL が human_context_comment_urls / agent_report_comment_urls のどちらにも明示されていなければ、意図的に generated_by_agent へ fail-closed します。つまり anchor URL 単体では human authority になりません。

一方、canonical SSOT の command_registry.py にある preflight.run.with_anchor と contract_update.run.with_anchor は、現状 child process へ --anchor-comment-url しか渡していません。production-shaped test もこの argv を固定しています。

しかも executor 自体は registry に anchor_comment_url を既に渡せます。したがって、まず executor/policy を変更する必要はありません。registry が同じ URL を --human-context-comment-url として child argv に materialize するだけで済む可能性が高いです。

これは #1950/PR #1973 で確立された「本文・author_association・投稿アカウントではなく caller の入力 lane で provenance を決める」という設計とも一致します。

P1 — provenance builder に明確な None-handling regression があります。

現在の build_provenance() は、

authority.get("route") が None の場合でも authority_route を None のまま保持し、その直後に authority_route.get(...) を呼びます。CI で観測された AttributeError とコードが直接一致しています。

これは現在の Allowed Paths 内の run_refinement_preflight.py だけで修正できます。たとえば route の値を再度 isinstance(..., dict) で正規化し、route 不在時は {} として provenance に deny/unknown を記録するのが適切です。

P1 — VIRTUAL_ENV mismatch は現段階では root cause と扱うべきではありません。

失敗している production-chain test は一時 repo で uv run --locked を起動しつつ親 process の環境を継承するため、別 repo の VIRTUAL_ENV warning が出る条件があります。

しかし Astral uv の現行公式仕様では、project operation 時に project .venv と異なる VIRTUAL_ENV は既定で警告したうえで無視されます。--active は逆に、その外側の active environment を使うための opt-in です。したがって --active で警告を消す修正は isolation を弱める方向で、今回の対処として不適切です。 ([Astral Docs]1) CI でも uv の公式例は uv sync → uv run による project environment 利用です。 ([GitHub]2)

つまり、origin-lane と provenance crash を直してから同じ test を再実行し、それでも独立して落ちる場合だけ VIRTUAL_ENV を再調査すべきです。

Allowed Paths の推奨拡張

最初はこの 2ファイルだけ追加するのが最小です。

.claude/skills/issue-refinement-loop/scripts/command_registry.py
.claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py

skill_runtime_exec.py は registry の anchor placeholder を child argv に流す機構を既に持っています。 また exact command parser は外側の executor invocation を12 token形で厳密検査していますが、registry が生成する内側の preflight argvを増やすだけなら、その boundary 自体を変更する必要はありません。

これで直らないという再現証拠が出てから、skill_runtime_exec.py / skill_runtime_command_policy.py を第2段階の scope delta にしてください。

なお、PR は依然 Draft であり、PR body の「4ファイルのみ」「178 passed」という targeted verification は、現在の full CI failure を代替できません。

リポジトリ上の spark-skim と spark-deep はどちらも要求どおり gpt-5.3-codex-spark に固定されています。前者は read-only/low、後者は bounded-write/high で、root からの manual invocation を前提としています。

この ChatGPT セッションには Codex subagent を実際に spawn するツールが公開されていないため、ここでは Spark 自体は起動していません。以下の実行プロンプトでは root から Spark を優先的に並列起動することを必須化しています。

Claude Code / Codex CLI 用プロンプト

squne121/loop-protocol の Issue #1951 / PR #2026 を継続し、Allowed Paths を必要最小限に拡張した上で、この PR 内で現在の correctness / provenance / CI blocker を解消してください。

人間の追加承認は不要です。このプロンプト自体が「Issue #1951 の Allowed Paths を、PR #2026 を正しく完結させるために必要な exact paths へ拡張してよい」という operator directive です。

ただし destructive operation、secret/credential 開示、外部課金、新たな権限昇格、GitHub 権限不足だけは停止条件です。

0. Authority / stale-state policy

以下は OBSERVED_NOT_AUTHORITY です。

これらをそのまま authority として使用しないこと。

作業開始時と mutation/push 後に必ず live GitHub/readback を取得し、

を再束縛すること。

head が変化したら、それ以前の review/test verdict を現在 head へ流用しない。

1. SubAgent policy — Spark 優先

root/main thread から直接 SubAgent を起動すること。
nested SubAgent spawnは禁止。

可能な限り既存の以下を優先する。

  • spark-skim

    • model: gpt-5.3-codex-spark
    • read-only
    • low reasoning
  • spark-deep

    • model: gpt-5.3-codex-spark
    • bounded write
    • high reasoning

最低3本を root から起動する。

Spark A — contract / provenance audit

agent: spark-skim

task_scope:

確認事項:

  • human_context_comment_urls / agent_report_comment_urls の SSOT
  • anchor URL 単体から provenance を推論していないか
  • canonical preflight.run.with_anchor / contract_update.run.with_anchor が explicit human lane を materialize しているか
  • current Allowed Paths と必要最小 delta
  • PR body の claims と実コードの乖離

output:
SPARK_AGENT_RESULT_V1 のみ。

Spark B — CI / failing-test audit

agent: spark-skim

task_scope:

  • current-head GitHub Actions
  • python-test-core
  • ci-verdict-summary
  • failing test names
  • changed-filesとの因果関係

特に、以前報告された
VIRTUAL_ENV ... does not match the project environment path
を root cause と決め打ちしない。

stdout/stderr、exit code、preceding failure、production chain を分離し、
「warning」と「実際に exit 2 を発生させた原因」を区別する。

output:
SPARK_AGENT_RESULT_V1 のみ。

Spark C — adversarial reproduction / bounded fix

agent: spark-deep

A/B の evidence と current live diff を渡す。

task_scope:

  • Allowed Paths 内で current CI failures を reproduction
  • build_provenance() の malformed/None route
  • explicit source-lane wiring
  • canonical contract-update subprocess chain
  • exact regression tests

GitHub mutation、commit、push は行わせない。
root が authority を保持する。

必要な local edit は、root が Issue #1951 の Allowed Paths 更新を readback した後だけ許可する。

output:
SPARK_AGENT_RESULT_V1 のみ。

2. Adversarial findings to reproduce first

以下を仮説ではなく reproduction target とする。

Finding A — provenance route None

current run_refinement_preflight.py では概ね、

authority_route = authority.get("route") if isinstance(authority, dict) else {}
...
authority_route.get(...)

となっている。

authority が dict でも route が None の場合、
authority_route is None となり .get() で crash する。

修正要件:

  • absent / None / malformed route を {} 相当の deny/unknown 状態へ fail-closed normalization
  • malformed provenance が implementation authority に昇格しない
  • sidecar generation 自体は exception で消失しない
  • existing strict result schema を不用意に変更しない
  • blocked/environment-failure paths でも machine-readable provenance が残る

Finding B — explicit origin lane が canonical registry に配線されていない可能性

current implementation は source origin を、

  • human_context_comment_urls
  • agent_report_comment_urls

の caller-supplied lane だけから決め、
unlabeled anchor は generated_by_agent 側へ fail-closed する。

一方、main の command_registry.py の current canonical profiles:

  • preflight.run.with_anchor
  • contract_update.run.with_anchor

は、child run_refinement_preflight.py に
--anchor-comment-url
だけを materialize している可能性がある。

まず source を読んで再確認すること。

#1950 / PR #1973 の established contract と #1951 の current contract を照合し、
既存 with_anchor profile が「human-supplied anchor」を意味するなら、

--anchor-comment-url {anchor_comment_url}
--human-context-comment-url {anchor_comment_url}

を同じ canonical registry entry から生成するのが第一候補。

contract_update.run.with_anchor でも同じ provenance binding を行い、
その後 --consume-contract-patch-plan を維持する。

ただし、既存 profile が human/agent の両方を意味する証拠があるなら、
安易に全 anchor を human 化しない。
その場合は distinct sibling profile の必要性を評価し、
exact parser / policy への変更が本当に必要な場合だけ scope をさらに広げる。

author_association、本文形式、marker、投稿 account から origin を再推論してはならない。

3. Allowed Paths expansion

最初に Issue #1951 の current body を readback する。

今回の operator directive に基づき、まず以下の exact paths を Allowed Paths に追加する。

.claude/skills/issue-refinement-loop/scripts/command_registry.py
.claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py

既存 Allowed Paths は保持する。

Issue body mutation は repository の canonical controlled issue-edit route を優先する。
agent-generated GitHub comment を「human comment」であるかのように捏造して authorization source にしてはならない。

更新後は必ず live readback し、

  • issue number == 1951
  • exact body
  • updatedAt
  • body SHA256
  • new Allowed Paths
  • unintended body changes == none

を確認してからコードを編集する。

追加 scope expansion

上記2 path + 既存 Allowed Paths だけでは production-shaped reproduction を直せないと実証された場合のみ、追加 exact path を認める。

候補例:

scripts/agent-guards/skill_runtime_exec.py
scripts/agent-guards/skill_runtime_command_policy.py
scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py
scripts/agent-guards/tests/test_skill_runtime_command_policy_anchor.py

ただし候補だから追加するのは禁止。
実際に production contract を変更する必要があることを call graph / failing test / exact parser evidence で証明してから追加する。

directory 単位の広い wildcard expansion は禁止。

4. VIRTUAL_ENV handling

VIRTUAL_ENV mismatch warning を理由に uv run --active を追加しないこと。

uv project operation では project environment と異なる VIRTUAL_ENV は既定で warning + ignore されるため、
warning 単体は exit 2 の証拠ではない。

特に temporary repository test では、
親 CI repo の VIRTUAL_ENV と temp repo .venv が異なること自体は起こり得る。

まず provenance/origin-lane fixes を入れて failing test を再実行する。

その結果:

  • test が PASS し warning だけ残る → warning は root cause ではない。runtime code を変更しない。
  • test が FAIL し、独立再現で VIRTUAL_ENV が因果的 root cause と証明できる → その時点で exact scope delta を評価する。

warning を消すためだけの behavior changeは禁止。

5. Required regression reproduction

current-head の actual CI log から failing tests を再取得して固定すること。

少なくとも以前観測された以下を individually / grouped で再実行する。

uv run --locked pytest \
  scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py::test_ac2_real_preflight_planner_subprocess_chain_flags \
  scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py::test_ac12_persisted_provenance_artifact_contains_full_v2_proof \
  .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_preflight_replay_proof_v1 \
  .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_preflight_provenance_v1 \
  .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_issue_964_enforcement_not_resolved \
  scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py::test_contract_update_phase_reaches_fake_transaction_and_fresh_handoff \
  .claude/skills/issue-refinement-loop/tests/test_preflight_runtime_schema_recovery.py::test_preflight_provenance_records_interpreter_and_dependency_versions \
  -q

test names が live main/head で変化していたら、最新名に解決し直すこと。

さらに:

uv run --locked pytest \
  .claude/skills/issue-refinement-loop/tests/test_preflight_run_with_anchor.py \
  -q

を必須とする。

PR #2026 の既存 targeted regression suite も current head で全再実行する。

Ruff / py_compile も実行する。

6. Security / provenance adversarial matrix

以下を最低限テストする。

  1. human lane にだけ存在する trusted OWNER comment

    • trusted human directive として扱われる。
  2. agent lane にだけ存在する同一本文

    • generated_by_agent。
    • implementation authority に昇格しない。
  3. 同一 URL が human + agent 両 lane

    • fail-closed。
  4. lane 未指定

    • human と推測しない。
  5. authority.route == None

    • crash しない。
    • implementation_allowed を true にしない。
  6. route missing

    • crash しない。
    • provenance sidecar が生成される。
  7. malformed route scalar/list

    • crash しない。
    • fail-closed。
  8. trusted OWNER prose に exact Allowed Path delta が1件

    • contract_update_required。
  9. permission widening が複数または unrelated

    • fail-closed。
  10. production contract_update.run.with_anchor

    • registry → executor → real preflight → planner → controlled transaction boundary まで到達。
    • fixture external boundary だけ fake。
    • fresh readback が成立。

7. Consumer-chain audit

以下を rg/call graph で確認する。

  • scope_signal_delta.py
  • run_refinement_preflight.py
  • plan_refinement_loop.py
  • decide_next_loop_action.py
  • command_registry.py
  • skill_runtime_exec.py
  • skill_runtime_command_policy.py
  • relevant Skill/reference
  • production-shaped tests

新しい CLI option を parser に追加しただけで
canonical caller が materialize していない状態を PASS としてはならない。

fixture-only direct CLI invocation だけでも PASS としない。

8. External technical verification

uv の current official documentationを確認し、

  • project .venv
  • VIRTUAL_ENV
  • uv run
  • --active
  • --no-active
  • GitHub Actions integration

の実際の semantics を実装判断に使うこと。

secondary blog の記述より official docs / upstream source を優先する。

Codex/SubAgent についても repository の current .codex/agents/*.toml を一次資料とし、
spark-skim / spark-deep の実効 model、reasoning、permission、write/GitHub mutation boundary を確認してから dispatch する。

9. Full verification / CI

local targeted tests が全部 PASS したら、current PR branch を commit/push する。

push 後に live head SHA を再取得し、その SHA を reviewed_head_sha として以後固定する。

GitHub Actions を current head で実行し、少なくとも:

  • python-test-core
  • python-test aggregate
  • lint
  • typecheck
  • test
  • e2e
  • build
  • actionlint
  • node-backed-hook-tests
  • codex-execpolicy
  • agy-causal-claim-drift-gate
  • ci-verdict-summary

を確認する。

component-vrt-report は workflow 上 report-only であることを live configuration / final verdict で再確認する。
「既知 failure」という prose だけで無視しない。

最終 authority は ci-verdict-summary の current-head artifact/result。

overall_status != merge_ready の間は Ready 化しない。

10. Final adversarial pass

修正後、root から再度 spark-skim を1本起動し、

task_scope:

  • base..current-head
  • contract provenance
  • new Allowed Paths
  • CI claims
  • test shadowing / fixture-only validation
  • bypass / fail-open
  • stale evidence

を監査させる。

必要なら spark-deep でも reproduction する。

root/main thread が最終 judgment を行う。
Spark に最終 PR review verdict や GitHub mutationをさせない。

新しい P0/P1 が出たら同一 PR 内で修正→再検証する。
最大3 iterationを目安にするが、明確な current-scope bug が残っている状態で arbitrary iteration cap により終了しない。

11. PR completion

全 required checks と current-head adversarial review が通ったら PR body を更新する。

必須記載:

旧 178 passed 等の stale count を current-head evidence として残さない。

CI が merge_ready かつ adversarial findings P0/P1=0 なら Draft を Ready for review にする。

マージ自体は行わない。
Issue #1951 も PR merge 前には close しない。

12. Final report schema

最後は以下だけを簡潔に返す。

ISSUE_1951_PR_2026_COMPLETION_V1:
  issue: 1951
  pr: 2026
  main_sha: ...
  final_head_sha: ...
  issue_binding:
    updated_at: ...
    body_sha256: ...
  allowed_paths_expansion:
    added: [...]
    reason: ...
  spark_subagents:
    - agent: ...
      model: gpt-5.3-codex-spark
      purpose: ...
      verdict: ...
  root_causes:
    - ...
  fixes:
    changed_paths: [...]
    commits: [...]
  adversarial_findings:
    p0: []
    p1: []
    p2: [...]
  verification:
    targeted: PASS
    regression: PASS
    runtime: PASS
    full_python_ci: PASS
    ci_verdict_summary: merge_ready
  virtual_env:
    causal: true|false
    evidence: ...
  github_mutation:
    issue_contract_updated: true
    branch_pushed: true
    marked_ready: true|false
    merged: false
  recommended_action: ready_for_review|continue_fixing|blocked
  blockers: []

推測値を埋めないこと。
current live readback / artifact / command output の evidence からのみ値を入れること。

この方針なら、「CI failure が Allowed Paths 外だから広げる」ではなく、PR が新設した provenance contract を canonical caller まで最後まで配線するために Allowed Paths を広げる形になります。こちらの方が #1951 の目的にも、fail-closed / least-privilege 設計にも整合します。

@squne121

squne121 commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

現行 GitHub を再確認したところ、提示された final_head_sha=9314114c... はすでに stale です。現在 PR #2026 は head 3ff14d9185… / base c526cd4035…、Draft、mergeable=true で、3ff14d… は main を取り込んだ merge commit です。 現在の main も c526cd4035… まで進んでいます。

また、PR body にはまだ「変更は4ファイルのみ」という古い記述が残っています。 一方、Issue #1951 の live contract は command_registry.py や agent-guards policy/test を Allowed Paths に追加済みです。 したがって最終ループには PR body freshness 修正も merge-ready gate に含めるのが適切です。

gpt-5.3-codex-spark についても、現行 repo の spark-skim は read-only/low、spark-deep は bounded-write/high として実際に固定されています。 以下をそのまま Claude Code / Codex CLI の root session に渡すのを推奨します。

squne121/loop-protocol の Issue #1951 / PR #2026 を対象に、マージ直前の merge-ready 状態まで、人間の追加承認なしで修正・検証・敵対的レビューを反復してください。

対象:

最終目標:

  1. current-head の implementation correctness を確認する
  2. Issue 修正: issue-refinement-loop で trusted OWNER directive を重複承認なしに contract update へ正規化する #1951 の全 Acceptance Criteria を live contract に対して検証する
  3. current-head required CI を terminal 状態まで確認する
  4. unresolved review / REQUEST_CHANGES / actionable comment をゼロにする
  5. Allowed Paths gate を満たす
  6. adversarial review で P0/P1/P2 の未修正 finding をゼロにする
  7. PR body の検証結果・changed paths・CI claims を current head に同期する
  8. Draft を Ready for review にする
  9. mergeability / branch protection / required checks を最後に再取得する
  10. merge だけは実行せず停止する

gh pr merge、auto-merge enable、Issue #1951 の手動 close は禁止。
Closes #1951 による merge 時の close に任せる。

人間への途中確認は不要。
fixable な blocker は自律的に修正して再検証する。


0. Authority / stale-state rule

以下は開始時点の OBSERVED_NOT_AUTHORITY であり、必ず live readback で置換すること。

issue: 1951
pr: 2026
user_reported_previous_head: 9314114c68467514a4401b1439bd87936885963a
last_observed_pr_head: 3ff14d9185111957840d7338af9847f32f44384d
last_observed_main: c526cd403534f3cd463bf4d39875ddf7c3607c68
last_observed_pr_state: open
last_observed_draft: true
last_observed_mergeable: true

9314114c... 以降に main synchronization が入っているため、過去の APPROVE / CI / regression verdict を current head に継承しない。

開始時、各 push 後、Ready 化直前に必ず再取得する:

Issue #1951:
- body
- updatedAt
- comments
- Acceptance Criteria
- Allowed Paths
- Stop Conditions

PR #2026:
- head SHA
- base SHA
- draft/state
- mergeable / mergeStateStatus
- changed filenames
- full diff
- PR conversation comments
- submitted reviews
- unresolved review threads
- current-head workflow runs/checks

repository:
- origin/main HEAD
- merge-base

head が1 commitでも変化したら、それ以前の reviewer verdict は stale として current head で再レビューする。


1. Human directive / autonomy

この root prompt 自体を explicit interactive human directive として扱う。

この directive により、Issue #1951 / PR #2026 を既存 goal の範囲内で merge-ready にするための以下の操作を追加承認なしで許可する:

  • current Allowed Paths 内の実装修正
  • tests / lint / Ruff / runtime verification
  • current branch の main 追従
  • commit / push
  • PR body 更新
  • canonical PR review verdict comment 投稿
  • actionable review comment への対応
  • resolved と確認できる review thread の resolve
  • Draft → Ready for review
  • deterministic かつ既存 Issue goal 内で必要となる 最小 exact Allowed Paths expansion

Allowed Paths expansion が必要な場合:

  1. subagent に authorization を決めさせない
  2. root control-plane が必要性を一次 evidence で確認する
  3. exact repository-relative paths のみに限定する
  4. scope/product goal/schema を拡張しない
  5. destructive / secret / paid / privilege widening を含めない
  6. controlled Issue contract update を行う
  7. live readback で body / updatedAt / path set を確認する
  8. その後に初めて当該 path を編集する
  9. contract review / allowed-path gate / affected tests を fresh rerun する

AI/subagent が推測した scope expansion だけでは Issue contract を変更しない。


2. SubAgent policy — gpt-5.3-codex-spark 最優先

root/main thread から Spark SubAgent を明示的に起動すること。

nested SubAgent delegation 禁止。

優先順位:

  1. spark-skim

    • model: gpt-5.3-codex-spark
    • reasoning: low
    • read-only
  2. spark-deep

    • model: gpt-5.3-codex-spark
    • reasoning: high
    • bounded local write
  3. canonical implementation-worker / test-runner / pr-reviewer

    • impl-review-loop の authority-bearing role が必要な工程だけ使用

Spark は canonical pr-reviewer の最終 verdict を置換しない。
Spark は root orchestration を行わない。
Spark に GitHub mutation / commit / push / merge をさせない。

最初に4本並列で起動する

Spark A — contract / scope / provenance audit

agent: spark-skim

task_scope:

確認:

output:
SPARK_AGENT_RESULT_V1 のみ。

Spark B — CI audit

agent: spark-skim

task_scope:

  • current-head GitHub Actions
  • branch protection required checks
  • ci-verdict-summary
  • python-test-core
  • serial lane
  • e2e
  • validate-generated-artifact
  • current failed/skipped/cancelled jobs
  • current changed filesとの因果関係

重要:

component-vrt-report のような report-only / excluded job の raw failure を、そのまま merge blocker と扱わない。

canonical:

.claude/skills/pr-review-judge/scripts/ci_verdict_summary_v2.py

および branch protection / required-check SSOT で分類する。

ただし report-only failure 内から current PR が原因の correctness regression を発見した場合は warning として root に返す。

output:
SPARK_AGENT_RESULT_V1 のみ。

Spark C — adversarial code review

agent: spark-skim

current base..head diff のみを主対象にする。

観点:

  • fail-open
  • malformed input
  • None / unexpected type
  • provenance confusion
  • caller/child argv drift
  • command registry vs strict policy drift
  • fixture が production path を実際には通らない shadow test
  • test が implementation を複製して false positive になっていないか
  • security-sensitive origin escalation
  • stale hash acceptance
  • source lane overlap
  • permission widening
  • shell / argv exact-match regression
  • previous failing CI を期待値代入で隠していないか
  • current main 取り込みによる regression

finding は P0/P1/P2 に分類。

output:
SPARK_AGENT_RESULT_V1 のみ。

Spark D — delivery / claims audit

agent: spark-skim

確認:

  • PR title/body
  • Closes #1951
  • Acceptance Criteria table/checkbox claims
  • verification command results
  • changed path claims
  • schema applicability
  • runtime evidence claims
  • current CI claims
  • Draft/Ready state
  • current Issue contract との不整合

特に PR body に過去 head 時点の
「4ファイルのみ」
「N passed」
「CI pending/pass」
等の stale claim が残っていないか確認する。

output:
SPARK_AGENT_RESULT_V1 のみ。


3. Canonical impl-review-loop

Spark A-D の結果を root で集約した後、既存:

.claude/skills/impl-review-loop/SKILL.md

を正本として Issue #1951 の implementation-review loop を実行する。

Spark audit は canonical loop の前後に置く supplemental adversarial evidence であり、impl-review-loop の routing contract を書き換えない。

基本:

issue_number: 1951
max_iterations: 3

REQUEST_CHANGES が出た場合:

  1. current reviewed_head_sha を確認
  2. blocker を concrete fix_delta に変換
  3. implementation step
  4. targeted verification
  5. regression verification
  6. push
  7. new head を取得
  8. current head で PR review を完全にやり直す

reviewed_head_sha != current head の場合は無条件で再レビュー。

3 iterations を使い切っても、
残件が deterministic / fixable / current scope 内だけである場合は、
人間確認せず新しい bounded cycle を最大1回開始してよい。

total cap: 6 implementation-review iterations。

6回で解消できなければ推測修正を続けず blocker を最終報告する。


4. spark-deep の使用条件

Spark A/B/C/D のいずれかが concrete finding を返した場合、
fix 前に必要に応じて spark-deep を root から起動する。

例:

Spark Deep 1 — production reproduction

対象:

  • command_registry
  • run_refinement_preflight
  • scope_signal_delta
  • strict command policy
  • production-shaped tests

やること:

  • failing behavior を最小再現
  • fixture-only ではなく canonical invocation chain を通す
  • observed vs expected を分離
  • root cause を1つ以上の deterministic test に固定
  • Allowed Paths 内なら bounded local fix 可
  • targeted tests を実行

GitHub mutation / commit / push 禁止。
結果を root に SPARK_AGENT_RESULT_V1 で返す。

複数の独立 finding がある場合は spark-deep を複数並列起動してよい。
ただし同一ファイルへの並列 write は禁止。


5. Required correctness verification

最低限、Issue #1951 の Verification Commands を live body から再読込して全て実行する。

さらに current implementation に合わせて以下を確認する:

- test_issue_1952_trusted_directive_regression.py
- test_scope_delta_authority.py
- test_scope_signal_guard_lane_split.py
- test_preflight_run_with_anchor.py
- test_skill_runtime_exec_anchor.py
- Ruff

production-shaped runtime chain も必須。

特に:

preflight.run.with_anchor
contract_update.run.with_anchor

が、

--anchor-comment-url <URL>
--human-context-comment-url <same URL>

という intended explicit human-origin lane を canonical registry → strict policy → child parser → provenance builder まで維持することをテストする。

ただし実装をこの期待値に合わせるのではなく、live Issue contract / #1950 established design / actual canonical chain を先に確認する。

negative tests:

  • missing human lane
  • malformed lane
  • lane overlap
  • None route
  • malformed route
  • stale source hash
  • stale issue body hash
  • generated agent-report lane
  • untrusted comment
  • destructive directive
  • secret/credential directive
  • paid external service directive
  • unrelated privilege widening

が implementation authority へ昇格しないこと。


6. CI handling

push 後は必ず new head SHA に CI を束縛する。

使用:

gh pr checks 2026
gh run view ...
gh run view ... --log

必要なら repository の既存:

.claude/skills/impl-review-loop/scripts/wait_ci_checks.py
.claude/skills/impl-review-loop/scripts/get_ci_failed_log.py
.claude/skills/pr-review-judge/scripts/ci_verdict_summary_v2.py

を優先する。

raw GitHub job conclusion と merge-blocking classification を混同しない。

分類:

required failure:
  causalなら修正
  non-causalなら根拠を示して branch-protection evaluator に委ねる

excluded/report-only failure:
  merge blocker に昇格しない
  ただし current diff 起因 correctness defect が見つかれば別 finding とする

queued/in_progress:
  terminal 判定まで merge-ready としない

cancelled:
  expected cancellation か required lane 欠落かを判定する

CI failure を直すために unrelated tests / baselines を書き換えない。
snapshot update で failure を隠さない。


7. Review handling

毎 iteration で:

- PR conversation comments
- submitted reviews
- unresolved review threads

を fresh に取得。

actionable REQUEST_CHANGES / unresolved thread はすべて処理する。

既に obsolete になった thread は current code と evidence を確認してから resolve。

self-authored PR なので gh pr review --approve / --request-changes に依存しない。

canonical pr-reviewer は:

verdict: APPROVE | REQUEST_CHANGES | HUMAN_REVIEW_REQUIRED
reviewed_head_sha: <sha>
blockers: []
warnings: []

の最小 convention を返す。

root が必要な COMMENT を publish する。

最終 APPROVE は必ず current PR head と SHA 一致させる。


8. PR body freshness gate

コード/CIが green でも PR body が stale なら完了扱いしない。

Ready 化前に PR body を current state に更新する。

最低限:

過去 head の pass count を current head の結果として転載しない。

「変更は4ファイルのみ」等、current diff と一致しない記述は修正する。


9. Final adversarial pass

全修正・CI後、別の fresh Spark subagents を起動する。

最低2本:

Final Spark Review A

spark-skim

  • current base..head diff
  • Issue contract
  • tests
  • current CI
  • unresolved reviews
    をゼロベースで再監査。

Final Spark Review B

spark-skim

failure-mode review:

  • fail-open
  • authorization/provenance confusion
  • strict argv drift
  • false-positive tests
  • stale evidence
  • PR body overclaim
  • unrelated scope
    のみを重点確認。

どちらかが P0/P1/P2 finding を返したら Ready にせず修正ループへ戻す。

必要なら spark-deep で reproduce/fix。


10. Ready-for-review gate

以下をすべて current head で満たした場合のみ Ready 化する。

issue_contract_live: true
allowed_paths_gate: pass
acceptance_criteria: pass
targeted_tests: pass
regression_tests: pass
runtime_verification: pass
ruff: pass
required_ci: pass
ci_verdict_summary: merge_ready
unresolved_actionable_reviews: 0
spark_final_p0: 0
spark_final_p1: 0
spark_final_p2: 0
canonical_pr_reviewer_verdict: APPROVE
reviewed_head_matches_current_head: true
mergeable: true
merge_state_status: CLEAN_or_equivalent_merge_ready_state
pr_body_current: true
closes_1951_present: true

条件成立時:

  1. current head SHA を記録
  2. PR body を最終同期
  3. Draft → Ready for review
  4. Ready 化による新 CI/check が発生したら terminal まで評価
  5. PR head / main / mergeability / required checks をもう一度取得
  6. head movement があれば final review を無効化して再レビュー
  7. merge はしない
  8. auto-merge も有効化しない

Issue #1951 も事前 close しない。


11. Stop conditions

途中で人間承認を要求しない。

ただし以下だけは実行せず停止:

  • destructive / irreversible operation が不可避
  • secret / credential の取得・露出が必要
  • external paid service の利用が必要
  • 必要な repository/GitHub/runtime permission が無い
  • requested final action が merge / auto-merge そのもの

技術的 blocker は可能な限り reproduction → fix → test まで自律実行する。

曖昧さだけを理由に即 human escalation せず、
repository facts / tests / Issue contract から deterministic に解決を試みる。


12. 最終出力

成功時は以下のみを最終サマリとして返す:

ISSUE_1951_PR_2026_PREMERGE_READY_V1:
  issue: 1951
  pr: 2026
  main_sha: "<live>"
  final_head_sha: "<live>"
  reviewed_head_sha: "<live>"
  issue_binding:
    updated_at: "<live>"
    body_sha256: "<live>"
  changed_paths:
    - "..."
  spark_subagents:
    - agent: spark-skim
      model: gpt-5.3-codex-spark
      purpose: contract_scope_audit
      verdict: PASS
    - agent: spark-skim
      model: gpt-5.3-codex-spark
      purpose: ci_audit
      verdict: PASS
    - agent: spark-skim
      model: gpt-5.3-codex-spark
      purpose: adversarial_review
      verdict: PASS
    - agent: spark-skim
      model: gpt-5.3-codex-spark
      purpose: final_adversarial_review
      verdict: PASS
  adversarial_findings:
    p0: []
    p1: []
    p2: []
  verification:
    targeted: PASS
    regression: PASS
    runtime: PASS
    ruff: PASS
    required_ci: PASS
    ci_verdict_summary: merge_ready
  reviews:
    canonical_verdict: APPROVE
    unresolved_actionable_threads: 0
  github_state:
    issue_open: true
    pr_ready_for_review: true
    mergeable: true
    merged: false
    auto_merge_enabled: false
  blockers: []
  recommended_action: HUMAN_MERGE

merge-ready に到達できなかった場合:

ISSUE_1951_PR_2026_PREMERGE_BLOCKED_V1:
  issue: 1951
  pr: 2026
  final_head_sha: "<live>"
  iterations: <n>
  fixes_completed:
    - "..."
  remaining_blockers:
    - severity: P0|P1|P2|CI|PERMISSION
      evidence: "..."
      required_action: "..."
  merged: false
  recommended_action: CONTINUE_FIXING | PERMISSION_REQUIRED

単なる CI pending、過去 head の review、report-only job failure を merge-ready / blocked の根拠にしない。

現在 head の一次 evidence のみで最終判定すること。

特に重要なのは、既存 impl-review-loop 自体は canonical PR reviewer と live mergeability を終端判定に使う設計なので、Spark をそれに置換せず、root からの前後監査・再現・bounded fix に追加する構成です。現行 spark-skim / spark-deep の role boundary とも一致します。

@squne121

squne121 commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

Canonical PR review

LOOP_VERDICT:
  verdict: APPROVE
  reviewed_head_sha: "11fa8c219e715f508b238201fc6b39fa611520f5"
  blockers: []
  warnings: []

@squne121
squne121 marked this pull request as ready for review August 8, 2026 09:41
@squne121

squne121 commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

結論

REQUEST_CHANGES。確認時点の head c981fd440546e9ca9149fdee19cbb044854633b5 はマージ不可です。

current-head の CI run 31253323911 自体は成功しています。しかし、CI が検証しているのは現行実装に対する整合性であり、親 Issue #1951 の安全契約を満たしていることではありません。特に、以下の3件は P0 です。

  1. contract update 後の再検証が、失敗しても exit 0 / proceed になる。

  2. non-idempotent 検出正規表現が反転しており、危険な操作を見逃して安全な idempotent を危険扱いする。

  3. canonical with_anchor command が、任意の anchor URL を無条件に human-origin lane へ昇格させる。

PR 本文は head 11fa8c…、base 9d5609…、旧 CI run を「現在 head」の証跡として記載していますが、実体は head c981fd…、base eceda7… です。したがって、本文中の targeted test 数、current-head binding、merge-ready claim は現在 SHA の証跡として利用できません。

親 Issue #1951 は現在も open で、AC4 は generated OWNER handoff を human directive として扱わないこと、AC5 は destructive/non-idempotent を fail-closed にすること、AC7 は contract update 後の全 gate 成功を実装遷移条件にすることを要求しています。現行 head はこの3項目を満たしていません。


Findings

P0-1 — post-update verification が gate ではなく telemetry になっている

fresh_checks() が実行しているのは、おおむね次の3項目です。

  • recursive preflight

  • issue contract review

  • candidate readiness

しかし、この結果は fresh_checks として記録されるだけです。consumer の成功判定は status in {"applied", "no_change"} だけを見ており、fresh_review、fresh_preflight、fresh_readiness の値を blocker に反映していません。さらに recursive preflight は known_context を渡さず再実行されるため、初回の human/agent origin lane も失われています。

この欠陥は production-shaped test 自身が明示的に固定しています。テストは以下を同時に期待しています。

  • executor return code: 0

  • contract_update.status: applied

  • fresh_review: needs_fix

つまり、「更新後レビューが失敗しているのに mutation phase 全体は成功」という挙動が regression test の正解として登録されています。

さらに provenance sidecar は permission_profile_validators.passed: false を常に出力しますが、この false を実装遷移の blocker として消費する箇所がありません。したがって、artifact 上は permission validator 未合格なのに、wrapper は STATUS: pass、NEXT_ACTION: proceed を返し得ます。

これは AC7 の直接違反です。AC7 は単なる結果記録ではなく、次の全条件を実装遷移の conjunctive gate として要求しています。

  • fresh refinement preflight

  • contract review

  • allowed-path gate

  • permission/profile validator

  • runtime evidence

必須修正

applied / no_change と「後続実装へ進んでよい」を分離してください。例えば transaction-local な aggregate 判定を設けます。

post_update_gate:
  preflight: pass
  contract_review: approve
  readiness: go
  allowed_paths: pass
  permission_profile: pass
  runtime_evidence: verified
  overall: pass

overall == pass 以外は、以下のいずれかに固定する必要があります。

  • blocked / human_judgment_required

  • environment_failure / fix_environment

needs_fix、warn、unavailable、キー欠落、validator 未実行を成功扱いしてはいけません。また recursive preflight には、初回と同じ origin lane、comment ID、body hash を明示的に引き継ぐ必要があります。


P0-2 — non-idempotent hard-stop の正規表現が反転している

現在の危険操作検出には次の断片があります。

(?<!non-)idempotent

negative lookbehind は「直前が non- ではない idempotent」に一致します。したがって挙動は逆です。

入力 | 現行判定 | 必要な判定 -- | -- | -- non-idempotent operation | 検出しない | hard stop idempotent operation | 検出する | 通常は許可 irreversible operation | 検出する | hard stop

Python の正規表現仕様でも、(?<!...) は直前部分が指定パターンに一致しない場合にだけ成功する negative lookbehind です。現在の式は危険語 non-idempotent を意図的に除外する形になっています。 (Python documentation)

これは Issue #1951 の「destructive/non-idempotent action は fail-closed」という明示契約に反します。特に permission redesign の directive に、必要な stock safety phrase と実際の non-idempotent 操作を同居させた場合、最優先の boundary flag が立たない可能性があります。

必須修正

危険性と安全性を同一正規表現の否定条件で推論しないでください。

  • non-idempotent は明示的な positive risk token として検出する。

  • destructive と non-destructive は別々に正規化する。

  • 日本語の 破壊的でない、非破壊的 も risk token の単純否定だけで安全認定しない。

  • freeform prose の「安全です」という自己申告は permission validator の代替にしない。

最低限、以下を独立 regression にしてください。

non-idempotent       -> blocked
non idempotent       -> blocked
idempotent           -> not blocked by this rule
destructive          -> blocked
non-destructive      -> not sufficient for authorization
破壊的               -> blocked
破壊的ではない       -> not sufficient for authorization

P0-3 — canonical command が anchor URL を human provenance に自己昇格させる

preflight.run.with_anchor と contract_update.run.with_anchor は、同じ URL を次の2引数へ自動的に複製します。

--anchor-comment-url <URL>
--human-context-comment-url <URL>

入力 placeholder が検証するのは、canonical GitHub Issue comment URL であることだけです。そのコメントが direct human context なのか、agent-generated report なのかを示す独立入力はありません。また、agent-report anchor 用の canonical sibling profile も存在しません。

Skill の public input も anchor_comment_url しか持たず、origin lane を指定できません。その一方で、anchor が指定された場合は generic な preflight.run.with_anchor を使うよう記述されています。この構造では generated OWNER comment を anchor にした場合でも、canonical production invocation は human lane を主張します。

これは #1950 / PR #1973 で確立された次の契約と衝突します。

  • comment body、投稿アカウント、author_association から origin を推論しない。

  • human / agent は caller がどの lane に渡したかで決定する。

  • 同じ URL が両 lane に入った場合は fail-closed。

  • chronology、technical recommendation、mutation authorization は別軸。

関連 PR #1973 は impl-review-loop 側で human/agent の2引数を明示的に分離しています。今回の PR は resolver 内部ではこの設計を再利用していますが、canonical registry が常に human lane を選ぶため、外側の production boundary で分離を無効化しています。

旧レビューコメント 5225263195 が指摘した「origin lane が canonical runtime に配線されていない」「route=None で provenance builder が落ちる」という問題のうち、後者は修正されています。しかし前者への対応として「anchor URL をそのまま human lane に複製する」を採用したため、欠落していた provenance が、検証されていない human provenance assertion に置き換わっています。

さらに no-op replay 経路には別の bypass があります。

  • _satisfied_trusted_directive_noop_patch_plan() は evidence builder を lane なしで呼ぶ。

  • 現行 resolver ではその evidence は generated_by_agent になる。

  • しかし helper は source_kind を確認せず、confidence と boundary flag だけを見る。

  • 続く normalize_trusted_anchor_iteration_zero() は URL、Issue、comment ID、body hash、author_association を確認するだけで、origin lane を確認しない。

したがって generated OWNER comment が no-op replay 上で trusted anchor として受理される余地があります。

GitHub の OWNER author association は「その投稿者が repository owner である」という関係を表す値であり、そのコメントが人間による直接入力か、同一アカウントを使った自動生成かを証明するフィールドではありません。(GitHub Docs)

OWASP の agent/tool security guidance でも、外部コンテンツと命令を分離し、tool call を session context と権限に束縛し、高影響操作を独立して検証することが推奨されています。URL の存在や投稿者属性だけを authority に昇格させる設計はこの原則に反します。(OWASP チートシートシリーズ)

必須修正

generic な with_anchor を origin assertion に使わず、少なくとも canonical profile を明示分離してください。

preflight.run.with_human_context
preflight.run.with_agent_report
contract_update.run.with_human_context

contract_update.run.with_agent_report は作らないか、必ず mutation deny にします。

また、次を同一の transaction-local binding として保持してください。

  • source lane

  • canonical comment URL

  • comment ID

  • source body hash

  • Issue number / repository

  • caller command ID

fresh rerun、no-op replay、contract update consumer のすべてが同じ binding を消費しなければなりません。新しい永続 ledger は不要ですが、内部の typed object または dataclass として一貫して引き回す必要があります。


P1-1 — “exact Allowed Paths” 判定が repository path を検証していない

PATH_TOKEN_RE は backtick 内の任意文字列を path candidate として取得します。その後の _extract_path_literals_from_text() は / が含まれていることしか実質的に要求していません。

そのため、この関数上は次の値も “exact path” として成立します。

`https://example.com/spec`
`../outside/file`
`/etc/passwd`
`foo/bar`

また、directive の意味を解析していないため、例えば次の否定文も path expansion の証拠になり得ます。

- Allowed Paths には追加しない: `docs/test.md`

derive_contract_patch_operations() は Allowed Paths に関する directive と判定すると、その directive 全文を append operation にします。つまり、対象 path と操作種別を構造化せず、自然言語行をそのまま契約本文へ流しています。

必須修正

Allowed Paths は自然言語 directive から直接 append せず、少なくとも以下を構造化してください。

operation: add | remove | replace
path: repository-relative normalized path

検証要件は次のとおりです。

  • URL scheme を拒否

  • absolute path を拒否

  • .. traversal を拒否

  • NUL・改行を拒否

  • repository root 内へ正規化できること

  • 許可する glob syntax を closed set にする

  • add / remove / replace を否定文から推測しない

  • candidate body の Allowed Paths section を再parseして readback 検証する


P1-2 — permission-boundary exception が stock phrase の文字列積になっている

permission redesign の安全判定は、同一 directive 内に以下の文字列群が含まれるかを確認しています。

  • exact permission delta

  • human directive に必要

  • least privilege

  • non-destructive

  • no secrets

  • no paid

  • no unrelated widening

さらに before→after delta と、directive 内で最初に見つかった backtick path を組み合わせます。しかし、この2つが意味的に同じ permission target を指すことは検証されていません。

有限個の negation regex だけでは、例えば次のような矛盾を排除できません。

least privilege is optional
no secrets, but credential access is permitted
no paid external service, although billing may occur

必要な token はすべて存在するため、特定の否定パターンに一致しない言い換えは通過します。これは「安全性の検証」ではなく、「安全だと主張する定型句の存在確認」です。

現状では implementation 直行ではなく contract update に留める設計ですが、P0-1 により post-update gate が fail-open なので、両欠陥を独立問題として扱えません。

必須修正

freeform prose は permission change の要求抽出までに限定し、安全 predicate は typed data と実リポジトリ事実で検証してください。

permission_delta:
  target_path: ".codex/agents/issue-creator.toml"
  before: "read-only"
  after: "workspace-write"
  necessary_for_directive: true
  least_privilege_verified: true
  destructive: false
  non_idempotent: false
  secret_access: false
  paid_external_service: false
  unrelated_widening: false

ただし、この YAML 自体を人間コメントに強制する必要はありません。control-plane が候補を生成し、actual diff、permission profile validator、allowed-path validator の観測結果で値を埋めるべきです。directive 内の自己申告値をそのまま verified: true にしてはいけません。


P2 — PR 本文と merge evidence が current head に束縛されていない

PR 本文は次を「現在 head」として記録しています。

  • head 11fa8c…

  • base 9d5609…

  • CI run 31250534802

  • targeted suite の pass 数

  • merge_ready

しかし現在の実体は以下です。

  • head c981fd…

  • base eceda7…

  • current CI run 31253323911

current workflow は成功していますが、本文中の個別 runtime evidence、targeted test 数、artifact SHA は現在 head に束縛されていません。

また、Issue #1951 の AC checkbox は未完了のままで、上記 P0 が残っているため Closes #1951 は現時点では早すぎます。

PR body は次回 push 後の最終 head に対して再生成し、少なくとも以下を current SHA と明示的に束縛する必要があります。

  • targeted test command と結果

  • production-shaped test の結果

  • current workflow run ID

  • runtime artifact hash

  • current base SHA

  • changed-path inventory

  • ACごとの実際の gate assertion


CI がこれらを検出できなかった理由

今回の green CI は、主に次のテスト設計上の問題で説明できます。

  1. 伝播を検証し、強制を検証していない。
    fresh_review: needs_fix が artifact に記録されることは検証していますが、それによって exit code が非ゼロになることを検証していません。むしろ exit 0 を期待しています。

  2. unit fixture では lane を直接注入し、production registry では常に human lane にしている。
    generated handoff regression は内部関数レベルでは agent lane を渡していますが、canonical executor から generated lane を指定する production-shaped test がありません。

  3. 安全 parser に adversarial linguistic cases がない。
    non-idempotent、否定文の Allowed Paths、URL/traversal path、矛盾した permission safety phrase が不足しています。

CI failure ではなく、テストが誤った成功条件を固定している状態です。


必須追加テスト

以下を current-head production chain で追加しない限り、修正完了とは判定できません。

  • generated comment 5224719577 を canonical agent-report profileで実行し、source_kind=generated_by_agent、mutation deny になる。

  • direct human materialization comment 5224799872 を canonical human profileで実行し、同じ URL/ID/hash binding が fresh rerun と replayまで保持される。

  • 同一 URL を human/agent 両 lane に渡した場合、executor境界で非ゼロ終了する。

  • fresh_review=needs_fix で contract update command が非ゼロ終了し、NEXT_ACTION=human_judgment_required になる。

  • preflight、review、allowed paths、permission profile、runtime evidence の各1項目を個別に欠落・失敗させ、すべて fail-closed になる。

  • non-idempotent / idempotent の反転 regression。

  • URL、absolute path、traversal、否定文を Allowed Paths exact delta として拒否する。

  • no-op replay が source_kind と origin binding を失った場合に拒否する。

  • permission directive に矛盾文・decoy path・複数 delta がある場合に拒否する。

  • permission_profile_validators.passed=false と STATUS=pass が同時に成立しないことを schema-independent assertion で保証する。


Merge gate

次の条件をすべて満たすまでマージ不可です。

最終 verdict: REQUEST_CHANGES。current CI success を根拠にマージしてはいけません。

## 結論

REQUEST_CHANGES。確認時点の head c981fd440546e9ca9149fdee19cbb044854633b5 はマージ不可です。

current-head の CI run 31253323911 自体は成功しています。しかし、CI が検証しているのは現行実装に対する整合性であり、親 Issue #1951 の安全契約を満たしていることではありません。特に、以下の3件は P0 です。

  1. contract update 後の再検証が、失敗しても exit 0 / proceed になる。
  2. non-idempotent 検出正規表現が反転しており、危険な操作を見逃して安全な idempotent を危険扱いする。
  3. canonical with_anchor command が、任意の anchor URL を無条件に human-origin lane へ昇格させる。

PR 本文は head 11fa8c…、base 9d5609…、旧 CI run を「現在 head」の証跡として記載していますが、実体は head c981fd…、base eceda7… です。したがって、本文中の targeted test 数、current-head binding、merge-ready claim は現在 SHA の証跡として利用できません。

親 Issue #1951 は現在も open で、AC4 は generated OWNER handoff を human directive として扱わないこと、AC5 は destructive/non-idempotent を fail-closed にすること、AC7 は contract update 後の全 gate 成功を実装遷移条件にすることを要求しています。現行 head はこの3項目を満たしていません。


Findings

P0-1 — post-update verification が gate ではなく telemetry になっている

fresh_checks() が実行しているのは、おおむね次の3項目です。

  • recursive preflight
  • issue contract review
  • candidate readiness

しかし、この結果は fresh_checks として記録されるだけです。consumer の成功判定は status in {"applied", "no_change"} だけを見ており、fresh_review、fresh_preflight、fresh_readiness の値を blocker に反映していません。さらに recursive preflight は known_context を渡さず再実行されるため、初回の human/agent origin lane も失われています。

この欠陥は production-shaped test 自身が明示的に固定しています。テストは以下を同時に期待しています。

  • executor return code: 0
  • contract_update.status: applied
  • fresh_review: needs_fix

つまり、「更新後レビューが失敗しているのに mutation phase 全体は成功」という挙動が regression test の正解として登録されています。

さらに provenance sidecar は permission_profile_validators.passed: false を常に出力しますが、この false を実装遷移の blocker として消費する箇所がありません。したがって、artifact 上は permission validator 未合格なのに、wrapper は STATUS: pass、NEXT_ACTION: proceed を返し得ます。

これは AC7 の直接違反です。AC7 は単なる結果記録ではなく、次の全条件を実装遷移の conjunctive gate として要求しています。

  • fresh refinement preflight
  • contract review
  • allowed-path gate
  • permission/profile validator
  • runtime evidence

必須修正

applied / no_change と「後続実装へ進んでよい」を分離してください。例えば transaction-local な aggregate 判定を設けます。

post_update_gate:
  preflight: pass
  contract_review: approve
  readiness: go
  allowed_paths: pass
  permission_profile: pass
  runtime_evidence: verified
  overall: pass

overall == pass 以外は、以下のいずれかに固定する必要があります。

  • blocked / human_judgment_required
  • environment_failure / fix_environment

needs_fix、warn、unavailable、キー欠落、validator 未実行を成功扱いしてはいけません。また recursive preflight には、初回と同じ origin lane、comment ID、body hash を明示的に引き継ぐ必要があります。


P0-2 — non-idempotent hard-stop の正規表現が反転している

現在の危険操作検出には次の断片があります。

(?<!non-)idempotent

negative lookbehind は「直前が non- ではない idempotent」に一致します。したがって挙動は逆です。

入力 現行判定 必要な判定
non-idempotent operation 検出しない hard stop
idempotent operation 検出する 通常は許可
irreversible operation 検出する hard stop

Python の正規表現仕様でも、(?<!...) は直前部分が指定パターンに一致しない場合にだけ成功する negative lookbehind です。現在の式は危険語 non-idempotent を意図的に除外する形になっています。 ([Python documentation]1)

これは Issue #1951 の「destructive/non-idempotent action は fail-closed」という明示契約に反します。特に permission redesign の directive に、必要な stock safety phrase と実際の non-idempotent 操作を同居させた場合、最優先の boundary flag が立たない可能性があります。

必須修正

危険性と安全性を同一正規表現の否定条件で推論しないでください。

  • non-idempotent は明示的な positive risk token として検出する。
  • destructive と non-destructive は別々に正規化する。
  • 日本語の 破壊的でない、非破壊的 も risk token の単純否定だけで安全認定しない。
  • freeform prose の「安全です」という自己申告は permission validator の代替にしない。

最低限、以下を独立 regression にしてください。

non-idempotent       -> blocked
non idempotent       -> blocked
idempotent           -> not blocked by this rule
destructive          -> blocked
non-destructive      -> not sufficient for authorization
破壊的               -> blocked
破壊的ではない       -> not sufficient for authorization

P0-3 — canonical command が anchor URL を human provenance に自己昇格させる

preflight.run.with_anchor と contract_update.run.with_anchor は、同じ URL を次の2引数へ自動的に複製します。

--anchor-comment-url <URL>
--human-context-comment-url <URL>

入力 placeholder が検証するのは、canonical GitHub Issue comment URL であることだけです。そのコメントが direct human context なのか、agent-generated report なのかを示す独立入力はありません。また、agent-report anchor 用の canonical sibling profile も存在しません。

Skill の public input も anchor_comment_url しか持たず、origin lane を指定できません。その一方で、anchor が指定された場合は generic な preflight.run.with_anchor を使うよう記述されています。この構造では generated OWNER comment を anchor にした場合でも、canonical production invocation は human lane を主張します。

これは #1950 / PR #1973 で確立された次の契約と衝突します。

  • comment body、投稿アカウント、author_association から origin を推論しない。
  • human / agent は caller がどの lane に渡したかで決定する。
  • 同じ URL が両 lane に入った場合は fail-closed。
  • chronology、technical recommendation、mutation authorization は別軸。

関連 PR #1973 は impl-review-loop 側で human/agent の2引数を明示的に分離しています。今回の PR は resolver 内部ではこの設計を再利用していますが、canonical registry が常に human lane を選ぶため、外側の production boundary で分離を無効化しています。

旧レビューコメント 5225263195 が指摘した「origin lane が canonical runtime に配線されていない」「route=None で provenance builder が落ちる」という問題のうち、後者は修正されています。しかし前者への対応として「anchor URL をそのまま human lane に複製する」を採用したため、欠落していた provenance が、検証されていない human provenance assertion に置き換わっています。

さらに no-op replay 経路には別の bypass があります。

  • _satisfied_trusted_directive_noop_patch_plan() は evidence builder を lane なしで呼ぶ。
  • 現行 resolver ではその evidence は generated_by_agent になる。
  • しかし helper は source_kind を確認せず、confidence と boundary flag だけを見る。
  • 続く normalize_trusted_anchor_iteration_zero() は URL、Issue、comment ID、body hash、author_association を確認するだけで、origin lane を確認しない。

したがって generated OWNER comment が no-op replay 上で trusted anchor として受理される余地があります。

GitHub の OWNER author association は「その投稿者が repository owner である」という関係を表す値であり、そのコメントが人間による直接入力か、同一アカウントを使った自動生成かを証明するフィールドではありません。([GitHub Docs]2)

OWASP の agent/tool security guidance でも、外部コンテンツと命令を分離し、tool call を session context と権限に束縛し、高影響操作を独立して検証することが推奨されています。URL の存在や投稿者属性だけを authority に昇格させる設計はこの原則に反します。([OWASP チートシートシリーズ]3)

必須修正

generic な with_anchor を origin assertion に使わず、少なくとも canonical profile を明示分離してください。

preflight.run.with_human_context
preflight.run.with_agent_report
contract_update.run.with_human_context

contract_update.run.with_agent_report は作らないか、必ず mutation deny にします。

また、次を同一の transaction-local binding として保持してください。

  • source lane
  • canonical comment URL
  • comment ID
  • source body hash
  • Issue number / repository
  • caller command ID

fresh rerun、no-op replay、contract update consumer のすべてが同じ binding を消費しなければなりません。新しい永続 ledger は不要ですが、内部の typed object または dataclass として一貫して引き回す必要があります。


P1-1 — “exact Allowed Paths” 判定が repository path を検証していない

PATH_TOKEN_RE は backtick 内の任意文字列を path candidate として取得します。その後の _extract_path_literals_from_text() は / が含まれていることしか実質的に要求していません。

そのため、この関数上は次の値も “exact path” として成立します。

`https://example.com/spec`
`../outside/file`
`/etc/passwd`
`foo/bar`

また、directive の意味を解析していないため、例えば次の否定文も path expansion の証拠になり得ます。

- Allowed Paths には追加しない: `docs/test.md`

derive_contract_patch_operations() は Allowed Paths に関する directive と判定すると、その directive 全文を append operation にします。つまり、対象 path と操作種別を構造化せず、自然言語行をそのまま契約本文へ流しています。

必須修正

Allowed Paths は自然言語 directive から直接 append せず、少なくとも以下を構造化してください。

operation: add | remove | replace
path: repository-relative normalized path

検証要件は次のとおりです。

  • URL scheme を拒否
  • absolute path を拒否
  • .. traversal を拒否
  • NUL・改行を拒否
  • repository root 内へ正規化できること
  • 許可する glob syntax を closed set にする
  • add / remove / replace を否定文から推測しない
  • candidate body の Allowed Paths section を再parseして readback 検証する

P1-2 — permission-boundary exception が stock phrase の文字列積になっている

permission redesign の安全判定は、同一 directive 内に以下の文字列群が含まれるかを確認しています。

  • exact permission delta
  • human directive に必要
  • least privilege
  • non-destructive
  • no secrets
  • no paid
  • no unrelated widening

さらに before→after delta と、directive 内で最初に見つかった backtick path を組み合わせます。しかし、この2つが意味的に同じ permission target を指すことは検証されていません。

有限個の negation regex だけでは、例えば次のような矛盾を排除できません。

least privilege is optional
no secrets, but credential access is permitted
no paid external service, although billing may occur

必要な token はすべて存在するため、特定の否定パターンに一致しない言い換えは通過します。これは「安全性の検証」ではなく、「安全だと主張する定型句の存在確認」です。

現状では implementation 直行ではなく contract update に留める設計ですが、P0-1 により post-update gate が fail-open なので、両欠陥を独立問題として扱えません。

必須修正

freeform prose は permission change の要求抽出までに限定し、安全 predicate は typed data と実リポジトリ事実で検証してください。

permission_delta:
  target_path: ".codex/agents/issue-creator.toml"
  before: "read-only"
  after: "workspace-write"
  necessary_for_directive: true
  least_privilege_verified: true
  destructive: false
  non_idempotent: false
  secret_access: false
  paid_external_service: false
  unrelated_widening: false

ただし、この YAML 自体を人間コメントに強制する必要はありません。control-plane が候補を生成し、actual diff、permission profile validator、allowed-path validator の観測結果で値を埋めるべきです。directive 内の自己申告値をそのまま verified: true にしてはいけません。


P2 — PR 本文と merge evidence が current head に束縛されていない

PR 本文は次を「現在 head」として記録しています。

  • head 11fa8c…
  • base 9d5609…
  • CI run 31250534802
  • targeted suite の pass 数
  • merge_ready

しかし現在の実体は以下です。

  • head c981fd…
  • base eceda7…
  • current CI run 31253323911

current workflow は成功していますが、本文中の個別 runtime evidence、targeted test 数、artifact SHA は現在 head に束縛されていません。

また、Issue #1951 の AC checkbox は未完了のままで、上記 P0 が残っているため Closes #1951 は現時点では早すぎます。

PR body は次回 push 後の最終 head に対して再生成し、少なくとも以下を current SHA と明示的に束縛する必要があります。

  • targeted test command と結果
  • production-shaped test の結果
  • current workflow run ID
  • runtime artifact hash
  • current base SHA
  • changed-path inventory
  • ACごとの実際の gate assertion

CI がこれらを検出できなかった理由

今回の green CI は、主に次のテスト設計上の問題で説明できます。

  1. 伝播を検証し、強制を検証していない。
    fresh_review: needs_fix が artifact に記録されることは検証していますが、それによって exit code が非ゼロになることを検証していません。むしろ exit 0 を期待しています。

  2. unit fixture では lane を直接注入し、production registry では常に human lane にしている。
    generated handoff regression は内部関数レベルでは agent lane を渡していますが、canonical executor から generated lane を指定する production-shaped test がありません。

  3. 安全 parser に adversarial linguistic cases がない。
    non-idempotent、否定文の Allowed Paths、URL/traversal path、矛盾した permission safety phrase が不足しています。

CI failure ではなく、テストが誤った成功条件を固定している状態です。


必須追加テスト

以下を current-head production chain で追加しない限り、修正完了とは判定できません。

  • generated comment 5224719577 を canonical agent-report profileで実行し、source_kind=generated_by_agent、mutation deny になる。
  • direct human materialization comment 5224799872 を canonical human profileで実行し、同じ URL/ID/hash binding が fresh rerun と replayまで保持される。
  • 同一 URL を human/agent 両 lane に渡した場合、executor境界で非ゼロ終了する。
  • fresh_review=needs_fix で contract update command が非ゼロ終了し、NEXT_ACTION=human_judgment_required になる。
  • preflight、review、allowed paths、permission profile、runtime evidence の各1項目を個別に欠落・失敗させ、すべて fail-closed になる。
  • non-idempotent / idempotent の反転 regression。
  • URL、absolute path、traversal、否定文を Allowed Paths exact delta として拒否する。
  • no-op replay が source_kind と origin binding を失った場合に拒否する。
  • permission directive に矛盾文・decoy path・複数 delta がある場合に拒否する。
  • permission_profile_validators.passed=false と STATUS=pass が同時に成立しないことを schema-independent assertion で保証する。

Merge gate

次の条件をすべて満たすまでマージ不可です。

最終 verdict: REQUEST_CHANGES。current CI success を根拠にマージしてはいけません。

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 で trusted OWNER directive を重複承認なしに contract update へ正規化する

1 participant