Skip to content

実装: codex execpolicy gate を fail-open から fail-closed へ修正し、execpolicy と hook の責務境界を明確化する (#1137 Blocker10 follow-up) #1150

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1137"
goal_ref: "codex execpolicy required gate を fail-open から fail-closed へ修正し、execpolicy の coarse routing 契約と cleanup-route contract evidence を CI で再現可能に検証する"
change_kind: workflow

Source

Parent Issue

#1137

Parent Goal Ref

  • Goal: codex execpolicy と cleanup-route guard の CI 契約を fail-open なしで維持する
  • Desired Destination: required gate で codex execpolicy decision と cleanup-route contract evidence を継続検証できる

Current Validated Scope

  • .github/workflows/ci.yml の required lane を Node 22 + stable pinned @openai/[email protected] で fail-closed に修正する
  • scripts/ci/** に strict JSON parser / matrix / artifact writer を分離し、install/probe/case failure を追跡可能にする
  • scripts/ci/tests/** と tests/codex/** で parser / matrix / contract の回帰 test を追加する
  • .github/ci/python-test-plan.json で python-test / node-backed-hook-tests の lane coverage SSOT に tests/codex/** の帰属を反映する
  • .claude/hooks/** や scripts/check-codex-agents.mjs など runtime hook 実体の変更は本 Issue の対象外とし、必要なら Stop Condition に従って別 scope へ送る

Remaining Parent Gaps

  • .codex/rules/default.rules 自体の policy 変更は本 Issue では扱わない
  • runtime hook aggregate parity(.codex/hooks.json の全 handler 再生)を required lane で検証する場合は別 scope で扱う

背景

PR #1143 で codex execpolicy CI の no-op(|| true + codex 不在時 skip)を撤廃し、JSON decision matrix を assert する実装を入れた。しかし現行 .github/workflows/ci.yml は @openai/[email protected] を install し、codex 不在なら EXECPOLICY_SKIPPED、execpolicy 非対応なら EXECPOLICY_UNSUPPORTED を出力して exit 0 するため、required gate が fail-open のまま残っている。

一方で、PR #1158 OWNER comment により、現時点の matrix が runtime hook aggregate decision そのものを再現しているとは言えないこと、malformed cleanup case と failure artifact が偽陽性を含むことが判明した。したがって本 Issue は、runtime hook 実体を変更せずに required CI lane 上の execpolicy / cleanup-route contract evidence を fail-closed に是正する scope として扱う。

Outcome

required CI lane が stable に pin した codex build 上で codex execpolicy check を実行し、top-level decision / matchedRules / return code / provenance を strict に検証する。artifact は install / probe / 各 case の expected / actual / raw JSON / reason code / return code を fail-closed に保持し、少なくとも local cleanup-route contract evidence が tombstone 由来の偽陽性に依存していないことを追跡できる状態。

In Scope

  • stable required lane の codex install を fail-closed にし、install 失敗・version 不一致・probe 失敗を CI failure に変更する
  • execpolicy を exact command 判定器として扱わず、coarse routing layer としての責務を Issue contract に明記する
  • malformed cleanup case を fresh contract 前提で独立実行し、decision だけでなく reason code まで回帰防止する
  • git branch -df / -fd / --delete --force / long option unique prefix 等の no-match / force variant を matrix と test に追加する
  • JSON parser を decision / matchedRules top-level contract の厳密検証へ置き換える
  • inline YAML 中の matrix ロジックを scripts/ci/** のテスト可能なプログラムへ分離し、artifact 出力を追加する
  • failure artifact を逐次保存し、install failure / probe failure / case mismatch でも途中証跡を失わない構造にする
  • native executable realpath / selected package / sha256 など npm 配布物の provenance を artifact に含める

Out of Scope

  • .codex/rules/default.rules の rule 内容変更
  • .claude/hooks/** / scripts/check-codex-agents.mjs / .codex/hooks.json の runtime hook 実体変更
  • cleanup route 以外の hook policy 拡張
  • prerelease canary を required lane の代替証跡として扱う設計
  • Codex 0.142.0 の aggregate hook executor(全 handler 並行実行)の完全再実装

Acceptance Criteria

  • AC1: required lane の codex install は stable build を exact pin し、install 失敗・binary/version 検証失敗・codex execpolicy check --help probe 失敗をすべて CI failure にする
  • AC2: required lane は EXECPOLICY_SKIPPED / EXECPOLICY_UNSUPPORTED を成功終了経路として残さず、prerelease canary を使う場合も non-required 観測 lane に限定する
  • AC3: execpolicy の役割を coarse routing layer として明記し、exact cleanup argv / contract / one-shot authorization は fixture-based cleanup-route contract evidence で表現する。runtime hook aggregate decision を検証したかのような表現は残さない
  • AC4: execpolicy matrix は read-only / exact cleanup + valid contract / malformed cleanup / force・余剰argv・複数target・missing target / branch -D / branch -df / branch -fd / branch --delete --force / long option unique prefix / worktree add / worktree prune を回帰防止し、malformed cleanup は fresh valid contract を前提に reason code まで assert する
  • AC5: JSON parser は subprocess return code、stdout JSON、top-level decision、matchedRules 型を厳密検証し、recursive token scan と alias 正規化を廃止する。schema drift / parse error / no-match 契約逸脱は CI failure にする
  • AC6: version / package route / selected platform package / native executable realpath / native executable sha256 / argv / expected / actual / raw JSON / reason code / return code を JSON artifact として逐次保存し、required run に skip marker が残っていないことを追跡できる
  • AC7: matrix 実装は scripts/ci/** に分離され、対応する tests/codex/** または scripts/ci/tests/** の fixture / unit test で parser と lane contract を再現検証できる

Verification Commands

# AC1
$ rg -n "codex execpolicy check --help" .github/workflows/ci.yml

# AC2
# baseline-expect: fail
$ test -f scripts/ci/codex_execpolicy_matrix.py

# AC3
# baseline-expect: fail
$ rg -n "coarse routing layer" .github/workflows/ci.yml scripts/ci

# AC4
# baseline-expect: fail
$ rg -n "branch -df" .github/workflows/ci.yml scripts/ci tests/codex scripts/ci/tests

# AC5
# baseline-expect: fail
$ rg -n "matchedRules" .github/workflows/ci.yml scripts/ci

# AC6
# baseline-expect: fail
$ rg -n "raw_json" .github/workflows/ci.yml scripts/ci

# AC7
# baseline-expect: fail
$ test -f tests/codex/test_execpolicy_matrix.py

Allowed Paths

  • .github/workflows/ci.yml
  • .github/ci/python-test-plan.json
  • scripts/ci/
  • scripts/ci/tests/
  • tests/codex/

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • .claude/hooks/** / scripts/check-codex-agents.mjs / .codex/hooks.json の修正が merge blocker として必要になった場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • stable codex build で required lane を fail-closed にできず、non-required canary 分離だけでは Owner comment の blocker を解消できないと判明した場合

Required Skills

  • GitHub Actions
  • Python 3
  • pytest

Runtime Verification Applicability

Activity

  1. added
    triage-required
    on Jun 23, 2026
  2. squne121 commented on Jun 25, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。

    方向性は妥当ですが、現状のIssue contractでは、execpolicyを一度も実行しないままCIをgreenにでき、さらにprefix policyを「exact command」と誤認する余地があります。

    Blocker 1: required gateでのloud-skipを禁止する

    #1150は「gateを完全有効化する」としながら、最終fallbackとしてEXECPOLICY_UNSUPPORTEDを出力して成功終了する設計を残しています。現行CIも、インストール失敗、CLI不在、非対応buildのすべてをexit 0で処理します。これはsilentではないだけで、enforcementとしてはfail-openです。

    手元検証では、公式npm経路の@openai/[email protected]で以下が成立しました。

    codex --version
    → codex-cli 0.142.0
    

    codex execpolicy check --help
    → exit 0

    上流のrust-v0.142.0にもhiddenなexecpolicy subcommandが組み込まれ、同tagのREADMEがcodex execpolicy checkとJSON response schemaを文書化しています。release tag、commit 3a76f3a、公開日時もIssue記載と一致します。 (GitHub)

    したがってrequired laneでは次を必須にすべきです。

    • install失敗、version不一致、probe失敗はCI failure

    • EXECPOLICY_SKIPPEDまたはEXECPOLICY_UNSUPPORTEDを出して成功する経路を削除

    • prerelease canaryは別のnon-required laneに限定

    • AC4は「green」だけでなく、matrixが全件実行され、skip markerが存在しない証跡を要求


    Blocker 2: exact removeという仕様表現が実装と一致しない

    上流execpolicyは、現時点ではprefix-rule subsetです。ルールはcommand全体の完全一致ではなく、先頭token列へのprefix matchです。

    現在のrulesも次のprefixをpromptにしています。

    git worktree remove ...
    git branch -d ...

    そのため、現行rulesを0.142.0で評価すると次のようになります。

    git worktree remove TARGET          → prompt
    git worktree remove --force TARGET → prompt
    git worktree remove TARGET --force → prompt
    git worktree remove TARGET EXTRA → prompt
    git worktree remove → prompt

    git branch -d BRANCH → prompt
    git branch -d A B → prompt
    git branch -d -f BRANCH → prompt

    これは直ちに認可迂回になるとは限りません。CodexのPreToolUseには共有worktree_scope_guard.pyが配線されているため、runtime hookが余剰argv、force、hash不一致等を拒否できます。

    問題は、IssueとPR #1143がexecpolicy側を「exact」と表現し、CI matrixも正常形しか検証していない点です。PR #1143自身も「exact remove / -dをprompt、forceをforbidden」と説明していますが、実際のexactnessはexecpolicy単体ではなくhookとの合成によって成立しています。(GitHub)

    仕様を次のように修正すべきです。

    execpolicyはcleanup mutationを静的allowにしないためのcoarse routing layerである。prompt corridor内のexact argv、contract、one-shot authorizationはPreToolUse hookが担当する。

    matrixもレイヤ別ではなく、以下の合成不変条件を検証してください。

    ケース execpolicy hook
    read-only allow allow
    exact cleanup + valid contract prompt allow
    force・余剰・複数target・missing target promptまたはforbidden deny
    branch -D、worktree add/prune forbidden deny

    .codex/rules/default.rulesをOut of Scopeに維持するなら、Issue本文から「execpolicyによるexact判定」を削除する必要があります。


    Blocker 3: 現行JSON parserはschema変更をfailさせない

    公式0.142.0のresponse contractは、トップレベルのdecisionとmatchedRulesです。no-matchの場合はdecision自体が省略されます。

    一方、現行CIはJSON全体を再帰走査して、どこかにallow、prompt、forbiddenという文字列があれば成功扱いします。さらにdeny → forbidden、ask → prompt等の非公式aliasも受理します。これは互換性を広げる実装であり、AC2の「schema変更でfail」と逆です。subprocessのreturn codeも確認せず、stdoutが空ならstderr上のJSONも受理します。

    必須修正は以下です。

    completed = subprocess.run(...)
    

    if completed.returncode != 0:
    fail()

    data = json.loads(completed.stdout)

    if set(data) - {"decision", "matchedRules"}:
    # 方針次第だが、少なくともfixtureとの差分を明示
    fail()

    decision = data.get("decision")
    if decision not in {"allow", "prompt", "forbidden"}:
    fail()

    if not isinstance(data["matchedRules"], list):
    fail()

    再帰探索とalias正規化は削除し、no-matchも独立ケースとして検証すべきです。


    High: 配布経路を一つに固定する

    OpenAIの公式READMEはnpm、Homebrew、GitHub release binaryを配布経路として案内しています。npm package builderも、umbrella packageからOS/architecture別native packageを選択する構成です。

    このCIはUbuntu固定なので、primaryは次の一経路で十分です。

    - uses: actions/setup-node@v6
    with:
    node-version: "22"

    • name: Install pinned Codex CLI
      run: |
      CODEX_PREFIX="$RUNNER_TEMP/codex-cli"
      npm install
      --prefix "$CODEX_PREFIX"
      --package-lock=false
      --no-audit
      --no-fund
      "@openai/[email protected]"

      CODEX="$CODEX_PREFIX/node_modules/.bin/codex"
      test "$("$CODEX" --version)" = "codex-cli 0.142.0"
      "$CODEX" execpolicy check --help >/dev/null

    現行python-test jobはPython環境だけを明示セットアップし、npmをrunner imageの暗黙状態に依存しています。リポジトリの標準Node setupはNode 22です。

    rust-v0.143.0-alpha.2は明示的なprereleaseです。stable installの代替として自動選択せず、互換性観測用のnon-required canaryに限定すべきです。(GitHub)


    推奨するAcceptance Criteria

    1. actions/setup-nodeでNode 22を固定し、temporary prefixへ@openai/[email protected]をexact pinでinstallする。install失敗はCI failure。

    2. 実行対象binaryのrealpathとcodex-cli 0.142.0をassertする。

    3. codex execpolicy check --helpがexit 0であることをassertする。required laneではprobe失敗をskipしない。

    4. subprocessのexit code、stdout JSON、トップレベルdecision、matchedRules型を厳密に検証する。aliasとrecursive token scanは禁止。

    5. allow/prompt/forbiddenの正常系に加え、no-match、missing argv、extra argv、複数target、force flag位置違い、combined flagを検証する。

    6. cleanup exactnessはexecpolicy単体ではなく、execpolicy decisionと実PreToolUse hook decisionの組でassertする。

    7. matrixロジックをinline YAMLからscript/ci配下のテスト可能なプログラムへ分離し、parser fixture testを追加する。

    8. version、package route、各argv、expected、actual、raw JSON、return codeをJSON artifactとしてif: always()で保存する。

    9. required run内にEXECPOLICY_SKIPPEDまたはEXECPOLICY_UNSUPPORTEDがあれば失敗する。

    10. alpha canaryはstable required gateと別stepまたは別jobにし、stableの代替証跡として扱わない。

    結論として、#1150はバージョン更新Issueではなく、fail-open gateをfail-closedへ変更し、execpolicyとruntime hookの責務境界を正確に定義するIssueへ改訂する必要があります。

    ## 判定

    REQUEST_CHANGES。

    方向性は妥当ですが、現状のIssue contractでは、execpolicyを一度も実行しないままCIをgreenにでき、さらにprefix policyを「exact command」と誤認する余地があります。

    Blocker 1: required gateでのloud-skipを禁止する

    #1150は「gateを完全有効化する」としながら、最終fallbackとしてEXECPOLICY_UNSUPPORTEDを出力して成功終了する設計を残しています。現行CIも、インストール失敗、CLI不在、非対応buildのすべてをexit 0で処理します。これはsilentではないだけで、enforcementとしてはfail-openです。

    手元検証では、公式npm経路の@openai/[email protected]で以下が成立しました。

    codex --version
    → codex-cli 0.142.0
    
    codex execpolicy check --help
    → exit 0
    

    上流のrust-v0.142.0にもhiddenなexecpolicy subcommandが組み込まれ、同tagのREADMEがcodex execpolicy checkとJSON response schemaを文書化しています。release tag、commit 3a76f3a、公開日時もIssue記載と一致します。 ([GitHub]1)

    したがってrequired laneでは次を必須にすべきです。

    • install失敗、version不一致、probe失敗はCI failure
    • EXECPOLICY_SKIPPEDまたはEXECPOLICY_UNSUPPORTEDを出して成功する経路を削除
    • prerelease canaryは別のnon-required laneに限定
    • AC4は「green」だけでなく、matrixが全件実行され、skip markerが存在しない証跡を要求

    Blocker 2: exact removeという仕様表現が実装と一致しない

    上流execpolicyは、現時点ではprefix-rule subsetです。ルールはcommand全体の完全一致ではなく、先頭token列へのprefix matchです。

    現在のrulesも次のprefixをpromptにしています。

    git worktree remove ...
    git branch -d ...
    

    そのため、現行rulesを0.142.0で評価すると次のようになります。

    git worktree remove TARGET          → prompt
    git worktree remove --force TARGET  → prompt
    git worktree remove TARGET --force  → prompt
    git worktree remove TARGET EXTRA    → prompt
    git worktree remove                 → prompt
    
    git branch -d BRANCH                → prompt
    git branch -d A B                   → prompt
    git branch -d -f BRANCH             → prompt
    

    これは直ちに認可迂回になるとは限りません。CodexのPreToolUseには共有worktree_scope_guard.pyが配線されているため、runtime hookが余剰argv、force、hash不一致等を拒否できます。

    問題は、IssueとPR #1143がexecpolicy側を「exact」と表現し、CI matrixも正常形しか検証していない点です。PR #1143自身も「exact remove / -dをprompt、forceをforbidden」と説明していますが、実際のexactnessはexecpolicy単体ではなくhookとの合成によって成立しています。([GitHub]2)

    仕様を次のように修正すべきです。

    execpolicyはcleanup mutationを静的allowにしないためのcoarse routing layerである。prompt corridor内のexact argv、contract、one-shot authorizationはPreToolUse hookが担当する。

    matrixもレイヤ別ではなく、以下の合成不変条件を検証してください。

    ケース execpolicy hook
    read-only allow allow
    exact cleanup + valid contract prompt allow
    force・余剰・複数target・missing target promptまたはforbidden deny
    branch -D、worktree add/prune forbidden deny

    .codex/rules/default.rulesをOut of Scopeに維持するなら、Issue本文から「execpolicyによるexact判定」を削除する必要があります。


    Blocker 3: 現行JSON parserはschema変更をfailさせない

    公式0.142.0のresponse contractは、トップレベルのdecisionとmatchedRulesです。no-matchの場合はdecision自体が省略されます。

    一方、現行CIはJSON全体を再帰走査して、どこかにallow、prompt、forbiddenという文字列があれば成功扱いします。さらにdeny → forbidden、ask → prompt等の非公式aliasも受理します。これは互換性を広げる実装であり、AC2の「schema変更でfail」と逆です。subprocessのreturn codeも確認せず、stdoutが空ならstderr上のJSONも受理します。

    必須修正は以下です。

    completed = subprocess.run(...)
    
    if completed.returncode != 0:
        fail()
    
    data = json.loads(completed.stdout)
    
    if set(data) - {"decision", "matchedRules"}:
        # 方針次第だが、少なくともfixtureとの差分を明示
        fail()
    
    decision = data.get("decision")
    if decision not in {"allow", "prompt", "forbidden"}:
        fail()
    
    if not isinstance(data["matchedRules"], list):
        fail()

    再帰探索とalias正規化は削除し、no-matchも独立ケースとして検証すべきです。


    High: 配布経路を一つに固定する

    OpenAIの公式READMEはnpm、Homebrew、GitHub release binaryを配布経路として案内しています。npm package builderも、umbrella packageからOS/architecture別native packageを選択する構成です。

    このCIはUbuntu固定なので、primaryは次の一経路で十分です。

    - uses: actions/setup-node@v6
      with:
        node-version: "22"
    
    - name: Install pinned Codex CLI
      run: |
        CODEX_PREFIX="$RUNNER_TEMP/codex-cli"
        npm install \
          --prefix "$CODEX_PREFIX" \
          --package-lock=false \
          --no-audit \
          --no-fund \
          "@openai/[email protected]"
    
        CODEX="$CODEX_PREFIX/node_modules/.bin/codex"
        test "$("$CODEX" --version)" = "codex-cli 0.142.0"
        "$CODEX" execpolicy check --help >/dev/null

    現行python-test jobはPython環境だけを明示セットアップし、npmをrunner imageの暗黙状態に依存しています。リポジトリの標準Node setupはNode 22です。

    rust-v0.143.0-alpha.2は明示的なprereleaseです。stable installの代替として自動選択せず、互換性観測用のnon-required canaryに限定すべきです。([GitHub]3)


    推奨するAcceptance Criteria

    1. actions/setup-nodeでNode 22を固定し、temporary prefixへ@openai/[email protected]をexact pinでinstallする。install失敗はCI failure。
    2. 実行対象binaryのrealpathとcodex-cli 0.142.0をassertする。
    3. codex execpolicy check --helpがexit 0であることをassertする。required laneではprobe失敗をskipしない。
    4. subprocessのexit code、stdout JSON、トップレベルdecision、matchedRules型を厳密に検証する。aliasとrecursive token scanは禁止。
    5. allow/prompt/forbiddenの正常系に加え、no-match、missing argv、extra argv、複数target、force flag位置違い、combined flagを検証する。
    6. cleanup exactnessはexecpolicy単体ではなく、execpolicy decisionと実PreToolUse hook decisionの組でassertする。
    7. matrixロジックをinline YAMLからscript/ci配下のテスト可能なプログラムへ分離し、parser fixture testを追加する。
    8. version、package route、各argv、expected、actual、raw JSON、return codeをJSON artifactとしてif: always()で保存する。
    9. required run内にEXECPOLICY_SKIPPEDまたはEXECPOLICY_UNSUPPORTEDがあれば失敗する。
    10. alpha canaryはstable required gateと別stepまたは別jobにし、stableの代替証跡として扱わない。

    結論として、#1150はバージョン更新Issueではなく、fail-open gateをfail-closedへ変更し、execpolicyとruntime hookの責務境界を正確に定義するIssueへ改訂する必要があります。

  3. changed the title [-]実装: codex execpolicy gate を codex 0.142.0 + execpolicy check --help capability probe で有効化する (#1137 Blocker10 follow-up)[/-] [+]実装: codex execpolicy gate を fail-open から fail-closed へ修正し、execpolicy と hook の責務境界を明確化する (#1137 Blocker10 follow-up)[/+] on Jun 25, 2026
  4. squne121 commented on Jun 25, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-25T10:25:05Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1150
      body_sha256: "sha256:3ee0416d51781c7fb2ae0b96070d428a87e5679d48d3e62909dc5b6a4c997b0c"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. added 6 commits that reference this issue on Jun 25, 2026
  6. squne121 commented on Jun 25, 2026

    @squne121
    OwnerAuthor

    PR #1158 がマージされ、#1150 の対応が完了しました。post-merge cleanup により手動で close しています。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions