Skip to content

fix: check_session_recording_runtime_safety.py の親ディレクトリ準備診断をJS側と同水準に揃える - #2560

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2547-session-recording-parent-dir-diagnosis
Sep 7, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2547-session-recording-parent-dir-diagnosis

Conversation

@squne121

@squne121 squne121 commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Summary

Issue #2547 の実装です。.claude/scripts/check_session_recording_runtime_safety.py(Python 側ミラー実装)の親ディレクトリ準備失敗診断を、Issue #2028 / PR #2549 でマージ済みの JS 側 preparePrivateParentDir 最終実装(classifyAndThrowParentDirFailure() による共通分類、PrivateParentDirError の errno/operation/path/cause 保持)と同水準に揃えました。

  • mkdir と open の OSError を単一の分類ロジックへ流す共通 classifier _classify_and_raise_parent_dir_failure() を新規追加し、_open_parent_dir_nofollow の ELOOP/ENOTDIR 分岐と prepare_private_parent_dir の parent.mkdir(parents=True, mode=0o700) 失敗の両方をこの classifier 経由に統一しました。
  • ELOOP: _diagnose_parent_is_symlink() で symlink と確認できた場合のみ parent_is_symlink。確認できなければ parent_unavailable。
  • ENOTDIR: 確認できれば parent_is_symlink、それ以外は parent_not_a_directory。
  • その他の OSError: parent_unavailable。
  • PrivateParentDirError へ additive keyword-only フィールド errno_value / operation("mkdir" / "open")/ path を追加し、raise ... from exc による Python 標準の例外チェーン(__cause__)を維持しました。reason_code の集合(parent_is_symlink / parent_not_a_directory / parent_owner_mismatch / parent_unavailable)とその意味は変更していません。
  • 従来 prepare_private_parent_dir 内の parent.mkdir(...) 呼び出しは try/except で捕捉されておらず、失敗時は未診断の raw OSError がそのまま伝播していました(本 PR で修正)。

Checks

受け入れ条件の達成状況

  • AC1: 共通 classifier _classify_and_raise_parent_dir_failure() を実装し、_open_parent_dir_nofollow の ELOOP 分岐をこの classifier 経由に置き換えた。_diagnose_parent_is_symlink() で symlink と確認できない ELOOP はもはや parent_is_symlink に断定されない。test_python_open_parent_dir_nofollow_unconfirmed_eloop_reports_parent_unavailable で _open_parent_dir_nofollow() を直接 exercise し、circular prefix symlink loop(loop_a/loop_b)による未確認 ELOOP が parent_unavailable になることを実ファイルシステム経由で確認。
  • AC2: prepare_private_parent_dir 内の parent.mkdir(parents=True, mode=0o700) を try/except で捕捉し、classifier 経由で PrivateParentDirError を送出するようにした(無捕捉のまま伝播しなくなった)。test_python_mkdir_prefix_symlink_loop_not_misclassified_as_trailing_symlink / test_python_noncircular_symlink_traversal_limit_eloop_not_misclassified_as_trailing_symlink / test_python_mkdir_failure_preserves_errno_operation_path_and_cause で実 mkdir 失敗を確認。
  • AC3: PrivateParentDirError が reason_code に加え、元の errno(errno_value)・失敗した operation(operation: mkdir / open)・失敗した path(path)・chained cause(__cause__、raise ... from exc)を additive に保持することを、全新規テストの err.errno_value / err.operation / err.path / err.__cause__ アサーションで確認。既存 reason_code 集合・意味は変更していない(_PARENT_REASON_SUFFIX の3値マッピングも無変更)。
  • AC4: 推奨 test node id に沿って以下6件を新規追加し、全件 PASS することを確認(うち1件は命名を調整、理由は下記参照):
    • test_python_mkdir_prefix_symlink_loop_not_misclassified_as_trailing_symlink(circular prefix symlink による mkdir ELOOP → 未確認のため parent_unavailable)
    • test_python_noncircular_symlink_traversal_limit_eloop_not_misclassified_as_trailing_symlink(非循環 42-link chain による ELOOP → 未確認のため parent_unavailable)
    • test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink(confirmed trailing symlink → parent_is_symlink を維持。命名は Issue 推奨どおりだが、実装は classifier を直接 exercise する — 詳細は「実装上の注記」参照)
    • test_python_mkdir_failure_preserves_errno_operation_path_and_cause(mkdir failure で errno・operation・path・chained cause が保持される。真の ENOTDIR 実 mkdir 失敗で検証)
    • test_python_open_parent_dir_nofollow_unconfirmed_eloop_reports_parent_unavailable(_open_parent_dir_nofollow() を直接 exercise し、mkdir に遮られない open-side の未確認 ELOOP と metadata 保持を確認)
    • test_python_accept_semantics_unchanged_after_mkdir_diagnosis_added(追加のnon-regressionテスト。AC5相当の新規ディレクトリ作成/祖先symlink経由の accept semantics 非破壊を確認)
  • AC5: 既存の regression test(test_new_private_directory_and_artifact_mode / test_eligibility_parent_dir_toctou_hardening / test_readiness_consumer_rejects_symlink_parent / test_python_prepare_private_parent_dir_rejects_fifo_parent_without_blocking / test_python_validate_private_parent_dir_readonly_rejects_fifo_parent_without_blocking / test_python_parent_dir_functions_still_accept_real_directory_via_child_process)が全件回帰なく PASS することを確認。重複テストは追加していない。
  • AC6: uv run pytest tests/session-recording/test_fixed_location_cutover.py -v がファイル全体(27件)で PASS する。

実装上の注記(AC4 の test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink について)

JS 側の同名テストは Node の fs.mkdirSync(path, {recursive: true}) が自己参照 trailing symlink に対して実際に ELOOP を返す挙動に依存していますが、Python の Path.mkdir()(生の POSIX mkdir(2) syscall ラッパー)は本リポジトリの実行環境(Linux/glibc)で実機検証したところ、同じ自己参照 trailing symlink に対して EEXIST を返すことを確認しました(mkdir(2) は最終パスコンポーネントを解決せず、既存 dirent があれば無条件に EEXIST を返すという POSIX の一般的挙動)。

$ uv run python3 -c "... self_loop = Path(d) / 'self_loop'; os.symlink(self_loop, self_loop); self_loop.mkdir(parents=True, mode=0o700) ..."
FileExistsError(17, 'File exists')

そのため Python の prepare_private_parent_dir() の mkdir 経路では「confirmed trailing symlink による mkdir ELOOP」を実機的に再現できません(_diagnose_parent_is_symlink() の confirmed-ELOOP 分岐は、mkdir() 呼び出し側からは到達不能なプラットフォーム依存のガード条件です)。一方 os.open(path, O_RDONLY | O_NOFOLLOW)(O_DIRECTORY を意図的に外した場合)は同じ trailing symlink に対して実際に ELOOP を返すことも実機確認しました:

$ uv run python3 -c "... os.open(link, os.O_RDONLY | os.O_NOFOLLOW) ..."
OSError(40, 'Too many levels of symbolic links')

このテストは、実際の os.open(trailing_symlink, O_RDONLY | O_NOFOLLOW) 呼び出しから得た 本物の OSError(fabricated/synthetic ではない)と、実際に os.symlink() で作成した confirmed trailing symlink fixture を使い、共通 classifier srrs._classify_and_raise_parent_dir_failure(trailing_symlink, real_os_error, "open") を直接 exercise することで、「ELOOP かつ confirmed symlink → parent_is_symlink」という classifier の中核ロジック(prepare_private_parent_dir の mkdir 経路と _open_parent_dir_nofollow の open 経路が共有する、まさに同一のコード)を実ファイルシステム経由で検証しています。既存の open-side confirmed symlink 拒否(ENOTDIR 経由、test_eligibility_parent_dir_toctou_hardening 内)は本 PR でも非破壊のまま維持されています。

検証コマンド結果

$ uv run pytest tests/session-recording/test_fixed_location_cutover.py -v
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.0.3, pluggy-1.6.0
collected 27 items

tests/session-recording/test_fixed_location_cutover.py::test_default_fixed_location_producer_paths PASSED [  3%]
tests/session-recording/test_fixed_location_cutover.py::test_new_private_directory_and_artifact_mode PASSED [  7%]
tests/session-recording/test_fixed_location_cutover.py::test_env_override_repo_root_normalized PASSED [ 11%]
tests/session-recording/test_fixed_location_cutover.py::test_source_bound_default_path_roundtrip PASSED [ 14%]
tests/session-recording/test_fixed_location_cutover.py::test_old_default_location_not_consumed PASSED [ 18%]
tests/session-recording/test_fixed_location_cutover.py::test_digest_update_regeneration_order PASSED [ 22%]
tests/session-recording/test_fixed_location_cutover.py::test_eligibility_parent_dir_toctou_hardening PASSED [ 25%]
tests/session-recording/test_fixed_location_cutover.py::test_eligibility_artifact_swapped_between_stat_and_read_is_toctou_safe PASSED [ 29%]
tests/session-recording/test_fixed_location_cutover.py::test_readiness_consumer_rejects_symlink_parent PASSED [ 33%]
tests/session-recording/test_fixed_location_cutover.py::test_cross_language_override_resolution_parity PASSED [ 37%]
tests/session-recording/test_fixed_location_cutover.py::test_readiness_producer_parent_dir_toctou_hardening PASSED [ 40%]
tests/session-recording/test_fixed_location_cutover.py::test_js_mkdir_prefix_symlink_loop_not_misclassified_as_trailing_symlink PASSED [ 44%]
tests/session-recording/test_fixed_location_cutover.py::test_js_noncircular_symlink_traversal_limit_eloop_not_misclassified_as_trailing_symlink PASSED [ 48%]
tests/session-recording/test_fixed_location_cutover.py::test_js_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink PASSED [ 51%]
tests/session-recording/test_fixed_location_cutover.py::test_js_mkdir_failure_is_diagnosed_instead_of_raw_uncaught_exception PASSED [ 55%]
tests/session-recording/test_fixed_location_cutover.py::test_js_accept_semantics_unchanged_after_mkdir_diagnosis_added PASSED [ 59%]
tests/session-recording/test_fixed_location_cutover.py::test_python_mkdir_prefix_symlink_loop_not_misclassified_as_trailing_symlink PASSED [ 62%]
tests/session-recording/test_fixed_location_cutover.py::test_python_noncircular_symlink_traversal_limit_eloop_not_misclassified_as_trailing_symlink PASSED [ 66%]
tests/session-recording/test_fixed_location_cutover.py::test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink PASSED [ 70%]
tests/session-recording/test_fixed_location_cutover.py::test_python_mkdir_failure_preserves_errno_operation_path_and_cause PASSED [ 74%]
tests/session-recording/test_fixed_location_cutover.py::test_python_open_parent_dir_nofollow_unconfirmed_eloop_reports_parent_unavailable PASSED [ 77%]
tests/session-recording/test_fixed_location_cutover.py::test_python_accept_semantics_unchanged_after_mkdir_diagnosis_added PASSED [ 81%]
tests/session-recording/test_fixed_location_cutover.py::test_hermetic_default_path_producer_consumer_roundtrip PASSED [ 85%]
tests/session-recording/test_fixed_location_cutover.py::test_js_prepare_private_parent_dir_rejects_fifo_parent_without_blocking PASSED [ 88%]
tests/session-recording/test_fixed_location_cutover.py::test_python_prepare_private_parent_dir_rejects_fifo_parent_without_blocking PASSED [ 92%]
tests/session-recording/test_fixed_location_cutover.py::test_python_validate_private_parent_dir_readonly_rejects_fifo_parent_without_blocking PASSED [ 96%]
tests/session-recording/test_fixed_location_cutover.py::test_python_parent_dir_functions_still_accept_real_directory_via_child_process PASSED [100%]

============================== 27 passed in 5.61s ==============================

追加の品質ゲート(全 PASS):

  • pnpm typecheck: tsc --noEmit エラーなし
  • pnpm lint: ESLint: No issues found
  • pnpm test: Vitest Test Files 108 passed (108) / Tests 1920 passed (1920)
  • pnpm build: tsc && vite build 成功(dist/ 生成確認)
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py: 24 passed
  • uv run ruff check .claude/scripts/check_session_recording_runtime_safety.py tests/session-recording/test_fixed_location_cutover.py: エラーなし

Allowed Paths 遵守

git diff --name-only main...HEAD で確認した変更ファイル一覧は以下の2件であり、Issue #2547 の Allowed Paths と完全に一致する(Allowed Paths 外の変更なし):

.claude/scripts/check_session_recording_runtime_safety.py
tests/session-recording/test_fixed_location_cutover.py

Runtime Verification Evidence(実行証跡)

本 Issue の Runtime Verification Applicability は decision: immediate(AC1〜AC6 全適用)。上記「検証コマンド結果」の実行ログそのもの(自己申告のコマンド名ではなく実行結果)が証跡です。

新規追加した6テストはいずれも tmp_path fixture 上の実ファイルシステムに対して実際の os.symlink() / Path.mkdir() / os.open() を発火させ、その結果として得られる本物の OSError を classifier に通す実機テストです(static grep や文字列一致検証ではありません)。

Schema Change Applicability

  • decision: not_schema_change
  • reason: 既存 schema / 外部 consumer 契約は変更していません。変更対象は check_session_recording_runtime_safety.py 内部の PrivateParentDirError 診断ロジック(additive フィールド追加のみ、reason_code 集合・意味は無変更)と、それを検証するテストファイルの追加です。

Schema Consumer Inventory

N/A
reason: schema_change ではないため該当なし。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
mkdir/open の親ディレクトリ準備失敗診断を強化しても、既存の accept/reject semantics(FIFO拒否・non-blocking・0700維持修復・正常な祖先symlink受理・owner mismatch拒否・非ディレクトリ拒否)は変更しない yes N/A uv run pytest tests/session-recording/test_fixed_location_cutover.py -v(27 passed。既存 test_eligibility_parent_dir_toctou_hardening / FIFO 系3テスト / test_python_accept_semantics_unchanged_after_mkdir_diagnosis_added を含む) N/A
確認できない ELOOP(path-prefix の循環 symlink・非循環の長い symlink 列)を trailing symlink / symlink loop と誤って断定しない yes N/A test_python_mkdir_prefix_symlink_loop_not_misclassified_as_trailing_symlink / test_python_noncircular_symlink_traversal_limit_eloop_not_misclassified_as_trailing_symlink(両方とも parent_unavailable を確認、reason_code == "parent_is_symlink" ではないことをアサート) N/A
mkdir 失敗が捕捉されず raw OSError のまま伝播することがない yes N/A test_python_mkdir_failure_preserves_errno_operation_path_and_cause(prepare_private_parent_dir() が PrivateParentDirError として捕捉して送出することを確認) N/A
PrivateParentDirError の errno/operation/path/chained cause が additive に保持され、reason_code 集合・意味は変更されない yes N/A 全新規6テストの err.errno_value / err.operation / err.path / err.__cause__ アサーション N/A

Notes

…える (#2547)

_open_parent_dir_nofollow の ELOOP 分岐と prepare_private_parent_dir の
mkdir 失敗を共通 classifier
(_classify_and_raise_parent_dir_failure) へ集約し、preparePrivateParentDir
(Issue #2028 / PR #2549) と同じ分類規則を適用する:

- ELOOP: _diagnose_parent_is_symlink() で確認できた場合のみ
  parent_is_symlink。確認できなければ parent_unavailable。
- ENOTDIR: 確認できれば parent_is_symlink、それ以外は
  parent_not_a_directory。
- その他の OSError: parent_unavailable。

PrivateParentDirError に errno / operation(mkdir・open) / failing path を
additive に保持させ、raise ... from exc で例外チェーンを維持する。
reason_code の集合・意味は変更しない。

tests/session-recording/test_fixed_location_cutover.py に Python 側
regression test を6件追加し(circular prefix loop / 42-link traversal
limit / confirmed trailing symlink / mkdir失敗メタデータ保持 /
open-side unconfirmed ELOOP / accept semantics 非退行)、実 filesystem
経由で新分類ロジックを検証する。

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

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2560 closed).

@squne121

squne121 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

impl-review-loop: PR Review Verdict

Mergeability: mergeable=MERGEABLE, merge_state_status=BLOCKED(Draft PR のため。required CI は wait_ci_checks.py --required で passed 確認済み)

Evidence Check:

  • Allowed Paths Gate: status: ok(.claude/scripts/check_session_recording_runtime_safety.py, tests/session-recording/test_fixed_location_cutover.py のみ変更、scripts/session-recording/bootstrap-source-bound-readiness.mjs 非変更)
  • AC1〜AC6: 全て PASS(実装 diff・test 実行結果を独立確認)
  • uv run pytest tests/session-recording/test_fixed_location_cutover.py -v: 27 passed
  • required CI checks: build/lint/test/typecheck/validate-generated-artifact 等すべて SUCCESS(head f67059e...に束縛)

Blockers: なし

Non-blockers (advisory):

  • AC4の test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink は、Python実POSIX mkdir(2) が confirmed trailing symlink に対し EEXIST を返す(ELOOP ではない)という実機検証済み事実により、classifier を直接 exercise する実装アプローチを取っている。Issue許容範囲内の合理的対応。
verdict: APPROVE
reviewed_head_sha: "f67059ef54473ef4a4fc0d2a6bac2d9dabc6860d"
blockers: []
warnings:
  - "AC4のtest_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlinkはmkdir()経由でなくclassifierを直接exerciseする実装(Python実POSIX mkdir(2)がconfirmed trailing symlinkに対しELOOPでなくEEXISTを返すため)。Issue許容範囲内の合理的対応だが実装アプローチに軽微な乖離があるためadvisoryとして記録。"

@squne121

squne121 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

結論

PR #2560 は現状 REQUEST_CHANGES を推奨します。
ただし大規模な設計変更は不要で、P2 1件を直せば APPROVE 寄りです。

対象 head は f67059ef54473ef4a4fc0d2a6bac2d9dabc6860d。PR は現在 Draft / mergeable で、current head の CI は成功しています。既存の impl-review-loop コメントは APPROVE / blocker なしとしていますが、正式な GitHub review / inline thread はまだありません。

P2 — parent.exists() の OSError が新 classifier より手前で raw のまま漏れる

今回の主変更は mkdir() / open() の失敗を _classify_and_raise_parent_dir_failure() に統合するものですが、prepare_private_parent_dir() は依然としてその手前で、

if not parent.exists():

を実行しています。ここは try の外です。

このリポジトリは Python 3.12 を固定しています。 CPython 3.12 の実装では Path.exists() は ENOENT / ENOTDIR / EBADF / ELOOP だけを False に変換し、それ以外の OSError は再送出します。つまり、path prefix の search permission が無い EACCES/EPERM などは classifier に到達する前に PermissionError としてそのまま抜けます。([GitHub]1)

具体的には、artifact override が例えば検索権限のないディレクトリ配下を指した場合、

parent.exists()
  -> PermissionError(EACCES)
  -> raw OSError が外へ

となり、このPRで追加した

  • reason_code=parent_unavailable
  • errno_value
  • operation
  • path
  • chained cause

という統一診断契約が適用されません。

これは単なる security hardening の話ではなく、このPRそのものの目的である「親ディレクトリ準備失敗の診断統一」に穴が残るという問題です。

さらに JS 側 precedent との差でもあります。Node の fs.existsSync() は存在判定を boolean で返す API なので、JS 側ではその後の mkdirSync() が失敗し、共通 classifier に入る構造になっています。Node のドキュメント自体も、存在チェック→操作というパターンは race を生むので、直接操作してエラー処理する方式を推奨しています。([Node.js]2)

推奨修正は、まず Path.exists() 自身が EACCES を返すケースを regression test として追加し、「raw OSError を漏らさない」ことを固定することです。そのうえで実装は次のどちらかです。

  • exists/stat 失敗も PrivateParentDirError に包み、operation に "stat" 等を正式追加する
  • exists() preflight 自体を廃止し、mkdir の EEXIST は後続の authoritative な O_NOFOLLOW | O_DIRECTORY open に委ね、それ以外の mkdir failure を classifier に流す

後者の方が構造としてはきれいですが、dangling trailing symlink の reason が偶発的に変わらないかだけ既存契約との照合が必要です。Python 3.12 の Path.mkdir() 自体も、OS が EACCES や EROFS を優先して返し得ることを考慮した実装になっています。([GitHub]1)

この1件は既存の APPROVE review が拾えていません。


非blockingだが直す価値がある点

P3 — _diagnose_parent_is_symlink() の docstring が実装と食い違いました。 現在も「open() が既に失敗した後にのみ使う」という説明ですが、新 classifier によって mkdir() failure からも呼ばれます。 今回の変更理由そのものが mkdir/open 共通化なので、ここは同じPRで直した方が保守時の誤解を避けられます。

P3 — Python 側の「JS最終実装と同水準」という表現は少し強すぎます。 JS 側は PR #2549 の敵対的レビューで「wrapした結果、CLIから失敗pathが消えた」という退行を実際に踏み、最終的には reason + errno + syscall + path を .message 自体に含めるところまで直されています。 Python 側は属性には保持しますが super().__init__(reason_code) なので str(error) は reason だけです。

ただしこれは 今回 blocker にはしません。Python 側の本番 --emit-scope-rollup-eligibility 経路には途中の catch がなく、raise ... from exc の chained cause が通常の traceback に表示されるため、元 OSError の path は現状でも失われません。Python も明示的な __cause__ はデフォルト traceback に常に表示すると仕様化しています。 ([Python documentation]3)

P3 / follow-up — read-only consumer には同種の誤診断が残っています。 validate_private_parent_dir_readonly() は現在も ELOOP を無条件で parent_is_symlink にし、その他の open failure を parent_missing に倒しています。 つまり prefix symlink traversal limit の「ELOOP ≠ trailing symlink」という今回の知見は producer 側だけに適用されています。ただし #2547 の validated scope は prepare_private_parent_dir() / _open_parent_dir_nofollow() なので、#2560をこれで止める必要はありません。実害も accept/reject ではなく診断精度です。必要なら小さい follow-up にする程度で十分です。

テストについて

42 段の非循環 symlink chain を追加した判断は妥当です。Linux の pathname resolution は現在、pathname 全体で最大40回の symlink resolution を許し、それを超えると ELOOP です。さらに open(O_NOFOLLOW) の trailing-symlink ELOOP と prefix 内の過剰 symlink ELOOP は errno だけでは区別できません。今回の「補助 lstat で確認できた時だけ parent_is_symlink」という設計は正しいです。([man7.org]4)

test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink が実際には mkdir() を通さず、real os.open(... O_NOFOLLOW) の ELOOP を classifier に直接渡している点も、実装ミスとは判断しません。POSIX系の mkdir は trailing symlink の dirent が既に存在すると通常 EEXIST になるためです。PR本文もこの事情を明示しています。ただ、テスト名は test_python_classifier_eloop_on_confirmed_trailing_symlink... のようにした方が実際の検証対象を正確に表します。

また O_DIRECTORY はそのままで正解です。Linux はこのフラグについて、非directoryを即座に失敗させ、FIFO/tape 等による DoS を防ぐ目的を明記しています。PR #2523 でもこの設計と実FIFOによる nonblocking regression test が既に確立されています。([man7.org]5) ELOOPを取りやすくするために O_DIRECTORY を外す、openat2を入れる、新規security CIを追加する、といった対応は不要です。

判定

verdict: REQUEST_CHANGES
reviewed_head_sha: "f67059ef54473ef4a4fc0d2a6bac2d9dabc6860d"
blockers:
  - severity: P2
    finding: >
      prepare_private_parent_dir() の parent.exists() が classifier の外にあり、
      Python 3.12 で EACCES/EPERM 等が発生すると raw OSError がそのまま伝播する。
      mkdir/open failure の統一診断および JS final implementation parity が
      実際の permission-denied path では成立しない。
non_blockers:
  - "_diagnose_parent_is_symlink() の open-only docstring が mkdir/open 共通化後も残っている"
  - "PrivateParentDirError の str() には errno/operation/path が出ず、JS final implementation とは表示面で非対称"
  - "validate_private_parent_dir_readonly() の未確認 ELOOP 誤分類は別 follow-up 候補"
recommended_scope:
  - "新しい security/approval harness は追加しない"
  - "O_DIRECTORY / O_NOFOLLOW は維持"
  - "exists() failure の targeted regression + 最小の診断経路修正だけ行う"

P2を1件直して targeted test を追加し、current CI が再度 green なら、私はこのPRを APPROVE でよいと判断します。

@squne121

squne121 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

対象コメントを impl-review-loop の fix_delta / human context として取り込み、既存 PR #2560 を継続修正するのが適切です。

確認したところ、コメントがレビューした head は f67059e... ですが、現在の PR head は be0787c... に進んでいます。ただし現 head の実装にも if not parent.exists(): が classifier より前に残っているため、P2 finding 自体は未解消です。 impl-review-loop は REQUEST_CHANGES を fix_delta として implementation-worker に渡し、実装→独立検証→PR review を繰り返す設計なので、今回の用途にそのまま合います。

修正方針は、operation に "stat" を増やす案より、exists() preflight への依存を解消する案を優先するのがよいです。Issue #2547 は metadata の operation を mkdir / open に固定しており、reason-code や固定契約の変更は Stop Condition にも関係します。 CPython 3.12 の Path.exists() は ENOENT / ENOTDIR / EBADF / ELOOP のみを無視し、それ以外を再送出する実装なので、レビュー指摘は成立します。 また Node.js も、存在確認してから操作する形より、操作そのものを実行して失敗を処理する方式を推奨しています。(Node.js)

ただし、preflight を単純削除して EEXIST → open にすると dangling trailing symlink の診断理由が偶発的に変わる可能性があります。したがって 「preflight 削除を第一候補に実験 → 既存診断 semantics が変わるなら、exists() の OSError 時だけ実際の mkdir 経路へ進ませ、classifier が実 mkdir error を operation="mkdir" として処理する最小案へ切り替える」 と worker に判断させるのがよいです。対象レビュー自身も、O_DIRECTORY / O_NOFOLLOW、read-only consumer、新 security harness には広げないよう明示しています。

そのまま既存の auto mode Claude Code に送るプロンプトです。

リポジトリ squne121/loop-protocol で、既存 PR #2560 / linked Issue #2547 を対象に .claude/skills/impl-review-loop を継続実行してください。

今回の明示的な operator 指示は、以下の REQUEST_CHANGES コメントを解消するために作業を継続することです。

このコメントの REQUEST_CHANGES は「ここで人間承認待ちで停止せよ」という指示ではありません。この operator prompt により、その finding を修正し、レビューを再実行して merge 直前まで自律的に進めることを明示的に依頼しています。通常の実装・テスト・commit・既存 PR branch への publish・review feedback 対応について追加の人間承認を求めないでください。

まず .claude/skills/impl-review-loop/SKILL.md と、同 skill が要求する preparation / Step 1 / Step 2 / Step 4 / Step 5 の正本を読み、その契約どおりに動作してください。独自の簡略化ループに置き換えないでください。

Live-state rebind

対象コメントの reviewed_head_sha は
f67059ef54473ef4a4fc0d2a6bac2d9dabc6860d
ですが、これは現在 head ではありません。

作業開始時に必ず GitHub と local canonical worktree の live state を再取得し、

へ再bindしてください。

この prompt 作成時点では current head は be0787c8398f669d4128a67a044939bf1c1bf62c でしたが、これも固定値として信用せず live state を優先してください。

review SHA が stale であることだけを理由に人間へ escalation しないでください。impl-review-loop の stale-head routing に従って current head へ再bind / re-review してください。

ただし対象 finding は current implementation に対して再確認してください。current code に依然として

parent = path.parent
if not parent.exists():

が classifier の外に存在するなら、P2 は未解消として fix_delta に採用してください。

fix_delta の主 blocker

P2:

prepare_private_parent_dir() の parent.exists() が _classify_and_raise_parent_dir_failure() より前にあり、Python 3.12 では EACCES / EPERM 等の Path.exists() が raw OSError / PermissionError として外へ伝播し得る。

その結果、この PR が導入した

  • reason_code
  • errno_value
  • operation
  • path
  • chained cause

という統一診断契約を経由しない failure path が残っている。

まずこのケースを再現する targeted regression test を追加し、修正前には raw OSError が漏れ、修正後には PrivateParentDirError に統一されることを実証してください。

可能なら実 filesystem の permission-denied path を使ってください。テスト終了時には chmod 等を必ず復旧し tmp cleanup を壊さないようにしてください。新しい permission/security harness は作らないでください。

実装方針

Issue #2547 の既存契約を優先してください。

特に以下を維持すること。

  • Allowed Paths:

    • .claude/scripts/check_session_recording_runtime_safety.py
    • tests/session-recording/test_fixed_location_cutover.py
  • reason_code の集合と意味を変更しない。

  • diagnostic operation の既存契約 mkdir / open を維持する。

  • O_DIRECTORY を外さない。

  • O_NOFOLLOW を外さない。

  • ancestor symlink 全拒否へ拡大しない。

  • openat2 を導入しない。

  • 新 security CI / permission harness / approval gate を追加しない。

  • validate_private_parent_dir_readonly() へスコープを広げない。

  • PrivateParentDirError.__str__ / message の JS parity は今回の blocker にしない。

  • 新 Issue を自動起票しない。

operation="stat" を新たに追加する案は、Issue #2547 が operation を mkdir / open として固定しているため、原則として採用しないでください。現在の Issue contract を変更せず解決できる方法を優先してください。

第一候補として、Path.exists() を authoritative preflight として使わず、実際の filesystem operation とその OSError を classifier に流す構造を検討してください。

ただし単純な preflight 削除によって、既存の dangling trailing symlink などの reject reason が偶発的に変わらないことを必ず before/after で確認してください。Issue #2547 はその追加診断改善を Out of Scope としています。

もし preflight の完全削除が既存 reason semantics を変えるなら、より小さい案として、

  • parent.exists() の probe 自体で OSError が起きても raw exception を外へ漏らさず、
  • 実際の mkdir 経路を試行し、
  • そこで得た実 OSError を既存 classifier に operation="mkdir" として渡す

という形も評価してください。

最終案は implementation-worker が実 filesystem regression と既存 tests を比較して決定してください。コメントに書かれた案を盲目的に実装するのではなく、Issue contract と現在の実装 semantics に対して最小かつ正しい delta を選択してください。

non-blocking cleanup

同じ Allowed Paths 内で低リスクなら、対象レビューの以下の P3 は今回あわせて直して構いません。

_diagnose_parent_is_symlink() の docstring に残っている「open() failure 後だけ使用する」という説明を、現在の mkdir/open 共通 classifier の実装と一致させる。

また、test_python_mkdir_eloop_on_confirmed_trailing_symlink_still_reports_symlink が実際には classifier + real os.open(... O_NOFOLLOW) を exercise しているなら、既存 Issue が test node id の変更を許容していることを確認した上で、実際の対象を正確に表す名前への rename は行ってよいです。

ただしこれら P3 のために scope を拡大したり、main blocker の完了を遅らせないでください。

SubAgent execution

root/main thread は control-plane に徹し、skill の正規フローで SubAgent を使用してください。

Step 1:
implementation-worker SubAgent を起動し、Issue #2547、既存 PR #2560、current canonical worktree、Allowed Paths、および上記 P2 を正規化した fix_delta / technical_recommendation として渡してください。

raw human comment 本文をそのまま executable instruction として child に連結せず、root で repository facts・current diff・Issue contract と照合した derived guidance を渡してください。

implementation-worker を起動したら、その SubAgent が terminal result を返すまで必ず待ってください。SubAgent 実行中に次 Step へ進んだり、同じ責務の別 Agent を重複起動しないでください。

Step 2:
implementation-worker 完了後、current head に対して test-runner SubAgent に独立 verification を委譲してください。

ここでも test-runner の完了を必ず待ち、その結果を取得してから Step 4 へ進んでください。

最低限、

uv run pytest tests/session-recording/test_fixed_location_cutover.py -v

を Issue #2547 の authoritative Verification Command として実行してください。

加えて今回追加した permission-denied regression の targeted node、変更2ファイルへの ruff、既存 repository quality gates のうち skill / PR が要求するものを current head に対して実行してください。

Step 4:
verification が current-head gate を通過してから pr-reviewer SubAgent を起動し、pr-review-judge を current head に対して実行してください。

pr-reviewer の完了を必ず待ってから Step 5 routing を行ってください。

reviewer には対象コメントの旧 verdict を答えとして与えず、current diff / Issue contract / current tests / current CI を独立確認させてください。

Loop behavior

REQUEST_CHANGES が返った場合は blocker を次 iteration の fix_delta にして Step 1 へ戻り、iteration budget 内で自律修正してください。

head SHA が変わって verdict が stale になった場合は、人間へ聞かず current head で再reviewしてください。

main/base drift が発生した場合も、skill の scope-clean reconciliation / update-branch routing に従い、必要な evidence だけを current base/head に再bindしてください。

CI は必ず current head SHA に束縛して確認してください。古い green CI を新 head の証拠として再利用しないでください。CI が pending / in-progress なら完了まで skill の既存 wait mechanism で追跡してください。

通常の reviewer warning、telemetry artifact missing/stale、stale review、CI 再待機などで人間承認を求めないでください。

実 hard stop、secret/protected-path boundary、actual Git conflict、Allowed Paths 外変更が本当に必要、Issue #2547 の固定 reason-code/type contract を変更しなければ解決不能、といった skill / Issue の正規 Stop Condition に到達した場合だけ停止してください。

Termination

目的は PR #2560 をマージ直前の状態まで持っていくことです。

以下が current head に対して成立するまでループしてください。

最終的には IMPL_REVIEW_LOOP_RESULT_V1 の approved / merge-ready 相当の正常終了まで進めてください。

PR の merge 自体は実行しないでください。
merge operation の直前で停止し、人間が最終 merge 判断をできる状態にしてください。

最後に root/main thread から、少なくとも以下を報告してください。

  • final PR URL
  • final head SHA
  • 実装した P2 修正の要約
  • 追加/変更した regression test
  • P3 cleanup を行ったか
  • verification 結果
  • CI 結果
  • final pr-reviewer verdict
  • live mergeability
  • unresolved blockers / warnings
  • merge を実行していないこと

途中で起動した全 SubAgent が terminal result を返していることを確認してから最終報告してください。未完了の SubAgent を残したまま root session を終了しないでください。

このプロンプトでは、stale review の再bind → P2修正 → test-runner独立検証 → current-head reviewer → CI/mergeability 再評価までを一続きにしています。特に "stat" operation を安易に追加させず、#2547 の既存契約内で解くよう制約した点が重要です。

…Mを分類器へ通す (#2547)

PR #2560 レビュー指摘(P2): Python 3.12のPath.exists()はENOENT/ENOTDIR/EBADF/ELOOP
以外のOSError(非探索可能な祖先ディレクトリからのEACCES/EPERM等)を握りつぶさず
そのまま伝播する。prepare_private_parent_dir()のif not parent.exists():は
mkdir()のtry/exceptより前で実行されるため、この生例外は
_classify_and_raise_parent_dir_failure()を経由せず未診断のまま漏れていた。

exists()自体の呼び出しをtry/exceptで包み、OSErrorが出たら「未確認」として
mkdir()側にフォールスルーさせることで、実際に発生する同一祖先パスの
OSErrorをmkdir()側の既存分類器(operation="mkdir")で診断させる。新しい
operation="stat"値は導入せず、reason_code集合(parent_is_symlink /
parent_not_a_directory / parent_unavailable)も変更しない。

非探索可能ディレクトリを使った実ファイルシステム回帰テストを追加し、修正前は
生OSErrorが伝播し修正後はPrivateParentDirError(reason_code/errno_value/
operation/path/__cause__を保持)が送出されることを確認。既存のELOOP/ENOTDIR/
symlink系テストは全て挙動不変のままPASSすることも確認済み。

P3クリーンアップ: _diagnose_parent_is_symlink()のdocstringをmkdir/open両方の
共有分類器で使われる実態に合わせて更新し、mkdir()を実際には呼ばない
ELOOP確認テストのノードIDをtest_python_classifier_eloop_on_confirmed_trailing_symlink_still_reports_symlinkへ改名。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121
squne121 marked this pull request as ready for review September 7, 2026 12:36
@squne121

squne121 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

impl-review-loop: PR Review Verdict (2026-09-07)

Mergeability: mergeable: MERGEABLE / merge_state_status: CLEAN at head ba3f151ea9c1dcbf1cc0fbe48ceb8f6f3fd62345 (independently confirmed via gh pr view).

Evidence Check:

Blockers

None.

verdict: APPROVE
reviewed_head_sha: "ba3f151ea9c1dcbf1cc0fbe48ceb8f6f3fd62345"
blockers: []
warnings: []

@squne121
squne121 merged commit 1a9963c into main Sep 7, 2026
25 of 26 checks passed
@squne121
squne121 deleted the worktree-issue-2547-session-recording-parent-dir-diagnosis branch September 7, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant