Repository navigation
fix(otel): preserve token accounting missingness - #74766
Conversation
Keep complete measured token aggregates separate from display defaults, preserve explicit zero counters, and omit unavailable totals without changing accounting ownership. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
What this change does: It carries token counters with explicit availability from proxy logs into the usage artifact and OTLP spans. Measured zeroes remain numeric, while missing or invalid values stay absent. The added tests cover parser, artifact propagation, runtime normalization, and ownership.
Should fix:
-
The integration matrix repeats normalization coverage (
actions/setup/js/parse_token_usage.test.cjs:L1299-L1345)- What this is: This table runs nine raw input shapes through a full parser-to-artifact-to-OTLP mock.
- Problem: The same invalid, string, partial, and overflow shapes are already covered by the new normalization matrix in
actions/setup/js/send_otlp_span.test.cjs. Each extra row reruns the large mock without testing a new boundary. - Fix: Keep one complete-counter and one partial-counter row here to verify propagation; leave raw-shape normalization to the focused span test.
- If we skip it: Future edits must maintain two overlapping matrices, making this already-heavy test harder to read and update.
Verdict: fix 1 first.
Lean: -7 lines possible.
Generated by ✂️ Ponytail Reviewer for #74766 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Found one test-isolation issue: the new regression overrides fs.readFileSync without restoring it, which can contaminate later tests. No production correctness issue was confirmed from the changed lines.
Review details
- Restore the filesystem mock in the test's existing cleanup path.
- The specialist pass was completed; its other candidates were not actionable after checking the normalization and OTLP attribute paths.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes distinguishing measured zero from unavailable token usage.
No open issues 🎉
What changed in this PR
This PR preserves the distinction between measured zero and unavailable token usage throughout gh-aw’s proxy parsing, usage artifacts, and OpenTelemetry export, without changing transport behavior.
Changes:
- Track complete per-counter aggregates separately from display and pricing totals.
- Preserve explicit zeros, omit unavailable counters, and emit total tokens only when both input and output are available.
- Add regression coverage for availability and span ownership, and document the accounting semantics.
| File | Description |
|---|---|
| docs/src/content/docs/reference/open-telemetry-attributes.mdx | Documents counter availability, totals, and span ownership. |
| actions/setup/js/send_otlp_span.test.cjs | Tests zero preservation, invalid counters, and exclusive usage ownership. |
| actions/setup/js/send_otlp_span.cjs | Exports measured zeros and requires both counters for totals. |
| actions/setup/js/parse_token_usage.test.cjs | Tests unavailable evidence and artifact-to-OTLP accounting. |
| actions/setup/js/parse_token_usage.cjs | Writes availability-aware artifacts without fabricated zeros. |
| actions/setup/js/parse_mcp_gateway_log.test.cjs | Tests complete aggregates and overflow handling. |
| actions/setup/js/parse_mcp_gateway_log.cjs | Tracks complete counters separately from display and pricing totals. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd (classified as a bug fix). Requesting changes on one correctness gap in the parser and one weakened test.
📋 Key Themes & Highlights
Key Themes
- Silent data loss on malformed lines: a dropped JSONL line can still yield a "complete" counter with an uncounted request (inline comment on
parse_mcp_gateway_log.cjs). - Conditional assertion in the
{}test case: the test name implies the empty-evidence path, but{}is counted as a request (inline comment onparse_token_usage.test.cjs). - Unresolved, not yet inline:
ambient_contextinparse_token_usage.cjsis still zero-coerced, which conflicts with the "no fabricated zeros" rule. Also,fs.readFileSyncis reassigned in a test body without afinallyrestore. Both are worth a follow-up. - Open question: the empty-evidence artifact changed from explicit zeros to
{}. Please confirm that the daily AIC guardrail and component coverage consumers (which treat empty detection as authoritative) still behave as intended.
Positive Highlights
- ✅ Keeping measured zero distinct from missing values is the right model for token accounting.
- ✅ Per-counter availability is documented in the OTel attributes reference.
- ✅ Good end-to-end coverage for the artifact-to-OTLP path.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~10 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again
Keep complete and partial propagation cases and restore the local filesystem override in the test cleanup path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retain malformed evidence through request deduplication and separate empty-request summary assertions from unavailable-evidence artifacts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Regarding the Ponytail completion notice: no additional code change is needed for this status message. The associated matrix feedback was addressed in 6979fde. |
|
Regarding the Test Quality Sentinel notice: no code change is requested by this reported_no_action status. Independently, the final local validation gate passed all 740 affected tests after the targeted fixes. |
|
Regarding the Design Decision Gate notice: this status contains no actionable design request or ADR draft, so no additional change was made. The accounting behavior is documented in the existing telemetry reference. |
|
Regarding the Code Quality Reviewer completion notice: no additional change is needed for this status message. The associated filesystem cleanup feedback was addressed with explicit local restoration in 6979fde. |
|
Regarding the skills-review completion notice: the two actionable inline findings are fixed in 4b0ae4d and their threads are resolved. Existing daily-AIC guardrail and component-coverage tests also passed; unavailable detection evidence remains unavailable rather than becoming measured zero. |
|
Regarding the managed comment-memory record: no source change or memory edit is needed for this historical metadata. Its recorded test-isolation concern was addressed in 6979fde. |
|
🎉 This pull request is included in a new release. Release: |
Summary
OTLP token accounting currently drops measured zeros and treats unavailable counters as zero upstream, making missing usage indistinguishable from a genuine zero measurement.
gen_ai.usage.total_tokensonly when both input and output counts are available, excluding cache counts. Keep existing attribute names/types and exclusive dedicated-agent, conclusion fallback, detection, and engine accounting ownership; downstream jobs do not re-export downloaded usage.Validation
make fmt-cjs && make lint-cjsnpm run typecheckmake agent-report-progress: build, lint, schema checks, and all 741 tests in the three affected suites passed.The shared validation machine has an ambient AWF config that affects two existing credit-cap tests. Validation isolated that lookup with
GH_AW_AWF_CONFIG_PATHpointing to a nonexistent session-local path. Existing nonblocking lint warnings remain. No live workflow dispatch was performed.