# Complete - m-usage-token-log-ops-mvp/02+01_usage_metrics

## 완료 일시

2026-07-10

## 요약

OpenAI-compatible usage metrics follow-up loop 5회차에서 sideband body/proto usage merge, token breakdown regression, verification evidence를 확인했고 최종 판정은 PASS다.

## 루프 이력

| Plan | Review | Verdict | 메모 |
|------|--------|---------|------|
| `plan_cloud_G07_0.log` | `code_review_cloud_G07_0.log` | FAIL | sideband/error terminal metric 누락과 request counter coverage 부족으로 후속 필요 |
| `plan_local_G04_1.log` | `code_review_local_G04_1.log` | FAIL | tool-validation retry dispatch failure metric 누락과 sideband write-failure cancel status 누락 |
| `plan_local_G04_2.log` | `code_review_local_G04_2.log` | FAIL | sideband metric emit이 provider body usage를 반영하지 않아 production tunnel body-only usage를 놓침 |
| `plan_local_G04_3.log` | `code_review_local_G04_3.log` | FAIL | sideband proto usage에서 reasoning/cached_input이 빠지고 body+proto input/output 중복 위험이 남음 |
| `plan_local_G04_4.log` | `code_review_local_G04_4.log` | PASS | body/proto merge 규칙과 regression tests가 SDD S05/S06 evidence를 충족 |

## 구현/정리 내용

- `writeProviderTunnelSidebandStream`과 `writeProviderTunnelSidebandResponse`가 provider body usage를 primary로, proto `USAGE` frame을 fill-missing 보조 source로 병합해 input/output 중복 집계를 막고 reasoning/cached_input을 보존한다.
- sideband streaming/non-streaming body-only, proto-only, body+proto regression이 input/output/reasoning/cached_input token counters를 검증한다.

## 최종 검증

- `GOTMPDIR=/config/workspace/iop/.cache/go-tmp GOCACHE=/config/workspace/iop/.cache/go-build go test -count=1 ./apps/edge/internal/openai -run 'TestProviderTunnelSideband.*UsageMetrics'` - PASS; `ok iop/apps/edge/internal/openai 0.064s`
- `GOTMPDIR=/config/workspace/iop/.cache/go-tmp GOCACHE=/config/workspace/iop/.cache/go-build go test -count=1 ./apps/edge/internal/openai -run 'Sideband|UsageMetrics|ToolValidation|Dispatch|Reasoning|Retry'` - PASS; `ok iop/apps/edge/internal/openai 0.119s`
- `GOTMPDIR=/config/workspace/iop/.cache/go-tmp GOCACHE=/config/workspace/iop/.cache/go-build go test -count=1 ./apps/edge/internal/openai` - PASS; `ok iop/apps/edge/internal/openai 1.867s`
- `gofmt -l apps/edge/internal/openai/stream.go apps/edge/internal/openai/usage_metrics_test.go` - PASS; no output
- `git diff --check` - PASS; no output

## Roadmap Completion

- Milestone: `agent-roadmap/phase/operational-observability-provider-management/milestones/usage-token-log-ops-mvp.md`
- Milestone link: [Milestone 문서](agent-roadmap/phase/operational-observability-provider-management/milestones/usage-token-log-ops-mvp.md)
- Completed task ids:
  - `openai-scope`: PASS; evidence=`plan_local_G04_4.log`, `code_review_local_G04_4.log`; verification=`go test -count=1 ./apps/edge/internal/openai -run 'Sideband|UsageMetrics|ToolValidation|Dispatch|Reasoning|Retry'`
  - `passthrough-safe`: PASS; evidence=`plan_local_G04_4.log`, `code_review_local_G04_4.log`; verification=`go test -count=1 ./apps/edge/internal/openai -run 'TestProviderTunnelSideband.*UsageMetrics'`
  - `token-breakdown`: PASS; evidence=`plan_local_G04_4.log`, `code_review_local_G04_4.log`; verification=`go test -count=1 ./apps/edge/internal/openai -run 'TestProviderTunnelSideband.*UsageMetrics'`
  - `reasoning-observed`: PASS; evidence=`plan_local_G04_4.log`, `code_review_local_G04_4.log`; verification=`go test -count=1 ./apps/edge/internal/openai -run 'Sideband|UsageMetrics|ToolValidation|Dispatch|Reasoning|Retry'`
  - `prometheus-metrics`: PASS; evidence=`plan_local_G04_4.log`, `code_review_local_G04_4.log`; verification=`go test -count=1 ./apps/edge/internal/openai`
- Not completed task ids: 없음

## 잔여 Nit

- 없음

## 후속 작업

- 없음
