Skip to content

fix(#841): fail closed on missing scope rollup marker - #869

Merged
squne121 merged 1 commit into
mainfrom
codex/issue-841-scope-rollup-fail-closed
Jun 13, 2026
Merged

squne121 merged 1 commit into
mainfrom
codex/issue-841-scope-rollup-fail-closed

Conversation

@squne121

@squne121 squne121 commented Jun 13, 2026 •

Copy link
Copy Markdown
Owner

概要

  • scope-rollup-runner が ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1 を返さない場合でも deferred で進めず、fail-closed で停止するよう実装しました。
  • marker_missing / marker_malformed / marker_ambiguous / rejected / failed / runner_unavailable / ok を判定し、問題時は LOOP_STATE に machine-readable な停止情報を残します。
  • parser の厳密化(fenced YAML、重複キー検出、raw_plan_location のパス厳格検証)を行い、raw fallback を禁止しました。
  • impl-review-loop の Step 2.5 判定ロジックは仕様どおり human_review_required / deferred / continue を切り分けます。

検証

  • 下記を実行しています。
uv run python3 -m pytest .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py -q
uv run python3 -m pytest .claude/skills/impl-review-loop/tests -q
  • 合格結果:
    • test_parse_scope_rollup_run_result.py: 12 passed
    • impl-review-loop/tests: 196 passed, 4 xfailed

@github-actions

github-actions Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-869/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #869 の方向性は正しいです。#841 は、#824 の impl-review-loop で scope-rollup-runner が ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1 を返さず、それでも deferred fallback で進んだ問題を fail-closed にする Issue です。#841 本文も、marker 欠落・不正時は human_review_required / human_escalation に固定し、raw JSON fallback を禁止することを AC にしています。

ただし、現 PR は control-plane fail-closed の実装としてまだ危険です。特に parser の状態表現、runner_unavailable / failed の扱い、YAML marker の厳格性、/tmp パス信頼が弱いです。


Blocker 1: marker_ambiguous が parser と decision schema で不整合

parser は duplicate marker を status: marker_ambiguous として返します。
一方、preparation.md の ISSUE_SCOPE_ROLLUP_DECISION_V2.runner_result.status enum は ok | runner_unavailable | rejected | marker_missing | marker_malformed で、marker_ambiguous がありません。

これは #841 AC3「marker_missing / marker_malformed / marker_ambiguous を保存する」に未達です。

修正案: どちらかに統一してください。

  • 案 A: runner_result.status に marker_ambiguous を追加する。
  • 案 B: parser は status: marker_malformed, reject_reason: marker_ambiguous に正規化する。

現状のままでは、ambiguous marker を fail-closed 判定できても、LOOP_STATE に machine-readable に正しく残せません。


Blocker 2: failed / runner_unavailable が ok → continue になっている

parser は status in {"failed", "runner_unavailable"} を見た時点で ("ok", None, None, False) を返します。つまり result block、generated_at > requested_at、verify_status、result hash の検証前に early return します。
その後 parse_status == "ok" は routing_action: continue に変換されます。

runner_unavailable は #841 で「valid marker が返された場合のみ成立」とされていますが、現実装では freshness 検証を通っていません。さらに failed も continue になっており、これは #841 の AC では明確に設計されていません。

修正案:

  • repo/current_issue/invocation_id/script_blob_sha256/requested_at/generated_at は ok/failed/runner_unavailable 全 status で検証する。
  • parser 出力は status: runner_unavailable や status: failed を保持し、ok に潰さない。
  • failed は原則 stop_human、または明示的に deferred 許容するなら reject_reason/status を別 enum として記録する。
  • stale な runner_unavailable marker のテストを追加する。

Blocker 3: marker 内の requested_at を検証していない

requested_at は required field に入っていますが、値の照合はされていません。
実際の freshness 判定では CLI 引数の requested_at と marker の generated_at だけを比較しています。

invocation_id があるので完全に無防備ではありませんが、marker provenance の一部として requested_at を要求するなら、marker 内の requested_at と orchestrator 側の REQUESTED_AT は一致確認すべきです。

修正案: ISO8601 正規化後に marker_payload["requested_at"] == requested_at を検証し、不一致なら reject_reason: requested_at_mismatch か stale に分類する。


Blocker 4: YAML marker の duplicate key を検出していない

parser は fenced YAML を yaml.safe_load で読み、top-level の ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1 を取得しています。
しかし duplicate marker のテストは「2つの fenced block」がある場合だけです。

1つの fenced YAML block 内に同名 key が複数あるケースは fail-closed できません。既存の JSON verifier は duplicate key を明示的に検出しています。

修正案:

  • YAML を続けるなら duplicate key 検出付き Loader を実装する。
  • 可能なら marker 自体を JSON fenced block に寄せ、既存 verifier と同じ object_pairs_hook 方針に揃える。
  • テスト追加: single fenced block 内の duplicate ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1。

Blocker 5: raw_plan_location.startswith("/tmp/") は弱い

現実装は raw_plan_location が /tmp/ で始まるかだけを見ています。
これは /tmp/../...、symlink、TOCTOU の扱いが弱いです。marker は LLM/subagent 由来の control-plane 入力なので、パスは信頼しない前提にするべきです。

修正案:

  • Path(raw_plan_path).resolve(strict=True) を使い、専用一時ディレクトリ配下か確認する。
  • 例: /tmp/loop-protocol-scope-rollup/<invocation_id>/result.json
  • symlink を拒否するか、os.open(..., O_NOFOLLOW) 相当で読む。
  • raw_plan_location に invocation_id を含めることも検証する。
  • テスト追加: /tmp/../...、symlink、存在しない file、directory。

Blocker 6: SubAgent 出力をどう /tmp/scope_rollup_<invocation_id>.txt に保存するかが未定義

preparation.md は parser に --assistant-output-file /tmp/scope_rollup_<invocation_id>.txt を渡すと書いています。
しかし、そのファイルを 誰が、どのタイミングで、どの SubAgent の最終応答から作るのか が書かれていません。

これは #841 の根本原因に直結します。Claude Code 公式 docs では、SubAgent は独自 context で作業し、main conversation には summary を返す構造です。つまり prompt 上で「必ず marker を返せ」と書くだけでは control-plane 証跡として不十分です。([Claude API Docs]1)

Claude Code hooks には SubagentStop があり、agent_type、agent_transcript_path、last_assistant_message を受け取れます。([Claude API Docs]2)
さらに SubagentStop は exit code 2 または decision block により subagent 停止をブロックできます。([Claude API Docs]2)

修正案:

  • 最小修正: preparation.md に「main が SubAgent final response をそのまま /tmp/scope_rollup_<invocation_id>.txt に保存してから parser に渡す」手順を明記。
  • 推奨修正: .claude/hooks/** に SubagentStop hook を追加し、agent_type == scope-rollup-runner の last_assistant_message を parser に渡して fail-closed する。
  • hook 実装しないなら、その判断理由と follow-up Issue を作る。

Blocker 7: CI が 1 本 failure

PR head 3199b000... に対して、workflow runs は ci success、deploy-pages success、agent-session-manifest success ですが、Check Japanese Content が failure です。
失敗 job は PR Body Japanese Check で、step Check PR body Japanese ratio が failure です。

これは機能レビュー以前の merge gate です。PR body の英語比率を下げるか、プロジェクト方針としてこの check を緩和する必要があります。


配布物 / preview 証跡の不整合

PR comment では preview URL が「publish requested / asset-level live check 未検証」と表示されています。
一方で deploy-pages の job step では Verify preview assets are live が success になっています。

これは実装差分の致命傷ではありませんが、配布物レビューとしては 証跡が矛盾しています。PR #837 では preview comment が ✅ verified live assets になっていたため、今回の PR #869 だけ comment が古い・更新されていない・条件分岐が壊れている可能性があります。

修正案: deploy workflow の live check 結果と PR comment の状態を一致させる。少なくとも PR 上の preview comment を verified live assets に更新するか、未検証なら job step success の意味を見直すべきです。


Non-blocking だが直した方がよい点

  • script_blob_sha256 という名前が misleading です。実際には Git blob SHA ではなく、sha256sum の raw file bytes です。preparation.md でも sha256sum plan_issue_scope_rollup.py を使っています。 既存 verifier は script_file_sha256 と呼んでいます。
  • marker schema は inputs, git_head_sha, script_path, verify_status, candidate counts を required 風に書いていますが、parser の required field はかなり少ないです。 required なら検証し、informational なら docs で optional と明記してください。
  • wrapper impl-review-loop/scripts/verify_scope_rollup_result.py は追加されていますが、parser は直接 issue-refinement-loop 版 verifier を import しています。 wrapper を canonical path にするなら parser も wrapper 経由に寄せるべきです。

追加すべきテスト

最低限、以下を追加してください。

1. marker_ambiguous が LOOP_STATE schema に保存可能であること
2. single fenced YAML block 内の duplicate key を marker_malformed / marker_ambiguous にすること
3. status: failed が continue にならないこと
4. stale runner_unavailable marker が rejected になること
5. marker requested_at != CLI requested_at が rejected になること
6. /tmp/../ path escape を raw_plan_location_invalid にすること
7. /tmp 配下 symlink を拒否すること
8. result_missing を明示的に返すこと
9. parser output から ISSUE_SCOPE_ROLLUP_DECISION_V2 を組み立てる fixture test

Web 調査を踏まえた設計方針

Claude Code SubAgent の最終応答は、API の structured output ではありません。SubAgent は独自 context で作業し summary を返すため、marker の完全性は prompt ではなく deterministic parser / hook で保証する必要があります。([Claude API Docs]1)

OpenAI API の Structured Outputs は schema adherence を保証できますが、これは json_schema / strict: true を使う API 経路の話です。Claude Code SubAgent の final response にそのまま適用できる前提にはできません。([OpenAI Platform]3)

したがって、この PR の正しい着地点は以下です。

SubAgent prompt 強化: 補助
deterministic parser: 必須
SubagentStop hook: 強く推奨
raw_plan_location の直接 fallback 禁止: 必須
marker / decision schema の enum 整合: 必須
preview / CI 証跡の整合: merge 前必須

結論

現 PR は #841 の問題意識には合っていますが、fail-closed 実装としてはまだ merge 不可です。特に marker_ambiguous schema 不整合、failed/runner_unavailable の early continue、duplicate-key 未検出、/tmp path 信頼、SubAgent output capture 未定義は、control-plane 強化の PR として看過できません。

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.

1 participant