Skip to content

実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#928"
goal_ref: "agent_retro_index の canonical parent marker と trusted post-merge workflow を deterministic に固定する"
change_kind: mixed

Parent Issue

#928

Parent Goal Ref

  • Goal: merged PR / Issue / run report / manifest artifact / follow-up issue を横断参照する agent_retro_index/v1 を再生成し、parent issue から辿れる状態にする。
  • Desired Destination: retro index の canonical payload / source comment set / trusted write pipeline が partial / ambiguous / orphan / blocked を区別しつつ、最小権限で parent marker comment を更新できる。

Current Validated Scope

  • retro index builder script と helper を追加する。
  • .github/workflows/agent-retro-index.yml を trusted context のみで設計する。
  • agent_retro_index:v1 / agent_retro_index_digest:v1 の parent marker comment upsert を追加する。
  • source comment set digest と canonical index digest を workflow summary / parent marker comment に記録する。

Remaining Parent Gaps

Outcome

retro index builder、専用 comment helper、workflow、tests、package wiring が 1 PR で追加され、現行 agent_retro_index/v1 schema を維持したまま partial / ambiguous / orphan / blocked を区別して dry-run 再生成でき、trusted workflow が parent issue の canonical marker comment を最小権限で update-or-noop できる状態。

In Scope

  • report comment 群から agent_retro_index/v1 payload を再生成する deterministic builder。
  • agent_run_report marker とは別 namespace の retro index parent marker / digest marker。
  • trusted workflow_dispatch / post-merge context のみを使う workflow。
  • canonical index digest、source comment set digest、artifact digest の分離。
  • merge_sha -> associated PR API -> PR closing keywords -> machine-readable refs -> parent child list -> branch hint の順に解決する trust hierarchy。
  • partial と blocked の厳密分類。
  • artifact は補助面、parent marker comment は永続正本とする設計。

Out of Scope

  • ChatGPT bundle export。
  • docs / skill handoff 更新。
  • EntireCLI safety checker。
  • docs/schemas/agent-retro-index.schema.json の key set 変更。
  • shared agent_run_report marker namespace への統合。

Acceptance Criteria

  • AC1: 現行 agent_retro_index/v1 schema を維持した payload が Child 1 schema を通る。
  • AC2: PR / Issue 解決順序が merge_sha -> associated PR API -> PR closing keywords -> machine-readable refs -> parent child list -> branch hint の固定順で解決され、branch pattern は weak hint としてのみ使われる。
  • AC3: 複数候補・未解決候補は ambiguous_links[] / orphan_reports[] に入り、non-authoritative な欠落は generation_verdict: partial になる。
  • AC4: workflow は workflow_dispatch と trusted post-merge context のみを使い、pull_request_target を使わない。
  • AC5: workflow は top-level permissions: {} を維持し、read-only build job と write-enabled upsert job を分離する。
  • AC6: artifact は補助生成のみで、永続正本は parent issue の marker comment である。
  • AC7: workflow / CLI / helper は report・index・GitHub API response body の全文を stdout/stderr に出さず、summary-only 出力に制限する。
  • AC8: canonical index digest と source comment set digest が agent_retro_index_digest:v1 marker と workflow summary に記録され、index JSON 本体へ未定義 key を追加しない。
  • AC9: agent_retro_index:v1 parent marker と agent_retro_index_digest:v1 digest marker を agent_run_report marker とは別 namespace で定義し、0件 create / 1件 update-or-noop / 2件以上 fail-closed にする。
  • AC10: generation_verdict=partial は orphan / ambiguous / non-authoritative missing data のみに使い、permission failure / validator failure / digest mismatch / duplicate marker は blocked にする。
  • AC11: canonical index digest、source comment set digest、artifact digest を別々に扱い、write job は artifact download 後に schema validation と digest verification を再実行する。
  • AC12: source comment set が retro index の trust boundaryを越える場合、full body を公開せず summary-only JSON と marker comment のみを出力する。
  • AC13: retro index posting は専用 helper 経由で行い、shared agent_run_report ownership tuple を再利用しない。
  • AC14: 現行 agent_retro_index/v1 schema に存在しない key が必要と判明した場合は、この Issue では実装せず follow-up Issue に分離して停止する。

Verification Commands

# AC1
# preflight-scope: pr_review_only
$ pnpm test

# AC2
# preflight-scope: pr_review_only
$ pnpm test

# AC3
# preflight-scope: pr_review_only
$ pnpm test

# AC4
# preflight-scope: pr_review_only
$ rg -n "workflow_dispatch|pull_request_target" .github/workflows/agent-retro-index.yml

# AC5
# preflight-scope: pr_review_only
$ rg -n "permissions: \\{\\}|contents: read|issues: read|issues: write|pull-requests: read|pull-requests: write" .github/workflows/agent-retro-index.yml

# AC6
# preflight-scope: pr_review_only
$ pnpm test

# AC7
# preflight-scope: pr_review_only
$ rg -n "cat .*report|cat .*index|JSON\\.stringify\\(.*index|tee .*index|jq \\.|set -x|gh api .*--verbose" .github/workflows/agent-retro-index.yml scripts/agent-logs/update-retro-index.mjs scripts/agent-logs/lib/retro-index-builder.mjs scripts/agent-logs/lib/retro-index-comment-helper.mjs

# AC8
# preflight-scope: pr_review_only
$ pnpm test

# AC9
# preflight-scope: pr_review_only
$ pnpm test

# AC10
# preflight-scope: pr_review_only
$ pnpm test

# AC11
# preflight-scope: pr_review_only
$ pnpm test

# AC12
# preflight-scope: pr_review_only
$ pnpm test

# AC13
# preflight-scope: pr_review_only
$ rg -n "agent_retro_index:v1|agent_retro_index_digest:v1|agent_run_report:v1" scripts/agent-logs/update-retro-index.mjs scripts/agent-logs/lib/retro-index-builder.mjs scripts/agent-logs/lib/retro-index-comment-helper.mjs tests/agent-logs/retro-index-comment-marker.test.ts

# AC14
# preflight-scope: pr_review_only
$ rg -n "schema migration|follow-up Issue|docs/schemas/agent-retro-index.schema.json" tests/agent-logs/retro-index-schema.test.ts scripts/agent-logs/update-retro-index.mjs scripts/agent-logs/lib/retro-index-builder.mjs scripts/agent-logs/lib/retro-index-comment-helper.mjs

Allowed Paths

  • scripts/agent-logs/update-retro-index.mjs
  • scripts/agent-logs/lib/retro-index*.mjs
  • .github/workflows/agent-retro-index.yml
  • tests/agent-logs/retro-index*.test.ts
  • package.json

Runtime Verification Applicability

decision: deferred
reason: "workflow write 実体確認は merge 後 trusted context が必要なため、local 実装では dry-run・static workflow inspection・artifact revalidation を success criteria にする"
deferred_destination:
  - destination_type: issue
    destination_ref: "#928"
deferred_verification_condition: "trusted post-merge context で parent issue marker upsert を実行できる状態になった後に live verification する"

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • trusted context 以外で write 権限を使わないと成立しないことが判明した場合
  • docs/schemas/agent-retro-index.schema.json の key set 変更が必要と判明した場合
  • shared scripts/agent-logs/lib/github-comments.mjs を直接変更しないと成立しないことが判明した場合

Required Skills

  • GitHub Actions / JavaScript

Scope Delta(任意)

  • 現行 schema を維持するため、digest / source refs は index JSON 本体ではなく parent marker comment / workflow summary に記録する。

Delivery Rule

  • 1 Issue = 1 PR で完了する。
  • Draft PR を既定とする。
  • live workflow write の成立確認は deferred verification に分離する。

Activity

  1. added
    workflow
    area/ai-ops
    enhancement
    phase/implementation
    agent/implementer
    on Jun 15, 2026
  2. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    結論

    #938 は方向性自体は妥当ですが、このまま実装に渡すと 「AC は通るが、retro index として信頼できない」false green を作れます。特に重大なのは、#938 が「source comment refs と generated index digest を記録する」と要求している一方、既存の agent_retro_index/v1 schema は additionalProperties: false で、index-level の generated_at、repository、parent_issue、source_comment_refs、index_digest、algorithm_version を受け付けない構造になっている点です。これは #938 の AC8 と schema 実体が衝突しています。

    #938 自体にコメントはありません。したがってレビュー対象は Issue 本文、親 #928、前段 Issue/PR、既存 schema/posting 実装、GitHub Actions/GitHub API の公式仕様です。

    参照した関連 Issue / PR

    親 #928 は、agent_session_manifest/v1 を provenance / validation / evidence index として残し、ChatGPT 改善検討用に agent_run_report/v1 と agent_retro_index/v1 を追加する delivery-rollup です。raw transcript、local path、secret 類は GitHub public surface に出さず、redacted report/index を Issue / PR comment に marker upsert で永続保存する設計です。

    前段 #934 は manifest 本文を Issue/PR comment に出さない境界を docs 側で固定し、redacted report/index だけを条件付き public comment 可にする整理です。
    #935 / PR #955 は agent_run_report/v1 / agent_retro_index/v1 schema と validator を追加し、retro index は report 本文の inline copy を禁止して、report_comment_url、report_digest、issue、pr、merge_sha、tags、friction_summary、quality_signals、follow_up_issues、orphan_reports、ambiguous_links、generation_verdict のような集約 field に閉じる方針です。
    #936 / PR #968 は lifecycle CLI を追加し、transcript 本文・local path・raw stdout/stderr を扱わず report を生成する前段です。
    #937 / PR #977 は agent_run_report/v1 用の GitHub comment posting surface を追加し、stable ownership marker と digest marker、marker-addressed upsert、dry-run、duplicate fail-closed、permission/404/410/422/pagination test を固定しています。
    #939 は ChatGPT 投入用 context bundle、#940 は docs / skill handoff、#941 は EntireCLI safety checker で、いずれも #938 からは out of scope です。

    敵対的レビュー

    Blocker 1: #938 の AC8 は現行 schema では満たせない

    #938 は「source comment refs と digest を index に保存する」「generated index の digest と source comment refs が記録される」ことを要求しています。ところが現行 agent-retro-index.schema.json の required key は schema、generation_verdict、entries、orphan_reports、ambiguous_links だけで、additionalProperties: false です。つまり source_comment_refs や index_digest を JSON index 本体へ追加できません。

    これは実装者が「digest marker は parent comment 側にあるから AC8 達成」と解釈して false green にできます。修正は二択です。

    1. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 の scope を変更し、schema migration を別 Issue に分離する。

    2. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 の AC8 を「index JSON 本体ではなく、parent marker comment の digest marker と workflow summary の source set digest に記録する」と明文化する。

    ただし #938 の stop condition には schema / key set 変更が必要なら停止とあるため、現状のままでは実装途中で stop するのが正しいです。

    Blocker 2: agent_run_report 用 upsert helper をそのまま使うと marker ownership が混線する

    #977 は agent_run_report:v1 の ownership marker と digest markerを追加しています。marker は agent_run_report:v1 repo=... issue=... pr=... run_id=... 形式で、digest marker も agent_run_report_digest:v1 です。

    #938 で parent issue に保存すべき正本は agent_retro_index/v1 です。ここで #977 の marker を再利用すると、parent comment 上で「run report」と「retro index」の所有権が同じ namespace になり、upsert 対象の取り違え・duplicate 判定漏れ・将来の export 側誤読が起きます。#938 には独立 marker が必要です。

    推奨 marker:

    <!-- agent_retro_index:v1 repo=squne121/loop-protocol parent_issue=928 algorithm=retro-index-builder@1 -->
    <!-- agent_retro_index_digest:v1 sha256=<canonical_index_payload_sha256> source_set_sha256=<source_comment_set_sha256> -->
    

    agent_run_report の marker helper は参考実装として使ってよいですが、marker namespace は絶対に分けるべきです。

    Blocker 3: PR → Issue 解決順が「決定的」だが「信頼度階層」になっていない

    #938 は Linked PR / Closes #N / branch pattern / parent issue refs / API linked data の固定順で解決するとしています。
    しかし、この順序は危険です。branch pattern は人間・AI が容易に間違えますし、parent issue refs は child list や tracker 構造と混ざります。GitHub API の commit-associated pull request endpoint は、default branch 上の commit について「その commit を入れた merged PR」を返せるため、post-merge workflow の PR 特定にはこちらを優先すべきです。(GitHub Docs)

    推奨順序は次です。

    1. validated agent_run_report の marker / payload にある target issue / PR。

    2. merge commit SHA → associated PR API。

    3. PR body の Closes|Fixes|Resolves #N。

    4. PR body / report body の machine-readable Linked PR / Linked Issue field。

    5. parent 導入: ChatGPT改善検討用のAI作業ログレポートをGitHubに永続保存する #928 の child issue list。

    6. branch pattern。これは weak hint 扱い。

    7. GitHub UI/API linked data。これは enrichment 扱いで、既存決定を上書きしない。

    複数候補が出た場合は ambiguous_links[] に入れて generation_verdict: partial。ただし validator failure、digest mismatch、permission failure、duplicate parent marker は partial ではなく blocked です。

    Blocker 4: workflow の write 権限分離が AC だけでは足りない

    GitHub Actions の permissions は top-level / job-level で指定でき、明示した permission 以外は none になります。最小権限にするには top-level permissions: {} と job-level permission を分離する必要があります。(GitHub Docs) (GitHub Docs)

    #938 は top-level permissions: {} と job-level contents: read, issues: write, pull-requests: write を要求していますが、read-only index generation job と write comment job を分ける AC がありません。Issue comment の create/update には Issues または Pull requests の write permission が必要です。(GitHub Docs)

    推奨 workflow 構造:

    on:
      workflow_dispatch:
        inputs:
          parent_issue:
            type: number
            default: 928
          dry_run:
            type: boolean
            default: true
      push:
        branches: [main]
    

    permissions: {}

    jobs:
    build-index:
    permissions:
    contents: read
    issues: read
    pull-requests: read
    # checkout main, collect report comments, build JSON, validate, upload artifact

    upsert-parent-comment:
    needs: build-index
    if: github.event_name == 'push' || inputs.dry_run == false
    permissions:
    contents: read
    issues: write
    pull-requests: write
    # download artifact, verify digest, revalidate, upsert parent marker

    pull_request_target は使わない方針で正しいです。GitHub は pull_request_target について、default branch context で動き、untrusted code を checkout/build/run すると cache poisoning や write token / secret access の危険があると警告しています。(GitHub Docs)

    High 1: artifact digest を使うなら、canonical comment digest と混同してはいけない

    actions/upload-artifact は artifact の SHA-256 digest output を持ちます。(GitHub)
    ただし artifact は補助面であり、#928 / #938 の正本は parent issue marker comment です。artifact digest は「build job が作った一時ファイルの検査値」で、parent comment の canonical payload digest とは別物として扱うべきです。

    必要な digest は最低3つです。

    canonical_index_digest      = parent comment に埋め込む index payload の digest
    source_comment_set_digest = 入力 comment URL + comment id + body digest の集合 digest
    artifact_digest = upload-artifact が返す補助 artifact digest

    この3つを混ぜると、artifact を再生成しただけで正本 digest が変わる、または入力 comment が変わったのに index payload が更新されない、という監査不能状態になります。

    High 2: 「workflow log に cat しない」だけでは漏洩防止にならない

    #938 の AC7 は cat .*report|cat .*index を grep しています。
    これは弱いです。console.log(JSON.stringify(index))、gh api の response body、Node の uncaught exception、Ajv error の raw value、shell set -x、tee、jq . でも同じ漏洩が起きます。

    AC7 は次に拡張すべきです。

    rg -n "cat .*report|cat .*index|JSON.stringify(.index|tee .index|jq .|set -x|gh api .--verbose" 
    .github/workflows/agent-retro-index.yml
    scripts/agent-logs/update-retro-index.mjs
    scripts/agent-logs/lib/retro-index
    .mjs

    さらに、CLI は成功時も status, entry_count, orphan_count, ambiguous_count, canonical_index_digest, source_comment_set_digest だけを出し、本文は stdout/stderr に出さない設計にするべきです。

    High 3: partial verdict の濫用で安全エラーを品質劣化に見せられる

    #938 は ambiguity / orphan を partial にする設計です。これは正しいですが、permission denied、validator failure、digest mismatch、duplicate parent marker、source comment body parse failure まで partial に落とすと危険です。

    分類は固定してください。

    状態 verdict 理由
    一部 report が Issue/PR に紐付かない partial データ欠落
    複数候補があり自動解決不能 partial ambiguity
    GitHub API 403 / permission denied blocked 信頼境界エラー
    source comment digest mismatch blocked tamper / race 可能性
    duplicate parent marker blocked upsert ownership 破損
    validator failure blocked public-safe contract 違反
    source comment が report marker ではない orphan_reports[] または skip 入力対象外

    高品質化した #938 実装案

    1. retro-index schema 互換を先に決める

    現行 schema を変えないなら、#938 の index JSON は現行 field に閉じる必要があります。source refs / index digest は parent comment marker と workflow summary の machine-readable result に記録するしかありません。現行 schema に入れるなら #938 は止めて、#935 follow-up として schema migration を切るべきです。

    推奨は後者です。agent_retro_index/v1 は index なので、最低限この形にした方が運用できます。

    {
      "schema": "agent_retro_index/v1",
      "repository": "squne121/loop-protocol",
      "parent_issue": 928,
      "generated_at": "2026-06-18T00:00:00Z",
      "algorithm_version": "retro-index-builder@1",
      "generation_verdict": "partial",
      "source_scope": {
        "issue_numbers": [928, 934, 935, 936, 937, 938, 939, 940, 941],
        "merged_after": "2026-06-15T00:00:00Z"
      },
      "source_comment_refs": [],
      "entries": [],
      "orphan_reports": [],
      "ambiguous_links": [],
      "index_digest": "sha256:..."
    }
    

    2. builder は pure function と GitHub fetcher を分ける

    lib/retro-index-builder.mjs は pure function にし、GitHub API や gh CLI を直接呼ばない方がよいです。入力は reports[], prs[], issues[], parentIssue, sourceComments[]。出力は { index, diagnostics, sourceSetDigest }。
    update-retro-index.mjs だけが GitHub fetch / upsert / artifact を扱う構造にします。

    これで tests は mocked REST ではなく fixture-based deterministic tests にできます。#937 側の comment upsert はすでに mocked REST tests を持っているため、#938 で同じ層を再実装する必要はありません。

    3. parent comment upsert は report posting と別 namespace にする

    実装 helper は #977 の github-comments.mjs を参照してもよいですが、#938 の allowed paths は scripts/agent-logs/lib/retro-index*.mjs に限定されています。既存 github-comments.mjs を変更したくなった時点で allowed paths に抵触します。

    したがって、#938 では以下のどちらかにしてください。

    • scripts/agent-logs/lib/retro-index-comments.mjs を新規作成し、既存 helperを import するだけにする。

    • allowed paths に scripts/agent-logs/lib/github-comments.mjs を明示追加する。

    後者は既存 report posting の regression risk が増えるため、前者が安全です。

    4. workflow は build と write を明確に分離する

    build-index job は issues: read, pull-requests: read, contents: read のみ。upsert-parent-comment job だけ issues: write, pull-requests: write を持たせる。GitHub の permissions 仕様上、job-level permission を使えば token 権限を job ごとに絞れます。(GitHub Docs)

    write job は artifact を download した後に必ず以下を再実行します。

    pnpm agent-retro-index:check artifacts/agent-retro-index.json
    pnpm agent-retro-index:verify-digest artifacts/agent-retro-index.json "$EXPECTED_DIGEST"
    pnpm agent-retro-index:post --parent-issue 928 --dry-run true
    

    live upsert は workflow_dispatch dry_run=false または push main のみで許可し、PR context では常に dry-run にするべきです。

    #938 に追加すべき Acceptance Criteria

    現在の AC1〜AC8 に加えて、以下を追加するのが妥当です。

    - [ ] AC9: `agent_retro_index:v1` parent marker と `agent_retro_index_digest:v1` digest marker を `agent_run_report` marker とは別 namespace で定義し、0件 create / 1件 update-or-noop / 2件以上 fail-closed にする。
    - [ ] AC10: `generation_verdict=partial` は orphan / ambiguous / non-authoritative missing data のみに使い、validator failure / digest mismatch / duplicate marker / permission failure は `blocked` にする。
    - [ ] AC11: source comment set digest、canonical index digest、artifact digest を別々に扱い、write job は artifact download 後に schema validation と digest verification を再実行する。
    - [ ] AC12: workflow / CLI は index/report body、GitHub API response body、Ajv raw value、full error body を stdout/stderr に出さず、summary-only JSON だけを出す。
    - [ ] AC13: PR → Issue link 解決は `merge_sha -> associated PR API -> PR closing keywords -> machine-readable Linked refs -> parent child list -> branch hint` の順に固定し、branch pattern は authoritative source にしない。
    - [ ] AC14: current `agent-retro-index.schema.json` に存在しない field が必要な場合、#938 は停止し、schema migration follow-up を起票する。
    

    実装者に渡すなら、この方針

    この Issue は「builder を作る」ではなく、public-safe comment index の canonicalization と trusted write pipeline を作る Issue として扱うべきです。最初の作業は coding ではなく、現行 schema と AC8 の衝突を解消する契約修正です。

    推奨する実装順は次です。

    1. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 本文に AC9〜AC14 を追記、または schema migration follow-up を切る。

    2. retro-index-builder.mjs を pure function として実装。

    3. retro-index-comments.mjs で report marker とは別の parent marker upsert を実装。

    4. update-retro-index.mjs は summary-only stdout、body は file/artifact/comment のみに限定。

    5. workflow は push: main + workflow_dispatch、top-level permissions: {}、read job / write job 分離。

    6. tests は schema pass だけでなく、schema/AC 不整合、duplicate marker、digest mismatch、ambiguous/orphan、permission failure、log leak grep を含める。

    最終判定は 要修正 です。#938 の目的は正しいですが、現行のままだと AC8/schema mismatch と marker namespace の未分離が残り、信頼できる agent_retro_index/v1 にはなりません。

    ## 結論

    #938 は方向性自体は妥当ですが、このまま実装に渡すと 「AC は通るが、retro index として信頼できない」false green を作れます。特に重大なのは、#938 が「source comment refs と generated index digest を記録する」と要求している一方、既存の agent_retro_index/v1 schema は additionalProperties: false で、index-level の generated_at、repository、parent_issue、source_comment_refs、index_digest、algorithm_version を受け付けない構造になっている点です。これは #938 の AC8 と schema 実体が衝突しています。

    #938 自体にコメントはありません。したがってレビュー対象は Issue 本文、親 #928、前段 Issue/PR、既存 schema/posting 実装、GitHub Actions/GitHub API の公式仕様です。

    参照した関連 Issue / PR

    親 #928 は、agent_session_manifest/v1 を provenance / validation / evidence index として残し、ChatGPT 改善検討用に agent_run_report/v1 と agent_retro_index/v1 を追加する delivery-rollup です。raw transcript、local path、secret 類は GitHub public surface に出さず、redacted report/index を Issue / PR comment に marker upsert で永続保存する設計です。

    前段 #934 は manifest 本文を Issue/PR comment に出さない境界を docs 側で固定し、redacted report/index だけを条件付き public comment 可にする整理です。
    #935 / PR #955 は agent_run_report/v1 / agent_retro_index/v1 schema と validator を追加し、retro index は report 本文の inline copy を禁止して、report_comment_url、report_digest、issue、pr、merge_sha、tags、friction_summary、quality_signals、follow_up_issues、orphan_reports、ambiguous_links、generation_verdict のような集約 field に閉じる方針です。
    #936 / PR #968 は lifecycle CLI を追加し、transcript 本文・local path・raw stdout/stderr を扱わず report を生成する前段です。
    #937 / PR #977 は agent_run_report/v1 用の GitHub comment posting surface を追加し、stable ownership marker と digest marker、marker-addressed upsert、dry-run、duplicate fail-closed、permission/404/410/422/pagination test を固定しています。
    #939 は ChatGPT 投入用 context bundle、#940 は docs / skill handoff、#941 は EntireCLI safety checker で、いずれも #938 からは out of scope です。

    敵対的レビュー

    Blocker 1: #938 の AC8 は現行 schema では満たせない

    #938 は「source comment refs と digest を index に保存する」「generated index の digest と source comment refs が記録される」ことを要求しています。ところが現行 agent-retro-index.schema.json の required key は schema、generation_verdict、entries、orphan_reports、ambiguous_links だけで、additionalProperties: false です。つまり source_comment_refs や index_digest を JSON index 本体へ追加できません。

    これは実装者が「digest marker は parent comment 側にあるから AC8 達成」と解釈して false green にできます。修正は二択です。

    1. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 の scope を変更し、schema migration を別 Issue に分離する。
    2. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 の AC8 を「index JSON 本体ではなく、parent marker comment の digest marker と workflow summary の source set digest に記録する」と明文化する。

    ただし #938 の stop condition には schema / key set 変更が必要なら停止とあるため、現状のままでは実装途中で stop するのが正しいです。

    Blocker 2: agent_run_report 用 upsert helper をそのまま使うと marker ownership が混線する

    #977 は agent_run_report:v1 の ownership marker と digest markerを追加しています。marker は agent_run_report:v1 repo=... issue=... pr=... run_id=... 形式で、digest marker も agent_run_report_digest:v1 です。

    #938 で parent issue に保存すべき正本は agent_retro_index/v1 です。ここで #977 の marker を再利用すると、parent comment 上で「run report」と「retro index」の所有権が同じ namespace になり、upsert 対象の取り違え・duplicate 判定漏れ・将来の export 側誤読が起きます。#938 には独立 marker が必要です。

    推奨 marker:

    <!-- agent_retro_index:v1 repo=squne121/loop-protocol parent_issue=928 algorithm=retro-index-builder@1 -->
    <!-- agent_retro_index_digest:v1 sha256=<canonical_index_payload_sha256> source_set_sha256=<source_comment_set_sha256> -->

    agent_run_report の marker helper は参考実装として使ってよいですが、marker namespace は絶対に分けるべきです。

    Blocker 3: PR → Issue 解決順が「決定的」だが「信頼度階層」になっていない

    #938 は Linked PR / Closes #N / branch pattern / parent issue refs / API linked data の固定順で解決するとしています。
    しかし、この順序は危険です。branch pattern は人間・AI が容易に間違えますし、parent issue refs は child list や tracker 構造と混ざります。GitHub API の commit-associated pull request endpoint は、default branch 上の commit について「その commit を入れた merged PR」を返せるため、post-merge workflow の PR 特定にはこちらを優先すべきです。([GitHub Docs]1)

    推奨順序は次です。

    1. validated agent_run_report の marker / payload にある target issue / PR。
    2. merge commit SHA → associated PR API。
    3. PR body の Closes|Fixes|Resolves #N。
    4. PR body / report body の machine-readable Linked PR / Linked Issue field。
    5. parent 導入: ChatGPT改善検討用のAI作業ログレポートをGitHubに永続保存する #928 の child issue list。
    6. branch pattern。これは weak hint 扱い。
    7. GitHub UI/API linked data。これは enrichment 扱いで、既存決定を上書きしない。

    複数候補が出た場合は ambiguous_links[] に入れて generation_verdict: partial。ただし validator failure、digest mismatch、permission failure、duplicate parent marker は partial ではなく blocked です。

    Blocker 4: workflow の write 権限分離が AC だけでは足りない

    GitHub Actions の permissions は top-level / job-level で指定でき、明示した permission 以外は none になります。最小権限にするには top-level permissions: {} と job-level permission を分離する必要があります。([GitHub Docs]2) ([GitHub Docs]2)

    #938 は top-level permissions: {} と job-level contents: read, issues: write, pull-requests: write を要求していますが、read-only index generation job と write comment job を分ける AC がありません。Issue comment の create/update には Issues または Pull requests の write permission が必要です。([GitHub Docs]3)

    推奨 workflow 構造:

    on:
      workflow_dispatch:
        inputs:
          parent_issue:
            type: number
            default: 928
          dry_run:
            type: boolean
            default: true
      push:
        branches: [main]
    
    permissions: {}
    
    jobs:
      build-index:
        permissions:
          contents: read
          issues: read
          pull-requests: read
        # checkout main, collect report comments, build JSON, validate, upload artifact
    
      upsert-parent-comment:
        needs: build-index
        if: github.event_name == 'push' || inputs.dry_run == false
        permissions:
          contents: read
          issues: write
          pull-requests: write
        # download artifact, verify digest, revalidate, upsert parent marker

    pull_request_target は使わない方針で正しいです。GitHub は pull_request_target について、default branch context で動き、untrusted code を checkout/build/run すると cache poisoning や write token / secret access の危険があると警告しています。([GitHub Docs]4)

    High 1: artifact digest を使うなら、canonical comment digest と混同してはいけない

    actions/upload-artifact は artifact の SHA-256 digest output を持ちます。([GitHub]5)
    ただし artifact は補助面であり、#928 / #938 の正本は parent issue marker comment です。artifact digest は「build job が作った一時ファイルの検査値」で、parent comment の canonical payload digest とは別物として扱うべきです。

    必要な digest は最低3つです。

    canonical_index_digest      = parent comment に埋め込む index payload の digest
    source_comment_set_digest   = 入力 comment URL + comment id + body digest の集合 digest
    artifact_digest             = upload-artifact が返す補助 artifact digest
    

    この3つを混ぜると、artifact を再生成しただけで正本 digest が変わる、または入力 comment が変わったのに index payload が更新されない、という監査不能状態になります。

    High 2: 「workflow log に cat しない」だけでは漏洩防止にならない

    #938 の AC7 は cat .*report|cat .*index を grep しています。
    これは弱いです。console.log(JSON.stringify(index))、gh api の response body、Node の uncaught exception、Ajv error の raw value、shell set -x、tee、jq . でも同じ漏洩が起きます。

    AC7 は次に拡張すべきです。

    rg -n "cat .*report|cat .*index|JSON\.stringify\(.*index|tee .*index|jq \.|set -x|gh api .*--verbose" \
      .github/workflows/agent-retro-index.yml \
      scripts/agent-logs/update-retro-index.mjs \
      scripts/agent-logs/lib/retro-index*.mjs

    さらに、CLI は成功時も status, entry_count, orphan_count, ambiguous_count, canonical_index_digest, source_comment_set_digest だけを出し、本文は stdout/stderr に出さない設計にするべきです。

    High 3: partial verdict の濫用で安全エラーを品質劣化に見せられる

    #938 は ambiguity / orphan を partial にする設計です。これは正しいですが、permission denied、validator failure、digest mismatch、duplicate parent marker、source comment body parse failure まで partial に落とすと危険です。

    分類は固定してください。

    状態 verdict 理由
    一部 report が Issue/PR に紐付かない partial データ欠落
    複数候補があり自動解決不能 partial ambiguity
    GitHub API 403 / permission denied blocked 信頼境界エラー
    source comment digest mismatch blocked tamper / race 可能性
    duplicate parent marker blocked upsert ownership 破損
    validator failure blocked public-safe contract 違反
    source comment が report marker ではない orphan_reports[] または skip 入力対象外

    高品質化した #938 実装案

    1. retro-index schema 互換を先に決める

    現行 schema を変えないなら、#938 の index JSON は現行 field に閉じる必要があります。source refs / index digest は parent comment marker と workflow summary の machine-readable result に記録するしかありません。現行 schema に入れるなら #938 は止めて、#935 follow-up として schema migration を切るべきです。

    推奨は後者です。agent_retro_index/v1 は index なので、最低限この形にした方が運用できます。

    {
      "schema": "agent_retro_index/v1",
      "repository": "squne121/loop-protocol",
      "parent_issue": 928,
      "generated_at": "2026-06-18T00:00:00Z",
      "algorithm_version": "retro-index-builder@1",
      "generation_verdict": "partial",
      "source_scope": {
        "issue_numbers": [928, 934, 935, 936, 937, 938, 939, 940, 941],
        "merged_after": "2026-06-15T00:00:00Z"
      },
      "source_comment_refs": [],
      "entries": [],
      "orphan_reports": [],
      "ambiguous_links": [],
      "index_digest": "sha256:..."
    }

    2. builder は pure function と GitHub fetcher を分ける

    lib/retro-index-builder.mjs は pure function にし、GitHub API や gh CLI を直接呼ばない方がよいです。入力は reports[], prs[], issues[], parentIssue, sourceComments[]。出力は { index, diagnostics, sourceSetDigest }。
    update-retro-index.mjs だけが GitHub fetch / upsert / artifact を扱う構造にします。

    これで tests は mocked REST ではなく fixture-based deterministic tests にできます。#937 側の comment upsert はすでに mocked REST tests を持っているため、#938 で同じ層を再実装する必要はありません。

    3. parent comment upsert は report posting と別 namespace にする

    実装 helper は #977 の github-comments.mjs を参照してもよいですが、#938 の allowed paths は scripts/agent-logs/lib/retro-index*.mjs に限定されています。既存 github-comments.mjs を変更したくなった時点で allowed paths に抵触します。

    したがって、#938 では以下のどちらかにしてください。

    • scripts/agent-logs/lib/retro-index-comments.mjs を新規作成し、既存 helperを import するだけにする。
    • allowed paths に scripts/agent-logs/lib/github-comments.mjs を明示追加する。

    後者は既存 report posting の regression risk が増えるため、前者が安全です。

    4. workflow は build と write を明確に分離する

    build-index job は issues: read, pull-requests: read, contents: read のみ。upsert-parent-comment job だけ issues: write, pull-requests: write を持たせる。GitHub の permissions 仕様上、job-level permission を使えば token 権限を job ごとに絞れます。([GitHub Docs]2)

    write job は artifact を download した後に必ず以下を再実行します。

    pnpm agent-retro-index:check artifacts/agent-retro-index.json
    pnpm agent-retro-index:verify-digest artifacts/agent-retro-index.json "$EXPECTED_DIGEST"
    pnpm agent-retro-index:post --parent-issue 928 --dry-run true

    live upsert は workflow_dispatch dry_run=false または push main のみで許可し、PR context では常に dry-run にするべきです。

    #938 に追加すべき Acceptance Criteria

    現在の AC1〜AC8 に加えて、以下を追加するのが妥当です。

    - [ ] AC9: `agent_retro_index:v1` parent marker と `agent_retro_index_digest:v1` digest marker を `agent_run_report` marker とは別 namespace で定義し、0件 create / 1件 update-or-noop / 2件以上 fail-closed にする。
    - [ ] AC10: `generation_verdict=partial` は orphan / ambiguous / non-authoritative missing data のみに使い、validator failure / digest mismatch / duplicate marker / permission failure は `blocked` にする。
    - [ ] AC11: source comment set digest、canonical index digest、artifact digest を別々に扱い、write job は artifact download 後に schema validation と digest verification を再実行する。
    - [ ] AC12: workflow / CLI は index/report body、GitHub API response body、Ajv raw value、full error body を stdout/stderr に出さず、summary-only JSON だけを出す。
    - [ ] AC13: PR → Issue link 解決は `merge_sha -> associated PR API -> PR closing keywords -> machine-readable Linked refs -> parent child list -> branch hint` の順に固定し、branch pattern は authoritative source にしない。
    - [ ] AC14: current `agent-retro-index.schema.json` に存在しない field が必要な場合、#938 は停止し、schema migration follow-up を起票する。

    実装者に渡すなら、この方針

    この Issue は「builder を作る」ではなく、public-safe comment index の canonicalization と trusted write pipeline を作る Issue として扱うべきです。最初の作業は coding ではなく、現行 schema と AC8 の衝突を解消する契約修正です。

    推奨する実装順は次です。

    1. 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する #938 本文に AC9〜AC14 を追記、または schema migration follow-up を切る。
    2. retro-index-builder.mjs を pure function として実装。
    3. retro-index-comments.mjs で report marker とは別の parent marker upsert を実装。
    4. update-retro-index.mjs は summary-only stdout、body は file/artifact/comment のみに限定。
    5. workflow は push: main + workflow_dispatch、top-level permissions: {}、read job / write job 分離。
    6. tests は schema pass だけでなく、schema/AC 不整合、duplicate marker、digest mismatch、ambiguous/orphan、permission failure、log leak grep を含める。

    最終判定は 要修正 です。#938 の目的は正しいですが、現行のままだと AC8/schema mismatch と marker namespace の未分離が残り、信頼できる agent_retro_index/v1 にはなりません。

  3. changed the title [-]実装: agent_retro_index/v1 builder と post-merge workflow を追加する[/-] [+]実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する[/+] on Jun 18, 2026
  4. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    更新内容

    • title を 実装: agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を追加する に更新
    • owner comment を一次ソースとして、agent_retro_index/v1 の canonical parent marker と trusted post-merge workflow を明示する形へ本文を更新

    検証結果

    • guard-issue-body.py: pass
    • contract_readiness_check.py --mode static: status=go
    • body sha256: sha256:4922398ebe1beb13a80b242ed2e32e90c81778e7a3fca14fb6e8a732913c1a01

    備考

    • 共有ワークツリーの無関係な変更は触れていません
  5. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  6. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-18T13:37:56Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/938
      body_sha256: "sha256:fe23ff807639f92592ae264a9e9ef7713be5fee111e6c4b1e5c5dbf2dced408e"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
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/implementerarea/ai-opsenhancementphase/implementationworkflow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions