Skip to content

設計: MVP 自動プレイテスト用の最小 telemetry / event log contract を定義する #419

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
related_issues: ["#417", "#418", "#415", "#284"]
goal_ref: "MVP 自動プレイテストにおけるイベントとメトリクスの構造化定義"
change_kind: docs
anchor_decision_comment: "https://github.com/squne121/loop-protocol/issues/419#issuecomment-4558164489"
diff_rationale: "PR #418 で追加された automation block / metrics_json field の隣接位置に、自動プレイテスト runner が出力する events.jsonl / metrics.json / trace artifact の構造化契約 (event taxonomy / envelope / invariant / artifact safety) を Markdown spec として追記する。telemetry 送信実装と JSON Schema file は別 Issue 扱い。"
changed_requirement_id: "playtest.telemetry.v1"
affected_sections:
  - "docs/product/playtest-log.md#Automation Artifact Contract"
  - "docs/product/playtest-log.md (automation block 近接位置)"

Parent Issue

none

Related Issues

Parent Goal Ref

  • Goal: 自動プレイテストの定量観測を可能にするためのデータ契約を確立する
  • Desired Destination: docs/product/playtest-log.md

Current Validated Scope

  • docs/product/playtest-log.md における Automation Artifact Contract 節の追加
  • イベントタクソノミー(session_start, collision 等)の enum 定義
  • event envelope 仕様(必須フィールド定義)
  • MVP 用の metrics.json スキーマ(fenced JSON example 込み)の定義
  • invariant 節と artifact safety 節の明記

Remaining Parent Gaps

  • 実際の telemetry 送信実装
  • schema validator の実装(別 Issue で対応予定)
  • JSON Schema ファイル(.schema.json)の作成(別 Issue で実施)

Outcome

docs/product/playtest-log.md に "Automation Artifact Contract" 節が追加され、events.jsonl / metrics.json / trace artifact / playtest-log の責務境界・event taxonomy・event envelope spec・metrics.json fenced JSON example・invariant・artifact safety policy が定義されている状態。

In Scope

  • docs/product/playtest-log.md への "Automation Artifact Contract" 節追加
    • 責務分離の明記:
      • playtest-log.md: playtest session 証跡台帳(automation artifact への参照を保持)
      • events.jsonl: runtime event 時系列(runner 出力)
      • metrics.json: events.jsonl から再計算可能な derived 集計
      • trace/replay: Playwright trace 等の raw artifact(public repo に置かない)
  • event taxonomy の enum 定義(必須 13 種)
  • event envelope spec(必須フィールド定義)
  • metrics.json fenced JSON example(parse 可能な内容)
  • invariant 節(rate / count / duration の整合性規則)
  • artifact safety 節(public_repo_safe flag・命名規約・trace 参照方針)
  • 単位規約の明記(率は 0.0-1.0 fraction、duration は ms 単位・suffix _ms)

Out of Scope

  • telemetry 送信コードの実装
  • JSON Schema ファイル(.schema.json)の作成(別 Issue で実施)
  • OpenTelemetry/CloudEvents SDK・Collector の直接導入
  • .claude/scripts/extract_fenced_json.py の実装(必要になった場合は follow-up Issue を起票)

Acceptance Criteria

  • AC1: docs/product/playtest-log.md に "Automation Artifact Contract" 節があり、schema_version: "playtest.telemetry.v1" を含む。
  • AC2: event taxonomy として最低限以下が enum 列挙されている: session_start, session_end, scenario_start, scenario_end, input_summary, collision, hit, damage, death, sortie_clear, sortie_fail, reward_granted, debrief_summary。
  • AC3: event envelope spec に最低限以下フィールドが定義されている: schema_version, event_id, event_type, session_id, run_id, seq, tick, occurred_at, build_ref, scenario_id, random_seed, agent_profile, actor_id, entity_type, data。
  • AC4: metrics.json 例が fenced ```json ブロックとして埋め込まれ、python -c "import json,sys; json.load(open(sys.argv[1]))" 相当でパース成功する内容である(raw counter と derived rate を分離、`computed_from: "events.jsonl"` を含む)。
  • AC5: invariant 節が以下を含む: run_count == success_count + failure_count + aborted_count、0.0 <= success_rate <= 1.0、success_rate == success_count / run_count、duration_ms_p95 >= duration_ms_p50、metrics.computed_from MUST reference events.jsonl、raw trace artifacts MUST NOT be committed to public repo。
  • AC6: 単位規約として、率は 0.0-1.0 fraction(または unit: percent 明示)、duration は ms 単位で field name suffix _ms を含むことを明記。
  • AC7: Artifact Safety 節に public_repo_safe flag、metrics.redacted.json 命名規約、trace は external-secure-artifact:// 参照とする方針を含む。

Verification Commands

# AC1: Automation Artifact Contract 節と schema 識別子
rg -nq "^### Automation Artifact Contract" docs/product/playtest-log.md
rg -nq "playtest\.telemetry\.v1" docs/product/playtest-log.md
# AC2: event taxonomy enum(JSON quoted form、必須 13 種)
rg -nq '"session_start"' docs/product/playtest-log.md
rg -nq '"session_end"' docs/product/playtest-log.md
rg -nq '"scenario_start"' docs/product/playtest-log.md
rg -nq '"scenario_end"' docs/product/playtest-log.md
rg -nq '"input_summary"' docs/product/playtest-log.md
rg -nq '"collision"' docs/product/playtest-log.md
rg -nq '"hit"' docs/product/playtest-log.md
rg -nq '"damage"' docs/product/playtest-log.md
rg -nq '"death"' docs/product/playtest-log.md
rg -nq '"sortie_clear"' docs/product/playtest-log.md
rg -nq '"sortie_fail"' docs/product/playtest-log.md
rg -nq '"reward_granted"' docs/product/playtest-log.md
rg -nq '"debrief_summary"' docs/product/playtest-log.md
# AC3: event envelope 必須フィールド(JSON quoted key form)
rg -nq '"schema_version":' docs/product/playtest-log.md
rg -nq '"event_id":' docs/product/playtest-log.md
rg -nq '"event_type":' docs/product/playtest-log.md
rg -nq '"session_id":' docs/product/playtest-log.md
rg -nq '"run_id":' docs/product/playtest-log.md
rg -nq '"seq":' docs/product/playtest-log.md
rg -nq '"tick":' docs/product/playtest-log.md
rg -nq '"occurred_at":' docs/product/playtest-log.md
rg -nq '"build_ref":' docs/product/playtest-log.md
rg -nq '"scenario_id":' docs/product/playtest-log.md
rg -nq '"random_seed":' docs/product/playtest-log.md
rg -nq '"agent_profile":' docs/product/playtest-log.md
rg -nq '"actor_id":' docs/product/playtest-log.md
rg -nq '"entity_type":' docs/product/playtest-log.md
rg -nq '"data":' docs/product/playtest-log.md
# AC4: metrics.json fenced JSON example の parse 可能性(pr-review-judge で検証)
# preflight-scope: pr_review_only
rg -nq "playtest\.metrics\.v1" docs/product/playtest-log.md
# AC5: invariant 節
rg -nq "run_count == success_count \+ failure_count \+ aborted_count" docs/product/playtest-log.md
rg -nq "0\.0 <= success_rate <= 1\.0" docs/product/playtest-log.md
rg -nq "success_rate == success_count / run_count" docs/product/playtest-log.md
rg -nq "duration_ms_p95 >= duration_ms_p50" docs/product/playtest-log.md
rg -nq '\$\.computed_from == "events\.jsonl"' docs/product/playtest-log.md
rg -nq "raw trace artifacts MUST NOT be committed to public repo" docs/product/playtest-log.md
# AC6: 単位規約
rg -nq "0\.0-1\.0 fraction" docs/product/playtest-log.md
rg -nq "duration_ms_p50" docs/product/playtest-log.md
# AC7: artifact safety
rg -nq "metrics\.redacted\.json" docs/product/playtest-log.md
rg -nq "external-secure-artifact://" docs/product/playtest-log.md

注: VC は実装着手前に baseline で fail することを期待する設計(expected baseline fail)。AC4 のみ # preflight-scope: pr_review_only を付与し、fenced JSON example の構文検証は pr-review-judge が行う。

Allowed Paths

  • docs/product/playtest-log.md

Stop Conditions

Required Skills

  • YAML
  • Telemetry design

Scope Delta(任意)

anchor comment #issuecomment-4558164489 による REQUEST_CHANGES 対応: Traceability 追加、責務分離ブロック追加、AC を grep 3 件から構造化 7 件に強化、VC を rg + loop ベースに置換、Stop Conditions に main 一致確認・JSON Schema/OTel 禁止を追加。

Source

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    triage-required
    on May 27, 2026
  2. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    Issue #419 の方向性は妥当です。PR #418 の人間コメントで「MVP から Publish まで一貫したログ設計は重いが、MVP 自動プレイテスト向けの最小 telemetry contract は切り出すべき」という流れがあり、#419 はその follow-up として成立しています。問題は、現状の #419 が 「実装可能な契約」ではなく「grep に通る説明文」になっている 点です。#419 は docs/product/playtest-log.md だけを Allowed Paths にし、telemetry 送信実装や .schema.json を Out of Scope にしていますが、AC/Verification も grep 中心なので、構造化ログ契約としての破綻を検出できません。([GitHub]1)

    致命的懸念

    1. Traceability が壊れている

    #419 は parent_issue: none になっていますが、実際には PR #418 のコメントから派生した follow-up で、さらに #417、#415、#284 と連鎖しています。#417 は AI playtest 用に execution_mode、agent_profile、random_seed、automation_metrics、reproduction_command、human_review_required を playtest-log.md に追加する話で、#419 はその次段階の runtime telemetry contract です。ここを parent none にすると、後続の実装エージェントが「なぜこの契約が必要か」「何を壊してはいけないか」を失います。([GitHub]2)

    修正要求: parent_issue または related_issues に少なくとも #417, #418, #415, #284 を明記する。dedupe_key だけで PR #418 を示すのは弱いです。


    2. playtest-log.md と runtime telemetry contract の責務が混線している

    #415/#417/#418 の流れでは、playtest-log.md は「人間・AI の playtest evidence を記録するログテンプレート」であり、runtime event stream そのものではありません。PR #418 のコメントでも、Playwright trace は useful だが、combat taxonomy の代替ではないと整理されています。([GitHub]3)

    #419 は docs/product/playtest-log.md に metrics.json schema と event taxonomy を押し込む設計ですが、これは許容するにしても 「playtest-log が参照する artifact contract」 と明記すべきです。そうしないと、playtest log、runtime events、derived metrics、trace artifact が 1 つの文書内で同格に混ざります。

    修正要求: 文書内に以下の責務分離を入れる。

    playtest-log.md:
      - human/AI playtest session の証跡台帳
      - automation artifact への参照を保持する
    
    events.jsonl:
      - 自動プレイテスト runner が出力する時系列イベント列
    
    metrics.json:
      - events.jsonl から再計算可能な集計値
    
    trace/replay artifacts:
      - Playwright trace / replay / raw runner output
      - public repo には原則 raw を置かない
    

    3. 現在参照できる main の playtest-log.md と PR #418 の状態が矛盾している

    PR #418 側では、execution_mode の扱い、metrics の invariant、PII 警告、enum mismatch、Unicode hygiene などを修正し、最終的に approve されています。([GitHub]3)

    しかし、私が現在参照できる main の docs/product/playtest-log.md では、automation block や metrics.json 参照が見えず、Example の validation_method: "automated test" が schema enum とまだズレています。少なくとも画面上は、#419 が前提としている PR #418 後のログ構造が正本に反映されているか不明です。([GitHub]4)

    修正要求: #419 の着手前に、ローカルで以下を確認する stop condition を追加する。

    git checkout main
    git pull --ff-only
    rg -n "automation|metrics.json|ai_simulation|validation_method" docs/product/playtest-log.md

    playtest-log.md が PR #418 の最終状態と一致しないなら、#419 ではなく「#418 反映状態の修復 Issue」を先に切るべきです。


    4. Markdown schema + grep verification では契約にならない

    #419 の Verification は session_start、metrics.json、unit を grep する程度です。これでは collision、damage、death、sortie_clear、sortie_fail などの必須 event が欠けても通ります。metrics.json の例が JSON として parse できなくても通ります。単位が文章中に 1 回出てくるだけでも通ります。([GitHub]1)

    JSON Schema では additionalProperties: false のように未定義フィールドを禁止でき、契約の実効性を作れます。#419 では .schema.json を Out of Scope にしているため、最低でも Markdown 内の fenced JSON example を parse する verification を AC に入れるべきです。([JSON Schema]5)

    修正要求: grep ではなく、少なくとも以下を AC に追加する。

    - events.jsonl の 1 行サンプルが JSON として parse できる
    - metrics.json サンプルが JSON として parse できる
    - event_type enum に必須イベントがすべて含まれる
    - metrics の derived field は raw counter から再計算式を持つ
    - 率は % ではなく 0.0-1.0 の fraction、または unit: percent を明示する
    - duration は ms / seconds のどちらかに統一し、field name に suffix を含める
    

    外部仕様から見た高品質化ポイント

    OpenTelemetry Logs は LogRecord を timestamp、body、attributes などの構造で扱い、イベントも標準化された LogRecord 形式として整理しています。OpenTelemetry を直接導入する必要はありませんが、#419 の event contract は少なくとも「top-level envelope」と「event-specific payload」を分けるべきです。([OpenTelemetry]6)

    CloudEvents は id, source, specversion, type を required attributes とし、dataschema により event data の schema を指せる設計です。また、大きいデータやセンシティブ情報は event payload に直接埋めず、参照に分けるべきだとされています。#419 も Playwright trace や replay を event に埋めるのではなく、artifact reference に分離すべきです。([GitHub]7)

    Playwright trace は DOM snapshot や action の前後状態を含むため、デバッグには有用ですが、公開 repo にそのまま置く artifact としては危険です。PR #418 で PII/raw artifact の扱いが問題化した文脈とも一致します。([Playwright]8)


    #419 に入れるべき最小 contract 案

    Issue #419 の本文は、次の形まで具体化すべきです。

    telemetry_contract:
      schema_version: "playtest.telemetry.v1"
      artifacts:
        events_jsonl:
          path_pattern: "artifacts/playtest/{session_id}/events.jsonl"
          format: "jsonl"
          public_repo_safe: false
        metrics_json:
          path_pattern: "artifacts/playtest/{session_id}/metrics.redacted.json"
          format: "json"
          public_repo_safe: true
        trace:
          path_pattern: "external-secure-artifact://playtest/{session_id}/trace.zip"
          public_repo_safe: false

    Event envelope は最低限これです。

    {
      "schema_version": "playtest.telemetry.v1",
      "event_id": "evt_000001",
      "event_type": "collision",
      "session_id": "pt_20260527_001",
      "run_id": "run_001",
      "seq": 42,
      "tick": 1830,
      "occurred_at": "2026-05-27T12:34:56.789Z",
      "build_ref": "git:abcdef0",
      "scenario_id": "mvp_sortie_smoke_001",
      "random_seed": 123456,
      "agent_profile": "ai_simulation:baseline-v1",
      "actor_id": "player_1",
      "entity_type": "player",
      "data": {
        "target_id": "wall_17",
        "position": { "x": 12.4, "y": 0.0, "z": -3.1 }
      }
    }

    Event taxonomy は最低限この粒度にするべきです。

    session_start
    session_end
    scenario_start
    scenario_end
    input_summary
    collision
    hit
    damage
    death
    sortie_clear
    sortie_fail
    reward_granted
    debrief_summary
    

    metrics.json は「人間が読める集計」ではなく、events.jsonl から再計算可能な派生物 として定義するべきです。

    {
      "schema_version": "playtest.metrics.v1",
      "session_id": "pt_20260527_001",
      "build_ref": "git:abcdef0",
      "scenario_id": "mvp_sortie_smoke_001",
      "random_seed": 123456,
      "run_count": 10,
      "success_count": 7,
      "failure_count": 3,
      "aborted_count": 0,
      "success_rate": 0.7,
      "death_count": 2,
      "collision_count_total": 14,
      "damage_taken_total": 83,
      "duration_ms_p50": 84321,
      "duration_ms_p95": 119450,
      "computed_from": "events.jsonl",
      "computed_by": "[email protected]"
    }

    必要な invariant は最低限これです。

    run_count == success_count + failure_count + aborted_count
    0.0 <= success_rate <= 1.0
    success_rate == success_count / run_count
    duration_ms_p95 >= duration_ms_p50
    metrics.computed_from MUST reference events.jsonl
    raw trace artifacts MUST NOT be committed to public repo
    

    Issue #419 本文への具体的修正案

    そのまま貼るなら、以下のレビューコメントでよいです。

    REQUEST_CHANGES
    
    #419 の方向性は妥当だが、現状のまま実装すると「grep に通るだけの Markdown」になり、MVP 自動プレイテスト用 telemetry contract としては不十分。
    
    Blocking concerns:
    
    1. Traceability
       - parent_issue: none は不正確。
       - #417, #418, #415, #284 を related として明記すること。
       - #419 は PR #418 の follow-up であり、dedupe_key だけでは文脈が弱い。
    
    2. Responsibility boundary
       - playtest-log.md は playtest session の証跡台帳であり、runtime event stream そのものではない。
       - events.jsonl / metrics.json / trace artifact / playtest-log の責務分離を明記すること。
       - playtest-log.md に書く場合も「automation artifact contract section」として分けること。
    
    3. Verification weakness
       - `grep session_start`, `grep metrics.json`, `grep unit` では契約検証にならない。
       - event_type enum に必須イベントがすべてあること、JSON example が parse 可能なこと、metrics の invariant が明記されることを AC に追加すること。
    
    4. Schema quality
       - event envelope に schema_version, event_id, event_type, session_id, run_id, seq, tick/occurred_at, build_ref, scenario_id, random_seed, agent_profile, actor_id/entity_type, data を定義すること。
       - metrics.json は events.jsonl から再計算可能な derived artifact とし、raw counter と derived rate を分離すること。
       - success_rate などの率は 0.0-1.0 fraction か percent かを明確にし、duration は ms / seconds のどちらかに統一すること。
    
    5. Artifact safety
       - Playwright trace / replay / raw runner output は DOM/action/context を含みうるため、public repo safe ではない前提にすること。
       - metrics.redacted.json のみ public_repo_safe: true とし、raw artifact は external-secure-artifact 参照にすること。
       - artifact_contains, public_repo_safe, raw_artifact_committed, pii_reviewed などの field を契約に含めること。
    
    6. Current main consistency
       - 現在の docs/product/playtest-log.md が PR #418 の最終状態と一致しているかを stop condition にすること。
       - automation block / metrics.json / validation_method enum の状態を確認してから #419 を実装すること。
    
    この Issue の scope は「MVP 自動プレイテスト用 telemetry artifact contract v1 の docs 定義」に絞るべき。
    Telemetry sender 実装、JSON Schema file、validator、OpenTelemetry Collector/SaaS、Publish-ready observability は out of scope でよい。

    最終結論

    #419 は 必要 です。ただし、現状の Issue 本文は弱すぎます。
    このまま実装すると、playtest-log.md に event 名と metrics.json という単語が増えるだけで、AI 自動プレイテストの再現性・比較可能性・安全な artifact 運用にはつながりません。

    採るべき修正方針は、「runtime telemetry を実装する」のではなく、「events.jsonl / metrics.json / trace artifact / playtest-log の境界と最小契約を定義する」 です。JSON Schema や validator は別 Issue でも構いませんが、#419 の AC は構造・単位・再計算式・PII artifact policy を検証できる水準まで上げるべきです。

  3. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    Contract Review: GO

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-28T00:00:00Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/419
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        ac_verifiability: pass
        product_spec_check:
          applicability: applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: true
          conditions:
            diff_first_rationale_present:
              status: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 40
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_skipped: 1
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []

    Contract Snapshot

    • Outcome: docs/product/playtest-log.md に "Automation Artifact Contract" 節を追加し、events.jsonl / metrics.json / trace artifact / playtest-log の責務境界・event taxonomy・envelope spec・metrics.json fenced JSON example・invariant・artifact safety policy を定義する。
    • Acceptance Criteria: AC1 (Contract 節 + schema_version) / AC2 (13 event enum) / AC3 (15 envelope field) / AC4 (metrics.json JSON parse, pr_review_only) / AC5 (6 invariant) / AC6 (単位規約) / AC7 (artifact safety)
    • Verification Commands: 40 件の rg -nq baseline fail + 1 件 pr_review_only skip
    • Allowed Paths: docs/product/playtest-log.md
    • Worktree: .claude/worktrees/issue-419-telemetry-contract
    • Branch: worktree-issue-419-telemetry-contract
    • VC preflight: baseline fail = 40, 想定外 pass = 0, 実行不可 = 0, skipped = 1 (AC4 pr_review_only)
  4. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-28T05:07:40Z)

    • PR: docs(#419): add Automation Artifact Contract to playtest-log #425
    • Worktree: .claude/worktrees/issue-419-telemetry-contract
    • Branch: worktree-issue-419-telemetry-contract
    • Verification: 4/4 PASS (typecheck / lint / test 61 passed / build) + AC rg checks ALL_AC_PASS
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup

    検証サマリ

    チェック 結果
    AC1: Automation Artifact Contract 節 + playtest.telemetry.v1 PASS
    AC2: event taxonomy 13 種 PASS
    AC3: envelope spec 15 フィールド PASS
    AC4: metrics.json fenced JSON parse PASS (python3)
    AC5: invariant 6 条 PASS
    AC6: 単位規約 (0.0-1.0 fraction / duration_ms_p50) PASS
    AC7: artifact safety (metrics.redacted.json / external-secure-artifact://) PASS
    pnpm typecheck PASS
    pnpm lint PASS
    pnpm test 6 files, 61 tests PASS
    pnpm build PASS
  5. added a commit that references this issue on May 27, 2026
  6. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: iteration 3 完了 (2026-05-28T05:24:00Z)

    対応 blocker サマリ

    Blocker 内容 状態
    1 PR body Schema Change Applicability を schema_change + initial_definition に修正 DONE
    2 events.jsonl Format Rules セクション追加 DONE
    3 Event-specific data Contract テーブル追加 (13 event types) DONE
    4 metrics.json Field Definitions + Mapping table 追加、fenced JSON を raw./derived. 構造に整合 DONE
    5 invariant を JSON Path 形式 $.computed_from == "events.jsonl" に変更、Issue #419 VC も更新 DONE
    6 Artifact Reference Metadata テーブル追加 DONE
    7 bidi check 実行: [] (問題なし)、PR body に記録 DONE

    検証結果

    • AC1-AC7 rg checks: ALL PASS
    • fenced JSON blocks (3件): PARSE OK
    • pnpm typecheck / lint / test (61 tests) / build: ALL PASS
  7. added a commit that references this issue on May 27, 2026
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/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions