Skip to content

fix(create-issue): create_issue_txn.py の hard predecessor 起票時の dependency 方向逆登録バグを修正する - #1949

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-1946-fix-create-issue-blocking-direction
Aug 2, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-1946-fix-create-issue-blocking-direction

Conversation

@squne121

@squne121 squne121 commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

概要

create_issue_txn.py の create parser に --blocking(新規Issueが既存Issueをブロックする方向、前提Issue/hard predecessor起票用)を、--blocked-by(--dependency を後方互換 alias として吸収)とは別 destination で追加した。reconcile parser にも --blocking を追加した。

役割を名前で固定する GraphQL addBlockedBy primitive(blocked_issue_node_id=/blocking_issue_node_id= の keyword-only 引数)を実装し、両方向で同一 mutation query を呼び出す。方向反転の原因になった direction= 型の汎用フラグは採用していない。

非正整数(0・負数・bool)、重複 issue number、同一 issue を blocked-by と blocking の両方に指定、dedupe/reconcile 対象 issue 自身の指定、cross-repository URL を、mutation 実行前に reject する。

readback を方向別に厳密化した(pageInfo.hasNextPage/totalCount 込みの集合完全一致)。--blocking 方向はさらに、各 blocking target 側の blockedBy に新規Issueが実在することを target-side cross-check する。

create・dedupe(_reconcile_issue_links)・reconcile(reconcile_transaction)・partial-failure audit comment・recovery hint の全経路を双方向対応させた。TransactionResult に blocking_verified フィールドを追加し(既存 dependency_verified は blocked-by 方向として維持)、failed_readbacks に direction/expected_issue_numbers を追加した。

_issue_create へ公式 CLI の --blocked-by/--blocking フラグを転送しないことを回帰テストし、design rationale(deferred/parallel semantics による receipt-loss リスク)をコード内コメントに明記した。

AC7: hard-predecessor producer/caller inventory を確認した。materialize_child_issues.py は既に depends_on を正しい blocked-by 方向(--blocked-by/--dependency)に写像しており、blocking 方向の配線が必要な自動 caller は現時点で存在しない。producer は直接 CLI 起票(人間/エージェント運用)のみであり、SKILL.md ガイダンス整備で対応済みのため follow-up hard-successor Issue の起票は不要と判断した。

AC8: disposable Issue 2件(target B・predecessor A を --blocking B で作成)を使う live canary スクリプト live_canary_blocking_direction.sh を追加し、実際に live 実行して PASS(exit 0)を確認済み(詳細は下記「Owner レビュー対応」参照)。

SKILL.md の該当箇所(helper 引数説明・depends_on 写像・Depends on #N 節・Blocker/Blocked-by 設定手順)に --blocked-by/--blocking を正式名称、--dependency を legacy alias として追記し、--blocking の設定方法・検証コマンドの節を新設した。

新規テストファイル test_create_issue_txn_blocking.py(Issue の Verification Commands に一致するノードID)を追加し、既存 test_create_issue_txn.py の回帰も維持している。

Closes #1946(本 Issue をクローズする)

Owner レビュー対応(REQUEST_CHANGES への fix_delta)

Owner から本 PR へ直接投稿された REQUEST_CHANGES レビュー(issuecomment-5154804485)に基づき、以下を追加修正した(コミット 05e0397e)。

  • P0-1(dedupe経路がrelationshipを収束させない): dedupe 経路(_reconcile_issue_links)は従来 --blocked-by/--blocking の readback しか呼んでおらず、リンクが欠けていても mutation を実行していなかった。create・dedupe・reconcile が共有する _apply_relationship_direction() helper を新設し、現在値との差分を計算して不足分のみ mutation するよう修正した。
  • P0-2(reconcileが非正整数をmutation前に拒否できない): reconcile_transaction() は方向間重複・自己参照のみ検証し、_normalize_dependency_numbers()(0・負数・bool・URL の拒否)を通していなかった。label/parent mutation より前に normalize を実行するよう修正した。
  • P1-1(canaryがcleanup失敗時にもexit 0を返す): live_canary_blocking_direction.sh の _cleanup() は失敗時に CLEANUP_FAILED=1 を記録するだけで終了コードを変えていなかった。cleanup 失敗時は明示的に exit 1 するよう修正し、RELATIONSHIP_REGISTERED の値に依存せず現在の relationship 状態を毎回 readback してから削除するよう変更した。
  • P1-2(partial_failureが既に検証済みの方向をnullに戻す): run_transaction() の例外ハンドラは parent_verified/dependency_verified/blocking_verified を常に None で返しており、--blocked-by 成功後に --blocking が失敗しても両方が null になっていた。try ブロック外で状態を初期化し進行に応じて更新するよう修正し、例外ハンドラへ実際の値を渡すようにした。
  • P1-3(relationship readbackが完全ページングされておらずnull payloadで例外終了する): _target_blockedby_contains() は first:100 のみ取得しページングせず、issue: null を AttributeError で落としていた。全ページ traversal を行う _paginated_relationship_numbers() を新設し、target-side cross-check をこの primitive 上に再構築した。この過程で、新規追加した pagination query 自体に f-string の {{ }} エスケープと通常文字列のリテラル {} を混在させたブレース不整合バグがあり、gh CLI が GraphQL 構文エラーを返して --blocking の readback が常に partial_failure に落ちる実バグを live canary 実行で発見・修正した(ユニットテストは run_command を mock するため発見できなかった)。

対応する追加テスト 7 本を test_create_issue_txn_blocking.py へ実装した(dedupe missing-link mutation・reconcile invalid-input rejection・dependency_verified/blocking_verified 独立性・101件超の pagination・issue: null の構造化失敗・live canary cleanup の exit code / leftover relationship discovery)。live canary の cleanup テストは Allowed Paths 外へ新規ファイルを追加せず、test_create_issue_txn_blocking.py から bash -c 経由で live_canary_blocking_direction.sh を LIVE_CANARY_TEST_MODE=1 でソースする方式にした。

修正後、live canary(AC8)を disposable Issue(#1969/#1970)で再実行し、PASS(exit 0)・relationship 削除・両 Issue の close を実機で確認済み。

Test plan(検証手順)

…ency 方向逆登録バグを修正する

--blocking を --blocked-by(--dependency は legacy alias)とは別 destination として追加し、
role-fixed な addBlockedBy primitive で両方向の GraphQL mutation・厳密な集合一致 readback・
非正整数/重複/自己参照/cross-repo の事前拒否・dedupe/reconcile/partial-failure/recovery-hint の
双方向対応を実装する。SKILL.md に --blocked-by/--blocking の正式名称化と legacy alias 明記を追加し、
disposable issue 2件を使う live canary スクリプトを追加する。

Closes #1946

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

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Preview URL

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

The preview will be removed when this PR is closed.

…ue_body.py の必須セクションに準拠させる

live_canary_blocking_direction.sh (#1946 AC8) を実行したところ、predecessor
Issue A の body が create_issue_txn.py の issue-body-validate 段(Blocker
2.5、--issue-kind 省略時の fallback 必須セクション: Acceptance
Criteria/Verification Commands/Allowed Paths)を満たさず status=failure で
落ちていた(依存関係方向の再現より前で失敗しており、#1943/#1842 の
reversal バグとは無関係)。disposable body に最小限の該当セクションを追加し、
実際に disposable Issue A(#1955)/B(#1954) を作成して双方向検証・relationship
削除・A/B close までの live canary を PASS で完走させた(証跡:
artifacts/1946/issue-metadata/live_canary_blocking_direction/20260802T023254Z.log)。

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

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

AC8 live canary 実行結果(fix_delta 対応)

pr-reviewer の REQUEST_CHANGES(AC8 証跡未提出)に対応し、live_canary_blocking_direction.sh を実際に実行しました。

実行環境 preflight

  • gh auth status --hostname github.com: 認証済み(account squne121)
  • gh api graphql -f query='query{ viewer { login } }': 到達可能({"data":{"viewer":{"login":"squne121"}}})
  • SKIP 条件(gh 未導入/未認証/graphql 到達不可)はいずれも非該当のため、live 実行を実施しました。

発見した問題と修正

1回目の実行は create_issue_txn.py の issue-body-validate 段(Blocker 2.5)で status=failure となりました。これは依存関係方向の再現(#1943/#1842 の reversal バグ)とは無関係で、disposable predecessor Issue A の body が --issue-kind 省略時の validator fallback 必須セクション(Acceptance Criteria / Verification Commands / Allowed Paths)を満たしていなかったことが原因でした。

live_canary_blocking_direction.sh の Allowed Paths 内で、disposable body に最小限の該当セクションを追加する修正をコミットしました(fd4b2f8)。

2回目の実行結果: PASS

artifact

  • 保存先(worktree 内、artifacts/ は .gitignore 対象のため git 管理外): artifacts/1946/issue-metadata/live_canary_blocking_direction/20260802T023254Z.log
  • secrets/Authorization header は含まれていないことを確認済み(rg -i "authorization|token|secret" で非該当)
  • transcript 全文(redaction 済み、そのまま貼付):
preflight: gh binary + auth + graphql reachability confirmed
created disposable target issue B #1954: https://github.com/squne121/loop-protocol/issues/1954
{"applied_steps": ["blocking"], "audit_comment_posted": null, "blocking_verified": true, "completed_steps": ["create", "label", "blocking", "blocking-readback"], "dedupe_number": null, "dependency_verified": null, "failed_readbacks": [], "failure_message": null, "failure_stage": null, "issue_number": 1955, "issue_url": "https://github.com/squne121/loop-protocol/issues/1955", "parent_verified": null, "pending_steps": [], "status": "success", "verified_steps": ["blocking-readback"]}
created disposable predecessor issue A #1955 (status=success)
A.blocking=1954
PASS(step3): A.blocking contains B
B.blockedBy=1955
PASS(step4): B.blockedBy contains A
A.blockedBy=
PASS(step5): A.blockedBy does NOT contain B (reversal bug not present)
PASS: blocking direction registered correctly on disposable issues A=#1955/B=#1954
cleanup: removing blocking relationship (A=#1955 blocks B=#1954)
{"data":{"removeBlockedBy":{"clientMutationId":null}}}cleanup: closing disposable issue A #1955
✓ Closed issue squne121/loop-protocol#1955 ([disposable-canary] blocking direction predecessor A 20260802T023254Z)
cleanup: closing disposable issue B #1954
✓ Closed issue squne121/loop-protocol#1954 ([disposable-canary] blocking direction target B 20260802T023254Z)

既存 AC への影響

test_create_issue_txn_blocking.py + test_create_issue_txn.py(AC1-AC6/AC10 対象、計136件)を再実行し、fix_delta 適用後も全 pass を確認しました。AC1-AC7/AC9/AC10 のコード(Allowed Paths 内の他ファイル)には手を加えていません。

@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。現状ではマージ不可です。

AddBlockedByInput の方向修正そのものは正しいです。GitHub GraphQL では issueId がブロックされる Issue、blockingIssueId がブロックする Issue であり、今回導入された role-fixed helper の引数割当は公式仕様と一致しています。([GitHub Docs]1) 実装も --blocked-by と --blocking で引数を正しく反転しています。

また、live canary の happy path は実行済みで、方向確認・relationship削除が成功したと報告され、使い捨て Issue #1954/#1955 が閉じられていることも確認できました。

ただし、Issue #1946 が明示的に要求する dedupe・reconcile・partial-failure・cleanup の契約に未達があります。

指摘事項

P0-1: dedupe 経路は relationship を「収束」させず、readback するだけ

_reconcile_issue_links() は parent については _issue_register_sub_issue_idempotent() を実行しますが、dependency_issue_numbers と blocking_issue_numbers については _readback_dependencies() / _readback_blocking() しか呼んでいません。リンクが欠けている dedupe Issue に対して mutation を実行せず、二度 readback して partial_failure にするだけです。

これは #1946 のレビューで明示された「dedupeされた既存 Issue に blocking 関係を収束させられない」という阻害条件が、そのまま残っている状態です。

テストも偽陽性です。dedupe 部分では _readback_blocking を無条件に True へ差し替え、status == "dedupe" だけを確認しており、_issue_register_blocking() が呼ばれたことを検証していません。

修正方針

  • create・dedupe・reconcile で共有する relationship apply/readback helper を作る。
  • 現在値との差分を計算し、不足分のみ mutation する。
  • dedupe テストでは最初の readback を不一致、mutation 後を一致にし、exact GraphQL IDs と呼出回数を検証する。
  • --blocked-by 側も同じテストを追加する。

P0-2: reconcile は非正整数を mutation 前に拒否できない

run_transaction() は _normalize_dependency_numbers() を通しますが、reconcile_transaction() は _validate_dependency_directions() しか呼びません。後者が確認するのは重複・方向間重複・自己参照だけで、0、負数、bool、URLを検証しません。

その後すぐ labels を再適用するため、例えば --blocking 0 --label x では、ラベルを変更した後に Issue #0 の node ID 解決で失敗します。コメントには「before any mutation」とありますが、実装はその不変条件を満たしていません。

修正方針

reconcile_transaction() の冒頭で、いかなる GitHub 操作より前に次を実行してください。

normalized_dependency_issue_numbers = _normalize_dependency_numbers(
    dependency_issue_numbers,
    label="--blocked-by",
)
normalized_blocking_issue_numbers = _normalize_dependency_numbers(
    blocking_issue_numbers,
    label="--blocking",
)
_validate_dependency_directions(
    normalized_dependency_issue_numbers,
    normalized_blocking_issue_numbers,
    self_issue_number=issue_number,
)

テストは labels と parent_issue_number も指定した状態で 0、-1、True を投入し、全 mutation helper が未呼出しであることを確認すべきです。

P1-1: canary は cleanup 失敗時にも exit 0 を返す

_cleanup() は失敗時に CLEANUP_FAILED=1 を設定してログへ partial_failure を出しますが、終了コードを変更していません。main は最後に exit 0 を実行しています。

Bash の exit n は指定された n を終了ステータスとし、EXIT trap は終了前に実行されます。trap 内で終了コードを明示的に変更しない限り、この構造では cleanup に失敗しても成功終了になります。([GNU]2)

さらに、relationship mutation 後の readback 失敗などで transaction が partial_failure を返した場合、RELATIONSHIP_REGISTERED は "yes" にならず、実際には存在する可能性がある relationship の削除を試みません。

修正例

_cleanup() {
  local status=$?
  trap - EXIT

  # 両 Issue 番号が分かる場合は、transaction status に依存せず
  # 現在の relationship を readback して存在時だけ削除する。

  if [ "${CLEANUP_FAILED}" = "1" ]; then
    status=1
  fi
  exit "${status}"
}

cleanup 後にも両方向を readbackし、relationship が消えたことまで確認してください。

P1-2: partial_failure が既に検証済みの方向を null に戻す

create 経路で --blocked-by の mutation/readback が成功した後、--blocking 側が失敗した場合でも、共通 exception handlerは次を固定で渡しています。

  • parent_verified=None
  • dependency_verified=None
  • blocking_verified は未指定、したがって None

その結果、verified_steps では dependency-readback 済みなのに、dependency_verified は null という矛盾した receipt になります。blocking の readback が明確に不一致でも blocking_verified=false ではなく null になります。

修正方針

各検証状態を try の前で初期化し、進行に応じて更新して exception handlerへ引き渡してください。

  • None: 未試行
  • False: readbackを実行したが不一致
  • True: 検証済み

合わせて failed_readbacks.actual_issue_numbers を常に空配列で埋めるのではなく、実際の取得集合または actual_state_unavailable を返すべきです。現状は「実際に空」と「取得不能」を区別できません。

P1-3: relationship readback が完全ページングされておらず、null payload で例外終了する

_target_blockedby_contains() は blockedBy(first:100) のみ取得し、pageInfo を取得せず cursor traversal もしません。対象 Issue に100件超の blocker があり、期待する Issue が次ページにあると偽陰性になります。

GitHub GraphQL の first / last は最大100件で、それ以上は endCursor と after を使ったページングが必要です。([GitHub Docs]3)

加えて、次の式は GraphQL が正常応答として issue: null を返した場合に AttributeError になります。

payload["data"]["repository"]["issue"].get(...)

catch対象は KeyError と TypeError のみなので、transactionの構造化された partial_failure を通らず traceback で終了します。_target_blockedby_contains() も同じ問題を持ちます。

PR #1897 には relationship の全ページ traversal と最終 combined readback の先例があります。新たな first:100 reader を増やすより、共通 primitive を抽出する方が安全です。

P2: PR本文と現在の検証状態が不一致

PR本文は現在も「live実行はしていない」と記載していますが、後続コメントでは実行済みです。

また、現在の head ではコード系チェックは成功していますが、Check Japanese Content の PR Body Japanese Check が失敗しています。requiredでないとしても、本文を最新状態へ更新すれば同時に修正可能です。

必須追加テスト

最低限、次の回帰テストが必要です。

  1. dedupe Issue の blocking link 欠落時に mutation が実行され、readback後に dedupe となる。
  2. reconcile の 0・負数・bool が label/parent/dependency mutation より前に拒否される。
  3. blocked-by成功後にblocking失敗した場合、dependency_verified=True と blocking_verified=False が保持される。
  4. target側 blockedBy が101件以上あり、期待値が2ページ目にある。
  5. issue: null が structured failureとなり、tracebackで終了しない。
  6. canary cleanupの relationship削除またはclose失敗時にexit 1となる。
  7. transactionがpartial failureでも、両Issue番号が分かればcleanupが残存relationshipを探索・削除する。

総括

方向反転バグの本体と happy-path integration は修正できています。しかし現在の実装は、dedupeでは修復せず、reconcileでは不正入力前に別mutationを実行し、canary cleanup失敗を成功終了として扱い、partial-failure receiptから検証済み状態を失います。

したがって、現時点の推奨レビューアクションは REQUEST_CHANGES です。

…ck bugs

Owner REQUEST_CHANGES (PR #1949) fix_delta for Issue #1946:

- P0-1: dedupe path (_reconcile_issue_links) only read back --blocked-by/
  --blocking, never mutated a missing link. Extracted a shared
  _apply_relationship_direction() diff-apply/readback helper (used by
  create/dedupe/reconcile alike) that computes the diff against the current
  relationship state and mutates only what's missing.
- P0-2: reconcile_transaction validated direction/self-reference but never
  normalized (0/negative/bool/cross-repo URL) before mutating labels/parent.
  Normalize now runs first, before any GitHub operation.
- P1-1: live_canary_blocking_direction.sh's cleanup only removed the
  relationship when RELATIONSHIP_REGISTERED="yes" and never changed the exit
  code on cleanup failure. Cleanup now always reads back the current
  relationship independently and forces exit 1 on any cleanup failure.
- P1-2: run_transaction's exception handler hardcoded parent_verified/
  dependency_verified/blocking_verified to None regardless of actual
  progress. These are now tracked outside the try block and passed through
  faithfully.
- P1-3: _target_blockedby_contains only fetched one page (first:100) with no
  cursor traversal, and null `issue` payloads raised AttributeError instead of
  a structured failure. Added _paginated_relationship_numbers() (full cursor
  pagination + null-issue handling) and rewired the target-side cross-check
  onto it.

Added regression tests for all of the above (dedupe missing-link mutation,
reconcile invalid-input rejection, dependency_verified/blocking_verified
independence, >100-item pagination, null-issue structured failure, and
live_canary cleanup exit-code/leftover-relationship discovery via bash -c
harnesses in test_create_issue_txn_blocking.py, staying within this Issue's
Allowed Paths instead of adding a new test file).

Fixed a real bug found only by the live canary (AC8): a brace-escaping
mismatch (f-string {{ }} mixed with plain-string literal braces) in the new
pagination query produced invalid GraphQL that gh rejected, silently
downgrading every --blocking readback to partial_failure.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121
squne121 marked this pull request as ready for review August 2, 2026 03:43
@squne121
squne121 merged commit 86cddff into main Aug 2, 2026
24 of 25 checks passed
@squne121
squne121 deleted the worktree-issue-1946-fix-create-issue-blocking-direction branch August 2, 2026 03:43
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.

実装: create-issue の hard predecessor 起票時に dependency 方向を逆登録するバグを修正する

1 participant