Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "skill_runtime_exec.py の typed shadow-log policy が security fail-close を維持したまま、総ログサイズに依存せず正規 append を検証できるようにする"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: skill_runtime_exec.py の shadow-log 観測が、ログの総サイズに依存せず bounded-memory で正規 append を検証できる状態にする
- Desired Destination: N/A(単独改善 Issue のため、明示的な parent tracker Issue は存在しない)
Current Validated Scope
scripts/agent-guards/skill_runtime_exec.pyの shadow-log 観測ロジック(_shadow_log_stable_observation()等)の改修scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.pyへの regression test 追加- 必要な場合のみ
docs/dev/agent-skill-boundaries.mdの契約記述更新
Remaining Parent Gaps
なし(単独改善 Issue のため、parent tracker Issue が存在しない)。関連する別 concern(writer 側の TOCTOU 耐性・書込み時 size limit の canonical writer 化)は既存 #1587 が別途扱う(本 Issue とは scope が異なる。上記 Related 参照)。
Runtime Verification Applicability
- decision: immediate
- reason: AC9 は synthetic fixture(8MiB 超
.guard_shadow_log.jsonl)に対して canonicalskill_runtime_exec.py経由の実 preflight smoke を要求しており、静的検証(typecheck/lint/unit test)だけでは成立しないプロセス起動・実ファイル I/O を伴う動作検証である。 - if immediate: AC9 に対応する VC(
uv run pytest scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py -q内の fixture ベース smoke test、または同等の runtime smoke script)で検証し、SKIP exit 77 / fallback FAIL を実装し、証跡を PR に添付する。
applicable_acs: AC9
execution_environment: ローカル/CI どちらでも実行可能な synthetic fixture(tmp path 上に生成する 8MiB 超.guard_shadow_log.jsonl相当ファイル)を用いたskill_runtime_exec.py経由の preflight smoke。repo実ファイルには依存しない。
skip_conditions:skill_runtime_exec.pyの privileged executor lane 自体が環境上利用できない場合(例:uvtoolchain 未解決)は SKIP exit 77 とし、fail-closed で握りつぶさない。
fallback_policy: smoke test 実行が SKIP 以外の理由で失敗した場合は fallback FAIL とし、AC9 は未充足として報告する。
artifact_requirements: smoke test の実行ログ(コマンド・exit code・fixture サイズ)を PR に証跡として添付する。
Background
Issue #2231 の refinement 実行中、preflight.run.with_human_context の privileged executor lane が unauthorized_write_path で fail-closed する事象が報告された(#2231 issuecomment-5315427655 / issuecomment-5316915493)。報告された原因は repo-root .guard_shadow_log.jsonl が既存の 8MiB 上限を超えていたことによるものとされている。
このファイルの typed exact-file transition policy は #1563 / PR #1572 で導入され、以下を保証する設計になっている。
- 正規の append-only
regular -> regulartransition は許可する - truncate / overwrite / malformed JSONL / record deletion を拒否する
- symlink / directory / FIFO / socket / device 等への kind substitution を拒否する
- directory-wide exclusion / broad allowlist にはしない
この安全境界自体は維持する。
本 Issue 起票時点の追加確認: 現在の origin/main(2b20de74683cc01d0a7e466f63268fb880f4280a)上の実 .guard_shadow_log.jsonl は 110,732 bytes(8MiB 未満)であり、現時点では実際に 8MiB を超えていない。したがって本 Issue の再現・検証は current 実ファイルへの依存ではなく、synthetic fixture(tmp path 上で生成する 8MiB 超 / 32MiB 級の JSONL ファイル)で行う。コード上の欠陥自体(下記 Problem)は再現条件に関わらず現存する。
Problem(source-level確認済み: scripts/agent-guards/skill_runtime_exec.py)
_shadow_log_stable_observation()(:1063-1175)は _SHADOW_LOG_MAX_BYTES = 8 * 1024 * 1024(:1041)を持つ。
pre-read fstat() の時点でファイルサイズがこの値を超える場合(:1135)、または読み取り中に累積バイト数がこの値を超えた場合(:1148)、無条件に _SHADOW_LOG_KIND_UNSTABLE を返し(:1140, :1152)、_is_allowed_shadow_log_kind_transition()(:1178)はこの sentinel をどの許可 tuple にも含めないため、typed transition policy は必ず fail-closed する。
しかし .guard_shadow_log.jsonl は複数 producer が継続的に append する永続ログである。したがって、
append-only file + fixed total-file-size ceiling = 時間経過によって必ず到達する permanent privileged-executor failure
となる。上限を16MiB/32MiB等へ単純に引き上げても問題を先送りするだけであり、解決とはしない。
また、現在の実装は「サイズ上限内であれば」有効な read でも chunks: list[bytes] に全チャンクを蓄積して b"".join(chunks) する(:1141-1154)ため、上限 (8MiB) の範囲内であっても常にファイル全体を Python heap にバッファする設計であり、上限を単純に引き上げるほど working memory も比例して増加する。
Outcome
.guard_shadow_log.jsonl の総サイズが8MiB、32MiB、あるいはそれ以上になっても、メモリ使用量を bounded に保ったまま正規 append-only transition を検証できる。
同時に以下は従来どおり fail-closed する。
- truncation
- prefix overwrite
- existing record mutation / deletion / reordering
- malformed JSONL
- incomplete append
- symlink / directory / FIFO / socket / device substitution
- stable filesystem generation を観測できない race
In Scope
scripts/agent-guards/skill_runtime_exec.pyscripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py- 必要な場合のみ関連する agent-guard regression tests
- 必要な場合のみ
docs/dev/agent-skill-boundaries.md
Required design
総ファイルサイズをメモリへ読み込む実装を廃止し、bounded-memory streaming validation を採用する。具体的アルゴリズムは実装調査で決定してよいが、最低限以下を満たすこと。
- before observation を bounded chunk 単位で読み、サイズ・cryptographic digest(sha256)・JSONL validity を確定する。
- after observation で before-size 分の prefix が before snapshot と同一であることを、before-size までのバイト列に対する再計算 digest 一致で検証する(before の全 record を再パースしての構造比較ではなく、bytes-level digest 一致で prefix 保存を証明してよい — 既存実装も
after.startswith(before)という byte-level 一致を主判定にしていたため、これは弱化ではない)。 - before-size より後方だけが append されたことを検証する。
- append 部分が complete / valid JSONL record sequence であることを検証する。
- existing typed kind-transition policy と fd/fstat/final-lstat generation consistency checks(
:1091-1175の TOCTOU-safe観測ループ)を維持する。 - total file size に比例する Python heap allocation を行わない(
chunks.append()→b"".join()パターンの排除)。 - 一つの巨大 record により working memory が無制限化しないこと。実装調査で決定してよいが、明示的な per-record bound(既存実データの record は 400〜610 bytes 程度)を設計し、既存データとの互換性を baseline で確認する。
- 純粋な DoS 対策として、非現実的に巨大なファイル(例: 数百MiB オーダー)に対する上限は維持してよいが、それは「bounded-memory streaming が機能する上での安全弁」であり、旧
_SHADOW_LOG_MAX_BYTESのように「これを超えたら即 fail-close」という主たる防御機構ではないこと。
cryptographic digest を用いる場合は repository 既存の SHA-256 convention を再利用し、競合する新規 digest scheme を作らない。
Out of Scope
- writer 側の TOCTOU 耐性・書込み時 size limit の canonical writer 化(実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587 の scope。本 Issue は reader 側=検証時の total-size ceiling のみを扱う)
_SHADOW_LOG_MAX_BYTESを単純に引き上げるだけの対応(下記 Prohibited fixes 参照).guard_shadow_log.jsonlを_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSに追加する対応.guard_shadow_log.jsonlの無条件 allowlist 化- kind/content validation の弱体化、または
unauthorized_write_pathの warning への降格
Prohibited fixes
以下を解決として採用しない。
_SHADOW_LOG_MAX_BYTESを単に増加させる.guard_shadow_log.jsonlを_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSに追加する.guard_shadow_log.jsonlを無条件 allowlist する- preflight 前にログを削除・truncate・rotate する
- kind/content validation を弱める
unauthorized_write_pathを warning に降格する
Acceptance Criteria
- AC1: 8MiBを超える valid
.guard_shadow_log.jsonl(synthetic fixture)に正規 JSONL append が発生してもunauthorized_write_pathにならない。 - AC2: 32MiB以上の synthetic log でも total-size proportional な全内容 buffer を生成せず検証が完了する(メモリ使用量の bound をテストで示す、または実装が構造的に total-size-proportional なバッファを持たないことをコードレベルで示す)。
- AC3: before prefix の1 byte改変、truncate、record deletion/reordering は fail-closed する。
- AC4: malformed/incomplete appended JSONL は fail-closed する。
- AC5: symlink / directory / FIFO / socket/device substitution の既存 negative tests が維持される。
- AC6: legitimate concurrent append の既存 regression tests が維持される。
- AC7 (改訂): observation は
fstat()時点で size をobserved_endとして固定した単一 audit epoch として実行される。[0, observed_end)の prefix 一致・JSONL 妥当性・typed kind-transition・fd/fstat/final-lstat generation consistency が確認できない場合(inode 変化、observed_endより前方の内容改変、非-regular kind 置換等)は bounded retry 後に fail-closed する。observed_end以降に発生した正規 append はこの audit epoch の失敗要因とはならず、次の audit epoch(次回 preflight 実行)で検証される。本関数は「呼び出し時点でファイルに存在した全 bytes を検証済み」ことを保証するのではなく、「observed_endまでの prefix が改ざんされていないこと」を保証する cutoff-bound snapshot 検証である。 - AC8:
scripts/agent-guards/tests/の関連 regression suite が PASS する。 - AC9: 8MiB を超える synthetic
.guard_shadow_log.jsonlfixture に対して、canonicalskill_runtime_exec.py経由の安全な preflight smoke(fixture ベース、repo実ファイルを使わない)がunauthorized_write_pathで停止しないことを runtime verification する。
Negative controls
最低限以下を mutation test または明示的 regression test で証明する。
- prefix comparison を無効化すると AC3 test が FAIL する
- JSONL validation を無効化すると AC4 test が FAIL する
- non-regular kind check を無効化すると AC5 test が FAIL する
Verification Commands
実装時に current test inventory を確認して正確な command を固定すること。最低限:
# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
# AC9
$ uv run pytest scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py -q
# AC8
$ uv run pytest scripts/agent-guards/tests/ -q
$ uv run ruff check scripts/agent-guards/skill_runtime_exec.py scripts/agent-guards/tests/Allowed Paths
scripts/agent-guards/skill_runtime_exec.pyscripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.pydocs/dev/agent-skill-boundaries.md(契約記述更新が必要な場合のみ)
追加 path が必要なら勝手に拡張せず Stop Condition として報告する。
Related
- 実装: 契約実行ラッパーのunauthorized_write_path誤検知が.guard_shadow_log.jsonlでも発生する問題を修正する #1563
- PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572
- 実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587(別 concern: writer 側 TOCTOU 耐性・書込み時 size limit の canonical writer 化。本 Issue は reader 側=検証時の total-size ceiling を扱い、scope が異なる)
- 実装: worktree-agent-runtime-smoke の Claude-GPT launcher 経由 live causal-evidence 検証を実施し native Claude Code との比較 receipt を記録する #2231 / issuecomment-5315427655 / issuecomment-5316915493
Contract Reconciliation Note
AC7 は PR #2248 への OWNER adversarial review (#2248 (comment) )の Blocker 1 を受けて改訂した。継続的な正規 append がある巨大ファイルに対し、全走査を bounded retry 回数(最大25回)繰り返した末に fail-close する挙動を避けるため、fixed-cutoff snapshot semantics(B案)を canonical contract として正式採用する。本改訂は実装を先行させず、live Issue contract を正規手順で reconcile したものである。
Stop Conditions
- existing typed exact-file security contract を弱める必要がある
- broad path exclusion が必要になる
- producer schema の変更が必要になる
- repository 外への shadow-log migration が必要と判明する
- Allowed Paths 外の変更が不可避になる
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Design References
docs/dev/agent-skill-boundaries.md「型付き shadow-log 遷移ポリシー(Issue 実装: 契約実行ラッパーのunauthorized_write_path誤検知が.guard_shadow_log.jsonlでも発生する問題を修正する #1563)」節(.guard_shadow_log.jsonlの typed kind/content transition policy の既存契約。本 Issue はこの契約を維持したまま observation 実装のみを変更する)docs/dev/agent-skill-boundaries.mdの#1154(root checkout からのpreflight.run専用 skill runtime executor)テーブル行(skill_runtime_exec.pyの実行境界の SSOT)- 実装: 契約実行ラッパーのunauthorized_write_path誤検知が.guard_shadow_log.jsonlでも発生する問題を修正する #1563(
.guard_shadow_log.jsonltyped exact-file transition policy 導入 Issue) / PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572(実装) - 実装: guard-shadow log writer の TOCTOU 耐性を canonical writer 化で強化する #1587(writer 側 TOCTOU 耐性・書込み時 size limit の canonical writer 化。本 Issue の Out of Scope と対になる関連 Issue)
Required Skills
なし
Activity
[-]修正: .guard_shadow_log.jsonl が8MiBを超えると privileged executor が恒久的に fail-closed する問題を bounded-memory 検証で解消する[/-][+]実装: .guard_shadow_log.jsonl が8MiBを超えると privileged executor が恒久的に fail-closed する問題を bounded-memory 検証で解消する[/+]squne121 commentedon Aug 17, 2026
implement-issue: 実装完了 (2026-08-17T15:48:16Z)
.claude/worktrees/issue-2243-guard-shadow-log-jsonl-8mib-privileged-e(agent isolation worktree を直接 branch rename して使用)worktree-issue-2243-guard-shadow-log-jsonl-8mib-privileged-euv run pytest scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py -q(39 passed, 1 skipped)、uv run pytest scripts/agent-guards/tests/ -q(1408 passed, 1 skipped)、uv run ruff check(0 issues)fix: shadow-log 観測を fixed-cutoff snapshot semantics へ改訂し OWNER Blocke…
fix: .guard_shadow_log.jsonl の shadow-log 検証を bounded-memory streamin…