Skip to content

feat: runner evidence に main-session init の permission_mode_observed を出力する - #2940

Draft
squne121 wants to merge 1 commit into
mainfrom
worktree-issue-2935-main-session-permission-mode
Draft

squne121 wants to merge 1 commit into
mainfrom
worktree-issue-2935-main-session-permission-mode

Conversation

@squne121

@squne121 squne121 commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • run_worktree_agent_runtime_smoke.py の structured 実行が出力する schema_summary(--evidence-json)の top-level に、permission_mode_observed(string | null)を常に出力するようにしました。値は stream-json の最初の system/init event の permissionMode だけから取り、非空の文字列で既存の閉集合 _PERMISSION_MODE_VALUES に含まれる場合に限って採用します。それ以外は null です。
  • 2 件目以降の init は、最初の init に有効値が無くても採用しません。launcher の argv、receipt、settings、declaration、worker の自己申告、SubagentStop 由来の値からは補完しません。exit code と --require-observed-runtime-field の契約、nested の named_subagent_resume.permission_mode_observed は変更していません。
  • 新規 offline regression test(22 件)と、docs/dev/runtime-verification-policy.md の第 16 節(位置付け: init 時点の runtime 報告に留まり、effective behavior / effective_permission_profile / argv との一致は証明しない)を追加しました。

本 PR は次の Issue に紐づきます(merge 時に close): Closes #2935

受け入れ条件の達成状況

  • AC1: 6 種類の閉集合内の値(auto / default を含む)で、--evidence-json を読み返して top-level の値が一致することを確認(-k "observed and not unobserved": 7 passed)
  • AC2: init なし、permissionMode なし、null / 数値 / bool / object / list、空文字、bogus、AUTO、最初の init が session_id も permissionMode も持たず後続 init が有効値を持つ場合、などを個別の negative case にして、top-level が null・exit 0 であることを確認。SubagentStop に auto があっても補完されないことも確認(-k unobserved: 14 passed)
  • AC3: 既存の permission_mode 関連 test 2 ファイルを変更せずに実行して PASS(93 passed、2 deselected)
  • AC4: 新規 test file 全体を直接実行して PASS(22 passed)。test plan は既に scripts/agent-ops/tests/ を directory target にしているため未変更
  • AC5: runner_help test(subprocess で --help を実行して exit 0)が PASS。rg -n "permission_mode_observed" docs/dev/runtime-verification-policy.md が命中(第 16 節)
  • AC6: 実機 runtime 検証は未実施(pending)。root control-plane が PR head に対して実行し、結果を下の Runtime Verification Evidence に記載します

検証コマンド結果

$ uv run --locked pytest <new test> -k "observed and not unobserved"   -> 7 passed
$ uv run --locked pytest <new test> -k unobserved                       -> 14 passed
$ uv run --locked pytest test_run_worktree_agent_runtime_smoke_permission_mode.py test_run_worktree_agent_runtime_smoke_named_subagent_resume.py -> 93 passed
$ uv run --locked pytest <new test>                                     -> 22 passed
$ uv run --locked pytest <new test> -k runner_help                      -> 1 passed
$ rg -n "permission_mode_observed" docs/dev/runtime-verification-policy.md -> 3 行命中
$ uv run --locked ruff check <変更した Python 2 ファイル>               -> All checks passed
$ validate_japanese_content.py --file docs/dev/runtime-verification-policy.md -> exit 0
$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -> 24 passed
$ pnpm typecheck / lint / build -> いずれも exit 0、pnpm test -> 108 files / 1943 tests passed
  • 実装を外すと新規 test 21 件が fail することを確認しました(変異確認)。
  • scripts/agent-ops/tests の runtime_smoke 系を広く実行したところ 468 passed / 33 skipped でした。並列実行時に test_run_worktree_agent_runtime_smoke_claude_gpt_live_causal_evidence.py::test_ac2_native_positive_hook_correlated が 1 回 fail しましたが、同ファイルを単独で実行すると 5 passed で、負荷依存と判断しています(本 PR の変更とは無関係)。
  • AC6 は実行していません。

Runtime Verification Evidence(実機動作検証の証跡)

AC6: 実 Claude Code での main-session init permission mode の観測

  • 状態: pending(実行待ち)。root control-plane が PR head に対して AC6 の runtime コマンドを実行し、ここに記入します。
  • 記録予定の項目: claude --version、起動条件、exit code、--evidence-json の top-level permission_mode_observed、evidence["subagent_causal_evidence"]["causal_evidence_source"]
  • 本 PR を作成した worker は AC6 を実行しておらず、PASS を主張していません。SKIP / exit 77 / null は PASS ではなく unconfirmed として扱います。

Allowed Paths 遵守

Checks

  • pnpm typecheck
  • pnpm lint
  • pnpm test
  • pnpm build
  • 上記コマンドをすべてローカルで実行し、成功したことを確認しました

Schema Change Applicability

Schema Consumer Inventory

変更対象 schema: WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1 の schema_summary top-level key

before/after 差分:

# before
schema_summary: { schema, run_id, ..., permission_denials, settings_provenance, ... }  # permission_mode_observed なし
# after
schema_summary: { ..., permission_denials, permission_mode_observed: <string | null>, settings_provenance, ... }

Consumer 列挙(rg コマンド例と結果):

rg -l "WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1" .
# scripts/agent-ops/run_worktree_agent_runtime_smoke.py
# scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_claude_gpt_live_causal_evidence.py
# scripts/agent-ops/tests/test_evidence_index_runtime_smoke.py
# scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_main_session_permission_mode.py
# docs/dev/runtime-verification-policy.md

Consumer 更新状況:

Consumer ファイル 更新有無 備考
scripts/agent-ops/run_worktree_agent_runtime_smoke.py 更新済み producer。key を常に出力
docs/dev/runtime-verification-policy.md 更新済み 第 16 節を追加
scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_main_session_permission_mode.py 新規 本変更の regression test
scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_claude_gpt_live_causal_evidence.py 不要(additive な key で既存の assertion に影響しない。実行して PASS を確認) 既存 test
scripts/agent-ops/tests/test_evidence_index_runtime_smoke.py 不要(additive な key で影響しない。実行して PASS を確認) 既存 test
#2931(PR #2931)の test_run_scoped_scratch_runtime.py 対象外(Out of Scope。#2860 / #2931 側の責務) 下流 consumer。key の欠落を null と同じく未観測として扱う

Compatibility Decision(互換性判定)

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: N/A
  • reason: 既存 key の名前・型・意味を変えず、top-level key を 1 つ追加するのみです。key が無い場合も consumer は null と同じく未観測として扱います。

Safety Claim Matrix

権限・サンドボックス・approval の境界は変更せず、runner の evidence に観測値を 1 つ追加するだけです。主張の射程は下表のとおりに限定します。

Claim Implemented? Not controlled Evidence Follow-up
init 時点で runtime が報告した mode を permission_mode_observed として観測できる yes effective behavior、effective_permission_profile、argv で要求した mode との一致は未検証 offline regression test 22 件 PASS(実機 AC6 は pending) #2860

Notes

本 PR は Claude Code で作成しました。
🤖 Generated with Claude Code

IMPLEMENTATION_SCOPE_COVERAGE_V1:
  schema_version: "IMPLEMENTATION_SCOPE_COVERAGE_V1"
  issue_number: 2935
  issue_body_sha256: "sha256:59e254e513b13b40e1d4b4f62613cedf711d71af8bcfef358d238ddfa5fb2f69"
  normalized_scope_manifest_sha256: "sha256:80d5b0d0253e97c7cf5b60653ec399270f94feece623461c6d20adbd136cedfa"
  pr_head_sha: "37eb1ae20b98cc72fed816a7c88aca0d9b623a39"
  scope_manifest: {"acceptance_criteria": ["init event が無い、permissionMode が無い、非 string、空文字 \"\"、閉集合外(\"bogus\" / \"AUTO\")の場合、また最初の system/init が permissionMode を持たず後続の system/init だけが有効値を持つ場合(最初の init だけを採用するため)、top-level permission_mode_observed は null となり、launcher argv・declaration・SubagentStop 由来の値で補完されない。上記の各 fixture(空文字 \"\" と、最初の init が session_id も permissionMode も持たず後続 init が有効値を持つ case を含む)が個別の negative case として存在する。", "init event に閉集合内の非空 string permissionMode がある structured 実行で、--evidence-json の top-level permission_mode_observed に、その値がそのまま出力される。少なくとも 2 種類の異なる値(例: auto と default)で検証し、値の固定実装を排除する。", "runner が変更後も起動可能であり(--help が exit 0。新 test file 内の subprocess 起動 test で確認する)、docs/dev/runtime-verification-policy.md に main-session init 由来の permission_mode_observed の位置付け(source、string | null、未観測の規約、「init 時点の runtime 報告」に留まり effective behavior / effective_permission_profile / argv との一致を証明しないこと、SubagentStop 由来の観測との区別)が記載されている。", "実 Claude Code で、linked worktree から未使用の output directory を使い、predecessor #2854 の live smoke と同じ foreground Agent fixture(scripts/agent-ops/tests/fixtures/subagentstop_handback_provenance_smoke_prompt.md)に --claude-adapter claude-gpt --claude-bin \"$PWD/scripts/claude-gpt/launch.sh\"(絶対 path 必須)--evidence-json <path> --require-subagent-causal-evidence --require-min-subagents 1 を付けた structured smoke を実行し、Claude Code の version、起動条件、exit code、--evidence-json の top-level permission_mode_observed と nested の subagent_causal_evidence.causal_evidence_source(JSON path は evidence[\"subagent_causal_evidence\"][\"causal_evidence_source\"]。permission_mode_observed と違い top-level ではない)を PR 本文に記録する。exit 0 で --evidence-json の top-level permission_mode_observed が _PERMISSION_MODE_VALUES 内の非空 string であり、かつ evidence[\"subagent_causal_evidence\"][\"causal_evidence_source\"] == \"hook_id_correlated\" のときだけ AC6 を満たす(後者は extension-surface policy の assertion subagent_start_stop_causal_evidence_correlated の確認)。観測値を launcher の argv / receipt と一致させて補完してはならない(一致は参考記録に留める)。permission_mode_observed が null(exit 77 / SKIP を含む)の場合は、その version / 起動経路では unconfirmed とし、PASS に読み替えず Stop Conditions に従って停止する。causal evidence だけが不成立の場合は permission_mode_observed の観測結果と分けて記録し、AC6 は満たさない。", "新規 regression test file scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_main_session_permission_mode.py が、既存の scripts/agent-ops/tests/ directory target により CI collection 対象になり(CI の test plan が既にこの directory 全体を target にしているため、個別 file の登録も test plan 設定ファイルの編集も要求しない)、focused pytest で直接実行して PASS する。", "既存 --require-observed-runtime-field permission_mode の SubagentStop 由来契約が変わらず、既存 permission_mode 関連 test(test_run_worktree_agent_runtime_smoke_permission_mode.py、test_run_worktree_agent_runtime_smoke_named_subagent_resume.py)が変更なしで PASS する(これらは read-only の回帰確認対象で、編集しない。変更が必要になった場合は Scope Delta で Allowed Paths を拡張する)。main-session init 由来の値は SubagentStop 由来の観測を満たさず、named_subagent_resume.permission_mode_observed の有効値の出力も変わらない。"], "allowed_paths": ["docs/dev/runtime-verification-policy.md", "scripts/agent-ops/run_worktree_agent_runtime_smoke.py", "scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_main_session_permission_mode.py"], "change_kind": "code", "goal_ref": "runner の structured 実行 evidence に main-session init permissionMode を観測値として出力し、Claude-GPT Auto の runtime 観測を可能にする", "in_scope": ["exact field contract(この 1 key の additive V1 extension は、OWNER が https://github.com/squne121/loop-protocol/issues/2935#issuecomment-5991689409 の REQUEST_CHANGES と本 refinement 依頼で明示承認した固定契約であり、Stop Conditions の「未知の schema 変更」には該当しない):", "init の permissionMode が未観測であること自体は runner の exit code を変えない(exit 0 のまま null を出力し、新たな exit 77 経路を追加しない。--require-observed-runtime-field の既存契約も変更しない)。", "key: permission_mode_observed、型: string | null、位置: schema_summary の top-level(named_subagent_resume 配下ではない)。別名(main_session_permission_mode 等)を使わない。schema の値 WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1 は変更しない。", "offline fixture の regression test を新規 test file に追加する。unobserved の negative fixture には、init なし・permissionMode なし・非 string・空文字 \"\"・閉集合外を含める。--evidence-json を読み返して top-level key を検証する。", "permissionMode == \"auto\" の観測は「init 時点で runtime が Auto と報告した」ことの証拠に留まり、個々の action の effective behavior、argv で要求した mode との一致、effective_permission_profile を証明しない。この位置付けを docs/dev/runtime-verification-policy.md に必要最小限だけ追記する。", "source: Claude stream-json の type == \"system\" && subtype == \"init\" の permissionMode のみ。runtime が実際に emit した値だけを観測値とする。", "structured 実行(claude-gpt adapter 含む)の stream-json から、main-session の system/init event(stream 内の最初の type == \"system\" && subtype == \"init\" event そのもの。session_id の有無には依存しない)の permissionMode を抽出し、schema_summary(WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1、--evidence-json が書き出す JSON)の **top-level key permission_mode_observed** として出力する。", "top-level 用の抽出は、nested の既存抽出(session_id is None ガードで init を採用する既存 helper)とは別に行ってよい(実装方法は固定しない)。ただし top-level の契約は常に「最初の system/init event そのもの」を基準とする。", "下流 consumer は key の欠落も null と同じく未観測として扱う(#2931 の observed_main_permission_mode が top-level evidence[\"permission_mode_observed\"] を first choice で読むことと整合する)。runner は structured 実行で key を常に出力する。", "既存 --require-observed-runtime-field permission_mode(SubagentStop 由来)の契約を変更しない。main-session init 由来の観測値は別 field であり、SubagentStop 観測値と混同・合成しない。effective_permission_profile の観測は扱わない。", "既存の named_subagent_resume.permission_mode_observed(nested)の有効値の出力は変更しない。nested の空文字・閉集合外の扱いを本 Issue で変更することは要求しない。", "未観測(null)となる入力: init event が無い、permissionMode が無い、非 string(number / bool / object / list / null)、空文字 \"\"、閉集合外(\"bogus\"、大文字小文字違い \"AUTO\" 等)。いずれの場合も launcher argv・declaration・settings・worker の自己申告・launcher receipt・SubagentStop 由来の値から補完しない。", "本 Issue の PR HEAD で、既存 runner + repository-owned Claude-GPT launcher を 1 回 bounded に live 実行し、--evidence-json の machine-generated evidence から main-session init の permission mode が観測できることを確認する(AC6)。", "観測値として出力するのは、init の permissionMode が **非空の string** であり、かつ既存の閉集合 _PERMISSION_MODE_VALUES(default / plan / acceptEdits / auto / dontAsk / bypassPermissions。#2854 と同一)に含まれるときだけである。それ以外は未観測として null を出力する。既存の閉集合を再利用し、新しい汎用 parser / enum / schema framework は作らない。"], "schema_version": "IMPLEMENTATION_SCOPE_MANIFEST_V1"}

…を出力する (#2935)

structured 実行の schema_summary top-level に、最初の system/init event の
permissionMode を string | null として常に出力する。既存の閉集合
_PERMISSION_MODE_VALUES を再利用し、argv / SubagentStop 等からは補完しない。
新規 offline regression test と policy 文書の位置付けを追加する。

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

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2940/

The preview will be removed when this PR is closed.

@squne121

squne121 commented Oct 5, 2026

Copy link
Copy Markdown
Owner Author

Runtime Verification Evidence(AC6 実機検証の証跡): unconfirmed(merge 停止)

対象 head: 37eb1ae20b98cc72fed816a7c88aca0d9b623a39(PR #2940)

  • Claude Code version: 2.1.289 (Claude Code)
  • 起動条件: linked worktree から --runtime claude --mode structured --claude-adapter claude-gpt --claude-bin "$PWD/scripts/claude-gpt/launch.sh"、Issue 実装: runner の structured 実行 evidence に main-session init permissionMode を観測値として出力する #2935 の AC6 コマンドそのまま(2 回実行)
  • runner exit code: 1(2 回とも)
  • permission_mode_observed(top-level): auto(2 回とも。main-session の最初の init 由来で、この値は effective behavior を証明しない)
  • evidence["subagent_causal_evidence"]["causal_evidence_source"]: no_evidence(期待値は hook_id_correlated)。agent_transcript_verified=false
  • artifact: artifacts/runtime-smoke/main-session-permission-mode-evidence-20261005T102559Z.json と ...20261005T102837Z.json(worktree-local、commit しない)
  • 切り分け: 変更を含まない main 0b230a34 でも同一の no_evidence が再現した。本 PR の変更とは独立した Claude Code 2.1.289 依存の事象である

判定: permission_mode_observed の観測は成立したが、causal evidence が不成立のため Issue の AC6 は満たさず unconfirmed とする。Stop Conditions に従い merge は止め、owner の判断を求める。causal evidence の是正は #2941 が所有する。静的 AC1〜AC5 は current head で PASS(test-runner 独立実行)。

This branch has not been deployed

No deployments
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.

実装: runner の structured 実行 evidence に main-session init permissionMode を観測値として出力する

1 participant