Fix unknown and duplicated AIC telemetry attribution by pelikhan · Pull Request #70864 · github/gh-aw · GitHub
Skip to content

Fix unknown and duplicated AIC telemetry attribution - #70864

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan-laughing-garbanzo
Oct 21, 2026
Merged

pelikhan merged 3 commits into
mainfrom
pelikhan-laughing-garbanzo

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Summary

Correct three concrete, locally reproduced AIC attribution problems without changing optimizer policy or backend infrastructure:

  • Preserve unknown cost: omit gh-aw.aic when no valid source exists rather than synthesizing zero; keep explicitly reported zero encoded as doubleValue.
  • Emit measured AIC exactly once per cost-owning job, using the same dedicated-agent-span versus conclusion-span boundary as token counters. Previously both spans received AIC, doubling unfiltered sums.
  • Correct the daily report consumer to prefer gh-aw.workflow.name, use confirmed numeric costs only, preserve unknown on both backends, deduplicate mirrored spans, and distinguish backend field/query failures from producer omissions.

Update the attribute reference, patch changeset, and generated workflow lock. The lock diff contains only body/admission hash updates; permissions, MCP imports, tool allowlists, destinations and runtime steps are unchanged.

Evidence and boundaries

Discussion #69681 reports unqueryable cost, not zero usage and not proof of an emission defect. The corrections above are grounded independently in the current producer and consumer code and regression fixtures.

The canonical cost-owning span carries gh-aw.aic, gh-aw.workflow.name, gh-aw.run.id and gh-aw.repository. Missing, invalid and unreadable cost sources now omit AIC. A 0.125 fixture produces one cost-bearing span in both the JSONL mirror and HTTP exports, not two.

Live Sentry/Tempo verification remains unavailable: this session exposes neither backend's query tools. A representative raw cost-owning production span, Sentry custom-field discovery/indexing, and Tempo attribute discovery/search are still needed to establish backend queryability. The current Grafana import already allowlists the expected Tempo tools; no permission or infrastructure expansion is justified by the historical report alone. No workflow was dispatched.

Validation

  • 408 focused exporter/OTel contract tests passed.
  • JavaScript typecheck, make fmt-cjs and make lint-cjs passed.
  • make recompile: all 346 workflows compiled; unrelated generated maintenance output was excluded.
  • PATH=/opt/homebrew/bin:$PATH make agent-report-progress passed, including impacted tests and full workflow lock drift checks. Modern Bash was needed because macOS's default Bash lacks mapfile.
  • Read-only source security review passed with no confirmed vulnerabilities. Credential routing, permissions, sandbox and safe-output controls remain unchanged. The generated normal lock was inspected separately for hash-only changes; no live-execution approval is claimed.

Markdown-source security overview

Source Before / after Security impact
daily-token-consumption-report.md:91–157 Guessed fields and Sentry zero-fill become canonical attribution, raw-span/schema discovery and numeric-only cost accounting. Improves evidence integrity; permissions, credentials, recipients, sandbox and output controls are unchanged.

The original branch name was retained because the app-managed rename encountered a shared packed-refs.lock; that lock was not removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review October 21, 2026 11:53
Copilot AI max review requested due to automatic review settings October 21, 2026 11:53
@github-actions

github-actions Bot commented Oct 21, 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 Oct 21, 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 · haiku45 · 5.23 AIC · ⌖ 7.52 AIC · ◇ 2.57 AIC · ⊞ 9.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

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 Ponytail Reviewer · gpt56 · 6.79 AIC · ⌖ 5.63 AIC · ⊞ 14.8K · ◷

Generated by Ponytail Reviewer for #70864

@github-actions

github-actions Bot commented Oct 21, 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 commented Oct 21, 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 🏗️ · opus55 · 10.2 AIC · ⌖ 32 AIC · ◇ 16.8 AIC · ⊞ 1.9K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

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

Verdict: approve

No actionable defects found in the changed lines. The exporter now preserves unknown AIC values, keeps explicit zero numeric, and places cost data on the owning span; the consumer guidance consistently treats missing values as unknown. Static review only; tests were not run in this review.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · 1.6 AIC · ⌖ 0.493 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd (per pr-triage: change_type=bug_fix). The core duplication and zero-fill fixes in send_otlp_span.cjs are sound and well-tested; one documentation consistency nit flagged inline.

📋 Key Themes & Highlights

Key Themes

  • Duplication fix verified: the single gh-aw.aic emission site was correctly moved into usageAttrs, which is attached to exactly one of the agent span or the conclusion span (never both) based on hasDedicatedAgentSpan — confirmed by tracing the code and by the new otel_contract.test.cjs assertion (toHaveLength(1)).
  • Unknown-vs-zero fix verified: removing the trailing ?? 0 from the aiCredits fallback chain lets the value stay undefined when no valid cost source exists, correctly gated by the typeof aiCredits === "number" check before emission. Explicit zeros (file or GH_AW_AIC env var) are still preserved.
  • Test coverage is solid: the new it.each (6 invalid-input cases) plus explicit-zero-from-file and explicit-zero-from-env tests cover the regression well; existing detection/engine-job tests remain unaffected.
  • Minor doc gap: daily-token-consumption-report.md still references "recognized AIC fields" (lines 103, 115) after the defining bullet list was removed from Step 4 — see inline comment.

Investigation note

Could not execute the test suite directly in this sandbox (network-restricted, no cached vitest binary) — verification was done via careful manual code tracing rather than empirical test runs. The PR description states 408 tests pass, which is consistent with the logic reviewed.

Positive Highlights

  • ✅ Clean, minimal diff that isolates the emission-site move without touching unrelated logic
  • ✅ New contract test directly guards against the regression class this PR fixes (single-span assertion)
  • ✅ Consumer workflow instructions correctly updated to match the new unknown-vs-zero semantics

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 159.9 AIC · ⌖ 14.9 AIC · ⊞ 10.2K
Comment /matt to run again

Comments that could not be inline-anchored

.github/workflows/daily-token-consumption-report.md:103

[/grill-with-docs] "recognized AIC fields" is now a dangling term — the "Recognized AIC fields" bullet list this phrase referred to was removed from Step 4 in this PR, but Steps 2 and 3 (lines 103, 115) still use the phrase without a definition.

Content redacted to fit size limit.

@copilot please address this.

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.

🟡 Changes recommended

Targeted checks confirmed unresolved cost-availability and job-attribution defects.

3 open issues
What changed in this PR

Corrects AI-credit (AIC) attribution in gh-aw’s telemetry exporter and daily reporting workflow.

Changes:

  • Removes the exporter’s default zero for unavailable cost.
  • Routes AIC through the token-usage span boundary to avoid duplicate emission.
  • Updates reporting guidance, regression tests, documentation, and release metadata.
File Description
docs/​src/​content/​docs/​reference/​open-telemetry-attributes.mdx Documents cost ownership and aggregation semantics.
actions/​setup/​js/​send_otlp_span.test.cjs Covers missing, invalid, and explicit-zero costs.
actions/​setup/​js/​send_otlp_span.cjs Changes cost selection and span placement.
actions/​setup/​js/​otel_contract.test.cjs Checks single cost-bearing spans across exports.
.github/​workflows/​daily-token-consumption-report.md Updates field discovery, numeric accounting, and deduplication.
.github/​workflows/​daily-token-consumption-report.lock.yml Refreshes body and admission hashes.
.changeset/​fix-unknown-and-duplicated-otel-aic.md Adds a patch release note.

Review effort: Max

Comment thread .github/workflows/daily-token-consumption-report.md Outdated
Comment thread actions/setup/js/send_otlp_span.cjs Outdated
Comment thread actions/setup/js/send_otlp_span.cjs
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot address the following outstanding work in one pass:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (.github/workflows/daily-token-consumption-report.md:95): Include timestamp explicitly in the fallback's requested fields. The next line still specifies sort: -timestamp, but this replacement drops the previously listed timestamp column. Sentry requires the sort column to be selected, so a request using the listed fields can fail with an "Ordered by columns not selected" error instead of fetching cost data. Also keep id and trace explicit so the returned records support Step 4's mirror deduplication. Regenerate the workflow lock after updating the prompt. - Fix unknown and duplicated AIC telemetry attribution #70864 (comment)
  3. Review (actions/setup/js/send_otlp_span.cjs:2390): [P2] Exclude inherited agent costs from detection fallbacks. Detection downloads the agent's agent_usage.json and agent-stdio.log, but prepare_threat_detection_files.sh clears the usage file only when detection runs. If detection is skipped and has no own GH_AW_AIC, this selector emits the agent's cost again on gh-aw.detection.conclusion. The spans have different IDs, so the report's mirror deduplication cannot remove this duplicate. - Fix unknown and duplicated AIC telemetry attribution #70864 (comment)
  4. Review (actions/setup/js/send_otlp_span.cjs:2391): [P2] Preserve unknown cost through the usage-file producer. Removing the final ?? 0 does not cover parser-generated zeros: computeInferenceCostUSD returns 0 when model pricing is unavailable (model_costs.cjs:197–198), and parse_token_usage.cjs:626 serializes that as ai_credits: 0. With token usage but no reported AIC, pricing, or env/engine cost, this selector still exports a measured zero, which the updated report counts as confirmed cost. - Fix unknown and duplicated AIC telemetry attribution #70864 (comment)

Push the necessary fixes, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved. Use the pr-finisher skill and stop when only human review or CI remains; do not trigger CI.

Sous-chef head: e8ebfbe
Sous-chef work: 2ddbfeb2553070af37df1b4acf75785d4d7ad5dcc954aec2aa9032bc2890b96b a4f04044fbed2bde7a626b1665fd4e3decf7653c04049dadf658c8c831e92913 e36da6e0174228622bdc48d9c8bbb82281bfd32fbdc4407c8317c947777f8c98
Sous-chef state: c7ffc7d193afa513a8dadd395ecf37063ca02069064b74e71afc970717d19557

Generated by 👨‍🍳 PR Sous Chef · pi · haiku45 · 8.89 AIC · ⌖ 8.84 AIC · ⊞ 1.1K · ◷
Comment /souschef to run again

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

In response to #70864 (comment): Accepted the approval; no additional change was requested by this review. The separate correctness findings are addressed in this batch with focused regressions.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In response to #70864 (comment): No code change is needed for this status-only report, and its no-op outcome is not treated as validation evidence. The batch was independently validated with 653 tests, typechecking, and the repository pre-publication gate.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In response to #70864 (comment): No code change is needed because this completion notice contains no actionable finding. Publication and correctness were verified separately rather than inferred from the reviewer no-op.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

In response to #70864 (comment): Accepted the associated review's clarity finding. Steps 2 and 3 now explicitly reference finite non-negative numeric gh-aw.aic or legacy aliases confirmed under Step 4, replacing the dangling 'recognized AIC fields' wording.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

…banzo

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot October 21, 2026 13:02
@pelikhan
pelikhan merged commit 321e8b0 into main Oct 21, 2026
2 checks passed
@pelikhan
pelikhan deleted the pelikhan-laughing-garbanzo branch October 21, 2026 14:05
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.

4 participants