Skip to content

調査: plan_refinement_loop.py 構文エラー停止の再現条件整理 #1035

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#964"
goal_ref: "plan_refinement_loop.py の SyntaxError 報告と loop 停止を再現不能化し、issue-refinement-loop を安全に再開させるための検出・証跡整合を修正する"
change_kind: tooling

Parent Issue

#964

Parent Goal Ref

  • #964 は plan_refinement_loop.py 実行時の SyntaxError を契機に issue-refinement-loop が human_judgment_required で停止したため、再発条件の切り分けと再開手順の安定化が必要。
  • 仕様は「実装: PR body hygiene 更新は update_pr.py wrapper 経由に限定する #964 本体修正の実装」を止めるのではなく、loop 運用の停止を解くために観測証跡と判定の整合を確認する。

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/artifacts/issue-refinement-loop/964/ (生成物として扱う。恒久 fixture は tests/fixtures/ に置く)

Remaining Parent Gaps

  • plan_refinement_loop.py の構文エラーが再現した実行環境(行番号付き traceback)を持つ再現手順。
  • loop 停止時の再開手順に対する実行環境不整合(ファイル/環境差分)ルール。

Outcome

issue-refinement-loop 実行時の SyntaxError 停止が再現しない前提を明文化し、発生時は「違うファイル/別コミット実行」起因であることを短時間で切り分けできるようにする。#964 の実装作業は再開可能な状態に導く。

In Scope

  • plan_refinement_loop.py の実行時実態確認(構文検証: py_compile)および PY_COMPILE_PROOF_V1 の記録
  • run_refinement_preflight.py 経由で planner 生成時の error path を確認し、PLANNER_FAILURE_CLASSIFICATION_V1 taxonomy に従って停止理由を分類・明文化
  • live preflight と fixture replay の両方を実行し、REFINEMENT_PREFLIGHT_REPLAY_PROOF_V1 として記録
  • REFINEMENT_PREFLIGHT_PROVENANCE_V1 フィールド(git HEAD / script blob SHA / python executable / cwd / stderr hash 等)を artifact または Issue コメントに残す手順の整備
  • .claude/artifacts/issue-refinement-loop/964/ は生成物として扱い、恒久 fixture は tests/fixtures/ に配置する区別の明確化

Out of Scope

  • #964 の AC/VC 本体修正(別Issueで確定)。
  • open-pr や update_pr.py 本体の直接改修。
  • Hook ルール(gh pr edit deny allowlist)の機能追加自体。
  • #964 の runtime enforcement blocker(gh pr edit --body, --body-file, gh api, GraphQL, shell chaining, Claude Code hook deny semantics)の解消。

Acceptance Criteria

  • AC1: 現行 plan_refinement_loop.py について PY_COMPILE_PROOF_V1 を記録する。記録すべき内容: python3 -m py_compile の成否 / python3 -V / sys.executable / git rev-parse HEAD / git hash-object plan_refinement_loop.py / cwd / realpath / stderr hash。
  • AC2: #964 anchor comment を使った live preflight と、保存済み raw snapshot を使った fixture replay の両方を実行し、結果を REFINEMENT_PREFLIGHT_REPLAY_PROOF_V1 として記録する。live run と fixture replay の差分が input drift の有無を示すことを確認する。
  • AC3: PLANNER_INTERNAL_ERROR が現れた場合、syntax_compile_failure / planner_stdout_non_json / planner_runtime_internal_error / wrapper_environment_failure / anchor_or_input_blocked に分類できる PLANNER_FAILURE_CLASSIFICATION_V1 taxonomy の手順を Issue コメントまたは artifact として記録する。
  • AC4: SyntaxError が再現した場合の traceback 採取手順を固定する。採取すべき情報: command / cwd / interpreter / script realpath / git HEAD / file blob SHA / traceback excerpt / failing line excerpt。
  • AC5: #964 への追記先と追記内容を決める。追記は loop 再開可否に限定し、#964 の runtime enforcement blocker(hook deny semantics / gh pr edit 全バリアント / GraphQL route)は解消扱いにしない。
  • AC6: .claude/artifacts/issue-refinement-loop/964/ は生成物として扱い、恒久 fixture が必要な場合は .claude/skills/issue-refinement-loop/tests/fixtures/ に置く。generated artifact を通常の source edit として扱わない。

Runtime Verification Applicability

decision: not_applicable
reason: "本Issueは再発原因の再現条件整理と運用手順整備が対象で、実行時の実装変更を前提としない。"

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_py_compile_proof_v1 -v

# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_preflight_replay_proof_v1 -v

# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_planner_failure_classification_v1 -v

# AC4
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_preflight_provenance_v1 -v

# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_issue_964_enforcement_not_resolved -v

# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py::test_artifacts_not_git_tracked -v

Allowed Paths

  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/tests/test_1035_provenance.py
  • .claude/skills/issue-refinement-loop/tests/fixtures/ (恒久 fixture 配置先)

Stop Conditions

  • 再現環境を特定するために別環境要因を切り分ける必要があり、別ファイル(別バージョン)起点の修正が必要になった場合。
  • 本Issueの対象範囲外である #964 の core AC 修正が必要と判断された場合。
  • 追加の安全対策(command wrapper/validator 変更)が必要と判明した場合。
  • #964 の runtime enforcement blocker(hook deny semantics / gh pr edit 全バリアント)の解消が本 Issue の調査結果として要求された場合。
  • fixture replay と live run の結果が異なり、input drift の特定に本 Issue のスコープを超える別 Issue が必要と判明した場合。
  • py_compile 以外の起因(encoding / BOM / worktree 汚染 / 別 interpreter)が判明し、本 Issue の Allowed Paths 外の修正が必要になった場合。

Required Skills

  • review-issue

Activity

  1. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #1035 は必要ですが、このままでは #964 の issue-refinement-loop 再開可否を安全に判断できません。現状の AC は「現行 plan_refinement_loop.py が py_compile できる」ことに寄りすぎており、実際に停止した実行の commit / worktree / interpreter / stdin / artifact / stderr の同一性を固定していません。#1035 自体はコメントなしで、親 #964 側には既に強い REQUEST_CHANGES コメントがあり、#964 は runtime enforcement の契約問題も抱えています。

    最大のリスクは、「現行ファイルは構文エラーにならない」=「停止原因は解消済み」 と誤分類することです。Python の py_compile は指定されたソースを bytecode にコンパイルし、コマンドラインではコンパイル不能なファイルがあれば非 0 終了します。したがって AC1 の検査自体は妥当です。ただし、それが証明するのは「その interpreter が、その path の、その時点のファイルを parse できる」だけで、停止時に実行された別 worktree・別 ref・別一時ファイル・壊れた artifact まで否定しません。([Python documentation]1)

    Blocker 1: SyntaxError と PLANNER_INTERNAL_ERROR の分類が粗すぎる

    SyntaxError は Python がファイルを parse/import する前に落ちるため、plan_refinement_loop.py 内部の try/except では捕捉できません。一方、planner 実行中の runtime exception は planner_internal_error を含む JSON plan と exit 3 を返す実装になっています。

    wrapper 側は planner を subprocess.run([sys.executable, str(PLANNER_SCRIPT)], shell=False, ...) で呼び、stdout を JSON parse できない場合は plan is None として扱います。つまり、構文エラー・stdout 非 JSON・runtime exception・timeout が同じ PLANNER_INTERNAL_ERROR 周辺に潰れて見える危険があります。

    #1035 には次の taxonomy を AC として追加すべきです。

    PLANNER_FAILURE_CLASSIFICATION_V1:
      syntax_compile_failure:
        evidence:
          - py_compile_failed
          - traceback_contains_SyntaxError
          - script_path
          - script_blob_sha
          - python_executable
          - python_version
      planner_stdout_non_json:
        evidence:
          - subprocess_exit_code
          - stdout_sha256
          - stderr_excerpt
          - json_decode_error
      planner_runtime_internal_error:
        evidence:
          - planner_exit_code: 3
          - fail_closed.reason_codes includes planner_internal_error
      wrapper_environment_failure:
        evidence:
          - gh_not_found
          - gh_auth_failure
          - timeout
          - result_schema_invalid
      anchor_or_input_blocked:
        evidence:
          - ANCHOR_NOT_IN_ISSUE
          - INPUT_SCHEMA_INVALID

    Blocker 2: provenance がないため「別ファイル/別コミット実行」を短時間で切れない

    #1035 の Outcome は「別ファイル/別コミット実行起因を短時間で切り分ける」ですが、AC に必要な証跡フィールドがありません。最低限、以下を artifact または Issue コメントに残すべきです。

    REFINEMENT_PREFLIGHT_PROVENANCE_V1:
      repo: squne121/loop-protocol
      issue_number: 964
      anchor_comment_url: https://github.com/squne121/loop-protocol/issues/964#issuecomment-4755261407
      git_head_sha: "<git rev-parse HEAD>"
      planner_script_path: ".claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py"
      planner_script_realpath: "<realpath>"
      planner_script_blob_sha: "<git hash-object ...>"
      wrapper_script_blob_sha: "<git hash-object ...>"
      python_executable: "<sys.executable>"
      python_version: "<python3 -V>"
      cwd: "<pwd>"
      py_compile_status: pass|fail
      wrapper_exit_code: 0|1|2|3
      wrapper_status: pass|warn|blocked|environment_failure
      blockers:
        - "<code>"
      planner_input_sha256: "sha256:..."
      raw_snapshot_sha256: "sha256:..."
      stderr_sha256: "sha256:..."

    run_refinement_preflight.py は artifact を .claude/artifacts/issue-refinement-loop/<issue_number>/ に書く設計なので、証跡化の受け皿はあります。 ただし #1035 の Allowed Paths にある .claude/artifacts/issue-refinement-loop/964/refinement_preflight_result_v1.json は runtime 生成物であり、リポジトリ上の通常ファイルとして扱うと ephemeral artifact を commit する設計になります。ここは 「生成される出力先」なのか「編集対象ファイル」なのかを分ける 必要があります。

    Blocker 3: fixture replay が AC にない

    #1035 は live 実行の verification command だけを要求していますが、GitHub Issue 本文・コメントは時間で変わります。停止時の再現性を扱うなら、live run だけでなく fixture replay が必須です。wrapper には --fixture が既にあります。

    追加すべき検証はこれです。

    python3 -V
    python3 -c 'import sys; print(sys.executable)'
    git rev-parse HEAD
    git hash-object .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py
    python3 -m py_compile .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py
    
    uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py \
      --issue-number 964 \
      --repo squne121/loop-protocol \
      --anchor-comment-url https://github.com/squne121/loop-protocol/issues/964#issuecomment-4755261407
    
    uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py \
      --issue-number 964 \
      --repo squne121/loop-protocol \
      --fixture .claude/artifacts/issue-refinement-loop/964/raw_issue_snapshot.json

    live run が pass/warn/blocked でも、fixture replay が別結果なら「再現不能」ではなく input drift です。

    Blocker 4: #964 の未解決 blocker を #1035 で消してはいけない

    #964 は現在、update_pr.py wrapper 経由以外の PR body mutation を PreToolUse で止める Issue です。親は #639 として整理されており、#639 は #631 / PR #638 で docs-level prohibition に留まっていた runtime enforcement の follow-up です。

    #964 コメントでは、gh pr edit --body-file だけでは狭すぎること、--body / -b / -F / shell chaining / gh api / GraphQL route をどう扱うか明記すべきことが既に指摘されています。 GitHub CLI 公式でも gh pr edit は --body と --body-file の両方で PR 本文更新が可能です。(GitHub CLI)

    したがって #1035 の AC4 は、次のように制限すべきです。

    AC4: #964 に追記する場合、追記内容は `issue-refinement-loop` の再開可否と planner provenance に限定する。
    #964 の runtime enforcement blocker(`gh pr edit --body`, `--body-file`, `gh api`, GraphQL, shell chaining, Claude Code hook deny semantics)は未解決として残す。

    Blocker 5: Claude Code hook の enforcement 仕様を #964 追記で崩す危険

    Claude Code hook は PreToolUse で tool call 前に実行され、hookSpecificOutput.permissionDecision: "deny" で制御できます。exit code 2 は block、exit code 1 は多くの場合 non-blocking です。([Claude API Docs]3) ([Claude API Docs]3)

    #964 の本質は runtime enforcement なので、#1035 で「loop は再開可能」とコメントする場合でも、少なくともこの条件を parent blocker として残す必要があります。

    - PreToolUse deny は exit 2 または `hookSpecificOutput.permissionDecision: "deny"` で返す。
    - deny reason には raw PR body / body-file 内容を含めない。
    - wrapper allow は shell metacharacter を含まない単一コマンドだけに限定する。

    Blocker 6: GitHub closing keyword / Refs の扱いを混同してはいけない

    #819 は closing keyword 全 variant、Refs #N、cross-repo reference を preserved token として保持する契約でした。 GitHub 公式でも issue を close する keyword は close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved で、PR が default branch に merge される場合に効きます。Refs #N は close しません。([GitHub Docs]4)

    #1035 が #964 再開コメントを出す場合、#964 の reference-block repair 論点を「単なる SyntaxError 再現問題」と一緒に解消扱いしてはいけません。これは別 blocker として残すべきです。

    Blocker 7: #1013 / PR #1030 の phase gate 変更も関連リスク

    #1013 は preflight 直後に decide_next_loop_action.py を誤って呼び、scope_signal_guard から premature human_escalation に落ちる問題を直す Issue でした。 PR #1030 は merge 済みですが、レビューコメントでは approve verdict + max_iterations 近傍で誤って human_escalation になる blocker が指摘されています。

    #1035 は plan_refinement_loop.py の SyntaxError だけでなく、「loop 再開を阻害する別の loop-control regression が残っていないか」も確認対象に入れるべきです。少なくとも AC4 の「loop 再開に必要な最小運用要件」には、#1013/#1030 の phase gate regression 状態を含めてください。

    推奨修正版 AC

    - [ ] AC1: 現行 `plan_refinement_loop.py` について `PY_COMPILE_PROOF_V1` を記録する。
      - `python3 -m py_compile` の成否
      - `python3 -V`
      - `sys.executable`
      - `git rev-parse HEAD`
      - `git hash-object plan_refinement_loop.py`
      - cwd / realpath / stderr hash
    
    - [ ] AC2: #964 anchor comment を使った live preflight と、保存済み raw snapshot fixture replay の両方を実行し、結果を `REFINEMENT_PREFLIGHT_REPLAY_PROOF_V1` として記録する。
    
    - [ ] AC3: `PLANNER_INTERNAL_ERROR` が現れた場合、`syntax_compile_failure` / `planner_stdout_non_json` / `planner_runtime_internal_error` / `wrapper_environment_failure` / `anchor_or_input_blocked` に分類できる手順を記録する。
    
    - [ ] AC4: SyntaxError が再現した場合の traceback 採取手順を固定する。
      - command
      - cwd
      - interpreter
      - script realpath
      - git HEAD
      - file blob SHA
      - traceback excerpt
      - failing line excerpt
    
    - [ ] AC5: #964 への追記先と追記内容を決める。ただし追記は loop 再開可否に限定し、#964 の runtime enforcement blocker は解消扱いしない。
    
    - [ ] AC6: `.claude/artifacts/issue-refinement-loop/964/` は生成物として扱い、恒久 fixture が必要な場合は `scripts/tests/fixtures/` に置く。generated artifact を通常の source edit として扱わない。

    結論

    #1035 は「やるべき調査」ですが、現行契約では 証跡の同一性が弱く、#964 の本質的 blocker を誤って unblock する危険があります。

    進めるなら、実装者への指示は次の方針が安全です。

    #1035 は `plan_refinement_loop.py` の現行構文健全性だけで閉じない。
    停止時と同一の file/ref/interpreter/stdin/artifact を固定する provenance を追加し、
    live preflight と fixture replay の差分で input drift / environment drift / wrong ref を分類する。
    #964 には「loop 再開可否」のみ追記し、runtime enforcement blocker は残す。

    この修正なしに #1035 を完了扱いにすると、「たまたま現在の main では py_compile が通る」だけで、実際の停止原因が別 worktree・古い生成物・壊れた stdout・phase gate regression だったケースを取り逃がします。

  2. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  3. added a commit that references this issue on Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions