Skip to content

fix(otel): preserve token accounting missingness - #74766

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan/otlp-accounting-missingness
Nov 4, 2026
Merged

pelikhan merged 3 commits into
mainfrom
pelikhan/otlp-accounting-missingness

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

OTLP token accounting currently drops measured zeros and treats unavailable counters as zero upstream, making missing usage indistinguishable from a genuine zero measurement.

  • Preserve complete-per-counter proxy aggregates separately from existing display and pricing totals. A counter is available only when every deduplicated request reports a valid value.
  • Retain explicit zero counters in usage artifacts and OTLP attributes. Empty detection usage evidence no longer fabricates zero token counts or AI credits.
  • Emit gen_ai.usage.total_tokens only 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.
  • Add focused parser, artifact-to-OTLP, normalization, and ownership regressions, and document availability semantics. No transport changes.

Validation

  • make fmt-cjs && make lint-cjs
  • npm run typecheck
  • make 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_PATH pointing to a nonexistent session-local path. Existing nonblocking lint warnings remain. No live workflow dispatch was performed.

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>
@pelikhan
pelikhan marked this pull request as ready for review November 4, 2026 06:16
Copilot AI adaptive review requested due to automatic review settings November 4, 2026 06:16
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #74766

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: gpt56 max · ~1 AIC · ⌖ ~1 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ 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: reported_no_action

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.

Generated from Design Decision Gate 🏗️ · routed: opus55 medium · ~11 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-04T06:20:05Z
review_event: COMMENT
top_themes: [test isolation]
files_reviewed: [actions/setup/js/parse_mcp_gateway_log.cjs, actions/setup/js/parse_mcp_gateway_log.test.cjs, actions/setup/js/parse_token_usage.cjs, actions/setup/js/parse_token_usage.test.cjs, actions/setup/js/send_otlp_span.cjs, actions/setup/js/send_otlp_span.test.cjs, docs/src/content/docs/reference/open-telemetry-attributes.mdx]
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on parse_token_usage.test.cjs).
  • Unresolved, not yet inline: ambient_context in parse_token_usage.cjs is still zero-coerced, which conflicts with the "no fabricated zeros" rule. Also, fs.readFileSync is reassigned in a test body without a finally restore. 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

pelikhan and others added 2 commits November 3, 2026 22:29
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>
@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Regarding the Ponytail completion notice: no additional code change is needed for this status message. The associated matrix feedback was addressed in 6979fde.

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@pelikhan
pelikhan merged commit 212d6e8 into main Nov 4, 2026
39 checks passed
@pelikhan
pelikhan deleted the pelikhan/otlp-accounting-missingness branch November 4, 2026 06:45
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants