Skip to content

調査: apply_workflow_signal()のimplementation_pr_observed分岐でcross-Task dedupeがactivity_terminal判定に先を越されるエッジケース #2685

Closed
1 of 1 issue completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: "#2565"
goal_ref: "apply_workflow_signal()のimplementation_pr_observed分岐において、implementation Activityのlocal-state gate(activity_missing / activity_terminal)がcross-Task accepted-fact identity/ownership判定より先に評価されるprecedence defectの再現可能性を確認し、必要なら実装Issueを起票する"
change_kind: research-only

Parent Issue

#2565

(さらに親は #2562。PR #2661〔mergeCommit e952e32885d5afa8d4284b9386aa9948b8144a4c〕が #2565 を実装済み。)

Outcome

scripts/task-context/task_context_workflow_signals.py の apply_workflow_signal() における implementation_pr_observed 分岐で、implementation Activity の local-state gate(activity_missing / activity_terminal のいずれも)が、cross-Task の accepted-fact identity/ownership 判定(FACT_TASK_IDENTITY_CONFLICT)より先に評価される precedence defect について、以下の2経路を同一根因として扱い、それぞれの再現可能性・実運用 reachability・既存テストカバレッジを確認する。

  1. cross-Task accepted fact × 現在Taskのimplementation Activityがterminal: current duplicate_noop/activity_terminal → expected conflict/FACT_TASK_IDENTITY_CONFLICT
  2. cross-Task accepted fact × 現在Taskのimplementation Activityが未作成(missing): current deferred/activity_missing → expected conflict/FACT_TASK_IDENTITY_CONFLICT

再現可能かつ修正が必要と判断した場合、両経路をカバーする実装Issueを起票する。再現不可能、または修正不要と判断した場合は、その判断根拠を本Issueに記録して close 可能な状態にする。

In Scope

  • apply_workflow_signal() の implementation_pr_observed 分岐の評価順序読解: implementation Activity 取得 → implementation is None の早期return(deferred/activity_missing) → accepted_implementation の dedupe_key 検索・same-Task 判定 → implementation["status"] != "ACTIVE" 早期return(duplicate_noop/activity_terminal) → _validate_implementation_claims_tx() → 後段の汎用 accepted-event dedupe (SAME_TASK_SAME_FACT / FACT_TASK_IDENTITY_CONFLICT) の到達順序を、行番号付きで本Issue本文に記録する
  • 上記2経路(terminal / missing)それぞれについて、既存テストでカバーされているか、実運用で発生しうるか(reachability)の確認
  • reachability 判断のための read-only dependency tracing。## Allowed Paths に列挙する範囲(.claude/skills/open-pr/scripts/open_pr.py の emit_implementation_pr_observed()、tests/task-context/ 配下の関連テスト)を読解対象に含める。Issue 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625(wrong-primary UserPromptSubmit advisory-only 化)の semantics との関係も確認する
  • 修正が必要と判断した場合の実装Issue起票(terminal / missing 両経路を含む)

Out of Scope

  • src/ および tests/ への実装変更そのもの(本Issueは調査。修正が必要なら別途実装Issueを起票する)
  • PR feat: Task Contextへworkflow trusted signalsを統合する #2661 の Finding 2 で既に対応済みの同一Task・同一PR・別Issueシナリオの再検証
  • 新規daemon、ledger、汎用authorization framework、security harnessの追加(read-only dependency tracingの結果がそれらを示唆する場合でも、本Issueのスコープでは提案に留め実装しない)
  • ## Allowed Paths に列挙した範囲を超えるモジュールへの読解・実装変更

調査対象シナリオ(背景)

PR #2661(#2565実装)の OWNER レビュー comment 5748354743(Finding 2)は、implementation_pr_observed 分岐において、同一Task・同一PR・別Issueの遅延signalが duplicate_noop/activity_terminal に誤分類される問題を指摘し、PR #2661でこの同一Taskケースは修正済みである。

その後 #2565 completion report comment 5748658065 が、修正で狭められたが解消されていない cross-Task(accepted_implementation が現在解決中の Task とは別 Task に属し、かつ現在の Task 自身の implementation Activity が既に terminal である場合に activity_terminal へ短絡し、後段の cross-Task dedupe FACT_TASK_IDENTITY_CONFLICT に到達しない)エッジケースを note_only_observation として記録した。

本Issueの調査(後述の Repository Evidence 参照)により、この根因は activity_terminal の早期returnに限定されず、その手前にある implementation is None → deferred/activity_missing の早期return(同ファイル該当行、accepted_implementation の dedupe_key 検索より前に評価される)にも同一構造で当てはまることが確認された。すなわち、

Task A owns accepted PR fact (dedupe_key = repo+PR)
Task C origin、Task C に implementation Activity がまだ無い
→ deferred/activity_missing で早期return
→ FACT_TASK_IDENTITY_CONFLICT まで到達しない

も、activity_terminal の場合と同型の precedence defect として成立する。

Repository Evidence(本Issue調査で確認済み・current main で再検証済み)

調査時点の current main: 33a6ffbf450dd4132201c59f243d723cdeeabdd8。直前調査時点の main(dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95)からの差分は、対象ファイル(scripts/task-context/task_context_workflow_signals.py、.claude/skills/open-pr/scripts/open_pr.py、tests/task-context/ 配下)に一切影響しないことを git diff --stat と現物の再読解の両方で確認済み。

  • scripts/task-context/task_context_workflow_signals.py の apply_workflow_signal()(implementation_pr_observed 分岐、L361-388付近)で、評価順序は次の通り: implementation Activity 取得(L362) → implementation is None なら deferred/activity_missing で即return(L363-364、accepted_implementation 検索より前) → accepted_implementation を dedupe_key で検索(L377) → same-Task なら metadata 確認(L378-385、別Issue合致なら FACT_TASK_IDENTITY_CONFLICT) → それ以外(accepted_implementation が None、または 別Taskに属する場合を含む)で implementation["status"] != "ACTIVE" なら duplicate_noop/activity_terminal で即return(L386-387、_validate_implementation_claims_tx() に到達しない) → _validate_implementation_claims_tx()(L388、cross-Task claim 照合により FACT_TASK_IDENTITY_CONFLICT を返しうる)。
    • L386 の elif 条件は「accepted_implementation が None」と「accepted_implementation が別Taskに属する」の両方を同一分岐に含めてしまうため、後者(cross-Task)でも implementation Activity が terminal であれば _validate_implementation_claims_tx() に到達せず activity_terminal に誤分類される。
    • implementation is None(L363-364)の早期returnは accepted_implementation 検索(L377)より前に評価されるため、Task の implementation Activity が未作成の場合は cross-Task 判定に一切到達しない。
  • .claude/skills/open-pr/scripts/open_pr.py::emit_implementation_pr_observed()(L563-615)は、origin = os.environ.get("CLAUDE_CODE_SESSION_ID") により現在のセッションの origin を決定し、GitHub GraphQL で PR↔Issue の closing relation を検証する(classify_closing_issue_relation())。この検証は GitHub 側の PR/Issue relation の正当性のみを確認するものであり、現在のセッションが束縛されている Task と、その dedupe_key の accepted fact を所有する Task が一致するかどうかは producer 側では一切チェックされない。
  • Issue 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625(実装済み、CLOSED)により、UserPromptSubmit の wrong-primary 検知は hard block ではなく advisory-only化されている。すなわち、別 Task を指す入力があっても Claude の workflow 自体は継続し、現在の Task binding は維持される。したがって、あるセッションが Task B に束縛されたまま、Task A が所有する accepted fact と同一 dedupe_key(同一 repo+PR)の implementation_pr_observed signal を(正当な GitHub PR↔Issue relationを伴って)送信すること自体は、producer / hook 双方の現行契約で妨げられない。
  • tests/task-context/test_workflow_signal_repair_regressions.py::test_given_merged_implementation_when_delayed_signal_for_different_issue_same_pr_arrives_then_it_is_identity_conflict_not_activity_terminal は Finding 2(同一Task・同一PR・別Issue・terminal)をカバーする。同ファイルの test_given_released_claims_when_same_task_or_other_task_replays_accepted_fact_then_no_state_is_written は cross-Task の FACT_TASK_IDENTITY_CONFLICT を検証しているが、cross-Task 側の Task(task_b)は workflow_signal_test_support.py::create_origin() により ACTIVE な implementation Activity を持つため、L386 の elif implementation["status"] != "ACTIVE" 分岐を経由せず、後段(L402-406)の汎用 accepted-event dedupe で conflict が検出される経路をテストしている。cross-Task の Task 側 implementation Activity が terminal または missing の状態で accepted fact が他Taskに属するケースは、test_signal_phase_monotonicity.py を含め、確認した既存テストのいずれにも直接のカバレッジがない(create_origin() は常に ACTIVE な implementation Activity を生成するため、cross-Task 側で terminal/missing を作るには追加のテスト構築が必要)。

Acceptance Criteria

  • apply_workflow_signal() 内の implementation_pr_observed 分岐について、identity/dedupe 判定と activity_missing / activity_terminal の評価順序(行番号付き)が本Issue本文に明記されている(上記「Repository Evidence」参照。以後の main 更新で行番号がずれた場合は再確認する)
  • cross-Task accepted fact × 現在Task terminal の組み合わせについて、current result と expected result が本Issue本文に記録されている
  • cross-Task accepted fact × 現在Task activity_missing の組み合わせについて、current result と expected result が本Issue本文に記録されている
  • 上記2組み合わせがそれぞれ既存テストで直接カバーされているか否かが確認され、結果が本Issue本文に記載されている
  • 実際の producer(open_pr.py::emit_implementation_pr_observed())と session/Task binding semantics(Issue 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625 を含む)から、上記シナリオが実運用で発生しうるか(reachability)についての判断が記録されている
  • Source で参照するコメントの provenance が検証され、齟齬があれば本Issue本文の Source 記述が修正されている
  • 修正が必要と判断された場合、terminal / missing 両経路を含む実装Issueが起票され本Issueからリンクされている。修正不要と判断された場合はその根拠が記載されている
  • 本Issueは close 可能、もしくは追加調査要件が明示されている

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本Issueは read-only のコード読解・既存テストの確認・provenance のfact-checkのみで完結する research Issue であり、プロセス起動・通信・新規I/Oを伴う動作検証は不要(change_kind: research-only)

Verification Commands

# baseline-expect: pass
$ rg -n "def apply_workflow_signal" scripts/task-context/task_context_workflow_signals.py
# baseline-expect: pass
$ rg -n "activity_missing" scripts/task-context/task_context_workflow_signals.py
# baseline-expect: pass
$ rg -n "activity_terminal" scripts/task-context/task_context_workflow_signals.py
# baseline-expect: pass
$ rg -n "FACT_TASK_IDENTITY_CONFLICT" scripts/task-context/task_context_workflow_signals.py
# baseline-expect: pass
$ rg -n "def emit_implementation_pr_observed" .claude/skills/open-pr/scripts/open_pr.py

上記のコード上の行位置確認だけでは AC2/AC3 の挙動・reachability を再現できないため、本Issue本文には以下の最小再現シーケンス(Task A / Task B / Task C、決定論的な入力と期待出力)を記録すること。既存 fixture(tests/task-context/workflow_signal_test_support.py::create_origin() 等)を利用した同等の deterministic reproduction でもよい。

Task A / session-a:
  implementation_pr_observed(issue=20, pr=21) → accepted
  (Task A がこの dedupe_key(repo+PR=21) の accepted fact を所有)

Task B / session-b:
  implementation_pr_observed(issue=30, pr=31) → accepted
  pr_merged_observed(issue=30, pr=31) → Task B の implementation Activity が terminal(DONE)

[経路1: terminal] session-b(Task Bに束縛されたまま)が Issue=20 / PR=21 の implementation_pr_observed signal を送信
  → current: duplicate_noop/activity_terminal
  → expected: conflict/FACT_TASK_IDENTITY_CONFLICT

Task C / session-c:
  implementation Activity 未作成(implementation_pr_observed を一度も受理していない)

[経路2: missing] session-c(Task Cに束縛されたまま)が Issue=20 / PR=21 の implementation_pr_observed signal を送信
  → current: deferred/activity_missing
  → expected: conflict/FACT_TASK_IDENTITY_CONFLICT

follow-up実装Issueを起票または既存Issueを再利用した場合は、その実Issue番号・URLを本Issue本文に記録したうえで、canonical approval後に live readback(gh issue view <実番号>)を行い、リンク・scope・terminal/missing 両経路の記載を確認すること(起票前の架空の Issue 番号をここに記載しない)。

Allowed Paths

  • 読み取り専用。リポジトリ変更なし(既定)
  • scripts/task-context/task_context_workflow_signals.py(precedence defect の調査対象。read-only)
  • .claude/skills/open-pr/scripts/open_pr.py(reachability 判断のための read-only 参照)
  • tests/task-context/(既存テストカバレッジ確認のための read-only 参照)

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
  • Allowed Paths 外への書き込みを試みた場合は即停止
  • 権限不足(permission denied)により操作が完了できない場合は即停止
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止

Handoff Contract

  • Current Objective: cross-Task accepted-fact identity判定が implementation Activity の local-state gate(activity_missing / activity_terminal)に先を越される precedence defect の reachability 確認と修正要否判断(両経路)
  • Bounded Current Context: PR feat: Task Contextへworkflow trusted signalsを統合する #2661(#2565実装)の OWNER レビュー Finding 2、実装: workflow trusted signalsとIssue/PR Task equivalenceをTask Contextへ統合する #2565 completion report の note_only_observation、OWNER anchor comment(issuecomment-5748838603)によるスコープ一般化指摘とその repository evidence 照合結果、前回 refinement-loop run の operator_intervention_required 停止(issuecomment-5748933140)とその body-author 側修正(Allowed Paths / placeholder VC / baseline annotation)
  • Open Questions: 両経路は実運用で reachable か(本調査では reachable と判断、Repository Evidence 参照)。reachable な場合の推奨修正方針は何か
  • Next Action: 修正要否の最終判断 → 必要なら実装Issue起票(両経路を含む)
  • Artifact Refs: scripts/task-context/task_context_workflow_signals.py の apply_workflow_signal()、.claude/skills/open-pr/scripts/open_pr.py の emit_implementation_pr_observed()

Source

dedupe_key: task-context-v1:implementation-pr-observed-cross-task-dedupe-edge-case

severity: optional_follow_up(non-blocking、緊急性なし、調査優先)

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    phase/research
    state/queued
    agent/research
    on Sep 20, 2026
  2. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    結論

    Issue #2685 の中心仮説は current main で成立しています。ただし、そのまま調査を完了して「activity_terminal の順序だけ直す実装Issue」を起票すると、同じ根因の別経路を残す可能性があります。レビュー判定は REQUEST_CHANGES 相当です。

    確認時点の main は dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95。PR #2661 の merge commit e952e328... から1 commitだけ進んでいますが、その1 commitは agent-guards 系のみで、対象の task_context_workflow_signals.py は変わっていません。したがって #2685 は現行 main にそのまま適用されます。Issue #2685

    Priority | Finding -- | -- P1 | 根因が activity_terminal より広い。activity_missing も cross-Task identity 判定を先取りする P1 | 「実運用reachabilityを確認する」というACと、「他モジュールの挙動調査はOut of Scope」が矛盾している P2 | Sourceとして指定された PR comment 5748250792 に、実際にはこの cross-Task warning が存在しない P2 | Verification Commands が行順検索だけで、AC2/AC3の挙動・reachabilityを再現できない

    P1 — 問題は activity_terminal だけではない

    current implementation の重要部分は次の順です。current main の apply_workflow_signal()

    origin Task 解決
    ↓
    implementation Activity 取得
    ↓
    Activity が無い
      → deferred/activity_missing             ← ここで終了
    ↓
    accepted_implementation を dedupe_key で検索
    ↓
    accepted fact が same Task なら metadata 確認
    ↓
    それ以外で current Activity が terminal
      → duplicate_noop/activity_terminal      ← #2685 が指摘
    ↓
    _validate_implementation_claims_tx()
    ↓
    後段の共通 accepted-event dedupe
      same Task → SAME_TASK_SAME_FACT
      other Task → FACT_TASK_IDENTITY_CONFLICT

    つまり #2685 が指摘する

    Task A owns accepted PR fact
    Task B origin
    Task B implementation = DONE
    → activity_terminal が cross-Task conflict を隠す

    は正しいです。

    しかし、そのさらに前に

    if implementation is None:
        return _outcome("deferred", "activity_missing")

    があります。したがって、

    Task A owns accepted PR fact
    Task C origin
    Task C に implementation Activity がまだ無い
    → deferred/activity_missing
    → FACT_TASK_IDENTITY_CONFLICT まで到達しない

    も同じ構造で成立します。

    これは親 #2565 AC3/AC10 の「claim/Task consistency → accepted-fact dedupe → phase/state judgment」「same fact resolved to another Task は typed identity conflict」という契約と整合しません。Parent Issue #2565

    したがって、調査対象を **「terminal short-circuit」ではなく「implementation Activity の local-state gate が cross-Task fact identity より先に評価される問題」**へ一段一般化した方がよいです。

    P1 — このケースは実運用上 reachable

    これは単なるDBを直接加工した人工ケースではありません。

    #2625 により wrong-primary UserPromptSubmit は hard block ではなく advisory-only です。別Taskを指す入力でも Claude の workflow 自体は継続し、Binding は元Taskのまま維持されます。さらに #2625 は、workflow signal が session origin と整合しない場合には Task Context 側で deferred / conflict に分類し、producer 本体をrollbackしない設計を明示しています。Issue #2625

    一方 open_pr.py::emit_implementation_pr_observed() は、現在の CLAUDE_CODE_SESSION_ID を origin としつつ、GitHubから取得した PR↔Issue relation を検証して、その evidence を signal apply に送ります。つまり GitHub上の PR A ↔ Issue A relation が正しければ、現在のセッションが Task B にbindingされていることは producer classifier では排除されません。

    実際に次の通常シーケンスだけで再現できます。

    Task A / session-a
      implementation_pr_observed(issue=20, pr=21)
      → accepted
    

    Task B / session-b
    implementation_pr_observed(issue=30, pr=31)
    → accepted
    pr_merged_observed(issue=30, pr=31)
    → Task B implementation = DONE

    session-b 上で PR #21 / Issue #20 の open-pr signal
    → GitHub relation 自体は正しい
    → origin resolves to Task B
    → accepted_implementation belongs Task A
    → CURRENT: duplicate_noop/activity_terminal
    → EXPECTED: conflict/FACT_TASK_IDENTITY_CONFLICT

    GitHub側の closing relation はあくまで PR と Issue の関係です。GitHubは別repositoryのIssueへのclosing referenceも正式にサポートしており、このrelation validationとローカルのTask identityは別問題です。(GitHub Docs)

    したがって reachability = yes と判断してよいです。

    P2 — 既存テストは「2軸を別々に」覆っているだけ

    current tests にはかなり近い証拠があります。

    test_workflow_signal_repair_regressions.py には、same Task / same PR / different Issue / terminal のケースがあり、FACT_TASK_IDENTITY_CONFLICT を期待しています。また同ファイルには、accepted fact の claim をreleaseした後に other Task から同じfactをreplayすると cross-Task conflict になるテストもあります。repair regressions

    一方 test_signal_phase_monotonicity.py は、新規fact + terminal implementation が activity_terminal になることだけを検証しています。phase monotonicity tests

    つまり、

    cross-Task accepted fact
    ×
    current Task terminal

    の組み合わせが抜けています。さらに cross-Task accepted fact × activity_missing も検索上カバーされていません。

    これは #2685 の「既存test evidenceなし」という結論を支持します。

    P2 — Source provenance が壊れている

    #2685 は最初の指摘元として PR #2661 comment 5748250792 を指定しています。しかし現在取得できるそのコメント本文の warnings は、

    PR body の test count が stale
    non-required deploy checks cancelled
    AC8 canaryをreviewer自身では再実行していない

    であり、cross-Task dedupe / activity_terminal の話はありません。comment 5748250792

    cross-Task edge が明示されているのは、後段の #2565 completion report 5748658065 です。ただしそのreport自身も 5748250792 を source_url としているため、provenance chain が循環的に誤っています。completion report 5748658065

    OWNER review 5748354743 には terminal ordering 問題がありますが、そこは same Task / same PR / different Issue の Finding 2 であり、今回の cross-Task variantそのものではありません。OWNER review 5748354743

    Issue本文では「最初に指摘された」と断定せず、**「#2565 completion report で follow-up observation としてmaterializeされた。元リンク 5748250792 は現在の本文からは裏付け不能。current code inspectionで独立確認済み」**程度へ修正した方が証跡として健全です。

    スコープとVerificationも修正した方がよい

    現在の Out of Scope にある「task_context_workflow_signals.py 以外のモジュールの挙動調査」は、AC3のreachability確認と両立しません。今回実際に reachability を判断するには、少なくとも open-pr producer と #2625 advisory semantics を読む必要がありました。

    「コード変更対象はなし。reachability判断のための read-only dependency tracing は open-pr / Task Context docs / relevant tests まで許可」と変えるのが適切です。

    Verification Commands も rg だけでは不足です。最低限、調査結果に上記の Task A / Task B sequence と current result / expected result を記録するべきです。実装Issue側では大型E2Eではなく、既存fixtureによるfocused regression 2本で十分です。

    修正方針も新しいledgerやDB schemaは不要です。SQLiteの BEGIN IMMEDIATE はwrite transactionを即時開始し、UNIQUE partial indexは対象row subsetの一意性を物理的に保証します。現行の events.dedupe_key WHERE dedupe_key IS NOT NULL 方針はそのままで妥当です。問題は 早期returnによってそのglobal identity判定まで到達しないapplication-level precedence にあります。(SQLite)

    実装Issueの修正順序は、概念的には

    origin resolution
    → implementation claim / Task consistency
    → accepted implementation fact の ownership + metadata + dedupe
    → ここまで全部通った「新規fact」にだけ
    activity_missing / activity_terminal を適用
    → claim attach + event append

    とするのが一番素直です。

    これなら既存の BEGIN IMMEDIATE、append-only events、partial UNIQUE indexをそのまま使えます。セキュリティ境界、retry framework、追加ledger、汎用ハーネスはいずれも不要です。

    要点としては、#2685 は close ではなく refinement 継続が妥当です。 activity_terminal の再現確認自体はほぼ完了していますが、実装Issueを起票する前に activity_missing を同じ根因へ取り込み、SourceとOut of Scope、Verificationを修正するのが最小かつ取りこぼしの少ない進め方です。

    ## 結論

    Issue #2685 の中心仮説は current main で成立しています。ただし、そのまま調査を完了して「activity_terminal の順序だけ直す実装Issue」を起票すると、同じ根因の別経路を残す可能性があります。レビュー判定は REQUEST_CHANGES 相当です。

    確認時点の main は dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95。PR #2661 の merge commit e952e328... から1 commitだけ進んでいますが、その1 commitは agent-guards 系のみで、対象の task_context_workflow_signals.py は変わっていません。したがって #2685 は現行 main にそのまま適用されます。[Issue #2685](https://github.com/squne121/loop-protocol/issues/2685?utm_source=chatgpt.com)

    Priority Finding
    P1 根因が activity_terminal より広い。activity_missing も cross-Task identity 判定を先取りする
    P1 「実運用reachabilityを確認する」というACと、「他モジュールの挙動調査はOut of Scope」が矛盾している
    P2 Sourceとして指定された PR comment 5748250792 に、実際にはこの cross-Task warning が存在しない
    P2 Verification Commands が行順検索だけで、AC2/AC3の挙動・reachabilityを再現できない

    P1 — 問題は activity_terminal だけではない

    current implementation の重要部分は次の順です。[current main の apply_workflow_signal()](

    def apply_workflow_signal(
    conn: sqlite3.Connection, payload: Any, *, origin_session_id: str | None = None
    ) -> dict[str, Any]:
    """Apply one validated workflow fact in one BEGIN IMMEDIATE transaction."""
    valid, rejected = validate_public_signal(payload)
    if rejected:
    return rejected
    assert valid is not None
    key = dedupe_key_for(valid)
    try:
    with db.write_transaction(conn):
    origin, outcome = _resolve_origin_tx(conn, origin_session_id)
    if outcome:
    return outcome
    assert origin is not None
    task_id, kind, evidence = origin["task_id"], valid["signal_kind"], valid["evidence"]
    if kind == "implementation_pr_observed":
    implementation = _activity_for_tx(conn, task_id, "implementation")
    if implementation is None:
    return _outcome("deferred", "activity_missing")
    # The implementation dedupe key deliberately identifies a PR,
    # not an Issue. Per AC3's precedence (claim/Task consistency
    # -> same-fact dedupe -> phase/terminal judgment), identity
    # must be judged before phase/terminal status: an exact
    # replay of the accepted fact falls through to the common
    # SAME_TASK_SAME_FACT dedupe below regardless of Activity
    # status, and a replay with the same PR but another Issue is
    # always an identity conflict -- never a duplicate_noop --
    # even once the implementation Activity has already reached
    # DONE. Only a genuinely new fact (no accepted event for this
    # dedupe key belongs to this Task) arriving after the
    # Activity is already terminal is `activity_terminal`.
    accepted_implementation = _accepted_event_tx(conn, key)
    if accepted_implementation and accepted_implementation["task_id"] == task_id:
    if not _metadata_matches(
    accepted_implementation,
    repo=evidence["repo"],
    issue_number=evidence["issue_number"],
    pr_number=evidence["pr_number"],
    ):
    return _outcome("conflict", "FACT_TASK_IDENTITY_CONFLICT")
    elif implementation["status"] != "ACTIVE":
    return _outcome("duplicate_noop", "activity_terminal", task_id=task_id)
    outcome = _validate_implementation_claims_tx(conn, task_id, evidence)
    elif kind == "pr_merged_observed":
    outcome = _validate_merged_prerequisites_tx(conn, task_id, evidence)
    elif kind == "cleanup_completed":
    accepted_merge, outcome = _matching_accepted_merge_tx(conn, task_id, evidence)
    if outcome:
    return outcome
    if accepted_merge is None:
    return _outcome("conflict", "OUT_OF_ORDER_SIGNAL")
    outcome = _validate_required_claims_tx(conn, task_id, evidence)
    else:
    outcome = _validate_required_claims_tx(conn, task_id, evidence)
    if outcome:
    return outcome
    existing = _accepted_event_tx(conn, key)
    if existing:
    if existing["task_id"] == task_id:
    return _outcome("duplicate_noop", "SAME_TASK_SAME_FACT", task_id=task_id)
    return _outcome("conflict", "FACT_TASK_IDENTITY_CONFLICT")
    if kind == "pr_merged_observed" and _has_cleanup_started_tx(
    conn, task_id, evidence["repo"], evidence["pr_number"]
    ):
    return _outcome("late_noop", "CLEANUP_ALREADY_BEGUN", task_id=task_id)
    activity_kind = {
    "refinement_approved": "refine",
    "implementation_pr_observed": "implementation",
    "pr_merged_observed": "implementation",
    }.get(kind)
    activity = _activity_for_tx(conn, task_id, activity_kind) if activity_kind else None
    if kind == "implementation_pr_observed":
    if activity is None:
    return _outcome("deferred", "activity_missing")
    _attach_implementation_claims_tx(conn, task_id, evidence)
    )

    origin Task 解決
    ↓
    implementation Activity 取得
    ↓
    Activity が無い
      → deferred/activity_missing             ← ここで終了
    ↓
    accepted_implementation を dedupe_key で検索
    ↓
    accepted fact が same Task なら metadata 確認
    ↓
    それ以外で current Activity が terminal
      → duplicate_noop/activity_terminal      ← #2685 が指摘
    ↓
    _validate_implementation_claims_tx()
    ↓
    後段の共通 accepted-event dedupe
      same Task → SAME_TASK_SAME_FACT
      other Task → FACT_TASK_IDENTITY_CONFLICT
    

    つまり #2685 が指摘する

    Task A owns accepted PR fact
    Task B origin
    Task B implementation = DONE
    → activity_terminal が cross-Task conflict を隠す
    

    は正しいです。

    しかし、そのさらに前に

    if implementation is None:
        return _outcome("deferred", "activity_missing")

    があります。したがって、

    Task A owns accepted PR fact
    Task C origin
    Task C に implementation Activity がまだ無い
    → deferred/activity_missing
    → FACT_TASK_IDENTITY_CONFLICT まで到達しない
    

    も同じ構造で成立します。

    これは親 #2565 AC3/AC10 の「claim/Task consistency → accepted-fact dedupe → phase/state judgment」「same fact resolved to another Task は typed identity conflict」という契約と整合しません。[Parent Issue #2565](https://github.com/squne121/loop-protocol/issues/2565?utm_source=chatgpt.com)

    したがって、調査対象を **「terminal short-circuit」ではなく「implementation Activity の local-state gate が cross-Task fact identity より先に評価される問題」**へ一段一般化した方がよいです。

    P1 — このケースは実運用上 reachable

    これは単なるDBを直接加工した人工ケースではありません。

    #2625 により wrong-primary UserPromptSubmit は hard block ではなく advisory-only です。別Taskを指す入力でも Claude の workflow 自体は継続し、Binding は元Taskのまま維持されます。さらに #2625 は、workflow signal が session origin と整合しない場合には Task Context 側で deferred / conflict に分類し、producer 本体をrollbackしない設計を明示しています。[Issue #2625](https://github.com/squne121/loop-protocol/issues/2625?utm_source=chatgpt.com)

    一方 open_pr.py::emit_implementation_pr_observed() は、現在の CLAUDE_CODE_SESSION_ID を origin としつつ、GitHubから取得した PR↔Issue relation を検証して、その evidence を signal apply に送ります。つまり GitHub上の PR A ↔ Issue A relation が正しければ、現在のセッションが Task B にbindingされていることは producer classifier では排除されません。

    実際に次の通常シーケンスだけで再現できます。

    Task A / session-a
      implementation_pr_observed(issue=20, pr=21)
      → accepted
    
    Task B / session-b
      implementation_pr_observed(issue=30, pr=31)
      → accepted
      pr_merged_observed(issue=30, pr=31)
      → Task B implementation = DONE
    
    session-b 上で PR #21 / Issue #20 の open-pr signal
      → GitHub relation 自体は正しい
      → origin resolves to Task B
      → accepted_implementation belongs Task A
      → CURRENT: duplicate_noop/activity_terminal
      → EXPECTED: conflict/FACT_TASK_IDENTITY_CONFLICT
    

    GitHub側の closing relation はあくまで PR と Issue の関係です。GitHubは別repositoryのIssueへのclosing referenceも正式にサポートしており、このrelation validationとローカルのTask identityは別問題です。([GitHub Docs]1)

    したがって reachability = yes と判断してよいです。

    P2 — 既存テストは「2軸を別々に」覆っているだけ

    current tests にはかなり近い証拠があります。

    test_workflow_signal_repair_regressions.py には、same Task / same PR / different Issue / terminal のケースがあり、FACT_TASK_IDENTITY_CONFLICT を期待しています。また同ファイルには、accepted fact の claim をreleaseした後に other Task から同じfactをreplayすると cross-Task conflict になるテストもあります。[repair regressions](https://github.com/squne121/loop-protocol/blob/dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95/tests/task-context/test_workflow_signal_repair_regressions.py?utm_source=chatgpt.com)

    一方 test_signal_phase_monotonicity.py は、新規fact + terminal implementation が activity_terminal になることだけを検証しています。[phase monotonicity tests](https://github.com/squne121/loop-protocol/blob/dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95/tests/task-context/test_signal_phase_monotonicity.py?utm_source=chatgpt.com)

    つまり、

    cross-Task accepted fact
    ×
    current Task terminal
    

    の組み合わせが抜けています。さらに cross-Task accepted fact × activity_missing も検索上カバーされていません。

    これは #2685 の「既存test evidenceなし」という結論を支持します。

    P2 — Source provenance が壊れている

    #2685 は最初の指摘元として PR #2661 comment 5748250792 を指定しています。しかし現在取得できるそのコメント本文の warnings は、

    PR body の test count が stale
    non-required deploy checks cancelled
    AC8 canaryをreviewer自身では再実行していない
    

    であり、cross-Task dedupe / activity_terminal の話はありません。[comment 5748250792](#2661)

    cross-Task edge が明示されているのは、後段の #2565 completion report 5748658065 です。ただしそのreport自身も 5748250792 を source_url としているため、provenance chain が循環的に誤っています。[completion report 5748658065](#2565)

    OWNER review 5748354743 には terminal ordering 問題がありますが、そこは same Task / same PR / different Issue の Finding 2 であり、今回の cross-Task variantそのものではありません。[OWNER review 5748354743](#2661)

    Issue本文では「最初に指摘された」と断定せず、**「#2565 completion report で follow-up observation としてmaterializeされた。元リンク 5748250792 は現在の本文からは裏付け不能。current code inspectionで独立確認済み」**程度へ修正した方が証跡として健全です。

    スコープとVerificationも修正した方がよい

    現在の Out of Scope にある「task_context_workflow_signals.py 以外のモジュールの挙動調査」は、AC3のreachability確認と両立しません。今回実際に reachability を判断するには、少なくとも open-pr producer と #2625 advisory semantics を読む必要がありました。

    「コード変更対象はなし。reachability判断のための read-only dependency tracing は open-pr / Task Context docs / relevant tests まで許可」と変えるのが適切です。

    Verification Commands も rg だけでは不足です。最低限、調査結果に上記の Task A / Task B sequence と current result / expected result を記録するべきです。実装Issue側では大型E2Eではなく、既存fixtureによるfocused regression 2本で十分です。

    修正方針も新しいledgerやDB schemaは不要です。SQLiteの BEGIN IMMEDIATE はwrite transactionを即時開始し、UNIQUE partial indexは対象row subsetの一意性を物理的に保証します。現行の events.dedupe_key WHERE dedupe_key IS NOT NULL 方針はそのままで妥当です。問題は 早期returnによってそのglobal identity判定まで到達しないapplication-level precedence にあります。([SQLite]2)

    実装Issueの修正順序は、概念的には

    origin resolution
    → implementation claim / Task consistency
    → accepted implementation fact の ownership + metadata + dedupe
    → ここまで全部通った「新規fact」にだけ
       activity_missing / activity_terminal を適用
    → claim attach + event append
    

    とするのが一番素直です。

    これなら既存の BEGIN IMMEDIATE、append-only events、partial UNIQUE indexをそのまま使えます。セキュリティ境界、retry framework、追加ledger、汎用ハーネスはいずれも不要です。

    要点としては、#2685 は close ではなく refinement 継続が妥当です。 activity_terminal の再現確認自体はほぼ完了していますが、実装Issueを起票する前に activity_missing を同じ根因へ取り込み、SourceとOut of Scope、Verificationを修正するのが最小かつ取りこぼしの少ない進め方です。

  3. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    対象コメントと現行 issue-refinement-loop 契約を確認しました。現時点の main HEAD はコメント記載どおり dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95 です。

    推奨は、コメント #5748838603 をoperator-selected human contextとして with_human_context lane に投入し、単なる activity_terminal 修正ではなく、Issue #2685 を次の根因へ一般化して refinement することです。

    • implementation Activity の local-state gate(activity_missing / activity_terminal)が、cross-Task accepted-fact identity 判定より先に評価される precedence defect
    • repository の実装変更はまだ行わず、Issue契約の Goal / Scope / AC / Source / Verification を修正する
    • reachability 調査に必要な open-pr producer、実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625、関連 Task Context docs/tests は read-only dependency tracing として許可する
    • 5748250792 を「最初の指摘元」と断定する provenance は修正する
    • focused regression の要求を terminal と missing の2ケースまで明示する
    • refinement が approved になり修正必要が確定した場合だけ、既存の dependency/follow-up materialization 契約に従って実装Issueを起票・再利用する。実装自体は開始しない
    • iteration 間の人間承認は要求しない。現行 skill 自体も loop_iteration_approval_gate.default_required: false
    • ただし skill が genuine human_judgment_required / environment failure / integrity failure / max-iterations 等を返した場合は、その stop condition を迂回しない
    • Step 1 の codebase-investigator など、canonical flow が起動した SubAgent は必ず完了結果を取得してから次へ進む
    • canonical Step 2 の root_review_pipeline.produce も run_in_background: true で起動後、completion join が完了するまで routing しない

    そのまま auto mode の ClaudeCode に貼るなら、以下を推奨します。

    Issue #2685 の refinement を、以下の OWNER comment を authoritative human context として実行してください。

    Target Issue:
    #2685

    Authoritative anchor / human-context comment:
    #2685 (comment)

    使用する Skill:
    https://github.com/squne121/loop-protocol/tree/main/.claude/skills/issue-refinement-loop

    既にこの ClaudeCode セッションは auto mode で起動済みです。
    permission mode や auto mode の設定変更は行わず、repository の issue-refinement-loop が定義する canonical workflow をそのまま使用してください。

    実行方針

    issue-refinement-loop を Issue #2685 に対して起動し、上記 comment を operator-selected human context として扱ってください。

    origin lane は URL や author_association から推定せず、今回オペレーターが明示的に指定した comment なので canonical with_human_context lane を使用してください。

    routine な iteration ごとの人間承認は不要です。
    loop_iteration_approval_gate.default_required: false に従い、needs-fix の場合は max_iterations の範囲で自律的に調査 → review → rewrite → fresh review を継続してください。

    ただし canonical workflow が以下を返した場合は勝手に bypass しないでください。

    • genuine human_judgment_required
    • operator_intervention_required
    • environment / transport / artifact integrity failure
    • max_iterations 到達
    • その他 skill が規定する fail-closed stop condition

    これら以外では途中確認を求めず、approved または正規の termination まで進めてください。

    今回の refinement で解消すべき中心事項

    anchor comment の findings を単なる追記として扱わず、Issue contract 全体へ整合的に反映してください。

    特に、現在の Issue #2685 の中心問題を

    activity_terminal が cross-Task dedupe に先行する

    だけに限定せず、

    implementation_pr_observed において、implementation Activity の local-state gate が cross-Task accepted-fact identity / ownership 判定より先に評価される precedence defect

    として一般化することを検討してください。

    少なくとも以下の2経路を同じ根因として扱える contract にしてください。

    1. cross-Task accepted fact × current Task implementation terminal

      • current: duplicate_noop/activity_terminal
      • expected contract direction: conflict/FACT_TASK_IDENTITY_CONFLICT
    2. cross-Task accepted fact × current Task implementation Activity missing

      • current: deferred/activity_missing
      • expected contract direction: conflict/FACT_TASK_IDENTITY_CONFLICT

    最終的な技術判断は current-main の repository evidence で再検証し、anchor comment の文章を無検証でコピーしないでください。

    必須調査

    current main を fresh readback して SHA を記録してください。
    このプロンプト作成時点では dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95 ですが、実行時点の live HEAD を authority としてください。

    Issue本文、anchor comment、関連Issue/PR/comment、および current repository assets を調査してください。

    最低限確認対象:

    anchor comment が指摘する provenance 問題も独立に fact-check してください。

    5748250792 に cross-Task warning が実際に存在しないことが確認できた場合は、Issue本文の Source を
    「最初に指摘された」
    と断定しない形へ修正してください。

    例えば意味としては、

    という provenance を残してください。

    Scope の修正方針

    現在の

    task_context_workflow_signals.py 以外のモジュールの挙動調査は Out of Scope

    という制約と、

    実運用での reachability を確認する

    という AC が矛盾しているため、必要なら contract を修正してください。

    推奨方向:

    • repository code の実装変更は引き続き Out of Scope
    • research-only を維持
    • reachability 判断のための read-only dependency tracing は許可
    • 少なくとも open-pr producer / Task Context docs / relevant tests / related contracts までは読めるようにする

    新しい daemon、ledger、generic authorization framework、security harness 等へ scope を広げないでください。

    Acceptance Criteria / Verification の改善

    AC が少なくとも次を検索可能・検証可能な形で固定されるよう refinement してください。

    単なる rg による行位置確認だけを Verification としないでください。

    Task A / Task B の最小再現シーケンス、または既存 fixture を利用した同等の deterministic reproduction を contract に記述してください。

    実装Issueを materialize する場合、少なくとも以下の focused regression が要求されるようにしてください。

    • cross-Task accepted fact × terminal implementation Activity
    • cross-Task accepted fact × missing implementation Activity

    巨大な新規E2Eや汎用ハーネスを追加する前提にはしないでください。

    修正方針の候補は、current architecture を維持しつつ概念的に

    origin resolution
    → claim / Task consistency
    → accepted implementation fact ownership / metadata / dedupe
    → 新規 fact と確定した後だけ local Activity state (activity_missing / activity_terminal) を評価
    → claim attach / event append

    となる precedence の妥当性を検討してください。

    ただしこれは anchor の technical recommendation であり、current code / contract evidence と照合したうえで採否を決めてください。

    SubAgent 実行契約

    repository evidence 調査が planner により必要と判定された場合、canonical Step 1 の codebase-investigator SubAgent を使用してください。

    SubAgent は read-only とし、mutation を行わせないでください。

    SubAgent を起動したら fire-and-forget にしないこと。
    必ずその SubAgent の実際の完了と structured result の返却を待ち、結果を取得してから次の phase へ進んでください。

    外部仕様調査が planner により必要とされた場合は canonical web-researcher を使用し、同様に完了結果を取得してから継続してください。

    SubAgent がまだ実行中の状態で review / rewrite / termination を開始しないでください。

    canonical planner が SubAgent 不要と判定した場合は、その判定を prose で上書きして独自 dispatch せず、planner authority に従ってください。

    また Step 2 は issue-reviewer SubAgent を独自起動しないでください。
    current issue-refinement-loop 契約どおり root-owned run_root_review_pipeline.py produce を使用してください。

    Step 2 の producer は明示的に background launch し、completion notification / completed JSON result を join してから routing してください。
    background task を起動しただけで Step 2 完了扱いにしてはいけません。

    Mutation 方針

    repository filesystem の production code / tests は変更しないでください。
    この run の対象は Issue contract refinement です。

    Issue本文の更新は issue-refinement-loop の canonical controlled transaction / issue-editor route に従ってください。
    raw gh issue edit 等で skill の transaction/readback gate を迂回しないでください。

    anchor comment を新規投稿し直さないでください。
    既存の comment 5748838603 を canonical anchor として使用してください。

    Issue body/title の mutation 後は、必ず live readback → fresh preflight → fresh review → readiness を実施し、stale な pre-mutation verdict を再利用しないでください。

    Follow-up issue

    refinement の結果、

    • defect が current main で成立
    • reachability が成立
    • implementation fix が必要

    と canonical review で確定した場合、Issue #2685 の既存契約および issue-refinement-loop の dependency/follow-up materialization gate が許可する範囲で、実装Issueを自律的に起票するか既存Issueを再利用してください。

    実装Issueには activity_terminal だけでなく、同じ root cause である activity_missing 経路も取り込んでください。

    ただしこの run では implementation code の変更や impl-review-loop の開始までは行わないでください。
    目的は Issue #2685 の refinement と、必要な follow-up implementation contract の materialization までです。

    既存Issueが同じ root cause を既に所有している場合は duplicate Issue を作らず reuse してください。

    最終出力

    canonical issue-refinement-loop が approved または正規の stop condition に到達するまで進めてください。

    終了時には GitHub 上の canonical termination/report 契約に従い、少なくとも以下を明示してください。

    • termination reason
    • authoritative anchor URL
    • refinement 前後の Issue body SHA
    • current-main SHA
    • 実際に調査した repository evidence
    • SubAgent を使用した場合、その completion を join 済みであること
    • anchor findings の各 disposition
    • reachability の最終判断
    • terminal / missing 両経路の扱い
    • Source provenance 修正結果
    • follow-up implementation Issue の create / reuse / not-needed
    • unresolved blocker があればその exact reason
    • impl-review-loop はこの run では起動していないこと

    途中で人間へ通常の承認確認を求めず、canonical workflow が許す範囲で自律的に最後まで実行してください。

    特に重要なのは、コメント本文をそのまま Issue に転記させるのではなく、with_human_context を「変更要求の authority」として使い、技術的主張自体は SubAgent の current-main 調査で再検証させる点です。これなら今回の OWNER comment の意図と、issue-refinement-loop の trust / mutation 境界の両方に沿います。

  4. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 終了報告(operator_intervention_required)

    • termination_reason: human_escalation(termination_cause: operator_intervention_required、canonical run_root_review_pipeline.py produce の canonical_step2_route: step_5_operator_intervention_required に基づく fail-closed 停止。本 run では bypass していません)
    • authoritative anchor: https://github.com/squne121/loop-protocol/issues/2685#issuecomment-5748838603(OWNER, with_human_context lane)
    • current-main SHA(調査・rewrite全体で使用): dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95
    • Issue body SHA(rewrite前): sha256:8233688d0e2f9e5cf3870196e8eb4daf90405335a2e54c442a89895ee1f2a6aa
    • Issue body SHA(rewrite後、live readback で独立確認済み): sha256:98286320cfde0f1a22c66796f629933093bb52851bd32f3db9fdad8a2768fd42

    実施した調査・rewriteの要約

    anchor comment(OWNER, comment 5748838603)の指摘を、codebase-investigator SubAgent(read-only, 完了・結果join済み)とmain thread自身の直接検証(gh api によるcomment本文取得、scripts/task-context/task_context_workflow_signals.py / .claude/skills/open-pr/scripts/open_pr.py の直接読解、tests/task-context/ 配下の既存テスト直接確認)の両方で照合した。

    • P1(activity_terminalに限定しない一般化): 確認済み・採用。apply_workflow_signal() の implementation_pr_observed 分岐で、implementation is None(L363-364, deferred/activity_missing)が accepted_implementation のdedupe_key検索(L377)より前に評価される。elif implementation["status"] != "ACTIVE"(L386-387, duplicate_noop/activity_terminal)も、accepted_implementation が別Taskに属するケースを含めて短絡し _validate_implementation_claims_tx()(L388)に到達しない。両経路とも同一のprecedence defect構造であることをコード直接読解で確認した。
    • P1(reachability = yes): 確認済み・採用。.claude/skills/open-pr/scripts/open_pr.py::emit_implementation_pr_observed()(L563-615)は CLAUDE_CODE_SESSION_ID ベースのorigin解決とGitHub側PR↔Issue relation検証のみを行い、現在のセッションが束縛されているTaskとaccepted factの所有Taskの一致は検証しない。Issue 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625(advisory-only化、CLOSED・実装済み)により、別Taskを指す入力があってもTask bindingは維持される。したがって記載のTask A/B/Cシーケンスは実運用でreachableと判断した。
    • P2(テストカバレッジgap): 確認済み・採用。tests/task-context/test_workflow_signal_repair_regressions.py::test_given_released_claims_when_same_task_or_other_task_replays_accepted_fact_then_no_state_is_written はcross-Task conflictを検証するが、task_bのimplementation ActivityはACTIVEであり、terminal/missing状態でのcross-Task defectは既存テストのいずれにも直接のカバレッジがないことを確認した。
    • P2(Source provenance): anchor commentの主張どおり修正。gh api repos/squne121/loop-protocol/issues/comments/5748250792 を直接fetchし、実際の本文がPR body test件数stale/non-required deploy check cancelled/AC8 canary未再実行の3件のみでcross-Task/activity_terminalへの言及が存在しないことを独立確認した。なお、調査過程で codebase-investigator SubAgentが一度この点について誤った報告(5748354743の内容を5748250792の内容として誤引用)をしたため、direct gh api fetchで再検証し、anchor commentの主張が正しいことを確定させた。Issue本文のSourceセクションはこの検証結果に基づき「最初に指摘された」という断定を避ける記述へ書き換え済み。
    • Issue本文は上記を反映して全面書き換え済み(issue-editor SubAgent経由、controlled transaction、live readback一致確認済み)。

    到達した停止条件

    書き換え後の fresh preflight は STATUS: pass / NEXT_ACTION: proceed だったが、続くcanonical Step 2 review(run_root_review_pipeline.py produce、background実行・完了JSON join済み)が以下を返した。

    canonical_step2_route: step_5_operator_intervention_required
    status: ok
    verdict: needs-fix
    next_action: request_changes
    failure_class: contract_readiness_human_judgment
    

    blocking_issues の内訳:

    • ## Verification Commands 内の5件の rg コマンドが broad_search_path_unbounded として blocked 判定(対象ファイル scripts/task-context/task_context_workflow_signals.py が本Issueの ## Allowed Paths に列挙した具体パス集合に含まれていないため、baseline_vc_preflight.py のcontainmentチェックでbroad扱いになった)
    • プレースホルダーの $ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBER コマンドが実行不能で Unable to automatically classify exit code として分類不能になった

    このうち broad_search_path_unbounded は readiness map 上は本来 needs_fix(body-author-fixable)に分類される既知カテゴリだが、分類不能な項目が同時に存在したため readiness 判定全体が human_judgment に引き上がり、canonical_step2_route が step_5_operator_intervention_required を返した。

    本runの実行方針(オペレーター指示)は「genuine ... operator_intervention_required ... の場合は勝手に bypass しないでください」と明記しており、canonical routing table(.claude/skills/issue-refinement-loop/SKILL.md Step 2)も本ルートを『通常のStep 4 rewriteサイクルへは進めない』5番目の独立分岐として扱う設計になっているため、本runはここで自律rewriteループを継続せず停止する。

    unresolved blocker(次の実行のために必要な対応)

    人間判断待ちの内容は技術的には body-author 側で解消可能に見える(Allowed Pathsへの scripts/task-context/task_context_workflow_signals.py の明記、およびプレースホルダーVCコマンドの $ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBER の除去/annotation)が、canonical routingが本ケースをoperator_intervention_requiredとして分離しているため、次のrefinement-loop起動時にこの2点を含めた追加rewriteの要否を人間側で判断されたい。

    follow-up 実装Issue

    本stop conditionにより canonical review が approve へ到達していないため、follow-up実装Issueの起票は行っていない(created: false, reused: false, not_needed: false — 判断ペンディング)。

    確認事項

    • SubAgent(codebase-investigator)は起動後、実際の完了・structured resultをjoin済み(fire-and-forgetではない)
    • web-researcher は planner の web_research_policy.required: false のため起動していない
    • impl-review-loop は本runでは起動していない
  5. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    推奨アクションは、前回の operator_intervention_required を bypass せず、人間判断で blocker 修正を明示的に承認した新しい refinement run を開始することです。前回 run は canonical Step 2 の step_5_operator_intervention_required で正しく停止しており、follow-up 実装Issueも未作成です。

    GitHub connector で live 状態も確認しました。現在の main は 33a6ffbf450dd4132201c59f243d723cdeeabdd8 で、前回の dc286d9f... から1 commit進んでいます。ただし変更対象は issue-refinement-loop の owner-reaction 系のみで、今回の defect 本体である task_context_workflow_signals.py / open_pr.py は変わっていません。したがって、再調査を最初からやり直すより、fresh readback を行ったうえで次の contract repair に集中するのが適切です。

    1. ## Allowed Paths に少なくとも scripts/task-context/task_context_workflow_signals.py と .claude/skills/open-pr/scripts/open_pr.py を具体パスとして明記し、必要なら tests/task-context/ も read-only 調査対象として明記する。既存コードを検索する rg は baseline で成功する性質なので、各コマンドに # baseline-expect: pass を付けるのが安全です。$ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBER は executable VC から削除し、実Issue番号確定後の live readback 要件を prose にするべきです。さらに canonical review が approve した場合だけ terminal/missing 両経路を含む follow-up 実装Issueを create/reuse し、調査: apply_workflow_signal()のimplementation_pr_observed分岐でcross-Task dedupeがactivity_terminal判定に先を越されるエッジケース #2685 自体では実装を始めません。

    そのまま ClaudeCode に貼るプロンプトです。

    Issue #2685 の issue-refinement-loop を、前回 run の operator_intervention_required を解消する 新しい run として再開してください。

    対象:

    このプロンプト自体を、前回 operator_intervention_required に対する operator decision として扱ってください。

    Operator decision

    前回 run が canonical_step2_route: step_5_operator_intervention_required で停止した判断は正当です。旧 run の結果を bypass・改竄・再分類しないでください。

    そのうえで、人間判断として 次の Issue body-author 側修正を行った上で、新しい canonical review を実施することを承認します。

    1. broad_search_path_unbounded の解消

      • ## Allowed Paths に、Verification Commands が直接参照する具体パスを明示してください。

      • 少なくとも以下を明記してください。

        • scripts/task-context/task_context_workflow_signals.py
        • .claude/skills/open-pr/scripts/open_pr.py
      • regression coverage の read-only 調査に必要なら tests/task-context/ も明記してください。

      • 「read-only」「repository変更なし」という prose だけで checker containment を満たしたことにしないでください。

      • Allowed Paths は、この research Issue の read-only investigation scope と矛盾しない形にしてください。

    2. placeholder VC の除去

      • executable Verification Command として存在する
        $ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBER
        は削除してください。
      • placeholder を実行可能 command として checker に渡さないでください。
      • follow-up implementation Issue の検証要件自体は削除せず、
        「canonical approval 後に実際に create/reuse された Issue 番号を live readback し、リンク・scope・terminal/missing 両経路を確認する」
        という conditional prose / handoff requirement として保持してください。
      • 実Issue番号が存在しない段階で架空の番号を埋めないでください。
    3. Verification Commands の baseline semantics

      • current code に既に存在する symbol を確認する rg は baseline で exit 0 が期待される evidence/readback command です。
      • current docs/dev/dor.md / checker contract を fresh に確認し、適用可能なら各コマンド直前に
        # baseline-expect: pass
        を付与してください。
      • annotation は per-command scope であるため、必要な各 $ command に個別に付けてください。
      • baseline-expect を static safety blocker の bypass として使ってはいけません。Allowed Paths containment は独立に正しく直してください。
      • 必要なら # vc-role: を advisory metadata として追加して構いませんが、不要な仕組みは増やさないでください。
    4. 前回の substantive refinement を維持

      • activity_terminal だけでなく activity_missing も同一根因として扱う。
      • expected contract direction は両方とも cross-Task accepted fact ownership/identity を local Activity state より先に判定すること。
      • terminal:
        current duplicate_noop/activity_terminal
        → expected conflict/FACT_TASK_IDENTITY_CONFLICT
      • missing:
        current deferred/activity_missing
        → expected conflict/FACT_TASK_IDENTITY_CONFLICT
      • reachability = yes という前回判断は fresh current-main evidence と矛盾しないか再確認する。
      • provenance 修正を維持する。
      • comment 5748250792 を「この cross-Task warning の最初の指摘元」と再度断定しないこと。

    Freshness / current-main

    前回 run の current-main SHA は
    dc286d9f23ab5d3e5ef2fc7ccea781e41be4cd95
    でした。

    この再開 run では必ず origin/main を fresh fetch/readback し、current-main SHA を取り直してください。

    開始時点で main が前回 SHA から進んでいる前提で扱い、古い行番号を無検証でコピーしないでください。

    main drift が対象ロジック

    • scripts/task-context/task_context_workflow_signals.py
    • .claude/skills/open-pr/scripts/open_pr.py
    • 関連 Task Context tests

    に影響している場合は、current evidence に合わせて本文を更新してください。

    影響していない場合も、そのことを evidence として明示してください。

    Canonical workflow

    .claude/skills/issue-refinement-loop/SKILL.md の current main 版を正本として使用してください。

    • substantive OWNER feedback の anchor は comment 5748838603
    • comment 5748933140 は前回 run の termination / handoff evidence として読む
    • 今回のこの operator prompt は、「5748933140 で要求された人間判断」に対して additional body rewrite を承認する新しい human decision
    • 旧 run の operator-intervention route を無かったことにしない
    • 新しい body SHA / current-main SHA で fresh preflight → canonical Step 2 review を行う

    Step 2 は current contract どおり root-owned
    run_root_review_pipeline.py produce
    を使用してください。

    issue-reviewer SubAgent を独自起動して canonical Step 2 を代替しないでください。

    needs-fix が通常の autonomous rewrite route に返った場合は、
    loop_iteration_approval_gate.default_required: false
    および max_iterations の範囲で
    review → rewrite → fresh review
    を人間確認なしで継続してください。

    ただし、新しい run でも genuine

    • step_5_operator_intervention_required
    • human_judgment_required
    • environment / integrity failure
    • max-iterations
    • その他 canonical fail-closed stop

    に到達した場合は、それを bypass しないで停止・報告してください。

    SubAgent

    SubAgent を fire-and-forget にしないでください。

    investigation

    canonical planner が repository investigation を required / permitted と判定した場合は codebase-investigator SubAgent を起動し、少なくとも以下を current main で確認させてください。

    • implementation_pr_observed の current precedence
    • activity_missing
    • activity_terminal
    • accepted implementation fact ownership/dedupe
    • _validate_implementation_claims_tx()
    • terminal/missing cross-Task regression coverage
    • open_pr.py::emit_implementation_pr_observed() から signal apply までの reachability
    • 前回 SHA 以降の drift がこの evidence に影響するか

    SubAgent を起動したら、必ず完了まで待ち、structured result を join してから次へ進んでください。

    planner が investigation SubAgent 不要と明示した場合は、以前の OWNER anchor の指示どおり planner authority を prose で上書きして独自 dispatch しないでください。その場合は「planner が不要と判定したため investigation SubAgent は起動しなかった」と最終報告に明記してください。

    Issue rewrite

    Issue body の mutation は current canonical flow に従い issue-editor SubAgent / controlled transaction を使用してください。

    issue-editor を起動した場合も、必ず completion を待って join してください。

    mutation 後は main thread 側で live Issue body を再取得し、期待 body/hash と一致することを独立確認してください。

    SubAgent の報告を盲信せず、critical facts は main thread でも直接検証してください。

    Rewrite の狙い

    今回の rewrite は defect scope を再拡張するためではなく、前回 substantively 完了した refinement を canonical checker が決定論的に review できる body にするための contract repair です。

    特に以下を満たしてください。

    • Verification Commands の search path と Allowed Paths が checker containment 上整合する
    • existing-code inspection command の baseline expectation が明示される
    • placeholder executable command が存在しない
    • Task A / Task B / Task C の deterministic reproduction contract は維持される
    • 行位置検索だけを defect verification の全てとして扱わない
    • reachability evidence を維持する
    • research Issue なので source implementation 自体は変更しない

    C9_runtime_applicability_present 等の非blocking warning が current review でも出る場合は、research-only Issue として canonical template 上適切な最小修正で解消できるか確認してください。ただし、今回の blocker 解消と無関係な scope expansion はしないでください。

    Approval 後

    fresh canonical review が approve に到達し、current main でも

    • defect成立
    • terminal/missing 両経路が reachable
    • implementation fix が必要

    と確定した場合のみ、Issue #2685 の dependency/follow-up materialization contract に従って implementation Issue を create または既存Issueを reuse してください。

    implementation Issue には最低限以下を固定してください。

    • terminal / missing を同一 precedence defect として修正

    • conceptual ordering:
      origin resolution
      → claim / Task consistency
      → accepted implementation fact ownership / metadata / dedupe
      → 新規 fact と確定した後だけ local Activity state (activity_missing / activity_terminal)
      → claim attach / event append

    • focused regression:

      • cross-Task accepted fact × current Task terminal
      • cross-Task accepted fact × current Task implementation Activity missing
    • same-Task既存 semantics を壊さない regression

    • unnecessary daemon / ledger / DB schema / generic security harness は追加しない

    作成・reuse 後は実Issueを live readback し、番号・URL・body・親子/依存関係を検証してください。

    この #2685 refinement run では implementation 自体を開始しないでください。
    impl-review-loop も起動しないでください。

    最終報告

    最終報告には最低限、以下を含めてください。

    • termination reason
    • fresh current-main SHA
    • rewrite 前後の Issue body SHA
    • prior operator_intervention_required を bypass せず、新runで operator decision を反映したこと
    • Allowed Paths blocker の具体的解消内容
    • placeholder VC の具体的解消内容
    • baseline annotation の disposition
    • terminal / missing 両経路の current evidence
    • reachability の fresh 判断
    • source provenance の状態
    • SubAgent の起動有無・種類・completion join 済みであること
    • canonical Step 2 の最終 route / verdict
    • follow-up implementation Issue の created / reused / not_needed
    • create/reuse の場合は実Issue番号とURL
    • unresolved blocker があればその内容

    auto mode なので routine な途中確認は求めず、canonical stop condition に到達するか、refinement と必要な follow-up materialization が完了するまで自律的に進めてください。

    この形なら「前回停止を無視して続きをやる」のではなく、停止で要求された operator decision を入力にして新しい canonical run を開始するため、監査上も扱いやすいです。

  6. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 終了報告(approved)

    Allowed Paths blocker の解消内容

    前回のbroad_search_path_unboundedは、## Allowed Pathsセクションの該当bulletが「reachability判断のためのread-only参照はpath1、path2まで許可する」というprose文中にpathを埋め込む形式だったため、checkerのpath抽出regex(^`path`$+任意paren)に一致せず、実質的にAllowed Pathsとして未登録だったことが原因と判明した。修正として、scripts/task-context/task_context_workflow_signals.py/.claude/skills/open-pr/scripts/open_pr.py/tests/task-context/をそれぞれ独立したbullet(`` -path(説明) ``形式)として明記した。ローカルでcontract_readiness_check.py --mode executeにより修正後本文がstatus: go`/exit 0であることを事前確認した上でrewriteを実行した。

    placeholder VC の解消内容

    $ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBERをfenced bashブロックから削除し、「follow-up実装Issueをcreate/reuseした場合は実Issue番号をlive readbackし、リンク・scope・terminal/missing両経路の記載を確認すること(起票前の架空番号を記載しない)」という条件付きprose記述に置き換えた。これによりverification要件自体は削除せず、実行不能なexecutable commandとしてcheckerに渡すことを回避した。

    baseline annotation の disposition

    5件のrgコマンド全てに# baseline-expect: passを各コマンド直前(空行を挟まない連続commentブロック内)に付与した。これらは現在のcode/testに既に存在するsymbol/関数を確認するevidence/readbackコマンドであり、baseline実行でexit 0が期待されるためpassを選択した。broad_search_path_unboundedはstatic safety blockerでありbaseline-expectではbypassできないため、annotationはbypass目的ではなくAllowed Paths修正の補完として付与した。

    terminal / missing 両経路の current evidence(fresh再確認)

    codebase-investigator(read-only、completion join済み)とmain thread自身の直接読解の両方で、current main (33a6ffbf...) 上でも以下が変わらず成立することを確認した。

    • implementation is None(L363-364, deferred/activity_missing)はaccepted_implementation検索(L377)より前に評価され、cross-Task識別判定に到達しない。
    • elif implementation["status"] != "ACTIVE"(L386-387, duplicate_noop/activity_terminal)は、accepted_implementationが別Taskに属する場合も含めて短絡し、_validate_implementation_claims_tx()(L388)に到達しない。
    • 両経路とも同一のprecedence defect構造であり、前回run(dc286d9f...)からの評価に変更はない。

    reachability の fresh 判断

    .claude/skills/open-pr/scripts/open_pr.py::emit_implementation_pr_observed()はcurrent main上でもCLAUDE_CODE_SESSION_IDベースのorigin解決とGitHub PR↔Issue relation検証のみを行い、Task所有権の一致は検証しないことを再確認した。Issue #2625(advisory-only化、実装済み・CLOSED)によりTask bindingは維持されるため、reachability = yesの判断を維持した。

    source provenance の状態

    comment 5748250792を「この cross-Task warning の最初の指摘元」と断定しない記述を維持。実際の内容(PR body test件数stale/non-required deploy check cancelled/AC8 canary未再実行の3点)と、5748658065がこれをsource_urlとして参照しているが裏付けられない、という記述を保持した。

    SubAgent 起動・completion join 状況

    • codebase-investigator(read-only): 本runで2回起動(旧run1回・新run1回)。いずれも完了・structured resultをjoin済み。新run分では、旧runの5748250792内容誤引用(別commentとの取り違え)を含め、既存findingsをcurrent main上で再検証し、変更なしと確認。
    • web-researcher: 新runでplannerがweb_research_policy.required: true(Out of Scopeの「新規daemon/ledger等追加禁止」記述をdispositive claimと誤検知)と判定したため起動。completion join済み。結果: not_applicable(scope宣言であり外部fact-check不要、planner heuristicの過剰検知と判断)。
    • issue-editor: 本run内で1回起動(Allowed Paths/VC修正のrewrite)。完了・completion join済み。main thread側でも独立にlive readbackしSHA一致を確認。
    • issue-creator: follow-up実装Issue起票のため1回起動。完了・completion join済み。main thread側でも独立にIssue #2690のlive readback(number/title/state/url/labels/body/親子関係)を実施し検証。

    canonical Step 2 最終route/verdict

    run_root_review_pipeline.py produce(background実行・完了JSON join済み):

    canonical_step2_route: step_2_5
    status: ok
    verdict: approve
    next_action: proceed
    failure_class: None
    blocking_issues: []
    

    Step 2.5 semantic_review_trigger.pyは全explicit signalsがfalse/0/emptyのためsemantic_review_applicable: falseと判定し、Step 2.5をスキップしてStep 4.5へ進んだ。

    follow-up 実装Issue

    • created: https://github.com/squne121/loop-protocol/issues/2690(`実装: apply_workflow_signal()のimplementation_pr_observed分岐でcross-Task accepted-fact identity判定をlocal Activity state判定より先に評価する`)
    • GitHub native sub-issueとして#2685の子に登録済み(gh api repos/squne121/loop-protocol/issues/2685/sub_issuesで確認)
    • terminal / missing 両経路を同一AC/focused regression要件として含む
    • Allowed Paths: scripts/task-context/task_context_workflow_signals.py, tests/task-context/
    • 重複確認済み(同一root causeを持つ既存open実装Issueなし)

    unresolved blocker

    なし。

    impl-review-loop 起動状況

    本run(および前回run)では impl-review-loop を一切起動していない。Issue #2685の refinement と follow-up実装Issue #2690の起票までがこのrunのスコープである。

  7. squne121 commented on Sep 20, 2026

    @squne121
    OwnerAuthor

    PR #2692 がマージされ、子 Issue #2690(apply_workflow_signal() の implementation_pr_observed 分岐における cross-Task accepted-fact identity 判定の precedence 修正)が完了・クローズ済みです。

    本 research Issue が特定した precedence defect(cross-Task dedupe が local Activity state 判定に先を越されるエッジケース)は、repair iteration を含め以下の2経路で是正されました:

    • cross-Task accepted fact × 現在Task implementation Activity terminal/missing → FACT_TASK_IDENTITY_CONFLICT
    • other-Task live claim(accepted event 未存在)× 現在Task implementation Activity terminal/missing → FACT_TASK_IDENTITY_CONFLICT(OWNER レビュー issuecomment-5749549802 で指摘された P1 precedence hole の追加是正)

    全 sub-issue(#2690)が closed のため、post-merge-cleanup による自動クローズです。

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

    agent/researchphase/researchstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions