Skip to content

[q] fix trend data collection in api-consumption-report #32637

@github-actions

Description

@github-actions

Q Workflow Optimization Report

Triggered by: /q fix trend data collection in discussion #32606

Issue Found (from live data)

api-consumption-report

  • Observation: The 2026-05-16 report noted: "The trend window currently holds only 2 data points (2026-05-15 → 2026-05-16)"
  • Root cause: The workflow fetches only the last 24 hours of logs per run (start_date="-1d"). There is no mechanism to populate historical data when the cache is first initialized or after a cache miss, so trending charts start with a single point and accumulate only one day at a time.
  • Impact: Trend charts (90-day heatmap, 30-day workflow breakdown, 7-day rolling average) are essentially empty for the first several weeks, making them meaningless.
Change Made

api-consumption-report (.github/workflows/api-consumption-report.md)

Added Step 2.5 — Backfill Historical Data between the daily aggregation step and the cache-append step.

Logic:

  • After saving today.json, count entries in the history file
  • If entry_count < 14 (less than two weeks of data), fetch logs for each of the past 30 days using logs(start_date=..., end_date=...) MCP calls
  • Apply the same aggregation logic as Step 2 for each historical day
  • Prepend historical entries to the history file (oldest first), deduplicating by date
  • Stop backfilling early if a day returns zero runs (logs unavailable that far back)
  • Normal daily runs (history ≥ 14 entries) skip this step entirely — zero extra MCP calls

Expected Improvements

  • Trend charts become meaningful from the first week of operation instead of after months
  • The 30-day workflow breakdown, 90-day heatmap, and 7-day rolling average all populate correctly after the first run post-cache-miss
  • No performance impact on steady-state daily runs (backfill is skipped when history is already rich)

Validation

Workflow compiled successfully using the compile tool from gh-aw MCP server:

  • ✅ api-consumption-report

Note: .lock.yml file regenerated but excluded from this PR — will be compiled automatically after merge.

🎩 Equipped by Q · ● 7.9M ·

  • expires on May 18, 2026, 2:38 PM UTC

Note

This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download bundle artifact

The bundle file is available in the agent artifact in the workflow run linked above.

To create a pull request with the changes:

# Download the artifact from the workflow run
gh run download 25964500595 -n agent -D /tmp/agent-25964500595

# Fetch the bundle into a temporary ref, then update the local branch
git fetch /tmp/agent-25964500595/aw-q-fix-trend-data-collection.bundle refs/heads/q/fix-trend-data-collection:refs/bundles/create-pr-q-fix-trend-data-collection-1b0ea73f6d00b052-4b8bb3e6
git update-ref refs/heads/q/fix-trend-data-collection-1b0ea73f6d00b052 refs/bundles/create-pr-q-fix-trend-data-collection-1b0ea73f6d00b052-4b8bb3e6
git checkout q/fix-trend-data-collection-1b0ea73f6d00b052
# Ensure the working tree matches the updated branch
git reset --hard
# Remove the temporary bundle ref
git update-ref -d refs/bundles/create-pr-q-fix-trend-data-collection-1b0ea73f6d00b052-4b8bb3e6

# Push the branch to origin
git push origin q/fix-trend-data-collection-1b0ea73f6d00b052

# Create the pull request
gh pr create --title '[q] fix trend data collection in api-consumption-report' --base main --head q/fix-trend-data-collection-1b0ea73f6d00b052 --repo github/gh-aw

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions