Repository navigation
Description
Parent Issue
なし(単独改善。#1830 の post-merge follow-up)
Machine-Readable Contract
contract_schema_version: "1.0"
issue_kind: implementation
parent_issue: null
goal_ref: "#1830"
change_kind: fixParent Goal Ref
#1830 は Codex session-recording を passive advisory recorder として再設計し、fail-open(記録失敗が agent 実行をブロックしない)であることを前提にしていた。PR #1849 でこの recorder(scripts/session-recording/codex-hook-adapter.mjs)が実装された。
Current Validated Scope
scripts/session-recording/codex-hook-adapter.mjs を直接確認したところ、以下 2 点が fail-open 契約・privacy 前提を満たしていない。
- L11
const WRITE_BUDGET_MS = 1000と L72-85withinWriteBudget()はPromise.race([promise, timeoutPromise])で実装されているが、timer.unref?.()(L79)は setTimeout の timer のみを unref し、recordBestEffort()(L63-70)内のmkdir/appendFileの fs promise 自体はキャンセルされない。timer 側が先に resolve してmain()は先に進めるが、pending の fs 操作は取り消されないまま残り続ける。recordingDirectory()が指す先(CODEX_PASSIVE_RECORDING_DIR環境変数または~/.codex/session-recording)がブロッキングする I/O 経路(reader のいない named pipe 等)だった場合、この pending 操作が Node のイベントループを保持し続け、hook の実プロセス終了が「1秒で fail-open して終了する」契約通りにならない。 - L64
appendFile(resolve(directory, 'passive-events.jsonl'), ..., { mode: 0o600 })は新規作成時のみmodeが適用される(Node.js のfs.promises.appendFile仕様)。既存のpassive-events.jsonlが別 permission・別 owner・non-regular file(symlink・FIFO・socket 等)であっても、target のlstatや type 検証を一切行わずそのまま書き込む。
Remaining Parent Gaps
blocked I/O の実環境再現(named FIFO を使った Linux CI 上の統合テスト)は、CI 実行環境の制約確認を要するため本 Issue の AC には含めず、コードロジックの修正と単体テストのみを Scope とする。CI 統合テストの追加は別途判断が必要であれば follow-up とする。
Outcome
scripts/session-recording/codex-hook-adapter.mjs の recordBestEffort() / withinWriteBudget() が、write budget 経過後に pending の fs 操作を実際に打ち切る(または「1秒 write budget」の主張を実装の実態に合わせて best-effort 記述へ修正する)コミットと、書き込み先ファイルの type/owner を検証してから append する(symlink・FIFO・socket 等の non-regular file を拒否する)コミットが追加され、対応する単体テストが pass する状態を完了とする。
In Scope
withinWriteBudget()が timeout に達した場合、pending の fs 操作(mkdir/appendFile)を実際に打ち切れる構造に変更する。プロセス自体を kill 可能な helper 経由にする、またはfs.promisesの代わりに abort 可能な I/O 経路に置き換えるなど、実装方針は Issue 起票者が指定しない(実装時に判断する)- 上記が technically 困難で hard deadline を保証できない場合は、
WRITE_BUDGET_MSの名称・コメント・関連ドキュメント(docs/dev/session-recording-policy.md等)を「1秒で確実に打ち切る」ではなく「best-effort、実際の上限は hook timeout(3秒)」である旨に修正する recordBestEffort()で書き込み対象ファイルのlstatを行い、存在する場合は regular file であることを確認してからappendFileする。symlink・FIFO・socket 等の non-regular file の場合は書き込みをスキップする
Out of Scope
- named FIFO を用いた実環境 blocked I/O の CI 統合テスト追加
- recording directory 自体の owner/mode 検証の強化(対象は
passive-events.jsonlファイル本体のみ)
Acceptance Criteria
- AC1:
withinWriteBudget()の timeout 到達時、pending の fs 操作が実際に打ち切られる(helper process の kill、または abort 可能な I/O への置き換え)挙動が単体テストで確認できる。またはWRITE_BUDGET_MS関連のコメント・ドキュメントが best-effort である旨に修正されている - AC2:
recordBestEffort()が書き込み対象の既存ファイルに対してlstatを実行し、non-regular file(symlink・FIFO・socket)を検出した場合は書き込みをスキップするロジックが実装されている - AC3: 既存 pytest / vitest(
tests/session_recording/、tests/hooks/配下)が変更後も pass する
Verification Commands
# AC1
$ git grep -n "WRITE_BUDGET_MS" scripts/session-recording/codex-hook-adapter.mjs# AC2
$ git grep -c "lstat" scripts/session-recording/codex-hook-adapter.mjs# AC3
$ rtk pnpm vitest run tests/hooks/Allowed Paths
scripts/session-recording/codex-hook-adapter.mjsscripts/session-recording/tests/(存在する場合)tests/hooks/codex-harness-advisory-recorder.test.tsdocs/dev/session-recording-policy.md(記述修正のみ、コードの実体変更を伴わない場合)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
Node.js(fs.promises、child_process、AbortSignal 有無の理解)
Required Design References
なし
Activity
squne121 commentedon Aug 30, 2026
not_planned として close します。
対象の
scripts/session-recording/codex-hook-adapter.mjsは Issue #2412(PR #2428)でnative Codex CLI runtime retirement(Issue #2161)の一環として削除されました。
write budget / file-type validation の対象そのものが存在しなくなったため、本 Issue の
実装対象はなくなりました。
superseded by: #2161(native Codex CLI retirement)、#2412(adapter DELETE_CHAIN)
OWNER レビュー(PR #2428 review, https://github.com/squne121/loop-protocol/pull/2428#issuecomment-5466835712)
での明示判断に基づく disposition です。