Skip to content

fix: retrospective-run marker malformed comment を discard せず記録する - #2366

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2308-retro-index-blocked-runs
Aug 28, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2308-retro-index-blocked-runs

Conversation

@squne121

@squne121 squne121 commented Aug 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Checks

  • pnpm typecheck
  • pnpm lint
  • pnpm test
  • pnpm build
  • 上記コマンドをすべてローカルで実行し、成功したことを確認してからチェックしてください

Schema Change Applicability

  • decision: schema_change
  • reason: docs/schemas/agent-retro-index.schema.json へ optional additive property retrospective_runs_blocked を新規追加する schema 変更のため。

Schema Consumer Inventory

変更対象 schema: docs/schemas/agent-retro-index.schema.json(agent_retro_index/v1、additionalProperties: false の closed schema への additive property 追加)

before/after 差分:

# before(top-level properties)
properties:
  schema: {const: agent_retro_index/v1}
  retrospective_runs: {type: array, items: {$ref: '#/$defs/retrospectiveRunEntry'}}
  generation_verdict: {enum: [complete, partial, blocked]}
  entries: {type: array, items: {$ref: '#/$defs/entry'}}
  orphan_reports: {type: array, items: {$ref: '#/$defs/orphanReport'}}
  ambiguous_links: {type: array, items: {$ref: '#/$defs/ambiguousLink'}}
# retrospective_runs_blocked は存在しない

# after
properties:
  schema: {const: agent_retro_index/v1}
  retrospective_runs: {type: array, items: {$ref: '#/$defs/retrospectiveRunEntry'}}
  retrospective_runs_blocked: {type: array, items: {$ref: '#/$defs/retrospectiveRunBlockedEntry'}}  # 追加(省略可)
  generation_verdict: {enum: [complete, partial, blocked]}
  entries: {type: array, items: {$ref: '#/$defs/entry'}}
  orphan_reports: {type: array, items: {$ref: '#/$defs/orphanReport'}}
  ambiguous_links: {type: array, items: {$ref: '#/$defs/ambiguousLink'}}
# $defs.retrospectiveRunBlockedEntry を新設: required [run_comment_url, reason]、
# run_comment_url は既存 retrospectiveRunEntry と同一パターンの URI、
# reason は orphanReport/ambiguousLink と同様の自由文字列(minLength 1 / maxLength 160)

retrospective_runs_blocked は省略可能な additive フィールドであり、既存 artifact(本フィールド欠落)は引き続き schema-valid のままである。

Consumer 列挙(rg コマンド例と結果):

rg -l "agent-retro-index.schema.json" . --glob '!.claude/worktrees/**' --glob '!node_modules/**'
tests/agent-run-report-schema.test.ts
scripts/lib/agent-run-report-validation.mjs
scripts/agent-logs/lib/retro-index-builder.mjs
docs/dev/agent-run-report.md
docs/schemas/agent-retro-index.schema.json
docs/dev/agent-retro-index.md
tests/agent-logs/chatgpt-context-marker-mode.test.ts
tests/agent-logs/retro-index-schema.test.ts
tests/agent-logs/chatgpt-retro-context-marker.test.ts

Consumer 更新状況:

Consumer ファイル 更新有無 備考
scripts/agent-logs/lib/retro-index-builder.mjs 更新済み retrospective_runs_blocked を生成し detectSchemaMigrationRequirement() の allowedKeys へ追加(本 PR の主対象)
tests/agent-logs/retro-index-schema.test.ts 更新済み ajv (ajv/dist/2020.js) で schema ファイルを直接 compile し、retrospective_runs_blocked あり/なし artifact・欠損 reason fixture・buildRetroIndex() の実出力を schema validation する回帰テストを追加
tests/agent-logs/retro-index-update.test.ts 更新済み buildRetroIndex() 経由の retrospective_runs_blocked 生成・generation_verdict 反映の behavior-based regression test を追加
scripts/lib/agent-run-report-validation.mjs(validateRetroIndexAgainstSchema()) 更新不要(Allowed Paths 外・不変) schema ファイルを実行時に動的読み込みして ajv compile するランタイム消費者。additive optional property のため既存呼び出しは無変更で追随(tests/agent-run-report-schema.test.ts の既存 fixture で回帰なしを確認)
tests/agent-run-report-schema.test.ts 更新不要(Allowed Paths 外・不変) validateRetroIndexAgainstSchema(createValidRetroIndex()) が既存 fixture(retrospective_runs_blocked 欠落)で valid: true のまま(pnpm test 全件 PASS で確認)
docs/dev/agent-retro-index.md 更新不要(Allowed Paths 外) 「スキーマの正本は docs/schemas/agent-retro-index.schema.json を参照」という参照のみで、フィールド一覧を複製していないため追随不要
docs/dev/agent-run-report.md 更新不要(Allowed Paths 外) 同上の参照のみ
tests/agent-logs/chatgpt-context-marker-mode.test.ts / tests/agent-logs/chatgpt-retro-context-marker.test.ts 更新不要(Allowed Paths 外・不変) schema_ref 文字列リテラル(docs/schemas/agent-retro-index.schema.json#agent_retro_index/v1)のみを参照しており、フィールド構造には依存しない

Compatibility Decision(互換性判定)

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: N/A
  • reason: retrospective_runs_blocked は top-level の任意 additive property であり、省略時も schema-valid(既存 artifact に影響なし)。既存 blockedReasons/entries[](agent_run_report/v1 側)の blocked semantics・publication_digest の暗号学的検証ロジックは変更していない。

Safety Claim Matrix

  • N/A
  • reason: 本 PR は transport / permission / sandbox / auth / mcp / .claude/skills/** / .github/workflows/** のいずれにも該当しない(scripts/agent-logs/lib/retro-index-builder.mjs、docs/schemas/agent-retro-index.schema.json、テストファイルのみの変更)ため safety-sensitive ではない。

Notes

受け入れ条件の達成状況

  • AC1: buildRetroIndex() の戻り値オブジェクトに retrospective_runs_blocked(run_comment_url + reason を保持する配列)フィールドが追加され、normalizeRetrospectiveRunComment() が kind: 'blocked' を返す malformed / structurally-invalid な run comment が記録される — scripts/agent-logs/lib/retro-index-builder.mjs 731行目 retrospective_runs_blocked: retrospectiveRunsBlocked で確認(rg -n "retrospective_runs_blocked" scripts/agent-logs/lib/retro-index-builder.mjs)
  • AC2: retrospectiveRunsBlocked が非空の場合、既存 blockedReasons が空である限り generation_verdict が partial になる(blockedReasons.length > 0 の場合は従来通り blocked 優先)。retrospective_runs_blocked のみを理由に index の生成・upsert 自体は中断されない — 726行目の generation_verdict 三項判定に retrospectiveRunsBlocked.length > 0 が組み込まれていることで確認(rg -n "retrospectiveRunsBlocked.length" scripts/agent-logs/lib/retro-index-builder.mjs)
  • AC3: marker prefix(<!-- agent_retrospective_run:v1)はあるが strict marker parse に失敗する comment(例: idempotency_key 欠損)が kind: 'ignored' ではなく kind: 'blocked' / reason: 'retrospective_run_marker_malformed' として記録される。marker prefix を一切持たない通常 comment は従来通り ignored のまま — 355行目 return { kind: 'blocked', reason: 'retrospective_run_marker_malformed' } で確認(rg -n "retrospective_run_marker_malformed" scripts/agent-logs/lib/retro-index-builder.mjs)
  • AC4: docs/schemas/agent-retro-index.schema.json に retrospective_runs_blocked が optional additive property として追加され、新フィールドを含む artifact が schema validation と detectSchemaMigrationRequirement() の両方を通る(既存 artifact に本フィールドが欠落していても schema-valid のまま)— schema 26行目に "retrospective_runs_blocked" プロパティ定義、builder 751行目 allowedKeys に同キーが追加済み(rg -n "retrospective_runs_blocked" docs/schemas/agent-retro-index.schema.json)
  • AC5: valid entry + malformed run fixture で entries[] を失わず retrospective_runs_blocked が1件記録され generation_verdict=partial になる、marker 自体が malformed なケースも記録される、marker のない通常 comment は ignored のまま、正常 run のみなら従来通り generation_verdict=complete になる、の behavior-based regression test が tests/agent-logs/retro-index-update.test.ts および tests/agent-logs/retro-index-schema.test.ts に追加され PASS — 対象2ファイルの focused test run で 2 files / 23 tests PASS(下記「検証コマンド結果」参照)
  • AC6: pnpm test が全件 PASS — 112 files / 1887 tests PASS(下記「検証コマンド結果」参照)

検証コマンド結果

検証は head 0a580ab5db69af438adcd4952993a44fa5398cf0 を detached checkout した独立 worktree で実行した。

# AC1
$ rg -n "retrospective_runs_blocked" scripts/agent-logs/lib/retro-index-builder.mjs
645:    // retrospective_runs_blocked[] and reflected into generation_verdict as at
731:    retrospective_runs_blocked: retrospectiveRunsBlocked,
751:  const allowedKeys = new Set(['schema', 'generation_verdict', 'entries', 'orphan_reports', 'ambiguous_links', 'retrospective_runs', 'retrospective_runs_blocked'])
# → PASS(マッチあり)

# AC2
$ rg -n "retrospectiveRunsBlocked.length" scripts/agent-logs/lib/retro-index-builder.mjs
726:      : (entries.length === 0 || orphanReports.length > 0 || ambiguousLinks.length > 0 || retrospectiveRunsBlocked.length > 0 ? 'partial' : 'complete'),
# → PASS(マッチあり)

# AC3
$ rg -n "retrospective_run_marker_malformed" scripts/agent-logs/lib/retro-index-builder.mjs
355:      return { kind: 'blocked', reason: 'retrospective_run_marker_malformed' }
# → PASS(マッチあり)

# AC4
$ rg -n "retrospective_runs_blocked" docs/schemas/agent-retro-index.schema.json
26:    "retrospective_runs_blocked": {
# → PASS(マッチあり)

# AC5
$ pnpm test -- tests/agent-logs/retro-index-update.test.ts tests/agent-logs/retro-index-schema.test.ts
Test Files  2 passed (2)
     Tests  23 passed (23)
# → PASS

# AC6
$ pnpm test
Test Files  112 passed (112)
     Tests  1887 passed (1887)
# → PASS

Allowed Paths 遵守

変更ファイル(gh pr view 2366 --json files で確認)は以下の4件であり、Issue #2308 の Allowed Paths と完全一致する。範囲逸脱(scope creep)はない。

変更ファイル Issue #2308 Allowed Paths 内
scripts/agent-logs/lib/retro-index-builder.mjs 一致
docs/schemas/agent-retro-index.schema.json 一致
tests/agent-logs/retro-index-update.test.ts 一致
tests/agent-logs/retro-index-schema.test.ts 一致

Issue #2308 が定義する Allowed Paths(4件)は次の通りである:

scripts/agent-logs/lib/retro-index-builder.mjs
docs/schemas/agent-retro-index.schema.json
tests/agent-logs/retro-index-update.test.ts
tests/agent-logs/retro-index-schema.test.ts

変更ファイル一覧との差分なし(4/4 一致、Allowed Paths 外の変更なし)。

buildRetroIndex() が normalizeRetrospectiveRunComment() の kind: 'blocked'
判定(構造的に無効な agent_retrospective_run_publication/v1 envelope、および
marker prefix はあるが strict marker parse に失敗するケース)を黙って discard
せず、retrospective_runs_blocked[](run_comment_url + reason)へ記録するよう
変更する。retrospective_runs_blocked が非空の場合、既存 blockedReasons が空
である限り generation_verdict を partial に反映し、index 生成・upsert 自体は
継続する。extractRetrospectiveRunPayload() は marker prefix はあるが strict
parse に失敗する first line を kind: 'blocked' / reason:
'retrospective_run_marker_malformed' として返すよう拡張する。
detectSchemaMigrationRequirement() の allowedKeys と
docs/schemas/agent-retro-index.schema.json へ optional additive property
として retrospective_runs_blocked を追加する。既存 blockedReasons 由来の
blocked semantics と publication_digest の暗号学的検証は変更しない
(PR #2304 の pr-reviewer 非ブロッキング指摘 P0-7 関連の解消)。

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

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2366 closed).

@squne121

Copy link
Copy Markdown
Owner Author

PR Review 判定 (impl-review-loop iteration 0)

Mergeability

  • mergeable=MERGEABLE, merge_state_status=BLOCKED, isDraft=true

Evidence Check

Blockers

なし

Non-blockers / Warnings

  • CI_TEST_PERFORMANCE_ADVISORY_V1(block:false, docs/schemas/ path advisory、非ブロッキング)
  • Allowed Paths gate advisory: contract_source metadata 欠落(非ブロッキング)
verdict: APPROVE
reviewed_head_sha: "ec924826a51e9f5ef1191f3bc3849d910521f86e"
blockers: []
warnings:
  - "ci_test_performance_advisory_v1_non_blocking_docs_schemas_path"
  - "allowed_paths_gate_advisory_contract_source_metadata_missing"

@squne121

Copy link
Copy Markdown
Owner Author

敵対的レビュー結果

Verdict: REQUEST_CHANGES — reframe_in_place

レビュー対象は current head ec924826a51e9f5ef1191f3bc3849d910521f86e。PR は Draft・OPEN・mergeable、1コミット・4ファイル・+275/-7 です。現在の main は PR の base SHA 02aad46679a2c14aea489d652bce695d06f96964 のままで、同一 head の必須 CI も成功しています。PRを作り直す必要はありません。

設計の大部分は妥当です。しかし、Issue #2308 の主目的である「marker prefix が見えている malformed comment を silent discard しない」という契約を、まだ破る入力が1種類残っています。

P1 — \b のため、区切り文字欠落の malformed marker が引き続き ignored になる

問題

実装された prefix 判定は次です。

const RETROSPECTIVE_RUN_MARKER_PREFIX =
  /^<!--\s*agent_retrospective_run:v1\b/u

Issue #2308 の AC3 は、先頭行に文字列 prefix

<!-- agent_retrospective_run:v1

が存在する一方で strict marker parse に失敗するコメントを、ignored ではなく retrospective_run_marker_malformed として記録する契約です。

しかし ECMAScript の \b は「文字列上の任意の境界」ではありません。前後の一方だけが WordCharacters の場合に成立し、ASCII の英字・数字・アンダースコアはすべて WordCharacters です。したがって 1 の直後が r や _ なら \b は成立しません。([tc39.es]1)

例えば、次のように required whitespace を欠落させたコメントです。

<!-- agent_retrospective_run:v1repository_id=squne121/loop-protocol idempotency_key=sha256:... -->

現行処理では以下になります。

RETROSPECTIVE_RUN_MARKER_LINE.test(firstLine)   === false
RETROSPECTIVE_RUN_MARKER_PREFIX.test(firstLine) === false
extractRetrospectiveRunPayload()                === null
normalizeRetrospectiveRunComment()              === { kind: "ignored" }

結果として、

という挙動になります。current head の builder は strict parse 失敗後、prefix regex にも失敗するとそのまま null を返す構造です。

手元の Node でも次を再現しました。

input after v1             strict match   prefix match
" repository_id=..."       false          true
"repository_id=..."        false          false  ← silent discard
"_repository_id=..."       false          false  ← silent discard

現在のテストが検出できない理由

追加された fixture は、

<!-- agent_retrospective_run:v1 repository_id=squne121/loop-protocol -->

のように、v1 の直後には正常な空白を置いたまま idempotency_key だけを欠落させています。そのため \b は成立し、問題なく blocked になります。区切り空白自体を欠落させるケースはテストされていません。

最小修正

数字による将来バージョン v10 を区別しつつ、v1 直後の malformed な文字列も拾うなら、次で足ります。

const RETROSPECTIVE_RUN_MARKER_PREFIX =
  /^<!--\s*agent_retrospective_run:v1(?![0-9])/u

これにより、

  • v1repository_id=... → v1 marker の malformed として blocked
  • v1_repository_id=... → v1 marker の malformed として blocked
  • v1.1 ... → v1 marker の malformed として blocked
  • v10 ... →別バージョンとして v1 prefix とは判定しない

という挙動になります。

より単純に Issue の literal-prefix 契約へ完全に合わせるなら、\b を外しても構いません。

const RETROSPECTIVE_RUN_MARKER_PREFIX =
  /^<!--\s*agent_retrospective_run:v1/u

ただし、この形は v10 も v1 prefix として扱います。現状では (?![0-9]) の方が将来拡張を阻害しません。

必須回帰テスト

少なくとも次の1ケースを追加すべきです。

it('records a v1 marker with a missing delimiter after the version as malformed', () => {
  const comment = {
    html_url:
      'https://github.com/squne121/loop-protocol/issues/928#issuecomment-5000000012',
    body:
      '<!-- agent_retrospective_run:v1repository_id=squne121/loop-protocol idempotency_key=sha256:abc -->',
    linkedPrHints: [],
    linkedIssueHints: [928],
    branchHint: null,
  }

  expect(normalizeRetrospectiveRunComment(comment)).toEqual({
    kind: 'blocked',
    reason: 'retrospective_run_marker_malformed',
  })
})

v10 を別バージョンとして維持するなら、その negative control も小さく追加すると安全です。


妥当だった点

1. blocked ではなく partial とする判断は正しい

malformed retrospective run が存在しても、既存の正常な entries[] を捨てず、index 生成と upsert を継続する設計は、個人開発での運用性に合っています。既存の agent_run_report/v1 側 blockedReasons がある場合だけ従来どおり blocked を優先しており、責務も混同していません。

2. run_comment_url と reason を残す形は実用的

単なる件数ではなく、修復対象のコメントへ直接到達できるため、運用時の調査コストを抑えられます。自由文字列の reason も、新しい parser reason code を追加するたびに schema migration を要求しないため、この用途では enum より適切です。

3. closed schema の更新方法は正しい

現行 schema は additionalProperties: false なので、新しいトップレベル property を出力する以上、properties と $defs の両方を更新する必要があります。PR は retrospective_runs_blocked を optional property として追加し、既存 artifact がフィールドを持たなくても有効な状態を維持しています。JSON Schema でも、additionalProperties: false は properties 等で宣言されていないフィールドを拒否します。 (JSON Schema)

4. 完全な暗号学的 verifier を Node 側へ複製しなかった判断も正しい

Node builder は derived index の生成者であり、一次永続化側には author、marker/payload、schema、public-safety、digest を再検証する共有 parse_verified_run_comment() が既にあります。ここへ別言語の canonicalization verifier を追加すると、正本が二重化し、今回の可観測性修正に対して保守負担が過大になります。

非ブロッキング事項

summarizeResult() は generation_verdict を保持していますが、retrospective_run_count や retrospective_run_blocked_count は返しません。CLI の短い summary だけを見る場合には件数がある方が便利ですが、Issue #2308 でも明示的に Out of Scope とされているため、本PRのマージ条件にはしません。

また、retrospective_runs_blocked: [] を正常時にも常時出力するため、マージ後最初の index 再生成では canonical digest が変わります。任意フィールドとして空配列時に省略すれば不要な更新を減らせますが、現行の内部 consumer は同一リポジトリの schema を動的に読む構成であり、これもブロッカーではありません。

セキュリティ・ハーネス・配布物について

このPRは parser、derived index、JSON Schema、Vitest fixture の変更に限定されています。transport、認証、mutation permission、Claude runtime、plugin package の挙動は変えていません。Issue契約も runtime verification を not_applicable とし、plugin distribution と smoke は #2240 の独立スコープにしています。したがって、今回追加すべきなのは上記の小さな parser regression testだけです。live GitHub mutation、dual-runtime smoke、security harness の追加は不要です。

マージ条件

次の3点だけで十分です。

  1. RETROSPECTIVE_RUN_MARKER_PREFIX の \b を、missing delimiter を拾える判定へ修正する。
  2. v1repository_id=... の回帰テストを追加する。
  3. focused Vitest と pnpm test を同一 head で再実行する。

それ以外の schema、verdict precedence、正常エントリ保持、upsert継続方針はマージ可能な品質です。

Test and others added 3 commits August 28, 2026 18:58
PR #2366 への human REQUEST_CHANGES fix_delta。RETROSPECTIVE_RUN_MARKER_PREFIX
の ECMAScript \b は両側が word 文字だと発火しないため、
`v1repository_id=...` や `v1_repository_id=...` のような区切り文字を欠いた
malformed マーカーが prefix 判定をすり抜け ignored のまま kind: 'blocked' に
昇格しなかった(AC3 違反)。`(?![0-9])` の負の先読みに置き換え、v10 等の
将来バージョンとの区別を保ったまま該当パターンを blocked に分類する回帰
テストを追加する。
@squne121

Copy link
Copy Markdown
Owner Author

PR Review 判定 (impl-review-loop iteration 2)

人間の adversarial review(#2366 comment 5451100881, REQUEST_CHANGES: \b 境界問題によりmalformed markerがignoredに落ちる)を受けたfix_delta適用後の再判定。

fix_delta 内容

  • RETROSPECTIVE_RUN_MARKER_PREFIX を \b から (?![0-9]) negative lookahead へ修正
  • v1repository_id=... / v1_repository_id=... malformed marker を検出する回帰テスト追加、v10 negative control 追加
  • iteration 1 の pr-reviewer が指摘したPR本文必須セクション欠落(## 受け入れ条件の達成状況 / ## 検証コマンド結果 / ## Allowed Paths 遵守)も追加済み
  • その後、外部の "Update branch" マージが2回連続で着地(head: ec924826 → 0a580ab5 → 6aacdf77 → 42046862be5a68c849885a463c7449700f2f112d)。いずれも Issue 実装: retro-index-builder が malformed/unverifiable な run comment を discard せず generation_verdict に反映する #2308 の Allowed Paths 4ファイルには触れていない base sync のみ

Mergeability

  • mergeable=MERGEABLE, merge_state_status=BLOCKED(Draft状態のため。branch protection上の required review 未充足であり Git conflict ではない), isDraft=true

Evidence Check

  • PR本文3セクション: 実データ入りで存在確認(placeholder ではない)
  • Allowed Paths gate: status=ok(live head で4/4ファイルが Issue 実装: retro-index-builder が malformed/unverifiable な run comment を discard せず generation_verdict に反映する #2308 Allowed Paths 内、GitHub Files API で直接確認)
  • CI: 最新 head 42046862be5a68c849885a463c7449700f2f112d で required checks(build/lint/test/typecheck/validate-generated-artifact)全 SUCCESS
  • AC1-AC4: live diff/ファイル内容を直接確認(RETROSPECTIVE_RUN_MARKER_PREFIX の negative lookahead 修正、retrospective_runs_blocked schema 追加を含む)
  • AC5/AC6: required test job が同一 head で pnpm test を実行し SUCCESS
  • P1 fix(\b → (?![0-9]))の正しさを再確認

Blockers

なし

Non-blockers / Warnings

  • 外部 "Update branch" マージが審査中に2回連続で着地し head が動いた(scope creep なし、advisory)
  • CI_TEST_PERFORMANCE_ADVISORY_V1(block:false, docs/schemas/ path、非ブロッキング)
  • e2e-core / e2e-responsive-matrix / python-test-core / component-vrt-report / deploy-pr は required set 外で審査時 pending だったが blocking ではない
verdict: APPROVE
reviewed_head_sha: "42046862be5a68c849885a463c7449700f2f112d"
blockers: []
warnings:
  - "head_sha_advanced_twice_via_external_update_branch_merges_during_review_window"
  - "ci_test_performance_advisory_v1_non_blocking_docs_schemas_path"
  - "non_required_checks_pending_at_review_time_not_blocking"

@squne121
squne121 marked this pull request as ready for review August 28, 2026 10:23
@squne121

Copy link
Copy Markdown
Owner Author

3ジョブの関係は明確です。

さらに、失敗テストには構造的なフレーク要因があります。テストは overall_timeout_sec=0.3 を指定して「実プロセスが起動→SIGTERM→reap→process_exit 記録」まで起きることを期待しています。 しかし実装では timeout の計測を subprocess 起動より前の validation/preflight から開始し、deadline 到達時に cancel_event を立てます。 そのうえ subprocess runner は、呼び出された時点ですでに cancel 済みなら Popen 自体を行わず overall_timeout_pending_cancelled を返す仕様です。この正規経路では process_exit は存在しません。

したがって推奨順位は 「#2366を修正しない → 対象テストを再現調査 → フレークならCI再実行 → 恒久対策は別スコープ」 です。単に0.3秒を数秒へ伸ばすより、「プロセス起動を同期確認してから cancellation を発火させる」テストへ直す方が妥当です。PR #2366 の最新レビューでも current head の本体変更は APPROVE され、当時 python-test-core は非required/pending扱いでした。

Claude Code には次を渡すのがよいです。サブエージェントを2系統に分け、両方の完了を必ず待ってから判断するよう明記しています。

PR #2366 の GitHub Actions failure を調査し、適切な推奨アクションまで実行してください。

対象:

既知の観測:

  • root failure は python-test-core。

  • python-test は core failure を aggregate して失敗している。

  • ci-verdict-summary は python-test / python-test-core failure を正しく伝播して blocked になっている。

  • python-test-core では 13,318 tests 中1件のみ失敗:
    .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py::test_timeout_termination_recorded

  • failure:
    assert len(exits) == 1
    に対して len(exits) == 0。

  • 同テストは fake provider を60秒sleepさせ、
    overall_timeout_sec=0.3
    で timeout cancellation を発火させて process_exit / termination_reason == "sigterm" を期待している。

  • fan_out_orchestrator.py は overall timeout の計測を subprocess spawn より前から開始する。

  • make_subprocess_runner() は呼出時に cancel_event.is_set() なら Popen せず
    overall_timeout_pending_cancelled
    を返す正規経路を持つ。

  • したがって高負荷CIでは preflight 中に0.3秒を超え、
    subprocess が一度も起動されないまま cancellation となり、
    process_exit が0件になる可能性がある。

  • PR fix: retrospective-run marker malformed comment を discard せず記録する #2366 / Issue 実装: retro-index-builder が malformed/unverifiable な run comment を discard せず generation_verdict に反映する #2308 の Allowed Paths は以下のみ:

    • scripts/agent-logs/lib/retro-index-builder.mjs
    • docs/schemas/agent-retro-index.schema.json
    • tests/agent-logs/retro-index-update.test.ts
    • tests/agent-logs/retro-index-schema.test.ts
  • failing Python test / fan-out implementationは 実装: retro-index-builder が malformed/unverifiable な run comment を discard せず generation_verdict に反映する #2308 の Allowed Paths 外。

重要な進行ルール

最初に独立したサブエージェントを最低2つ起動してください。

SubAgent A: CI root-cause investigator

read-only で以下を調査する:

  • 3つのActions jobの完全なlog/step
  • failing test
  • _run_fanout_with_fake_provider()
  • run_fanout()
  • make_subprocess_runner()
  • deadline watcher / cancel_event / process registry / SIGTERM / reap / process lifecycle journal
  • 関連Issue/PR/commit履歴
  • 同テストまたは同failure signatureの既知flake有無

特に次を判定する:

  1. timeout が subprocess Popen より前に発火した正規の pending-cancel 経路か
  2. Popen/process_start 後なのに process_exit が欠落する production bug か
  3. pytest-xdist / runner load に依存する timing flake か
  4. PR fix: retrospective-run marker malformed comment を discard せず記録する #2366 の変更との因果関係が存在するか

コード変更はしない。
nested SubAgent は起動しない。
最後に evidence と verdict を返す。

SubAgent B: PR scope / regression investigator

read-only で以下を調査する:

コード変更はしない。
nested SubAgent は起動しない。
最後に evidence と verdict を返す。

必須: SubAgent completion barrier

2つのサブエージェントを起動したら、両方が完全に終了して最終レポートを返すまで待つこと。

片方だけの結果で次工程へ進まない。
SubAgentをfire-and-forgetしない。
サブエージェント実行中に推測でコード修正・CI rerun・PR mutationを開始しない。

両方のレポートを受領してから、main agent自身で証拠を照合して最終判断すること。

再現調査

SubAgent完了後、current PR headを再確認する。

gh pr view 2366 --json headRefOid,baseRefOid,headRefName,baseRefName,isDraft,mergeStateStatus

run 33163197490 が対象としていた head:
42046862be5a68c849885a463c7449700f2f112d

headが進んでいた場合は、古いSHAを現在の事実として扱わずcurrent headで再評価する。

まず production code を変更せず focused test を再現する。

uv run --locked pytest \
  .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py::test_timeout_termination_recorded \
  -vv

単発PASSだけでflake認定しない。
可能なら少なくとも以下を行う:

  • serial repeat
  • CI相当の xdist / -n 4 環境で repeat
  • failing時の events.ndjson と outcome.failure_class を保存
  • process_start の有無を確認

必要に応じて20回程度繰り返す。ただし単に回数を増やすことより、failure pathのイベント列を採取することを優先する。

判定を以下の2経路に分ける。

Case A: process_start が存在しない

かつ outcome が
overall_timeout_pending_cancelled
またはそれと同等の before-start cancellation の場合:

これは production invariant violation ではない。

run_fanout() の overall deadline が preflight を含む仕様と、
make_subprocess_runner() の cancel-before-Popen 仕様に対し、
テストが「0.3秒以内に必ずPopenされる」と暗黙に仮定している timing-sensitive test と判定する。

この場合:

恒久対策案としては、単純な timeout 値増加より、
「実processの開始を同期確認してから cancellation を発火させ、その後 process_exit/sigterm を検証する」
deterministic test への変更を第一候補にする。

例えば:

  • fake provider に pid/start sentinel を書かせる
  • runner を別threadで開始
  • sentinel または process_start event を待つ
  • その後 cancel_event.set() / 正規 termination path を発火
  • thread join
  • process_exit が exactly once
  • termination_reason == sigterm
    を検証する。

overall timeout watcher 自体のテストと、
「spawn済みprocess cancellation → process_exit telemetry」のテストは、
必要なら責務を分離する。

ただしこの修正は Issue #2308 / PR #2366 の Allowed Paths 外なので、
PR #2366へ混ぜないこと。

Case B: process_start が存在する

にもかかわらず process_exit が欠落する場合:

production process-lifecycle bug の可能性がある。

以下を追跡する:

  • deadline watcher の ctx.terminate_all()
  • runner側 _terminate_process_group()
  • process registry register/unregister race
  • proc.wait()/returncode
  • journal write ordering
  • worker completion barrier
  • ThreadPoolExecutor.shutdown(wait=True)
  • exception pathで process_exit emission前に抜けられる経路

この場合も #2366 へ直接修正を混ぜない。
別スコープの defect として扱う。

PR #2366に対するアクション

原則:
CIを緑にするために Issue #2308 の Allowed Paths を拡張しない。

root failure が Case A の timing flake であり、
current PR headで再実行する価値があると判断した場合は、
まず python-test-core の再実行を選ぶ。

GitHub CLI/APIで job rerun が可能なら、
対象 job:
98822420865

を再実行する。

再実行後は dependent result を最後まで確認し、
最低限以下が同じ current head SHA でどうなったか確認する:

  • python-test-core
  • python-test
  • ci-verdict-summary

python-test-core がPASSしただけで作業完了としない。
aggregate/verdictまで最終状態を確認する。

再実行でも同じテストが失敗した場合は、rerun連打をしない。
deterministic test defect / base regression として別修正を優先する。

恒久修正が必要な場合

Allowed Paths 外修正が必要と判定したら、
PR #2366 ブランチでは変更しない。

以下を最終報告する:

  • root cause
  • reproduction
  • production bug か test bug か
  • 推奨変更ファイル
  • 最小修正方針
  • 必要な回帰テスト
  • #2366と分離すべき理由
  • 別Issue/PRが必要か

別Issueの自動作成や別branchへの実装を既存repo policyが明示的に許可していない場合は、勝手に始めず、
そのまま貼れる Issue draft / implementation plan を提示して停止する。

禁止事項

  • CIを通す目的だけで assertion を削除
  • xfail / skip 化
  • retry wrapperで隠す
  • python-test aggregate policy をsuccess扱いへ緩和
  • ci-verdict-summary のAC9を緩和
  • #2366のAllowed Paths外ファイルを同PRへ追加
  • unrelated formatting/refactor
  • サブエージェントの完了を待たずに作業続行
  • サブエージェントからさらにnested SubAgentを起動

最終出力

以下の形式でまとめる:

  1. Root cause
  2. SubAgent A findings
  3. SubAgent B findings
  4. Reproduction evidence
  5. PR #2366との因果関係
  6. Recommended action
  7. 実際に行ったaction
  8. CI rerun結果
  9. 恒久修正の要否
  10. 変更ファイル一覧(変更なしなら明記)
  11. 残存リスク

最も重要なのは、
「PR #2366の問題」と
「base/mainに存在するCI/test infrastructureの問題」
を混同しないこと。

このプロンプトなら、再実行だけで偶然緑にして終了するのではなく、「before-Popen cancellation ならテスト側の同期不足」まで確認してから判断させられます。現時点では、#2366へのコード追加修正よりこの切り分けを優先するのが妥当です。

@squne121
squne121 merged commit 97fd045 into main Aug 28, 2026
67 of 74 checks passed
@squne121
squne121 deleted the worktree-issue-2308-retro-index-blocked-runs branch August 28, 2026 11:25
squne121 added a commit that referenced this pull request Aug 28, 2026
…2373)

* fix: fan-out timeout/cancellation テストを readiness sentinel 同期へ書き換える (#2371)

PR #2366 の CI 安定化調査で発見した readiness race に依存する fan-out
timeout/cancellation テストを、pid sentinel 同期と責務分離された assert へ
書き換える。

- test_timeout_termination_recorded を
  test_running_process_cancellation_records_sigterm へ rename し、固定の
  overall_timeout_sec=0.3 deadline watcher 経路(Popen 前に発火しうる)で
  はなく、pid_file readiness sentinel を確認してから手動 cancel_event.set()
  する設計に変更。process_start/process_exit の PID 一致と termination_reason
  も assert する。
- test_sigkill_escalation_recorded も同じ readiness sentinel helper を使用
  するよう変更し、time.sleep(0.3) による readiness race を除去。
- test_subprocess_runner_terminates_process_group_on_timeout の false-green
  (Popen 未到達でも ok is False と "timeout" in failure_class だけで PASS
  してしまう構造)を、pid sentinel で実 subprocess 起動を確認し、cancel 後に
  実プロセスが本当に消えたことまで確認する形に修正。
- test_overall_timeout_cancels_pending_and_terminates_running を
  test_overall_timeout_cancels_pending_subtasks へ rename し、
  overall_timeout_reached event と pending subtask の cancellation のみを
  assert する形に整理(起動済み process の termination までは主張しない)。
- 上記いずれも sentinel timeout・assertion failure・thread 内例外の全経路で
  thread / child process を finally で cleanup し、thread.join() 後に
  not thread.is_alive() を assert する。

production code (fan_out_orchestrator.py) には diff なし。

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

* fix: fan-out cancellation テストの finally cleanup を cancel_event 経路から独立させる

OWNER 敵対的レビュー(PR #2373, reviewed_head_sha f664bfa)の REQUEST_CHANGES を反映する。

- test_running_process_cancellation_records_sigterm / test_sigkill_escalation_recorded
  / test_subprocess_runner_terminates_process_group_on_timeout の finally cleanup が、
  検証対象そのものである cancel_event 協調キャンセル経路にのみ依存しており、runner
  thread 内で無処理例外が発生した場合や cancel_event セット後も runner がハングした
  場合に non-daemon thread と child process がリークしうる構造上の欠陥を修正(P1)。
  thread 内例外を別 list に捕捉し、finally 内で ctx.terminate_all(grace_period=0.1) を
  cancel_event 経路とは独立に必ず呼び、thread がまだ生きている場合または thread 内
  例外が捕捉された場合のみ child_pid ベースの test-only fallback(os.getpgid 一致確認
  後 os.killpg SIGKILL)で強制終了する。
- test_sigkill_escalation_recorded に process_start の件数(1件)と sentinel PID との
  一致 assert を追加し、SIGTERM 側テストと対称な lifecycle pairing 検証にする(P1)。

Issue #2371 の全 Verification Commands を再実行して確認済み:
- pytest 通常実行 50 passed
- pytest -n4 --dist load 50 passed
- 修正対象 3 テストのみ fresh pytest process で 20 回連続実行し flake なし
- fan_out_orchestrator.py に diff なし(AC8)
- ruff check クリーン

Related: #2371

---------

Co-authored-by: Test <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

実装: retro-index-builder が malformed/unverifiable な run comment を discard せず generation_verdict に反映する

1 participant