Repository navigation
fix: issue-refinement preflight の anchor comment 取得を credentialless transport へ統一する (#2257) - #2260
Conversation
…ransport へ統一する (#2257) isolated Claude-GPT session では `_fetch_issue()` / `_fetch_issue_comments()` のみが credentialless read transport (`github_credentialless_read.py`) に 配線済みで、`_fetch_single_comment()` だけが無条件に `gh api` を呼んでいた (split-brain transport)。isolated profile では host の gh credential が 意図的に遮断されているため、この呼び出しは常に auth failure (gh exit 4) で失敗し、実在する anchor comment (#2197 comment 5315264311) が誤って missing と分類されていた。 - `github_credentialless_read.py` に `read_single_comment()` / `InvalidCommentIdRejected` / `TransportConnectivityFailure` / `MalformedResponseBody` を追加し、DNS/接続/timeout/不正JSON も typed exception で分類する。 - `run_refinement_preflight.py` の `_fetch_single_comment()` を isolated profile で credentialless transport 専用にし、gh api への fallback を排除。true 404 (semantic_missing) と、それ以外の transport failure (auth/rate-limit/5xx/DNS/timeout 等) を明確に区別し、 transport failure は ANCHOR_COMMENT_NOT_FOUND ではなく environment_failure として報告する。 - `_validate_anchor_comment_url()` と後段の再フェッチ経路の両方で err を握りつぶさず分類する。 - 実際の GitHub REST API に対して issue #2197 のアンカーコメント 5315264311 を isolated HOME / 空 GH_CONFIG_DIR / token unset で 解決する exact incident replay テストを追加 (live, PASS)。 - fault-injection matrix (401/403/404/429/5xx/DNS/接続/timeout/ 不正JSON/pagination cycle) の回帰テストを追加。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #2260 closed). |
pr-review-judge REQUEST_CHANGES (iteration 1) への fix_delta:
- test_run_refinement_preflight_credentialless_transport.py:388 の
E501(行長121文字)を関数化して解消
- 新規テスト scripts/agent-guards/tests/test_isolated_anchor_single_authority.py を追加:
- test_isolated_anchor_comment_resolves_via_single_credentialless_authority:
本番の run_refinement_preflight.py を実際の uv run python3 子プロセスとして
起動し、isolated HOME / 空 GH_CONFIG_DIR / token unset / fail-on-use gh marker
環境で Issue #2197 のアンカーコメント 5315264311 を実ネットワーク経由で解決し、
gh が一度も呼ばれないことを確認する(プロセス境界を跨いだ検証、既存の
in-process テストでは検証できなかった部分を補う)
- test_production_command_registry_wires_anchor_command_to_run_refinement_preflight_script:
本番の command_registry.py / skill_runtime_command_policy.py を用いて
preflight.run.with_anchor コマンドクラスが run_refinement_preflight.py を
正しく呼び出すよう配線されていることを確認する
…トを追加する (#2257) pr-reviewer REQUEST_CHANGES iteration 2 blocker対応。既存の test_isolated_anchor_single_authority.py の2テストは _fetch_single_comment() の直接呼び出しまたは command_registry.py の 静的 wiring 検証に留まり、skill_runtime_exec.py 自体を subprocess として 起動していなかった。test_skill_runtime_exec_anchor.py が確立した disposable repo fixture(_install_real_contract_update_fixture())を 再利用し、preflight.run.with_human_context の実 subprocess を起動して Issue #2197 の実アンカーコメント 5315264311 を live network 経由で 解決し、sitecustomize.py の独立計装で gh invocation 回数 0 を検証する。 修正前コミットへの一時差し替えでregressionを実際に検出することも確認済み。
PR #2260 fix_delta iteration 3: scripts/agent-guards/tests/test_isolated_anchor_single_authority.py:306 の1行が120文字制限を超過していたため、括弧で分割して修正する。
結論PR #2260 は Issue #2197 の実在 anchor comment 問題は、最終版 Issue #2257 が要求する設計へ実装が追随しておらず、「局所的な Blockers
問題ない部分方向性としては、public Issue commentの無認証GETはGitHub公式に認められており、このtransportを使う判断は妥当です。([GitHub Docs]1) また REST API version 推奨 fix_delta 順序最優先は transport selectorをinvocation-scopeへ引き上げ、initial anchorをcomments traversalから解決する構造変更です。その上で structured 現状は「#2197 の直接症状を直した」ことまでは評価できますが、refinement後の #2257 を PRが更新されたら、このblocker群が解消したか再レビューできます。 |
OWNER REQUEST_CHANGES fix_delta(先行 SubAgent レビュー APPROVE を覆す指摘)に 対応する。局所的な _fetch_single_comment() isolated 分岐修正に留まっていた実装を、 Issue #2257 が要求する「1 invocation = 1 read authority」設計へ再設計した。 - run_preflight() が live-mode で transport を一度だけ選択し、 _fetch_single_comment / _validate_anchor_comment_url / _validate_anchor_comments_batch へ明示的に渡す。initial anchor は常に live で取得済みの comments traversal から解決し、以前のような毎回の single-comment GET 再実行を廃止した(決定的な修正)。 - refinement_preflight_result_v1 schema に environment_failure 時のみ 必須の reason_code/source/operation 構造化 projection を追加。 - github_credentialless_read.py の 403 分類を安全な header evidence ベースへ変更(AC9)、UnicodeDecodeError/malformed Link header の closed taxonomy 化、pagination hardening(同一ホスト誤 endpoint reject・ non-progressing page 検出・cycle 検出・comment ID dedupe)を追加。 - docs/dev/workflow.md の過大主張(AC1-AC7 解決済み表記)を是正し、 live subprocess replay テストが依然 pytest.skip() へフォールバックする 未解決の残課題(P1-6)を明示した。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
…redentialless-anchor-comment # Conflicts: # docs/dev/workflow.md
概要
Closes #2257(isolated profile の split-brain transport を修正するため本 Issue をクローズする)
isolated Claude-GPT session の
issue-refinement-looppreflight で、_fetch_single_comment()だけが isolated profile 分岐を持たず無条件でgh apiを呼んでいた split-brain transport を修正する。isolated profileでは host の
ghcredential が意図的に遮断されているため、この呼び出しは常に auth failure (gh exit 4) で失敗し、実在する anchor comment(Issue
#2197 comment 5315264311)が誤って
ANCHOR_COMMENT_NOT_FOUNDと分類されていた。
2026-08-20 追記(OWNER REQUEST_CHANGES fix_delta): 先行 SubAgent レビューの
APPROVE を覆す OWNER の詳細レビュー
(https://github.com/squne121/loop-protocol/pull/2260#issuecomment-5344930146)
を受け、局所的な
_fetch_single_comment()修正に留まっていた実装を、Issue #2257が要求する「1 invocation = 1 read authority」設計まで追随させた。以下は今回の
fix_delta で追加した変更内容(旧内容は本文末尾に保持)。
変更内容(fix_delta 追加分)
P0-1: 「1 invocation = 1 read authority」契約違反の解消
run_preflight()の live-mode 冒頭で_select_read_transport()を一度だけ呼び、isolated 時は
_CredentiallessPreflightTransport、非 isolated 時は_GhCliPreflightTransportを選択する。_fetch_single_comment()/_validate_anchor_comment_url()/_validate_anchor_comments_batch()はこの選択済みtransportを明示的な引数として受け取り、内部で
_is_isolated_claude_gpt_profile()を再評価しない。_fetch_issue_comments()が既に取得したcomments(complete paginated traversal の結果)を
_validate_anchor_comments_batch()のfixture_commentsとして渡すよう変更した(従来はfixture_comment_lookup = Noneが固定されており、initial anchor は毎回別の single-comment GET で再解決していた)。
これにより initial anchor は常に comments traversal から解決され、single-comment
GET は「traversal に anchor が含まれない場合のフォールバック」および
「trusted-anchor contract update の fresh-readback/TOCTOU 検証」でのみ使われる。
_fetch_issue()/_fetch_issue_comments()は_select_read_transport()を内部で呼ぶよう再設計した(
GitHubReadTransportProtocol に準拠する transport抽象を経由するようになった)。この 2 関数は、
test_main_drift_evidence_epoch.py(Allowed Paths 外の既存テスト)が固定 2 引数シグネチャで
monkeypatchしているため、呼び出し箇所(
run_preflight())からはtransport=を明示的に渡さない形を維持しているが、
_is_isolated_claude_gpt_profile()はプロセス生存期間中決定的であるため、途中で異なる authority へ分岐することはない。
P0-2: AC10 の構造化された
environment_failure出力refinement_preflight_result_v1.schema.jsonにreason_code/source/operation(すべて closed enum)を追加し、status == "environment_failure"の場合のみ必須・それ以外では禁止という top-level
allOfconditional を追加した。_build_result()/_emit_failure_result()にenvironment_failure_reason_code/_source/_operationパラメータを追加し、transport 読み取り失敗・fixture load 失敗・result/failure artifact 書き込み失敗・
planner 内部エラーなど、この PR が変更した全ての
status="environment_failure"発生箇所(および Allowed Paths 外の既存テストが直接呼ぶ汎用呼び出し経路)
で schema-valid な projection を発行するようにした。
P0-3 / AC9: 403 の無条件 rate-limit 分類を修正
github_credentialless_read.pyの_classify_http_error()を、429 は無条件でRateLimitedRejected、403 はx-ratelimit-remaining: 0(primary)またはRetry-Afterヘッダ(secondary/abuse-detection)が存在する場合のみRateLimitedRejected、それ以外は新設のForbiddenRejected(
http_403_forbidden)に分類するよう変更した。response body は判定に使わない。P0-4: transport の分類体系を closed 化する
_credentialless_get_page()にUnicodeDecodeError(malformed_response_body: invalid_encoding)を追加した。read_issue/list_issue_comments/read_issue_comment)の未知例外は、_classify_credentialless_exception()により固定コード
transport_internal_errorへフォールバックし、str(exc)を一切結果へ転記しない設計に統一した。
P1-5: pagination の堅牢化
_validate_pagination_target()を host/scheme に加え、repo/issue_number/endpoint(
/repos/<repo>/issues/<issue_number>/commentsprefix)まで検証するよう拡張した。
Linkheader(rel="next"はあるが URL がパースできない)をMalformedResponseBodyとして reject するようにした。nextURL)を即時検出し、複数ホップのcycle も引き続き検出する。
list_issue_comments()内で dedupe する。test_credentialless_github_read.pyに追加した。P1-6: production-graph fault matrix(部分対応・残課題あり)
test_isolated_anchor_single_authority.py/test_skill_runtime_exec_anchor.pyの live subprocess replay は変更していない。未解決: これらのテストは
GitHub API へ到達できない場合に
pytest.skip()へフォールバックしたままであり、docs/dev/runtime-verification-policy.mdが要求する「到達不能は SKIP ではなくenvironment_failure として扱う」という規約への完全準拠、および production graph
側の
environment_failureartifact 直接検証は未実装。fix_delta の時間内ではこの書き換えまで到達できなかった。
P1-7: docs 過大主張の是正
docs/dev/workflow.mdの該当節を「部分的に解決・残課題あり」に改め、今回実装した内容と、P1-6 で未解決の残課題を明記した。
制約遵守
scripts/agent-guards/github_credentialless_read.py、scripts/agent-guards/tests/test_credentialless_github_read.py、.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py、.claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json、docs/dev/workflow.md。gh auth login要求なし、host credentialコピーなし、
gh apiフォールバックなし)。検証(fix_delta 後の再実行)
uv run --locked pytest scripts/agent-guards/tests/test_credentialless_github_read.py -v— 48 PASS(AC7 negative control (a)-(e) 追加分含む)uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_run_refinement_preflight_credentialless_transport.py -v— 16 PASSuv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_trusted_anchor_iteration_zero.py -v— 18 PASSuv run --locked pytest scripts/agent-guards/tests/test_isolated_anchor_single_authority.py -v— 3 PASSuv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_anchor.py -v— 8 PASSuv run --locked pytest .claude/skills/issue-refinement-loop/tests/全体 — 1611 PASS(regression なし)pnpm typecheck— PASSpnpm lint— PASSpnpm test— 1872 PASS(112 files)pnpm build— PASSuv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py— 24 PASSuv run --directory <worktree> ruff check変更対象ファイル — All checks passed残課題(silent scope-out ではなく明示)
pytest.skip()するままで、environment_failureartifact を直接検証する形へは未改修。follow-up が必要。
_run_gh()エラー文字列は、この Issue のスコープである credentialless transport 側の closed taxonomy 化の対象外のまま
維持している(AC8 の非退行要件を優先)。
旧内容(初回実装、参考として保持)
変更内容(初回実装分)
scripts/agent-guards/github_credentialless_read.pyread_single_comment()を追加(単一 issue comment の無認証 REST read)InvalidCommentIdRejected/TransportConnectivityFailure(DNS/接続/timeout)/
MalformedResponseBody(不正 JSON)を追加.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py_fetch_single_comment()を isolated profile では credentiallesstransport 専用にし、
gh apiへの fallback を排除semantic_missing(真の 404)とtransport_failure(認証依存/rate-limit/5xx/DNS/timeout/不正JSON/pagination不完全等)を明確に区別
_validate_anchor_comment_url()と後段の再フェッチ経路の両方でerrを握りつぶさず分類し、transport failure はANCHOR_COMMENT_NOT_FOUND(human_judgment_required)ではなくenvironment_failure(fix_environment)として報告するdocs/dev/workflow.md再度「部分的に解決」へ改訂済み)
scripts/agent-guards/tests/test_isolated_anchor_single_authority.py(レビュー fix_delta iteration 2)test_ac5_ac6_skill_runtime_exec_with_human_context_live_subprocess_resolves_anchor_via_credentialless_authorityを追加。production command graph(
skill_runtime_exec.py --command-id preflight.run.with_human_context→command_registry.py→ 実run_refinement_preflight.py)を実 subprocess として起動し、fresh isolatedHOME・空GH_CONFIG_DIR・token unset の環境で Issue 実装: control-plane preflight の remote default-ref OID observe/fetch/pin/verify プロトコルを実装する #2197 の実アンカーコメント 5315264311 を live network 経由で解決することを確認する。
絶対に避けた事項
gh auth login要求: 行っていないcredentialless transport のみを使用)