fix: populate AI credits footer for copilot-sdk workflows#38755
Closed
Copilot wants to merge 3 commits into
Closed
fix: populate AI credits footer for copilot-sdk workflows#38755Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
- copilot_sdk_session.cjs: capture session.shutdown event and write modelMetrics + currentModel to events.jsonl before closing stream (disconnect is now called before stream.end so the shutdown handler fires while the stream is still open) - parse_copilot_log.cjs: handle session.shutdown in normalizeCopilotSdkEventsToTrace — sets init entry model from currentModel and attaches modelMetrics to the result entry - log_parser_bootstrap.cjs: compute AIC from result.modelMetrics using computeInferenceAIC and export GH_AW_AIC via core.exportVariable - parse_mcp_gateway_log.cjs: when token-usage.jsonl has no pricing-eligible entries (totalAIC = 0), fall back to process.env.GH_AW_AIC set by the preceding bootstrap step and propagate it as the aic step output so downstream jobs receive it - Add tests for all four changes Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…-write-wins Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pelikhan
June 12, 2026 00:29
View session
Collaborator
|
@copilot ensure all messages are logged to stderr as JSONL |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Done in 00ae8f1. Replaced the two |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
copilot-sdk: trueworkflows (e.g.pr-triage-agent) were missing agent AIC in the footer — showing only threat-detection AIC (⌖ 38.8 AIC) with no agent cost.Root cause: Copilot SDK inference bypasses the AWF API proxy; only ambient-context calls hit the proxy, and those carry no model name. Every
token-usage.jsonlentry hasmodel: ""→totalAIC = 0→parse-mcp-gatewaynever sets theaicstep output →GH_AW_AICis empty downstream. The actual token data is available in thesession.shutdownSDK event (data.modelMetrics,data.currentModel), but it was being silently dropped.Changes
copilot_sdk_session.cjs— addsession.shutdowncase to capturemodelMetrics/currentModelin a closure variable. Swapfinallyorder todisconnect → write shutdown entry → stream.endso the event fires (synchronous Node.js EventEmitter semantics) while the stream is still writable.parse_copilot_log.cjs(normalizeCopilotSdkEventsToTrace) — handlesession.shutdownentries: attachmodelMetricsto the result entry; usecurrentModelas the init model instead of the hardcoded"copilot-sdk".log_parser_bootstrap.cjs— after parsing, ifresult.modelMetricsis present, compute AIC viacomputeInferenceAIC(provider"github-copilot") and export asGH_AW_AICviacore.exportVariable.parse_mcp_gateway_log.cjs(writeStepSummaryWithTokenUsage) — whentotalAIC === 0, fall back toprocess.env.GH_AW_AICset by the preceding bootstrap step and callsetOutput("aic", ...)to propagate it as the job-level output consumed by downstream jobs.The step ordering in the agent job already makes this work:
log_parser_bootstrapruns beforeparse-mcp-gateway, socore.exportVariablein the first step is visible asprocess.env.GH_AW_AICin the second.