Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "agent_session_manifest/v1 の phase_instance_id が衝突リスクのない CI-native ID を受け付けられるようにする"
change_kind: mixedParent Issue
none(単独改善。関連 closed: #242 session recording policy, #432 manifest validation gate)
Parent Goal Ref
- Goal: agent_session_manifest/v1 の phase_instance_id フィールドが CI ラン固有の一意な値を表現できるようにする
- Desired Destination: schema と validator が
ci:<producer_slug>:<run_id>:<run_attempt>形式を受け付け、workflow が CI-native ID を生成・設定できる状態
Current Validated Scope
docs/schemas/agent-session-manifest.schema.jsonのphase_instance_idpattern を拡張(現行^issue-[0-9]+:[a-z_]+:[0-9]{3}$に加えてci:<producer_slug>:<run_id>:<run_attempt>形式を受け付ける。非捕捉グループ形式:^(?:issue-[0-9]+:[a-z_]+:[0-9]{3}|ci:[a-z0-9_.-]+:[1-9][0-9]*:[1-9][0-9]*)$)scripts/generate-session-manifest.mjsの--phase-instance-idバリデーションロジックを更新(新 pattern を許容、help 文言・invalid-format error の更新を含む).github/workflows/session-manifest.ymlのPHASE_SEQ生成ロジックをci:session-manifest:${{ github.run_id }}:${{ github.run_attempt }}形式に変更- 関連する validator スクリプト・unit test を更新
Remaining Parent Gaps
なし(スタンドアロン改善)
Outcome
docs/schemas/agent-session-manifest.schema.json の phase_instance_id pattern が ci:<producer_slug>:<run_id>:<run_attempt> 形式を受け付けるよう拡張され、.github/workflows/session-manifest.yml が CI-native な一意 ID を生成して pnpm manifest:check が PASS する状態で PR がマージされている。
In Scope
docs/schemas/agent-session-manifest.schema.json:phase_instance_idのpatternを非捕捉グループ形式^(?:issue-[0-9]+:[a-z_]+:[0-9]{3}|ci:[a-z0-9_.-]+:[1-9][0-9]*:[1-9][0-9]*)$に更新。schema のphase_instance_id.descriptionには「GitHub Actions の workflow name ではなく、schema-safe な固定 slug」と明記する.github/workflows/session-manifest.yml:PHASE_SEQベースの暫定 ID 生成をci:session-manifest:${{ github.run_id }}:${{ github.run_attempt }}に変更scripts/generate-session-manifest.mjs: 新しい format の--phase-instance-id値を受け付けるバリデーション更新。help 文言・invalid-format error の更新を含む- 変更に対応する unit test の追加・更新(schema validation テスト、generator スクリプトテスト)
Contract Clarification
ci:<producer_slug>:<run_id>:<run_attempt> の producer_slug は GitHub Actions の workflow name(github.workflow)ではなく、schema-safe な固定 producer slug とする。本 Issue の生成対象は session-manifest に限定し、.github/workflows/session-manifest.yml は固定値 ci:session-manifest:${{ github.run_id }}:${{ github.run_attempt }} を使用する。schema の phase_instance_id.description には「GitHub Actions の workflow name ではなく、schema-safe な固定 slug」と明記する。
Out of Scope
issue-<N>:<phase>:<seq>形式の廃止または後方非互換変更- CI 以外のコンテキスト(local 実行等)での ID 生成ロジック変更
- session-manifest 以外の schema への変更
- phase_instance_id を参照する他システムの変更
Acceptance Criteria
- AC1:
docs/schemas/agent-session-manifest.schema.jsonのphase_instance_idpattern がci:session-manifest:12345678:1を valid と判定する - AC2: 既存の
issue-432:impl:001形式が引き続き valid と判定される(後方互換) - AC3: schema が以下の malformed CI ID を reject する:空白入り slug
ci:session manifest:12345678:1、run_id=0 のci:session-manifest:0:1、run_attempt=0 のci:session-manifest:12345678:0、run_attempt 欠落のci:session-manifest:12345678 - AC4:
scripts/generate-session-manifest.mjs --phase-instance-id ci:session-manifest:12345678:1(他の必須引数を補完した上で)--validateが成功する - AC5:
scripts/generate-session-manifest.mjs --helpの出力がissue-<N>:<phase>:<seq>とci:<producer_slug>:<run_id>:<run_attempt>の両形式を列挙し、invalid-format error も両形式を示す - AC6:
.github/workflows/session-manifest.ymlが--phase-instance-id ci:session-manifest:$GITHUB_RUN_ID:$GITHUB_RUN_ATTEMPT(または${{ github.run_id }}/${{ github.run_attempt }})を渡し、PHASE_SEQベースのロジックが削除されている - AC7:
pnpm manifest:check artifacts/agent-session-manifest-ci.jsonが PR の CI run で PASS する(deferred: CI 上で確認) - AC8:
pnpm testが PASS し、phase_instance_idの positive ケース(ci:session-manifest:12345678:1・issue-432:impl:001)と negative ケース(空白スラッグ・run_id=0・run_attempt=0・フィールド欠落)を含む TypeScript テストが追加されている
Verification Commands
# AC1
$ rg -n "ci:\[a-z0-9_\.\-\]" docs/schemas/agent-session-manifest.schema.json# AC2
$ rg -n "issue-\[0-9\].*ci:" docs/schemas/agent-session-manifest.schema.json# AC3
$ rg -n "\[1-9\]\[0-9\]" docs/schemas/agent-session-manifest.schema.json# AC4
$ rg -n "ci:session-manifest" scripts/generate-session-manifest.mjs# AC5
$ rg -n "producer_slug" scripts/generate-session-manifest.mjs# AC6
$ rg -n "ci:session-manifest" .github/workflows/session-manifest.yml# AC7
# preflight-scope: runtime_only
$ rg -n "ci:session-manifest" artifacts/agent-session-manifest-ci.json# AC8
$ rg -rn "ci:session-manifest" tests/Runtime Verification Applicability
- decision: deferred
- reason: AC7 は CI 上で session-manifest workflow が実際に実行されて artifact を生成しないと検証できない。local 実行では artifact が存在しないため
pnpm manifest:checkが実行不能。AC1-AC6 と AC8 は local で検証可能(immediate)。 - deferred_destination:
- destination_type: phase
- destination_ref: PR CI run(session-manifest workflow の validate-generated-artifact step)
- deferred_verification_condition: PR に対する CI run で
agent-session-manifest / validate-generated-artifactcheck が PASS し、生成 artifact の phase_instance_id がci:session-manifest:<run_id>:<run_attempt>形式であることを artifact ログで確認できる状態
Allowed Paths
docs/schemas/agent-session-manifest.schema.json.github/workflows/session-manifest.ymlscripts/generate-session-manifest.mjstests/— phase_instance_id schema validation に対応するテストファイル
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- JSON Schema (pattern / anyOf)
- GitHub Actions workflow 変数展開(
${{ github.run_id }}等)
Scope Delta(任意)
N/A
Background
PR #540(feat: enforce manifest validation required check (#432))の実装で、phase_instance_id を CI ラン固有の値にしようとしたが、agent_session_manifest/v1 の現行 schema(^issue-[0-9]+:[a-z_]+:[0-9]{3}$)が issue-<N>:<phase>:<seq> 形式しか受け付けないため、暫定として (run_id + run_attempt) % 1000 の 3 桁 seq を使って issue-432:impl:<seq> を生成している(.github/workflows/session-manifest.yml L47, L54)。
この 3 桁 seq は uniqueness が 1000 通りに限定され、長期運用では衝突する。PR #540 の non-blocking コメントで指摘済み。
source: post_merge_cleanup
anchor_pr: "https://github.com/squne121/loop-protocol/pull/540"
dedupe_key: "follow-up:squne121/loop-protocol:pr/540:phase_instance_id_schema"
created_by: post-merge-cleanup
created_at: "2026-05-31T15:30:00Z"Delivery Rule
1 Issue = 1 PR- Draft PR から開始する
- worktree:
.claude/worktrees/issue-<N>-phase-instance-id-ci-native/
Activity
squne121 commentedon May 31, 2026
敵対的レビュー結論
判定: そのまま実装に入るべきではない。Issue #547 は方向性は正しいが、契約の精度が低く、実装者がACを満たしたつもりで破綻したPRを出す余地がある。
#547 の目的は、agent_session_manifest/v1 の phase_instance_id が現行の issue-:: 形式だけでなく、CIラン固有の ci::<run_id>:<run_attempt> を受け付けるようにすること。背景として #540 で 3桁seqによる暫定IDを使っており、長期運用で衝突リスクがある、という整理は妥当です。GitHub公式でも github.run_id はリポジトリ内のworkflow runごとに一意で、rerunしても変わらず、github.run_attempt はrerunごとに増えるため、この2つを組み合わせる設計は筋がよいです。
ただし、Issue本文のAC・検証・パス指定に複数の不整合があります。
重大指摘
#547 のAC4は pnpm manifest:check artifacts/agent-session-manifest-ci.json を検証対象にしていますが、現行 main の .github/workflows/session-manifest.yml は artifacts/private-agent-session-manifest-ci.json に出力しています。Issue本文でもOutcome/AC側は artifacts/agent-session-manifest-ci.json を前提にしており、実ファイル名とズレています。
これは単なる表記揺れではありません。PR実装者がIssueどおりに agent-session-manifest-ci.json を検証すると、workflowの生成物とは別ファイルを見に行くか、存在しないファイルを検証することになります。AC4は現行workflowに合わせて artifacts/private-agent-session-manifest-ci.json に修正するべきです。
#547 はAC5で uv run pytest tests/ -k "phase_instance_id" -v を要求していますが、リポジトリの tests/ 配下は .test.ts 群で、#540の検証実績も pnpm test です。
これはかなり危険です。実装者がPythonテストを新設して uv run pytest だけ通しても、既存のVitest/TypeScript系テスト・Node producer・Ajv schema validationとの結合が壊れている可能性を見逃します。AC5は pnpm test -- ... または既存テストランナーに合わせたコマンドへ修正すべきです。
推奨:
pnpm test -- tests/agent-session-manifest.test.ts tests/agent-session-manifest-producer.test.ts tests/agent-session-manifest-check.test.ts
pnpm manifest:check artifacts/private-agent-session-manifest-ci.json
Issueは ci::<run_id>:<run_attempt> と書いていますが、実装例では ci:session-manifest:${{ github.run_id }}:${{ github.run_attempt }} を固定値で使っています。GitHub公式の github.workflow / GITHUB_WORKFLOW は「workflowのname」であり、スペースや大文字を含み得ます。一方、Issueのpattern案は [a-z0-9_.-]+ のため、実際のworkflow nameをそのまま入れる仕様とは互換しません。
ここは仕様名を変えるべきです。workflow ではなく workflow_slug または producer_id と定義するべきです。例:
ci:<producer_slug>:<run_id>:<run_attempt>
ci:session-manifest:12345678:1
また、schema descriptionにも「GitHub Actionsのworkflow nameではなく、schema-safeな固定slug」と明記するべきです。
IssueのIn Scopeは次のpatternを例示しています。
^issue-[0-9]+:[a-z_]+:[0-9]{3}$|^ci:[a-z0-9_.-]+:[0-9]+:[0-9]+$
これは各分岐に ^ / $ があるため現時点では大きな誤マッチにはなりにくいですが、保守性が悪いです。JSON Schema の pattern は正規表現で制約するもので、JSON Schema docsでも ^ と $ による境界指定の意味が説明されています。分岐を増やす契約では、全体を非捕捉グループで囲む方が安全です。
推奨:
^(?:issue-[0-9]+:[a-z_]+:[0-9]{3}|ci:[a-z0-9_.-]+:[1-9][0-9]:[1-9][0-9])$
さらに run_id / run_attempt はGitHub仕様上「number」なので、[0-9]+ より 0 を拒否する [1-9][0-9]* が妥当です。GitHub公式では run_attempt は1から始まり、rerunごとに増加するとされています。
中程度の指摘
#547 のAC1/AC2/AC3検証は rg が中心です。これは「文字列がある」ことしか確認できず、以下を検出できません。
ci:session-manifest:12345678:1 が本当にschema validか
ci:session manifest:123:1 のような空白入りslugがrejectされるか
ci:session-manifest:0:0 をrejectするか
既存 issue-432:impl:001 が後方互換でvalidか
scripts/generate-session-manifest.mjs のCLIバリデーションとschemaが同じ正規表現を使っているか
最低限、以下をACに入れるべきです。
node scripts/generate-session-manifest.mjs
--repository squne121/loop-protocol
--phase-main-loop impl
--phase-ledger-phase post_commit_verification
--phase-instance-id ci:session-manifest:12345678:1
--actor-type github_action
--actor-name session-manifest-workflow
--evidence-source-kind ci_check
--evidence-source-ref https://github.com/squne121/loop-protocol/actions/runs/12345678
--evidence-visibility private_artifact
--format json
--validate > /tmp/agent-session-manifest-ci.json
pnpm manifest:check /tmp/agent-session-manifest-ci.json
現行 generate-session-manifest.mjs はhelpで --phase-instance-id を issue-:: 形式と説明し、validatePhaseInstanceId も ^issue-[0-9]+:[a-z_]+:[0-9]{3}$ を直書きしています。
Issueはバリデーションロジック更新を含めていますが、help文言・エラーメッセージ・例示の更新を明示していません。これは小さく見えて、運用時に「schemaは通るがCLI説明が古い」状態を作ります。ACに含めるべきです。
Issueでは .github/workflows/session-manifest.yml の生成値を ci:session-manifest:${{ github.run_id }}:${{ github.run_attempt }} にするとしています。これは実用上よいですが、GitHubの github.workflow とは別物です。
したがって、以下のどちらかに決めるべきです。
固定slug方式: ci:session-manifest:<run_id>:<run_attempt>
GitHub context方式: ci::<run_id>:<run_attempt>
敵対的には、固定slug方式を推します。github.workflow は表示名であり、renameや空白混入の影響を受けるため、schema IDには不向きです。
修正後のIssue文案
Contract Clarification
ci:<producer_slug>:<run_id>:<run_attempt>のproducer_slugは GitHub Actions の workflow name ではなく、schema-safe な固定 producer slug とする。本Issueでは
session-manifestのみを生成対象とする。Required Pattern
phase_instance_idMUST accept both:issue-<issue_number>:<phase_slug>:<seq3>ci:<producer_slug>:<github_run_id>:<github_run_attempt>Recommended schema pattern:
squne121 commentedon May 31, 2026
Contract Review: BLOCKED (2026-05-31T09:42:00Z)
不足項目
VC preflight: human_judgment
preflight-scope: runtime_onlymarker が# AC7の 前 に配置されており、「コマンド行の直前行」ルール違反ですrg ... artifacts/agent-session-manifest-ci.json(存在しないファイル)を実行 → exit_code 2 →category: unknown/decision: human_judgment現状(誤):
正しい順序:
推奨アクション
上記 1 箇所の順序を入れ替えるだけで VC preflight が
status: passになります。gh issue editで直接修正するか、issue-refinement-loopを起動してください。squne121 commentedon May 31, 2026
(誤投稿)削除してください
squne121 commentedon May 31, 2026
Contract Snapshot (2026-05-31T09:46:00Z)
docs/schemas/agent-session-manifest.schema.jsonのphase_instance_idpattern がci:<producer_slug>:<run_id>:<run_attempt>形式を受け付けるよう拡張され、.github/workflows/session-manifest.ymlが CI-native な一意 ID を生成してpnpm manifest:checkが PASS する状態で PR がマージされているdocs/schemas/agent-session-manifest.schema.json.github/workflows/session-manifest.ymlscripts/generate-session-manifest.mjstests/.claude/worktrees/issue-547-agent-session-manifest-schema-phase-instworktree-issue-547-agent-session-manifest-schema-phase-instsqune121 commentedon Jun 1, 2026
implement-issue: 実装完了 (2026-06-01T12:00:19Z)
.claude/worktrees/issue-547-agent-session-manifest-schema-phase-instworktree-issue-547-agent-session-manifest-schema-phase-instsqune121 commentedon Jun 1, 2026
impl-review-loop: 完了 (2026-06-01T12:30:00Z)
test(#547): add generator CLI integration tests for phase_instance_id…
feat(#547): extend phase_instance_id to accept CI-native ci:<slug>:<r…
squne121 commentedon Jun 1, 2026
post-merge-cleanup: 完了 (2026-06-01T12:40:00Z)
unresolved_cleanup_items
worktree
.claude/worktrees/issue-547-agent-session-manifest-schema-phase-instに untracked ファイルが残っています:このファイルは PR マージ前から存在していたもので、PR #551 とは独立しています。
削除可能であれば以下を実行することで worktree を完全に削除できます:
feat(#550): generalize scope collision detection with scope_context (#…