gh-aw icon indicating copy to clipboard operation
gh-aw copied to clipboard

gh-aw.aic/turns/gen_ai.usage.* missing on summary spans under runner.topology: arc-dind (parse_token_usage.cjs hardcodes /tmp/gh-aw, same class as #63717)

Open ekbritecore opened this issue 2 months ago • 2 comments

Analysis

Same root-cause class as #63717 (mine as well), but on a different consumer: actions/setup/js/parse_token_usage.cjs hardcodes every path it reads as a literal /tmp/gh-aw/... string, never rewritten for runner.topology: arc-dind:

const TOKEN_USAGE_AUDIT_PATH = "/tmp/gh-aw/sandbox/firewall-audit-logs/api-proxy-logs/token-usage.jsonl";
const TOKEN_USAGE_PATH = "/tmp/gh-aw/sandbox/firewall/logs/api-proxy-logs/token-usage.jsonl";
const TOKEN_USAGE_AWF_AUDIT_PATH = "/tmp/gh-aw/sandbox/firewall/audit/api-proxy-logs/token-usage.jsonl";
const TOKEN_USAGE_PATHS = [TOKEN_USAGE_AUDIT_PATH, TOKEN_USAGE_AWF_AUDIT_PATH, TOKEN_USAGE_PATH];
const AGENT_USAGE_PATH = "/tmp/gh-aw/agent_usage.json";
const AGENT_USAGE_JSONL_PATH = "/tmp/gh-aw/agent_usage.jsonl";
const COPILOT_SESSION_STATE_DIR = "/tmp/gh-aw/sandbox/agent/logs/copilot-session-state";

generateTokenUsageSummary() (pkg/workflow/compiler_yaml_ai_execution.go:317) runs this as a plain actions/github-script step — outside the AWF sandbox, on the bare runner filesystem — after the agent job. Under runner.topology: arc-dind, the real files live under ${RUNNER_TEMP}/gh-aw/... (per rewriteArcDindEngineCommand(), same mechanism #63717 already documents), not literal /tmp/gh-aw/.... So on arc-dind:

  1. getReadableTokenUsagePaths(TOKEN_USAGE_PATHS) finds nothing → tokenUsagePaths.length === 0.
  2. Falls back to findCopilotUsageCheckpoint(COPILOT_SESSION_STATE_DIR) — also a hardcoded literal path → also finds nothing → returns null.
  3. Falls through to writeEmptyUsageEvidence() (actions/setup/js/parse_token_usage.cjs:41-42, writes literal {"ai_credits":0}) and returns without ever calling core.exportVariable("GH_AW_AIC", ...).

GH_AW_AIC (or its absence) is what send_otlp_span.cjs reads to build the gh-aw.aic attribute on the gh-aw.agent.conclusion/gh-aw.agent.agent spans — explaining the gh-aw.aic=0/missing gh-aw.turns/missing gen_ai.usage.* symptom below, and (separately) why the Step Summary's own token table goes missing on the same runs — same silent-empty-fallback path, not two different bugs.

Reproduction

Direct before/after OTLP trace comparison, same repo, both engine: pi:

vm-poc topology (not arc-dind), gh-aw v0.89.20 — gh-aw.agent.conclusion span:

gh-aw.aic=313.14946
gh-aw.turns=168
gen_ai.usage.input_tokens=64872
gen_ai.usage.output_tokens=30014
gen_ai.usage.total_tokens=94886

runner.topology: arc-dind, gh-aw v0.90.0 — same span type, same workflow shape:

gh-aw.aic=0

gh-aw.turns and all gen_ai.usage.* fields absent entirely. In the same trace, the underlying api_proxy.copilot.request child spans still show real, non-zero, correctly-accumulating cost:

awf.ai_credits=2.5404, awf.ai_credits_total=17.29828
awf.ai_credits=1.69931, awf.ai_credits_total=27.79273

confirming AWF's own proxy is logging real data throughout the run — it just never reaches the summary/OTLP layer, consistent with the hardcoded-path analysis above rather than a data-loss issue.

(Initially reported this as a v0.89.20→v0.90.0 version regression before tracing the code — it isn't; the v0.89.20 comparison run happened to be on vm-poc, not arc-dind. This is an arc-dind topology gap present since arc-dind support was added, same as #63717, just not exercised/reported until now.)

Also confirmed on our own runs: Log path not found: /tmp/gh-aw/pi-streaming.jsonl in the job log alongside Removed symbolic link before artifact upload: /tmp/gh-aw/pi-streaming.jsonl — the #63717 workaround (mount + pre-touch) is applied and fixes the exit-1 crash, but the summary/OTLP gap above persists independently, since it's a different file entirely.

Implementation Plan

  1. Make the arc-dind path rewrite apply to every consumer, not just the engine command. Either:
    • Extend rewriteArcDindPath()/rewriteArcDindEngineCommand() (pkg/workflow/awf_arc_dind.go) to also cover the generated parse_token_usage.cjs step's own path constants when compiling for runner.topology: arc-dind, or
    • Have parse_token_usage.cjs resolve these paths via ${{ runner.temp }}/gh-aw/... (an env var already available to the step) instead of a hardcoded literal, falling back to /tmp/gh-aw/... when unset/equal — same fix shape as #63717's proposed fix for the pi streaming log.
  2. Audit every other hardcoded /tmp/gh-aw literal in a step that runs outside the sandbox, not just this file — generateAgentStepSummaryAppend() and the "Write agent output placeholder" step (pkg/workflow/compiler_yaml_ai_execution.go) use the same literal pattern and may have the same gap; worth the broader sweep #63717's own plan already called for ("audit other engines for the same pattern") extended to post-sandbox parsing steps in general.
  3. Tests: a runner.topology: arc-dind case in parse_token_usage.test.cjs asserting main() still finds/reports real AIC when the underlying files exist only under the rewritten path, not the literal one.

No workaround available from workflow frontmatter for this one (unlike #63717's) — the read-side paths are compiled into the generated step, not configurable per-workflow.

ekbritecore avatar Sep 29 '26 20:09 ekbritecore

🔗 AWF tracking issue: github/gh-aw-firewall#9352

Generated by Firewall Issue Dispatcher · copilot · auto · 22.2 AIC · ⊞ 9.1K · ◷

lpcox avatar Oct 02 '26 01:10 lpcox

@lpcox @pelikhan does the awf merge solve this one?

ekbritecore avatar Oct 06 '26 15:10 ekbritecore