Skip to content

perf(claude): #295 軽量化後の runtime /usage 計測(3 代表 Issue) #389

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: 293
goal_ref: "claude/AI 運用の usage コスト削減(#295 軽量化後の runtime 計測検証)"
change_kind: workflow
closure_mode: pr-merged

Parent Issue

#293

Depends On

Parent Goal Ref

  • Goal: perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 で導入された issue-refinement-loop 軽量化(max_iterations=1 デフォルト / investigation_policy / web_research_policy / NEEDS_SECOND_PASS)が、実際の /usage ホットスポット削減につながっているかを runtime 観測で検証する
  • Desired Destination: 3 代表 Issue(small / medium / large)で issue-refinement-loop を実走した before/after 計測が記録され、/usage snapshot・agent_spawn_count・iteration_count・各 step の skip_reason が比較可能な形で残っている

Preconditions

In Scope

  • 3 代表 Issue を選定(small = docs-only 軽微修正、medium = workflow 中規模、large = same-file 衝突 / external claim ありの高負荷)
  • 各 Issue に対し以下を 2 回実走:
    1. before: git checkout <pre-#295-merge-commit> で SKILL.md を baseline に戻して issue-refinement-loop を実走
    2. after: 現行 main(perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 merged)で issue-refinement-loop を実走
  • 各 run で記録するメトリクス:
    • /usage snapshot(tokens / cost)
    • agent_spawn_count(SubAgent 起動回数)
    • iteration_count(実イテレーション数)
    • 各 step(Step 1 / Step 1b)の skip_reason
    • 総 wall-clock time
  • 計測結果を新規 docs(docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md)に before/after 比較表として保存
  • 本 Issue は SKILL.md を変更しない(計測のみ)

Out of Scope

Outcome

  • docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md が存在する
  • 同ドキュメントに 3 代表 Issue × before/after の比較表(/usage tokens、agent_spawn_count、iteration_count、各 step skip_reason、wall-clock time)が記録されている
  • cost reduction の方向性(増加 / 維持 / 削減)が明示的に結論されている
  • 結論が「削減」でない場合、原因仮説と次の改善 Issue 候補が記録されている

Acceptance Criteria

  • AC1: docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md が存在する
  • AC2: 同ドキュメントに ## Before/After Summary セクションがあり、3 代表 Issue × before/after の比較表が含まれる(各セルに数値 or N/A が入っている)
  • AC3: 同ドキュメントに各 run の agent_spawn_count / iteration_count / skip_reason 列が含まれる
  • AC4: 同ドキュメントに ## Conclusion セクションがあり、cost reduction の方向性(削減 / 維持 / 増加)が明示されている
  • AC5: pnpm typecheck && pnpm lint && pnpm test && pnpm build が PASS する(docs-only 変更だが既定品質ゲートは通す)

Verification Commands

# AC1: 計測ドキュメントが存在
$ test -f docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md && echo PASS || echo FAIL  # AC1

# AC2: Before/After Summary セクション
$ rg -n "^## Before/After Summary" docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md  # AC2

# AC2: 3 代表 Issue 番号が記載
$ rg -c "small|medium|large" docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md  # AC2

# AC3: メトリクス列の存在
$ rg -n "agent_spawn_count|iteration_count|skip_reason" docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md  # AC3

# AC4: Conclusion セクション
$ rg -n "^## Conclusion" docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md  # AC4

# AC5: 既定品質ゲート
$ pnpm typecheck && pnpm lint && pnpm test && pnpm build  # AC5

Allowed Paths

  • docs/dev/measurements/(新規ディレクトリ + ファイル作成可)

Stop Conditions

  • .claude/skills/issue-refinement-loop/SKILL.md に手を入れる必要が出た場合 → 別 Issue
  • 既存 LOOP_STATE フィールドの schema 変更が必要になった場合 → 別 Issue
  • 計測対象 Issue を実走中に環境問題(gh API 不可・gemini auth 不可等)で 3 件揃わない場合 → 取得可能件数で停止し、残件は本 Issue に追記で人間判断
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格が必要になった場合
  • pnpm 既定ゲートが FAIL する場合

Runtime Verification Applicability

decision: not_applicable
reason: AI 運用観測(cost measurement)のみ。ゲーム runtime に影響しない。

Required Skills

  • issue-refinement-loop を 3 代表 Issue に対して before/after で実走できる権限
  • /usage snapshot を session-local に保存できる仕組み

Delivery Rule

Related

Source

Activity

  1. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    人間からのコメントです。
    計測方法が記載されていないため、適切な効果が測定できるのか不明です。そのため、このGitHub Issueはクローズにしたいと思います。

  2. squne121 commented on May 25, 2026

    @squne121
    OwnerAuthor

    結論

    #389 は現状のままならクローズで妥当です。
    人間コメントの「計測方法が記載されていないため、適切な効果が測定できるのか不明」は、敵対的に見ても正当な blocker です。

    理由は、#389 が「何を測るか」は列挙している一方で、「どう測るか」「何を同一条件として固定するか」「/usage の session-global な値から対象 run の差分をどう切り出すか」を定義していないためです。#389 は 3 代表 Issue、before/after、/usage snapshot、agent_spawn_count、iteration_count、skip_reason、wall-clock time を要求していますが、測定プロトコルそのものは未定義です。

    敵対的レビュー

    #389 の一番の問題は、「計測ドキュメントを作る Issue」なのに、計測方法の正本がないことです。

    特に危険なのは以下です。

    1. /usage snapshot の差分算出方法がない
      Claude Code 公式 docs では、/usage は current session の token 使用統計を出すもので、ドル額は token count からローカル計算された推定値であり、実請求とは異なり得るとされています。つまり、単に before/after の /usage 画面を貼るだけでは、対象 run だけの効果とは言えません。([Claude API Docs]1)

    2. session 境界が定義されていない
      PR perf(#295): issue-refinement-loop の SubAgent spawn 上限を軽量化 — max_iterations=1 + policy state 化 #388 の時点でも、runtime /usage は session-global で PR-local artifact として再現可能性に乏しいため、3 代表 Issue の選定基準・再現可能性が独立 contract を要すると明記されています。perf(claude): #295 軽量化後の runtime /usage 計測(3 代表 Issue) #389 はその follow-up ですが、独立 contract と呼べるほどの測定設計にはなっていません。

    3. before/after の比較条件が固定されていない
      model、effort、Claude Code version、作業ディレクトリ、session reset、cache/compaction、同一プロンプト、同一 Issue snapshot、GitHub/API 状態、SubAgent 起動ログの取得方法が未定義です。Claude Code docs も、挙動や cost reporting は変更され得るため version 確認が必要としています。([Claude API Docs]1)

    4. manual count と自動計測の境界が曖昧
      perf(claude): #295 軽量化後の runtime /usage 計測(3 代表 Issue) #389 は runtime 計測ツールの新規実装を Out of Scope にし、既存 /usage と手動 SubAgent カウントを使うとしています。しかし、手動カウントでは agent_spawn_count、Step 1/1b skip_reason、iteration_count の漏れ・解釈差を防げません。

    5. perf(claude): issue-refinement-loop を script-first / thin entrypoint 化し OPEN 改善 Issue を段階統合する #391/実装: issue-refinement-loop の deterministic planner/checker script を抽出する #392/実装: issue-refinement-loop SKILL.md を thin entrypoint + references 構成へ分割する #393 と順序が悪い
      perf(claude): issue-refinement-loop を script-first / thin entrypoint 化し OPEN 改善 Issue を段階統合する #391 は perf(claude): #295 軽量化後の runtime /usage 計測(3 代表 Issue) #389 を measurement follow-up として参照しつつ、issue-refinement-loop を script-first / thin entrypoint / SubAgent-owned contract へ段階移行する親 Issue です。実装: issue-refinement-loop の deterministic planner/checker script を抽出する #392 では policy 判定を deterministic planner/checker script + JSON evidence に移す計画があります。これがない状態で perf(claude): #295 軽量化後の runtime /usage 計測(3 代表 Issue) #389 を実走すると、「LLM の prose 判定揺れ」を含んだ noisy な測定になります。

    WEB 調査込みの判断

    Claude Code の公式 docs 上、より信頼できる計測には /usage 画面より OpenTelemetry が適しています。Claude Code は claude_code.cost.usage と claude_code.token.usage を export でき、さらに cost/token を skill、plugin、agent で分解できるとされています。([Claude Code]2) ([Claude Code]2)

    また、Skill の設計としては、SKILL.md は使用時に context に入り、その後 session 内に残ります。公式 docs は SKILL.md を 500 行未満に保ち、詳細は supporting files に逃がすことを推奨しています。#295/PR #388 後の issue-refinement-loop/SKILL.md は 1262 行であり、#393 の thin entrypoint 化が先にある方が、固定 token cost の測定対象として筋が良いです。([Claude API Docs]3)

    推奨アクション

    推奨: #389 は not planned でクローズ。
    ただし「計測そのものを不要」とするのではなく、理由は measurement protocol 不備による premature issue とするのが適切です。

    その後、必要なら以下のいずれかに分けるべきです。

    案 A: #392/#393 後に再起票

    タイトル案:

    perf(claude): issue-refinement-loop の OTel ベース計測プロトコルを定義し、#295/#392/#393 後の効果を測定する
    

    最低限入れるべき AC:

    - [ ] AC1: 計測プロトコルが docs/dev/measurements/issue-refinement-loop-measurement-protocol.md に定義されている
    - [ ] AC2: model / effort / claude --version / git refs / session reset / prompt / Issue snapshot / run order / cache・compaction扱いが固定されている
    - [ ] AC3: `/usage` を使う場合、pre/post snapshot の差分算出手順が定義されている
    - [ ] AC4: 可能なら OpenTelemetry の `claude_code.token.usage` / `claude_code.cost.usage` を取得し、skill.name / agent.name / query_source で集計する
    - [ ] AC5: agent_spawn_count は手動ではなく OTel tool event または trace/event log から算出する
    - [ ] AC6: 3 代表 Issue の選定基準、除外基準、再実行不能時の扱いが定義されている
    - [ ] AC7: before/after の結論は「削減」だけでなく、信頼区間または少なくとも confounder 一覧付きで記録されている

    案 B: #389 を閉じずに全面 rewrite

    これは可能ですが、既存 body の構造をかなり変える必要があります。単に AC を足す程度では不十分です。runtime 計測ツール新規実装は Out of Scope という制約も、OTel 採用を妨げるなら緩和が必要です。

    クローズコメント案

    そのまま GitHub に貼れる文面です。

    ## Close rationale
    
    人間コメントを受けて再確認した結果、本 Issue は現状のままでは close が妥当と判断します。
    
    理由:
    - 本 Issue は `/usage` snapshot / agent_spawn_count / iteration_count / skip_reason / wall-clock time を列挙しているが、測定プロトコルを定義していない
    - `/usage` は session-global な値であり、対象 run 単体の差分算出方法・session reset・model/effort/version・cache/compaction・同一 prompt / Issue snapshot の固定条件がない
    - `agent_spawn_count` と `skip_reason` を手動カウントする前提では、再現性と監査性が不足する
    - #391/#392/#393 により issue-refinement-loop は script-first / thin entrypoint 化される予定であり、その前に runtime 効果測定を行っても prose 判定揺れ・固定 token cost・SubAgent routing の confounder が大きい
    - Claude Code 公式 docs 上も、token/cost の組織的な把握には `/usage` だけでなく OpenTelemetry metrics/events による `claude_code.token.usage` / `claude_code.cost.usage`、skill/agent 別 attribution の利用が適している
    
    したがって、本 Issue は「計測不要」ではなく「計測方法未定義のため premature」として `not planned` で close します。
    
    後続で再起票する場合は、先に measurement protocol を定義し、少なくとも以下を AC に含める:
    - model / effort / claude --version / git refs / session reset / run order / prompt / Issue snapshot の固定
    - `/usage` pre/post snapshot の差分算出手順
    - 可能なら OpenTelemetry による token/cost/tool/skill/agent attribution
    - agent_spawn_count と skip_reason の監査可能な取得方法
    - 3 代表 Issue の選定基準・除外基準・再実行不能時の扱い

    最終判定

    APPROVE close.
    #389 は「効果測定 Issue」ではなく「測定したい項目のリスト」に留まっています。現状で実装 PR を作ると、もっともらしい表は作れますが、削減効果の証明にはなりません。

  3. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    CLOSE_DECISION_V1

    CLOSE_DECISION_V1:
      generated_at: "2026-05-28T00:00:00Z"
      generated_by: issue-395-sweep
      issue_number: 389
      decision: completed
      state_reason: completed
      evidence: "計測完了済み(Issue の stateReason: COMPLETED)。Remaining Parent Gaps での measurement pending 記録は不要"
      absorbed_by: []
      sweep_source: https://github.com/squne121/loop-protocol/issues/395
  4. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    CLOSE_DECISION_V1_CORRECTION

    CLOSE_DECISION_V1_CORRECTION:
      generated_at: "2026-05-28T12:00:00Z"
      generated_by: issue-395-sweep-correction
      issue: "#389"
      decision: still_needed
      github_state: CLOSED
      github_state_reason: completed
      note: "measurement artifact (docs/dev/measurements/issue-refinement-loop-295-cost-reduction.md) が未作成であることを確認。#389 は CLOSED だが measurement protocol が未定義のまま閉じられており、実質的な計測は未実施。#391 parent closure には measurement 証跡が必要。"
      residual_gaps:
        - "measurement protocol 未定義"
        - "artifact ファイル未作成"
        - "#391 parent closure rule (token/agent_spawn/iteration/skip_reason の増減判断) が充足されていない"
      next_action: "create follow-up Issue for measurement protocol definition"

    訂正理由: 前回コメントの decision: completed は不正確。docs/dev/measurements/ ディレクトリが存在せず measurement artifact が未作成。GitHub の stateReason: COMPLETED は Issue の close 操作を表すに過ぎず、measurement の実施完了を意味しない。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions