Skip to content

Distinguish missing AI credit cost from zero in logs --json - #79904

Merged
pelikhan merged 11 commits into
mainfrom
copilot/fix-logs-json-aic-zero-cost
Nov 22, 2026
Merged

pelikhan merged 11 commits into
mainfrom
copilot/fix-logs-json-aic-zero-cost

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

gh aw logs --json reports missing AI credit cost as 0, indistinguishable from a measured zero. A report with missing costs can therefore understate cost per output.

  • Per run: Add aic_coverage as available or unavailable. Keep aic numeric; ignore it when coverage is unavailable.
  • Summary: Emit total_aic even when zero. It sums only recorded costs, and aic_coverage identifies whether all (available), some (partial), or none (unavailable) of the returned runs have recorded cost.
  • Cache: Preserve measured zero on cache hits. Treat zeros in older cache records without cost evidence as unavailable.
{
  "runs": [
    { "run_id": 101, "aic": 0, "aic_coverage": "available" },
    { "run_id": 102, "aic": 0, "aic_coverage": "unavailable" }
  ],
  "summary": { "total_aic": 0, "aic_coverage": "partial" }
}

pelikhan and others added 3 commits November 21, 2026 21:58
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@pelikhan pelikhan changed the title [WIP] Fix logs --json serialization for AIC when usage is unavailable Distinguish missing AI credit cost from zero in logs --json Nov 21, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 22, 2026 00:06
Copilot AI adaptive review requested due to automatic review settings November 22, 2026 00:06
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~5 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷

@github-actions

github-actions Bot commented Nov 22, 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.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

github-actions Bot commented Nov 22, 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 by Ponytail Reviewer for #79904 · codex · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 22, 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 · copilot · routed: haiku55 xhigh · ~12 AIC · ⌖ ~2 AIC · ⊞ 6.6K · ◷

@github-actions

Copy link
Copy Markdown
Contributor

🚀 PR Specification Reviewer has started processing this pull request

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (122 new lines under pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/79904-add-aic-coverage-to-logs-json.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff

  2. Complete the missing sections — resolve the [TODO: verify] markers: the rationale for rejecting a nullable aic, the partial denominator, and the cache and schema impact

  3. Commit the finalized ADR to docs/adr/ on your branch

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-79904: Add Explicit AI Credit Coverage to logs --json (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

🔍 Gate notes

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 8.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.

🟡 Changes recommended

The cached record’s AICCoverage now changes from empty to unavailable, but the preservation test still expects whole-record equality with empty coverage, causing its assertion to fail.

1 open issue
What changed in this PR

This PR addresses #79253 by distinguishing unknown AI credit costs from measured zero costs in gh aw logs --json, while keeping cost fields numeric.

Changes:

  • Adds per-run and summary cost coverage, and always emits summary.total_aic.
  • Preserves recorded zero costs through caching, with tests and documentation.
  • Updates two generated workflows to use hash-verified PageIndex dependencies and include the requirements file in cache keys.
File Description
pkg/​cli/​token_usage_types.go Persists evidence of recorded zero cost.
pkg/​cli/​logs_report.go Tracks cost coverage and aggregates recorded costs.
pkg/​cli/​logs_report_test.go Tests missing, zero, and mixed cost coverage.
pkg/​cli/​logs_orchestrator_unit_test.go Checks coverage across disk and JSONL caches.
docs/​src/​content/​docs/​setup/​cli.md Documents JSON cost coverage semantics.
.github/​workflows/​spec-librarian.lock.yml Uses hash-verified PageIndex dependencies and updated cache keys.
.github/​workflows/​daily-doc-updater.lock.yml Applies the same PageIndex installation and cache changes.

Review effort: Balanced (adaptive)

Comment thread pkg/cli/logs_report.go
func (agg *logsAggregate) recordCachedRun(runData RunData) RunData {
// Older cache records cannot distinguish a recorded zero from missing cost.
if runData.AICCoverage == "" {
runData.AICCoverage = logsAICUnavailable

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.

Updated the expected cached record’s coverage while retaining whole-record equality in d385d69.

@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 two blocking schema-compatibility issues: the new aic_coverage fields and serialized aic_found field are not represented in the strict logs output schemas. Please update the schemas before merging. The specialist pass also identified a legacy-cache test gap, but I did not treat that as a blocking defect.

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

CacheEfficiency float64 `json:"cache_efficiency"`
TotalAIC float64 `json:"total_aic,omitempty"`
AICFound bool `json:"-"`
AICFound bool `json:"aic_found,omitempty"` // Preserves recorded zero cost across cache loads.

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.

Changing AICFound from json:"-" to a serialized field also changes token_usage_summary output, but schemas/logs.schema.json and schemas/logs-jsonl.schema.json omit aic_found while enforcing additionalProperties: false. Any logs JSON containing this field will fail schema validation. Please update the schemas (and any other affected output contract) with this new property.

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.

Added aic_found to the generated logs, JSONL, and audit schemas in 2c8f0c5, with validation coverage in d385d69.

Comment thread pkg/cli/logs_report.go Outdated
TotalDuration string `json:"total_duration" console:"header:Total Duration"`
TotalAIC float64 `json:"total_aic,omitempty"`
TotalAIC float64 `json:"total_aic"`
AICCoverage string `json:"aic_coverage" console:"-"`

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.

aic_coverage is now emitted in both the summary and each run, but the checked-in schemas/logs.schema.json and schemas/logs-jsonl.schema.json do not define this property (their relevant objects use additionalProperties: false). JSON produced by this change will therefore fail the repository schema validation. Please update the output schemas alongside the new fields.

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.

Updated both generated logs schemas and added coverage enum validation in 2c8f0c5 and d385d69.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-dcc7c772-6b61-49bb-9815-30b99d8abafb","parents":[],"payload":{"id":"ldg-e11fc57e-04c2-4bb8-abd2-c61a703ee5ba","operation":"append","value":{"finding_count":0,"head_sha":"e7c906e44fcf3ddb77fda92aac0cc241a8c937ad","outcome":"incomplete"}},"sha":"sha256:0eb84a6738212997a3bca4a13bca48b7b5a7290811fe066208fe7082c0a37577","timestamp":"2026-11-22T00:17:34.245Z","type":"ledger_append","version":1}
History

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-93aa7856-aa18-4f38-a6f3-cc7781244f0a","parents":[],"payload":{"id":"ldg-9eb303d7-9609-4134-a147-ebf276659160","operation":"append","value":{"finding_count":2,"head_sha":"e7c906e44fcf3ddb77fda92aac0cc241a8c937ad","outcome":"findings"}},"sha":"sha256:b18a4c074648115d39ab0f0aa13ca8ba04abb98c6f50cba63dc60fa42ab71bbc","timestamp":"2026-11-22T00:18:13.874Z","type":"ledger_append","version":1}
History

@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 /tdd, /diagnosing-bugs, and /codebase-design. Requesting changes: the PR fails go test ./pkg/cli, and the published JSON schemas do not match the new output.

📋 Key Themes and Highlights

Key Themes

  • Failing test: TestBuildLogsDataPreservesCachedRunRecord expects an empty AICCoverage on a legacy zero-cost cache record. The new behavior correctly returns unavailable, so the test expectation must change. The test is not in this diff.
  • Schema drift: aic_coverage (runs[], summary) and aic_found (token_usage_summary) are missing from schemas/logs.schema.json, schemas/logs-jsonl.schema.json, and schemas/audit.schema.json. All three use additionalProperties: false.
  • Episode totals still conflate unknown with zero: logs_episode_rollup.go (line 22) and logs_episode.go (line 58) add run.AIC without checking AICCoverage. The episodes[].total_aic value can still show 0 for runs whose cost is unknown. The PR does not touch these files.
  • Docs still default missing AIC to 0: docs/src/content/docs/reference/cost-management.md (lines 75, 128, 133) and glossary.md (line 1517) use // 0 in jq examples. The PR updates cli.md but not these.

Positive Highlights

  • ✅ The coverage state machine in logs_report.go is clear: recordRunAIC, recordCachedRun, and summary agree. totalRuns always matches the number of recorder calls, because no early return skips recordRunAIC.
  • ✅ TestLogsJSONAICCoverage covers the no-evidence, recorded-zero, and mixed cases.
  • ✅ Preserving a measured zero across cache round-trips with aic_found is the right fix.
  • ✅ The cli.md description of aic_coverage matches the implementation.
🔍 Verification
  • go test ./pkg/cli -run TestBuildLogsDataPreservesCachedRunRecord: FAIL (AICCoverage expected "", actual "unavailable").
  • TestLogsJSONAICCoverage, TestBuildLogsDataAggregatesAIC, and TestDownloadWorkflowLogsFromStdinReportsCollectionStatsForJSONLAndDiskCacheHits: PASS.
  • No runtime test validates logs --json output against the schemas, so the drift is not caught by CI.

Next actions

  1. Update the expectation in TestBuildLogsDataPreservesCachedRunRecord to unavailable.
  2. Declare aic_coverage and aic_found in the three schemas.
  3. Decide whether episode total_aic should use the coverage rule. If so, change logs_episode_rollup.go and logs_episode.go in this PR or in a follow-up, and update the docs jq examples.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~12 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

CacheEfficiency float64 `json:"cache_efficiency"`
TotalAIC float64 `json:"total_aic,omitempty"`
AICFound bool `json:"-"`
AICFound bool `json:"aic_found,omitempty"` // Preserves recorded zero cost across cache loads.

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.

[/codebase-design] Exposing aic_found changes the JSON of every TokenUsageSummary, not only the cache. audit output (firewall_token_usage) also gains the key. schemas/audit.schema.json and schemas/logs.schema.json set additionalProperties: false on token_usage_summary and do not declare aic_found, so schema-conformant consumers will reject it.

💡 Suggested fix

Either declare aic_found in both schemas under token_usage_summary, or keep the cache-only marker out of the public type, for example in a private cache wrapper. Declaring the field is the smaller change.

@copilot please address this.

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.

Declared aic_found in the generated audit and logs schemas in 2c8f0c5, and added schema validation tests in d385d69.

Comment thread pkg/cli/logs_report.go

func (agg *logsAggregate) recordCachedRun(runData RunData) RunData {
// Older cache records cannot distinguish a recorded zero from missing cost.
if runData.AICCoverage == "" {

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.

[/tdd] Legacy cache records with AIC == 0 now become unavailable, which matches the PR intent. This breaks TestBuildLogsDataPreservesCachedRunRecord in pkg/cli/logs_cached_json_test.go, which expects an empty AICCoverage. That test is not in this PR, so go test ./pkg/cli fails. Update its expectation to unavailable.

💡 Verified locally

go test ./pkg/cli -run TestBuildLogsDataPreservesCachedRunRecord fails with expected AICCoverage "", actual "unavailable". TestLogsJSONAICCoverage, TestBuildLogsDataAggregatesAIC, and the stdin JSONL/disk-cache test all pass.

@copilot please address this.

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.

Updated the legacy-cache expectation in d385d69; the focused test passes.

Comment thread pkg/cli/logs_report.go
// discover the field and distinguish "no tokens recorded" from "field absent".
TokenUsage int `json:"token_usage" console:"header:Tokens,format:number,omitempty"`
AIC float64 `json:"aic"`
AICCoverage string `json:"aic_coverage" console:"-"`

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.

[/codebase-design] aic_coverage is added to runs[] here and to summary at line 121, but schemas/logs.schema.json sets additionalProperties: false on both objects and does not declare the field. The published contract no longer matches gh aw logs --json output. Declare aic_coverage on summary (available, partial, unavailable) and on runs[] (available, unavailable), and make the same change in schemas/logs-jsonl.schema.json.

💡 Details

I found no test that validates these schemas, so CI will not catch this. The cli.md docs added by this PR already describe the field, so the schema is the remaining gap.

@copilot please address this.

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.

Added the fields and constrained the run and summary coverage values in 2c8f0c5 and d385d69, with schema validation tests.

@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_report.go:572): address unresolved feedback - Review comment
  3. Review (pkg/cli/token_usage_types.go:285): address unresolved feedback - Review comment
  4. Review (pkg/cli/logs_report.go:121): address unresolved feedback - Review comment
  5. Review (pkg/cli/token_usage_types.go:285): address unresolved feedback - Review comment
  6. Review (pkg/cli/logs_report.go:571): address unresolved feedback - Review comment
  7. Review (pkg/cli/logs_report.go:213): address unresolved feedback - Review comment

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

Structured data
{
  "completed_task": 0,
  "head": "87bfefb223390cf2ab8758d5e7e17cb0287e16dc",
  "kind": "requested",
  "schema_version": "1",
  "state": "5d295f2a0002a1aa5b9ed7c2167fa0712cb0fbf2c4500fbd4217541565a78765",
  "work": [
    "1142525aa3933194e37b2f70f28ea8e5955b5a428b1451cf10e81927d7859b3e",
    "347b66281611050a0c5d74ede3f95425a58e8234d8e558be349ea05076bf191f",
    "872a9eebe8877ceed825d25d80e6e1a78ed25a25e576e90b13025f6c7260025b",
    "b969b5b5cb9290b5848e3d4586c35d7d031b521923763799c6b7b3b5e30e3338",
    "db13618455d40a01ce338a3842e9979f8571ae1e68e42f33143486986c892088",
    "e1a5724d86de6390d49d28b8140f674d7313ee71466a367821febed8fdfd807f"
  ],
  "workflow": "pr-sous-chef"
}

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

gh-aw-bot and others added 3 commits November 22, 2026 01:05
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…-aic-zero-cost

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Merged main in 04a14ea and addressed the linked feedback in 2c8f0c5 and d385d69. Focused and impacted tests and Go lint passed; full workflow recompilation, custom lint, and CodeQL did not complete.

@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. Fix failing check Fast unit tests (N-R) (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": "d385d697922eb7d0e8aa2c91afbc278330fe309b",
  "kind": "requested",
  "schema_version": "1",
  "state": "e053972f9ce5ef1781717a989ae6b32ced85989300b150d084314c79fa076e10",
  "work": [
    "00c67337de75cbb14e7e442f3cd0c94ae2f69d353cccd0b2cd3b3a7b77eb9ebc"
  ],
  "workflow": "pr-sous-chef"
}

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

…-aic-zero-cost

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot fix ci failures

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Merged main in 82b35efe and fixed the failing schema fixtures in 4b3b6050. Targeted tests pass; the repository-wide workflow-drift check did not finish.

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot fix ci failures

The prior failure was fixed in 4b3b605; Fast unit tests (N–R) now passes. No current checks have failed; Fast unit tests (C) is still running.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot use null instead?

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot use null instead?

Yes: runs[].aic: null can represent missing cost while 0 remains a measured zero. This changes the JSON type. For partial summaries, should total_aic remain the known subtotal with aic_coverage, or become null?

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot become null so client handles it

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot become null so client handles it

Implemented in e09ffff: incomplete or unavailable summary totals are null; missing run costs are also null. Measured zero remains numeric. Targeted tests and Go lint pass; the full gate did not finish, and CodeQL skipped analysis due to database size.

@pelikhan
pelikhan merged commit ca5f846 into main Nov 22, 2026
88 checks passed
@pelikhan
pelikhan deleted the copilot/fix-logs-json-aic-zero-cost branch November 22, 2026 03:07
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