Repository navigation
Closed as not planned
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "PR #1572 の post-merge cleanup で分離された、repo-root `.guard_shadow_log.jsonl` の全 producer を TOCTOU 耐性・bounded size・partial-write handling を備える canonical writer へ統合する"
change_kind: code
dedupe_key: "follow-up:squne121/loop-protocol:pr/1572:guard-shadow-log-canonical-writer-toctou"
origin_skill: post-merge-cleanup
source_pr: "#1572"Parent Issue
なし(PR #1572 の post-merge cleanup から抽出した単独 follow-up)
Parent Goal Ref
- Goal: 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 が解消した
unauthorized_write_path誤検知を維持しつつ、repo-root.guard_shadow_log.jsonlの書込み開始前 path 差替えを writer 境界で fail-close にする。 - Desired Destination: repo-root
.guard_shadow_log.jsonlの全 producer を、trusted directory FD・O_NOFOLLOW/利用可能時の安全な path 解決・regular-file 検査・bounded size・partial-write handling を持つ canonical writer へ段階的に統合する。
Current Validated Scope
- PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 は
skill_runtime_exec.pyの実行終了時点の exact-path postcondition を型付きに検査する。書込み開始前の symlink 差替えを完全に防ぐ writer hardening は、PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 の Out of Scope だった。 - 現在の producer は
.claude/hooks/shadow_log.py、同 helper を呼ぶ2つの shell hook、及びscripts/check-codex-agents.mjsの Node writer である。shell hook は helper 呼出しを維持し、helper と Node writer を同一 canonical writer に収束させる。 docs/dev/agent-skill-boundaries.md#Parallel Agent Runtime Safetyは 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 の typed postcondition と provenance の限界を正本化している。本 Issue はその保証を置換せず、書込み側の防御境界を追加する。
Remaining Parent Gaps
skill_runtime_exec.pyの typed postcondition、strict process attribution(実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363)、及び log の長期 retention/rotation policy は本 Issue では変更しない。
Outcome
.guard_shadow_log.jsonl の Python/Node producer が共通 canonical writer を通じて、trusted directory FD に束縛された regular file へ 0600・サイズ上限付き・完全 record write の JSONL append のみを行い、symlink/FIFO/directory/identity 不一致/size 超過/partial write は記録前に fail-close する実装と回帰テストが揃う。
In Scope
scripts/agent-guards/shadow_log_canonical_writer.pyを追加し、repo root を trusted directory として FD で開き、.guard_shadow_log.jsonlをO_NOFOLLOWと regular-filefstatで検査してから append する共通 writer を実装する。- writer に共通 lock、0600 file mode、1つの明示的な size limit、partial-write loop、strict JSON object record serialization(
allow_nan=False)を実装し、失敗時は既存 file を truncate/replace せず非0で終了する。 .claude/hooks/shadow_log.pyを canonical writer の呼出し口へ更新し、既存2 shell hook を変更せず同じ経路に収束させる。scripts/check-codex-agents.mjsの directfs.appendFileSync()writer を廃止し、同じ canonical writer 経路へ更新する。- 新規 Python integration test で Python helper、両 shell hook 経路、Node caller の append、同時 producer、non-regular substitution、inode identity 異常、size limit、partial-write failure を検証する。
- SSOT に writer の owner、許容する file kind/permission/size、失敗時の fail-close、及び rotation/retention が本 Issue の対象外であることを追記する。
Out of Scope
scripts/agent-guards/skill_runtime_exec.pyと 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 の typed postcondition の変更.guard_shadow_log.jsonlの record schema/envelope の再設計openat2()が利用できないプラットフォームでの OS 固有 syscall 実装や、strict process attribution- log rotation、retention、外部 state root への移行、既存ログの自動削除
.claude/hooks/guard-japanese-prose.shと.claude/hooks/rtk_boundary_shadow_guard.shの判定ロジック変更
Acceptance Criteria
- AC1: Python helper と Node caller が、同一 canonical writer を通じて
.guard_shadow_log.jsonlへ strict JSON object の改行終端 record を append する。 - AC2: canonical writer は trusted directory FD と
O_NOFOLLOWを用い、final path が symlink/directory/FIFO/socket/device、または open 前後で identity 不一致のとき file を変更せず非0で fail-close する。 - AC3: canonical writer は regular file を 0600 として扱い、明示された size limit 超過と partial-write failure で truncate/replace せず非0で fail-close する。
- AC4: 複数 OS process を barrier で同時起動しても、Python helper・両 shell hook 経路・Node caller 由来の全 record が strict JSONL として欠落・部分混在なく保存される。
- AC5:
skill_runtime_exec.pyの 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 typed postcondition は変更せず、SSOT は writer 側 hardening と事後検査の責務境界を明記する。
Runtime Verification Applicability
decision: immediate
reason: "実 producer、並行 process、FD/path kind、partial write と size limit を実ファイルシステムで検証する必要がある"
applicable_acs: [AC1, AC2, AC3, AC4]
execution_environment: "Linux/WSL、uv-managed Python、Node.js、POSIX file descriptor と flock を利用可能な専用 worktree"
skip_conditions: "必要な Python/Node/POSIX 機能が欠ける場合だけ exit 77 で停止し、それ以外の writer/test failure は FAIL とする"
fallback_policy: "fallback 実装・direct append・mock のみの成功は PASS としない"
artifact_requirements: "artifacts/runtime-verification-AC<N>-<timestamp>.log に producer 別 record count、file mode、inode、size、executor exit code を保存する"Verification Commands
# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py::test_python_and_node_callers_share_canonical_writer -q
# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py::test_nonregular_and_identity_change_fail_closed_without_mutation -q
# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py::test_size_limit_and_partial_write_fail_closed_without_replacement -q
# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py::test_barrier_synchronized_real_producers_preserve_all_records -q
# AC5
# baseline-expect: pass
$ git diff --exit-code origin/main...HEAD -- scripts/agent-guards/skill_runtime_exec.pyAllowed Paths
- .claude/hooks/shadow_log.py
- scripts/check-codex-agents.mjs
- scripts/agent-guards/shadow_log_canonical_writer.py(新規)
- scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py(新規)
- docs/dev/agent-skill-boundaries.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
openat2()相当が必須で、O_NOFOLLOWと trusted directory FD による代替では受容できないと判明した場合- log rotation 又は record schema 再設計が size limit 導入に必須と判明した場合
- 動作検証 AC の VC が exit 77 を返した場合
Required Skills
- Python(POSIX file descriptor / pytest 統合テスト)
- Node.js(child process integration)
- POSIX ファイルシステムの race-condition 耐性設計
Required Design References
- docs/dev/agent-skill-boundaries.md#Parallel Agent Runtime Safety
- Issue 実装: 契約実行ラッパーのunauthorized_write_path誤検知が.guard_shadow_log.jsonlでも発生する問題を修正する #1563
- PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572
Scope Delta
- source: post-merge-cleanup / PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 / safety-claims-toctou
- validated_scope_delta: PR 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 は実行終了時点の事後検査のみを保証し、書込み開始前の symlink 差し替え完全防止は明示的に Out of Scope。未起票 follow-up として検出。
- deterministic_fix: 全 producer を同一 canonical writer に集約し、writer 内の FD/identity/lock/size/write-loop を回帰テストで固定する。
- workaround_comparison: prompt 注記や executor 側の許容拡大は、producer の direct append と path race を残し再現可能な防御にならないため採用しない。
Delivery Rule
- 1 Issue = 1 PR とし、専用 worktree で実装して Draft PR を作成する。
Notes for Reviewer
- Dedupe key:
follow-up:squne121/loop-protocol:pr/1572:guard-shadow-log-canonical-writer-toctou - 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 のマージ済み postcondition を保持する writer hardening follow-up であり、実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 の session manifest external-root concern とは対象 path と outcome が異なる。
- Scope Collision (C1): related_issue=実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546, 実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542, 実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363, 実装: issue-refinement-loop の SubAgent 起動を planner-declared launch plan に制限する #1288, 導入: agent-ops-auditor SubAgent を追加し、監査を main context から隔離する #1025, 実装: feat(agent-ops): issue-refinement-ops-review で agent_ops_inventory を必須 preflight 化する #1009, 実装: schema-governance.md の Initial Known Schemas を catalog から生成するスクリプト(#131 FU-5) #521, 実装: playtest-log の JSON Schema / validator の追加 #420, 実装: docs/dev/agent-skill-boundaries.md に impl-review-loop 開始の人間起点ゲート原則を追記 #260, 改善: VC 設計ガイドラインに否定パターン誤マッチ防止チェックを追加 #237, 実装: rate limit / API error 由来の停止を StopFailure hook でログ保存し resume playbook を整備する #225, 実装: normal Stop による未完了 LOOP_STATE を一度だけ補正する Stop hook safety net を導入する #224, 改善: executable bit audit CI guard の適用範囲を .claude/skills 外のスクリプトへ拡張する #213, 実装: .claude/skills 配下スクリプトの executable bit を監査し CI guard を追加する #205, 実装: AI駆動開発における SubAgent 観察結果の Orchestrator ルーティングと GitHub 反映責務を定義する #197, 実装: docs/dev/agent-skill-boundaries.md に「方針 vs 作業手順」の責務分離原則と Issue 本文オーサリングの方針記述を追加する #82, 実装: .claude/settings.json の Bash allow リストに uv 系コマンド (uv run / uv lock / uv sync) を追加する #63, 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56; overlapping_paths=.claude/hooks/shadow_log.py, docs/dev/agent-skill-boundaries.md, scripts/agent-guards/shadow_log_canonical_writer.py, scripts/agent-guards/tests/test_guard_shadow_log_canonical_writer.py, scripts/check-codex-agents.mjs.
- non_conflict_reason: 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 は session manifest の外部 root、実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542 は Git staging guard、実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363 は strict trace attribution を扱い、本 Issue の canonical shadow-log writer/FD write protocol を扱わない。残る候補は共有 SSOT、広い
scripts/docsglob、又は hook/agent runtime の別 concern による path-only hit である。 - edit_intent:
.claude/hooks/shadow_log.pyとscripts/check-codex-agents.mjsは direct append を共通 writer 呼出しへ限定して置換し、SSOT は shadow-log writer の責務境界の段落だけを追記する。 - dependency_ordering: 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を .guard_shadow_log.jsonl 専用の型付き exact-file ポリシーで解消する #1572 は merge 済みである。本 Issue は open candidate の完了を前提にせず、実装開始時に overlap state を再確認する。対象 path を同時に変更する Open PR が現れた場合は実装を停止して serialisation を Issue comment に記録する。
- non_conflict_reason: 実装:session-manifest-peer-writeをruntime-guardの誤検知から分離する #1546 は session manifest の外部 root、実装: workspace モードと Git staging guard の Allowed Paths 契約を整合させる #1542 は Git staging guard、実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363 は strict trace attribution を扱い、本 Issue の canonical shadow-log writer/FD write protocol を扱わない。残る候補は共有 SSOT、広い
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Aug 19, 2026
Disposition: superseded / not_planned
2026-08-20 OWNER decision により、
.guard_shadow_log.jsonlは security authority / canonical audit ledger ではなく shadow rollout / false-positive 観測用の local telemetry であることが確認され、subsystem 自体(persistent shadow logging)を廃止する方針が確定した。削除する telemetry artifact の writer を TOCTOU 耐性・canonical writer 化で harden することは、この decision と直接矛盾する(廃止対象のセキュリティサーフェスをむしろ維持・拡大することになるため)。したがって本 Issue(canonical writer / common lock / 0600 / size limit / partial-write hardening の実装)は着手しない。
superseded/not_planned本 Issue は close する。過去の contract 内容自体は歴史的事実として書き換えない。