Skip to content

fix(issue-refinement-loop): compact artifact wire pathをrepo-relativeにする - #1907

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1882-compact-review-wire-reference
Aug 1, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1882-compact-review-wire-reference

Conversation

@squne121

@squne121 squne121 commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Closes #1882(クローズ対象)
Refs #1887(merge 後の再実行対象)

この PR は #1882 の producer-level 最小スコープだけを扱い、#1887 は merge 後の fresh rerun に参照を留める。

Summary

  • 根本原因は、compact producer が filesystem の解決済み書込み先から wire path を作り、repo-relative 専用 validator と受理集合がずれていたことです。
  • 最小スコープは producer とその focused regression tests に限定し、wire reference を常に lexical な canonical repo-relative 値 .claude/artifacts/issue-refinement-loop/<positive issue number>/<filename> から構築します。
  • --repo-root なしでは canonical relative artifact-dir だけを受理します。任意相対値・traversal・非canonical artifact-dir は fail-closed です。
  • canonical base と issue slot の既存 component は os.lstat() で symlink を拒否し、issue directory の作成後・書込み直前にも再確認します。
  • success と producer failure は共通の failure envelope を使い、success artifact write の OSError も traceback を出さず fail-closed にします。
  • --issue-number は required の positive integer に統一します。

Checks

  • focused tests: 137 passed。producer と validator の境界を重点確認した。
  • related verification command: 1159 passed。関連経路への回帰がないことを確認した。
  • git diff --check、python3 -m compileall、変更 Python files の Ruff: PASS。静的検査も成功した。
  • current-head evidence: d4d5b4aeede32f9927d95be9a5db7575b57fb13b

受け入れ条件の達成状況

  • AC1: wire reference は filesystem の resolved path から逆算せず、canonical lexical repo-relative value から作る。
  • AC2: --repo-root なしでは canonical relative artifact-dir のみを受理し、それ以外は failure envelope で拒否する。
  • AC3: canonical base / issue slot の symlink を lstat で拒否し、作成後にも再確認する。
  • AC4: success write の OSError を含め、success/failure とも canonical failure envelope と fail-closed を維持する。
  • AC5: issue number の省略、0、負数を拒否し、positive integer を必須化する。
  • AC6: producer→validator の path policy を focused tests で確認した。

検証コマンド結果

  • focused producer / validator regression: 137 passed。current head 上で focused 回帰を確認した。
  • related verification command: 1159 passed。関連 VC も current head に再束縛した。
  • git diff --check、python3 -m compileall -q .claude/skills/issue-refinement-loop/scripts、変更 Python files の ruff check: すべて PASS。差分静的検査も成功した。

Allowed Paths 遵守

Schema Change Applicability

  • decision: not_schema_change
  • schema / validator の field 集合と absolute-path rejection は変更せず、producer 側の出力を既存 validator の canonical policy に合わせる。

Schema Consumer Inventory

  • schema change なし。既存 validator consumer の契約は維持し、入力受理を緩和しない。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
lexical canonical repo-relative wire reference yes - current-head focused tests -
symlink 拒否と作成後再確認 yes - current-head focused tests -
failure envelope と success write OSError の fail-closed yes - current-head focused tests -
external issue-reviewer caller の実行・証跡 no repository 外の runner intentionally unimplemented and unverified #1887

Notes

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1907 closed).

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author
iteration: 1
reviewed_head_sha: c1b9f29e13604f066d69f2b94aa93b88924cefc7
reviewer: pr-reviewer + spark-deep
model: gpt-5.6-terra / gpt-5.3-codex-spark
verdict: REQUEST_CHANGES
blocking_findings:
  - PR本文に受け入れ条件、検証コマンド、Allowed Paths の対応節がなく、AC1–AC6 の current-head 根拠が不足していた。
overimplementation_findings: []
tests:
  - focused: 132 passed
  - related_regression: 1154 passed
next_action: PR本文へAC・VC・Allowed Paths の対応根拠を追記し、同一headを再レビューする。

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author
iteration: 2
reviewed_head_sha: c1b9f29e13604f066d69f2b94aa93b88924cefc7
reviewer: pr-reviewer
model: gpt-5.6-terra
verdict: APPROVE
blocking_findings: []
overimplementation_findings: []
tests:
  - focused: 132 passed
  - related_regression: 1154 passed
next_action: Draft PRを人間が確認し、merge後に#1887 refinementをfresh rerunする。

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES

修正方針そのもの、すなわち「filesystem write path と wire reference を分離し、validator の repo-relative 制約を維持する」は妥当です。#1877/PR #1884 から #1882 を分離したスコープにも沿っており、変更ファイルも producer と回帰テストの4件に限定されています。 し/validator split-brain がまだ残っています。現状の AC1–AC4、特に「canonical subtree のみ」「issue slot symlink は fail-closed」「#1887 の incident shape を再現」という主張は実装より強すぎます。


Findings

P1-1. --repo-root 省略時、相対 traversal/非canonical artifact-dir をそのまま受理する

_artifact_path_and_wire() は repo_root is None の場合、artifact_dir / issue_slot / filename を無検証で返します。CLI の事前検査も「repo-root なしの絶対 artifact-dir」しか拒否していません。したがって、次のような入力が残っています。

--artifact-dir ../outside
--artifact-dir arbitrary/artifacts

前者は repository 外へ書き込み、wire に ../outside/... を出力できます。後者も canonical prefix を持たない wire path を出します。一方、validator は .. を artifact_parent_traversal_rejected、canonical regex 外を artifact_path_invalid として拒否します。これは今回直そうとしている「producer 自身が validator-invalid output を生成する」問題と同型です。

さらに、変更後の budget test は長い任意の相対 artifact-dir を --repo-root なしで渡し、実際にそのディレクトリへ failure artifact が生成されることを期待しています。つまりこの挙動は単なる未テストではなく、新しいテストによって許容状態として固定されています。

必須修正

repo_root is None の許容範囲を次のどちらかに限定してください。

  1. artifact_dir == .claude/artifacts/issue-refinement-loop の厳密な相対値だけ許可し、root は検証済み CWD から得る。
  2. 明示的な --artifact-dir を使う場合は常に --repo-root を必須にする。

wire path は filesystem path の as_posix() から作らず、常に次の lexical canonical value を構築すべきです。

wire_path = (
    _CANONICAL_ARTIFACT_DIR
    / str(issue_number)
    / filename
).as_posix()

Path.resolve() は symlink を解決し .. を除去する関数であり、入力が canonical lexical form だったことを保証する関数ではありません。([Python documentation]1)


P1-2. canonical base 内の symlink alias は fail-closed にならない

現実装が拒否するのは、解決後のパスが repository または canonical base の外へ出る場合だけです。canonical base 内の alias は通過します。

例えば次の状態です。

.claude/artifacts/issue-refinement-loop/1887
  -> .claude/artifacts/issue-refinement-loop/1888

Path.resolve() 後の書込み先は 1888/... です。しかし containment 上は同じ canonical base 内なので許可され、wire path も解決後の .../1888/... から生成されます。その後 validator は active Issue が 1887 であるため artifact_issue_number_mismatch として停止します。canonical base 自体が repository 内の別ディレクトリへの symlink である場合も、repository containment は通る一方、wire path が canonical regex から外れます。

追加テストが扱うのは、issue slot または canonical base が repository 外を指すケースだけです。同じ base 内の sibling Issue や repository 内の別ディレクトリを指すケースはありません。したがって、PR本文の「issue slot symlink は fail-closed」という AC3 は過大主張です。

必須修正

  • wire path は resolved write path から導出せず、canonical lexical path から構築する。
  • .claude、artifacts、issue-refinement-loop、<issue_number> の既存各 component を os.lstat() で確認し、symlink を拒否する。
  • issue directory 作成後、書込み直前にも再確認する。

os.lstat() は symlink を追跡せず link 自体の情報を返すため、この用途に適しています。([Python documentation]2)

ローカルの悪意ある並行プロセスまで threat model に含めるなら、通常の resolve() → write は TOCTOU race を残します。その場合は Unix の directory FD と O_NOFOLLOW、os.replace(..., src_dir_fd=..., dst_dir_fd=...) を使うか、Linux 限定で openat2() の RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS を使う設計が必要です。os.replace() の atomicity は成功した rename 操作に対する保証であり、それ以前の pathname resolution を保護するものではありません。([Python documentation]2)

個人開発向け minimal harness としては、まず lexical wire 固定と lstat による全 component 拒否で十分です。openat2() wrapper の導入までは本PRへ要求しません。


P1-3. 実際の repo 外 caller が新しい invocation contract を使用する証拠がない

Issue #1882 は actual issue-reviewer caller が repository 外の control-plane にあり、その変更と runtime evidence を本スコープ外としています。

一方、新規 subprocess test は次を「exact Issue #1887 incident shape」としています。

absolute --artifact-dir
+
--repo-root

しかし repository 内の証拠から確認できるのは「absolute artifact-dir が渡された」ことまでであり、actual caller が --repo-root も渡していた、または今後渡すよう更新済みであることは証明されていません。新テストは incident の実呼出しを再現したのではなく、修正後に成功する理想的な呼出しを構成しています。

actual caller が引き続き absolute --artifact-dir のみを渡す場合、このPR後は absolute path の出力こそ止まりますが、producer が即座に failure envelope を返すだけです。#1887 の停止原因は解消されず、別の producer failure に置き換わります。repository 内の issue-reviewer の実行例も relative artifact-dir のみで、--repo-root の rollout evidence にはなっていません。

必須対応は二択です。

  • actual external caller を更新し、その実 argv による producer → validator smoke の証跡を current head に束縛する。
  • caller 変更を不要にするため、absolute canonical artifact-dir から candidate root を導出し、git -C <candidate> rev-parse --show-toplevel で一致を検証する。

git rev-parse --show-toplevel は working tree の absolute top-level を返し、working tree が存在しない場合はエラーになるため、単なる /tmp/not-a-repo を repo root として信頼する現実装より適切です。([Git]3)

external caller evidence を意図的に取得しない方針を維持するなら、PR/Issue の表現を「#1887 を解消する」から「producer に repo-relative 出力 capability を追加する。caller rollout は未完了」へ狭め、Closes #1882 も再検討すべきです。


P2-1. success artifact の書込み失敗が canonical failure envelope を通らない

compact_review_result() の構築処理は try/except に入っていますが、最終的な _atomic_write(artifact_path, artifact_content) はその外側です。したがって次の失敗は Python traceback として stderr へ漏れます。

  • issue directory が regular file
  • permission denied
  • mkstemp() failure
  • os.replace() failure
  • symlink/directory race による OSError

PR の AC2 は success と producer-failure の両経路で absolute repository/HOME path を stdout/stderr に出さないと主張しています。しかし PermissionError や FileExistsError の traceback は通常 absolute write path を含むため、現実装はこの主張を満たしていません。

修正

try:
    _atomic_write(artifact_path, artifact_content)
except OSError as exc:
    _emit_failure_envelope(
        reason_code="schema_mismatch",
        next_action="human_judgment_required",
        detail=str(exc),
        ...
    )
    return 2

failure detail の redaction は既存 _safe_failure_detail() を通せます。

テストは permission bit に依存させず、canonical issue directory の位置へ regular file を事前作成して mkdir() を決定論的に失敗させる subprocess test にすれば、root 実行環境でも安定します。期待値は「traceback なし」「absolute root/HOME なし」「canonical producer-failure grammar」です。


P2-2. Issue number の producer/validator 入力契約も不一致

producer の --issue-number は単なる type=int、任意引数です。一方 validator は positive integer を必須にしています。

現状では次の不一致が起きます。

  • --issue-number 0 は producer 内で falsy と評価され、slot が unknown になる。
  • --issue-number -1 は -1 slot として書き込まれる。
  • 省略時も unknown になる。
  • validator は unknown、0、leading zero、active Issue と異なる segment を明示的に拒否する。

actual caller が正常な Issue 番号を渡す限り incident には直結しませんが、「producer CLI stdout を validator CLI へそのまま渡せる」という AC4 を一般化するなら未解消です。

producer も validator と同じ positive-int parser を使用し、CLI では required=True にしてください。少なくとも 0、負数、省略の producer→validator subprocess negative test が必要です。


P2-3. current-head review と PR 本文の証跡が失効している

PR の現在 head は 2301ef043ac058379e85721e8e46b7f4cfeaafba ですが、PR本文は current head を c1b9f29e... と記載したままです。

iteration 2 の APPROVE コメントも reviewed_head_sha: c1b9f29e... に束縛されています。現在 head に対する independent review ではありません。

現在の変更対象が4ファイルのままであることは確認できていますが、head-bound workflow を採用している以上、次は必要です。

  1. focused 132件と related regression を current head で再実行する。
  2. PR本文の current-head SHA とテスト結果を更新する。
  3. current head に対して再レビューする。
  4. それまでは Draft を維持する。

Issue #1882 側の契約不整合

Runtime Verification Applicability が誤分類

Issue は decision: not_applicable とし、理由を「workflow documentation and script changes only」「game runtime behavior ではない」としています。しかし AC1~AC5 は subprocess、filesystem write、symlink、stdout/stderr、producer→validator boundary という明白な実行時挙動です。実際、PR自身も subprocess regression を主要証拠にしています。

次のように直すべきです。

decision: immediate
applicable_acs: [AC1, AC2, AC3, AC4, AC5]
execution_environment:
  - Python >= 3.12
  - pytest
  - POSIX filesystem
artifact_requirements:
  - producer argv
  - producer exit code
  - exact stdout/stderr bytes
  - validator exit code/result
  - filesystem postcondition

「ゲーム runtime ではない」は applicability 判定の根拠になりません。

Issue title と現在のスコープが一致していない

Issue のタイトルは「空値field・旧field混入・reviewed-body SHA欠落」まで解消するように読めますが、現在本文と PR #1907 は wire path normalization に限定されています。

Closes #1882 を維持するなら、以下のどちらかを明示すべきです。


推奨する最小修正設計

新しい schema、registry、state store、retry framework は不要です。以下だけで十分です。

def _artifact_path_and_wire(...):
    issue_number = validate_positive_issue_number(issue_number)

    wire = _CANONICAL_ARTIFACT_DIR / str(issue_number) / filename

    root = verify_git_worktree_root(repo_root or Path.cwd())

    if repo_root is None:
        if artifact_dir != _CANONICAL_ARTIFACT_DIR:
            raise ValueError("artifact_dir_not_canonical")
    else:
        require_supplied_base_matches_canonical(root, artifact_dir)

    write_path = root / wire
    reject_symlink_components(root, wire.parent)
    verify_containment(write_path, root / _CANONICAL_ARTIFACT_DIR)

    return write_path, wire.as_posix()

設計上の要点は次の4点です。

  1. wire は canonical lexical value から作る。
  2. resolved filesystem target から wire を逆算しない。
  3. containment と no-symlink は別の不変条件として検査する。
  4. success write の OSError も failure envelope に正規化する。

追加すべき回帰テスト

最低限、次の7ケースが必要です。

relative ../outside without repo-root
arbitrary relative artifact-dir without repo-root
same-base issue-slot symlink: 1887 -> 1888
in-repository canonical-base symlink
issue-number omitted / 0 / negative
success artifact write OSError
actual external caller argv -> producer stdout -> validator

各 negative case では、単に producer exit 2 を確認するだけでなく、次も確認してください。

repository 外への file creation なし
traceback なし
absolute repo/HOME path が stdout/stderr にない
validator-invalid success envelope が存在しない
producer-failure envelope の path policy が canonical

総括

このPRは最小差分で正しい方向へ進んでいますが、現状では absolute-path という1例だけを直し、producer と validator の受理集合を一致させていません。特に relative noncanonical path と same-base symlink alias は、#1887 と同じ「producer は出せるが validator は受理しない」停止を再現します。

したがって、マージ条件は次のとおりです。

  1. P1-1 と P1-2 の path invariant 修正。
  2. external caller の actual invocation evidence、または incident closure claim の縮小。
  3. success write failure の envelope 化。
  4. positive Issue number 契約の統一。
  5. 2301ef04... 以降の current-head tests と再レビュー。
  6. Issue 実装: compact artifact wire reference をrepo-relativeへ正規化する #1882 の Runtime Verification Applicability と closure scope の修正。

作者申告の 132 passed/1154 passed は、このレビュー環境では独立再実行していません。上記 findings は current-head の producer、validator、tests、Issue/PR契約を直接追跡し、該当分岐を最小再現した結果に基づきます。

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

impl-review-loop Round 1: current-head review

  • reviewed head: d4d5b4aeede32f9927d95be9a5db7575b57fb13b
  • required CI: 6件すべてPASS
  • Allowed Paths: 4ファイル、違反なし
  • 検証: Issue VC 10 / 107 / 1159 passed、git diff --check、compileall、変更PythonのRuffがPASS
  • owner指摘: lexical wire reference、no-root制限、同一base内symlink拒否、success書込み失敗のfailure envelope、正のissue番号、絶対path非出力、external runnerの主張縮小を確認
iteration: 1
reviewed_head_sha: d4d5b4aeede32f9927d95be9a5db7575b57fb13b
reviewer: pr-reviewer
model: gpt-5.6-terra
verdict: APPROVE
blocking_findings: []
overimplementation_findings: []
tests:
  required_ci: pass
  issue_verification_commands: pass
  allowed_paths_gate: pass
next_action: Draftを維持し、人間による最終マージ判断へ進む
verdict: APPROVE
reviewed_head_sha: d4d5b4aeede32f9927d95be9a5db7575b57fb13b
blockers: []
warnings: []

@squne121
squne121 marked this pull request as ready for review August 1, 2026 05:46
@squne121
squne121 merged commit 7ab7a70 into main Aug 1, 2026
25 checks passed
@squne121
squne121 deleted the worktree-issue-1882-compact-review-wire-reference branch August 1, 2026 05:46
@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

post-merge-cleanup: 部分完了(2026-08-01T05:48:30Z)

cleanup_exec.py を唯一の削除経路として実行しましたが、root checkout が別作業の pr-1897-verify であり、default branch main ではないため root_not_default_branch で拒否されました。

  • PR fix(issue-refinement-loop): compact artifact wire pathをrepo-relativeにする #1907 のマージは確認済み(merge commit: 7ab7a70755a039b249739d8246c24db1168dd395)。
  • 対象worktree/branchは未削除のまま保持しました。bare Gitによるfallbackは行っていません。
  • root / 他Issue worktree / tmp/・.claude/tmp/ のresidueは変更していません。
  • 親Issueはなし。Issue #1882はclosedです。
  • follow-upは既存OPEN Issue #1887で継続します(新規Issueは起票しません)。
POST_MERGE_CLEANUP_REPORT_V1:
  status: partial
  human_review_required: true
  cleaned_branches: []
  cleaned_worktrees: []
  unresolved_cleanup_items:
    - root_branch_drift
    - cleanup_exec_refused: root_not_default_branch
  follow_up_issues:
    - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/1907:1887-fresh-rerun"
      status: reused_open
      issue:
        number: 1887
        url: "https://github.com/squne121/loop-protocol/issues/1887"
      reason: "PR #1907 merge後のfresh rerunは既存Issue #1887で管理する"

次アクション: pr-1897-verify の所有者がrootを main へ戻した後、同じ cleanup_exec.py 経路で再実行する。

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

post-merge-cleanup: 完了

先行したpartial cleanup後、root checkoutを main へ戻して再実行しました。

POST_MERGE_CLEANUP_REPORT_V1:
  status: ok
  pr_number: 1907
  linked_issue_number: 1882
  cleaned_worktrees:
    - .claude/worktrees/issue-1882-compact-review-wire-reference
  cleaned_branches:
    - worktree-issue-1882-compact-review-wire-reference
  unresolved_cleanup_items: []
  follow_up_issue_requests: []
  note_only_observations:
    - "#1887 のfresh rerunは既存Issueで継続する"

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.

実装: compact artifact wire reference をrepo-relativeへ正規化する

1 participant