Skip to content

Label forecast output as AI Credits and cache AIC across runs - #48797

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan/forecast-aic-labels-cache
Jul 29, 2026
Merged

Label forecast output as AI Credits and cache AIC across runs#48797
pelikhan merged 3 commits into
mainfrom
pelikhan/forecast-aic-labels-cache

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Summary

Two improvements to gh aw forecast:

1. Make it clear the figures are AI Credits (AIC)

The forecast table previously showed bare numbers (P50/Run, Weekly (P50), …) with no unit. Now:

  • Column headers carry the unit: P50 AIC/Run, P95 AIC/Run, Weekly AIC (P50), Monthly AIC (P50).
  • A new header line: "All numeric figures are AI Credits (AIC) — the gh-aw cost metric."
  • The footnote opens with "AIC = AI Credits."

2. Maximize cache reuse across repeated forecast runs

Runs first seen by forecast (not by gh aw logs) had no run_summary.json, so every repeat re-scanned the run directory and re-parsed the usage artifact. Writing a partial run_summary.json was unsafe — it's the "fully processed" marker for gh aw logs/audit. Instead:

  • Added a dedicated, CLI-version-gated forecast_aic.json per-run cache (pkg/cli/forecast_cache.go).
  • loadCachedRunAIC now checks run_summary.jsonforecast_aic.json → download, and persists the computed AIC after a download.
  • Cache hits/misses/writes are logged via forecastRunLog, enabled through the DEBUG env var (e.g. DEBUG=cli:forecast_run, DEBUG=*, or ACTIONS_RUNNER_DEBUG=true in the runner).

Verification

DEBUG=cli:forecast_run gh aw forecast smoke-copilot:

  • Run 1: wrote forecast_aic.json for each sampled run.
  • Run 2: 75 forecast-cache hits, 0 downloads, 0 writes.

Build, go vet, and forecast tests pass. Added unit tests (forecast_cache_test.go) and documented the file in audit_report.go and the forecast spec (R-SAMP-013). Cache files live under the gitignored .github/aw/logs/.

Make `gh aw forecast` output clearly denote AI Credits (AIC) and reuse
cached AIC values across repeated runs.

Output clarity:
- Table headers now carry units: P50 AIC/Run, P95 AIC/Run,
  Weekly AIC (P50), Monthly AIC (P50).
- Added an "All numeric figures are AI Credits (AIC)" header line and an
  "AIC = AI Credits" prefix on the explanatory footnote.

Caching:
- Add a dedicated, CLI-version-gated forecast_aic.json per-run cache so
  repeated forecast runs reuse computed AIC without re-scanning the run
  directory or re-parsing the usage artifact.
- loadCachedRunAIC now checks run_summary.json -> forecast_aic.json ->
  download, and persists the computed AIC after a download. A dedicated
  file avoids corrupting the shared run_summary.json "fully processed"
  marker used by `gh aw logs`/`audit`.
- Cache hits/misses/writes are logged via forecastRunLog (enable with the
  DEBUG env var, e.g. DEBUG=cli:forecast_run).

Also document forecast_aic.json in the artifact description map and the
forecast specification (R-SAMP-013), and add unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 07:37

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.

Pull request overview

Clarifies forecast units and adds reusable per-run AI Credits caching.

Changes:

  • Labels forecast cost projections as AIC.
  • Adds version-gated forecast_aic.json caching.
  • Documents and tests the cache format.
Show a summary per file
File Description
pkg/cli/forecast_types.go Adds AIC units to table headers.
pkg/cli/forecast_render.go Clarifies forecast output units.
pkg/cli/forecast_compute.go Integrates forecast-cache reads and writes.
pkg/cli/forecast_cache.go Implements the AIC cache.
pkg/cli/forecast_cache_test.go Tests cache validation and persistence.
pkg/cli/audit_report.go Describes the cache in audit output.
docs/src/content/docs/specs/forecast-specification.md Documents forecast caching requirements.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Medium

forecastRunLog.Printf("AIC from usage artifact for run %d: aic=%.3f", runID, tokenUsage.TotalAIC)
// Persist the computed AIC so subsequent forecast runs hit the fast forecast cache
// instead of re-scanning the directory and re-parsing the usage artifact.
saveForecastAICCache(dir, runID, tokenUsage.TotalAIC)

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.

Fixed in 4536c1a by isolating the forecast cache tests in a temporary working directory in pkg/cli/forecast_test.go.

Comment thread pkg/cli/forecast_render.go Outdated
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(
fmt.Sprintf("Workflow Forecast — weekly & monthly projections (based on last %d days of history)", config.Days)))
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(
"All numeric figures are AI Credits (AIC) — the gh-aw cost metric."))

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.

Fixed in 4536c1a by narrowing the banner text in pkg/cli/forecast_render.go to cost/projection figures.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot run pr-finisher skill

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@copilot run pr-finisher skill

Ran it. Ready for human merge pending CI re-trigger.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit e3ca145 into main Jul 29, 2026
@pelikhan
pelikhan deleted the pelikhan/forecast-aic-labels-cache branch July 29, 2026 08:15
Copilot stopped work on behalf of pelikhan due to an error July 29, 2026 08:15
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.5

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.

3 participants