Skip to content

Distinguish unavailable AIC from measured zero in logs --json - #79257

Closed
mnkiefer wants to merge 6 commits into
mainfrom
copilot/fix-aic-zero-cost-issue
Closed

mnkiefer wants to merge 6 commits into
mainfrom
copilot/fix-aic-zero-cost-issue

Conversation

@mnkiefer

@mnkiefer mnkiefer commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

runs[].aic was always written as a number, so 0 meant either "the run cost nothing" or "there was no usage data". summary.total_aic used omitempty, so a missing total and a zero total looked the same. As a result, summing runs[].aic understated cost whenever some runs had no usage artifact.

// before: a failed run with no usage artifact
{ "runs": [{ "aic": 0 }, ...], "summary": { /* total_aic omitted if 0 */ } }

// after
{ "runs": [{ "aic": null }, ...],
  "summary": { "total_aic": 67.3281, "aic_coverage": "partial" } }

Changes

  • JSON fields (logs_report.go)
    • RunData.AIC is now *float64. It holds a value only when the run reported AI credits (AICFound), or for older cached data where TotalAIC > 0. A reported zero stays 0; anything else is null.
    • LogsSummary.TotalAIC is now *float64 without omitempty. It adds up only runs that have a value, and is null when none do.
    • New summary.aic_coverage field:
      • available when every run has a value.
      • partial when only some do.
      • unavailable when none do, or when there are no runs.
  • Cache (logs_cache.go, logs_models.go)
    • TokenUsageSummary.AICFound is tagged json:"-", so the flag was lost when run_summary.json was saved. It is now stored as RunSummary.TokenUsageAICFound (token_usage_aic_found) and restored on load.
    • Cache files written before this change fall back to the TotalAIC > 0 rule.
  • Schemas
    • Cached logs JSONL schema_version goes from 7 to 8.
    • Regenerated logs.schema.json and logs-jsonl.schema.json: aic and total_aic are now ["null","number"], and total_aic and aic_coverage are required.
  • Other outputs
    • Episodes: EpisodeRunCost.AIC is now *float64. Rollups skip nil values, and the view shows "AI credits unavailable".
    • TSV shows - for a missing value.
    • Compact output leaves the total out when it is nil, shows - for each run without a value, and adds aic_coverage=partial when the total is incomplete.
    • The MCP logs tool description now explains the null value and the coverage field.
  • Docs: cost-management.md explains null aic and aic_coverage, and its jq example now reports runs_without_aic.

Review notes

  • Breaking for consumers: jq or scripts that do arithmetic on .aic must handle null. summary.aic_coverage tells consumers whether total_aic is complete.
  • Not changed: EpisodeData.TotalAIC stays float64,omitempty, and the audit schema version is unchanged.

@mnkiefer mnkiefer changed the title [WIP] Fix logs --json: distinguish zero cost from unavailable usage Distinguish unavailable AIC from measured zero in logs --json Nov 19, 2026
@mnkiefer

Copy link
Copy Markdown
Collaborator Author

@copilot Fix failing checks

Copilot AI commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@copilot Fix failing checks

The earlier rollout failure is fixed by the main merge (15b338e). The unrelated connector test passed locally and on retry; the dependent canary is still running: https://github.com/github/gh-aw/actions/runs/44559161666

@github-actions

Copy link
Copy Markdown
Contributor

Hey @mnkiefer 👋 — thanks for tackling this important distinction! The PR looks ready for review. You've done a great job:

✓ Clear focus — the diff consolidates changes to JSON schema, caching, output formatting, and tests all around one concept (unavailable vs. measured zero AIC).
✓ Comprehensive tests — new test cases cover the preservation of null vs. 0 through caching and episode reporting.
✓ Detailed documentation — updated cost-management.md with examples and jq patterns that account for the new aic_coverage field.
✓ Breaking change properly noted — your review notes flag the JSON format change and explain how consumers should handle null values.

This looks solid. Ready for team review.

Generated by ✅ Contribution Check · copilot · routed: haiku55 xhigh · ~18 AIC · ⌖ ~2 AIC · ⊞ 5.4K · ◷

@pelikhan
pelikhan marked this pull request as ready for review November 20, 2026 10:29
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 10:29

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

Coupling lifecycle-ledger versions to the run-cache schema causes readers to reject retained v7 or newly written v8 ledgers, breaking delivery/adoption collection and retained operational-value reporting.

4 open issues
What changed in this PR

Updates gh aw logs to distinguish unavailable AI-credit evidence from measured zero, addressing #79253 across JSON output, caches, and display formats.

Changes:

  • Makes run and summary AIC values nullable and adds summary coverage metadata.
  • Preserves AIC availability in caches and adapts episode, TSV, and compact output.
  • Updates schemas, regression tests, MCP tool help, and cost-management documentation.
File Description
schemas/​logs.schema.json Defines nullable AIC fields and required summary coverage.
schemas/​logs-jsonl.schema.json Updates nullable run AIC and schema version 8.
pkg/​cli/​mcp_tools_privileged.go Clarifies null AIC and coverage in tool help.
pkg/​cli/​logs_report.go Tracks observed AIC and calculates aggregate coverage.
pkg/​cli/​logs_report_test.go Tests missing, zero, positive, and cached AIC values.
pkg/​cli/​logs_models.go Adds persisted AIC availability to run summaries.
pkg/​cli/​logs_format_tsv.go Displays unavailable AIC as -.
pkg/​cli/​logs_format_tsv_test.go Tests unavailable and measured TSV values.
pkg/​cli/​logs_format_compact.go Handles nullable totals and marks partial coverage.
pkg/​cli/​logs_format_compact_test.go Tests compact AIC values and coverage labels.
pkg/​cli/​logs_episode_view.go Labels unavailable run cost in episode views.
pkg/​cli/​logs_episode_test.go Adapts episode fixtures to nullable AIC.
pkg/​cli/​logs_episode_rollup.go Skips unavailable AIC during episode aggregation.
pkg/​cli/​logs_episode_retrieval_test.go Checks nullable totals and available coverage.
pkg/​cli/​logs_episode_lineage_test.go Adapts lineage fixtures to nullable AIC.
pkg/​cli/​logs_episode_hops.go Makes episode run-cost AIC nullable.
pkg/​cli/​logs_episode_hops_test.go Tests nullable run costs and unavailable-cost rendering.
pkg/​cli/​logs_episode_coverage_test.go Adapts coverage fixtures to nullable AIC.
pkg/​cli/​logs_cached_json.go Bumps the cached JSONL schema version.
pkg/​cli/​logs_cached_json_test.go Tests AIC cache preservation and updates version fixtures.
pkg/​cli/​logs_cache.go Saves and restores the AIC availability flag.
docs/​src/​content/​docs/​reference/​cost-management.md Explains null semantics, coverage, and missing-cost counts.

Review effort: Max (adaptive)

type cachedLogsRuns map[int64]cachedLogsJSONLRunData

const cachedLogsJSONLSchemaVersion = 7
const cachedLogsJSONLSchemaVersion = 8
Comment thread pkg/cli/logs_report.go
TotalAIC *float64 `json:"total_aic" console:"header:Total AIC"`
// AICCoverage is "available" when every run has observed AI credits, "partial"
// when only some runs do, and "unavailable" when none do.
AICCoverage string `json:"aic_coverage" console:"header:AIC Coverage"`
Comment thread pkg/cli/logs_report.go
TokenUsage int `json:"token_usage" console:"header:Tokens,format:number,omitempty"`
// AIC is the run's observed AI credits. It is always emitted: null means cost
// evidence is unavailable (for example, no usage artifact), while 0 is a measured zero.
AIC *float64 `json:"aic"`
Comment thread pkg/cli/logs_report.go
TokenUsage int `json:"token_usage" console:"header:Tokens,format:number,omitempty"`
// AIC is the run's observed AI credits. It is always emitted: null means cost
// evidence is unavailable (for example, no usage artifact), while 0 is a measured zero.
AIC *float64 `json:"aic"`
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/logs_cached_json.go:25): address unresolved feedback - Review comment
  3. Review (pkg/cli/logs_report.go:125): address unresolved feedback - Review comment
  4. Review (pkg/cli/logs_report.go:218): address unresolved feedback - Review comment
  5. Review (pkg/cli/logs_report.go:218): address unresolved feedback - Review comment
  6. Fix failing check impacted-go-tests (FAILURE): Check run.
  7. Fix failing check prefetch (FAILURE): Check run.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "15b338e8dba5fd7015d69feded7124a9b0ec573e",
  "kind": "requested",
  "schema_version": "1",
  "state": "1000d2dbd8c99f6768c4d55aebd97ac607042b9d857d03ae76aae9cb7d0793f1",
  "work": [
    "23027a7a3ebe972cffc3eabad4a22e44dac70312f0e8b312d61f867187f7f01d",
    "42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac",
    "526701581f32f211b30387aa941f7a6a514327e3ea3a9c5e5e15a5980ed93110",
    "5688aa5f7ddadb7b8282331e8fd0a6dee900a09111561c77b45b4d1d60d6184a",
    "7925451dea9b230345e1e8331f85d3467e9b4b27f0df1e3ac71216d08b94b58a",
    "bc190b1bdb7008fdc0dee50ab31fb2b425378feb85a48e8df0afe8e090ce38f4"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

gh-aw-bot and others added 3 commits November 20, 2026 11:09
@mnkiefer

Copy link
Copy Markdown
Collaborator Author

No longer needed

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.

logs --json: runs[].aic is 0 when usage is unavailable, indistinguishable from zero cost

4 participants