Skip to content

Clarify github_api_calls provenance and recover snapshot-only core_consumed accounting#39623

Merged
pelikhan merged 5 commits into
mainfrom
copilot/deep-report-investigate-github-api-calls
Jun 16, 2026
Merged

Clarify github_api_calls provenance and recover snapshot-only core_consumed accounting#39623
pelikhan merged 5 commits into
mainfrom
copilot/deep-report-investigate-github-api-calls

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The API-consumption report showed a sharp 06-13 → 06-14 github_api_calls discontinuity that looked non-organic and likely instrumentation-related. This change makes the underlying core_consumed derivation explicit and robust when log shape shifts from per-call headers to rate-limit snapshots.

  • Metric provenance surfaced in run summaries

    • Added core_consumed_source to GitHubRateLimitUsage so downstream analysis can distinguish how core_consumed was derived (response_headers_delta, rate_limit_api_delta, rate_limit_api_single_snapshot).
  • Snapshot-only runs now produce usable core_consumed

    • Extended parser logic to compute core_consumed from rate_limit_api snapshot deltas when response_headers entries are absent.
    • Added reset-safe fallback for snapshot deltas (if window resets, use last used as lower-bound estimate), mirroring existing resilience for header-based deltas.
  • Targeted parser regression coverage

    • Updated and added focused tests to validate:
      • provenance tagging for header-derived vs snapshot-derived consumption
      • snapshot-only delta calculation
      • snapshot window-reset fallback behavior
if state.requestsMade > 0 {
	consumedSource = "response_headers_delta"
} else if state.snapshotCount >= 2 {
	consumedSource = "rate_limit_api_delta"
} else if state.snapshotCount == 1 {
	consumedSource = "rate_limit_api_single_snapshot"
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate discontinuity in github_api_calls measurement Clarify github_api_calls provenance and recover snapshot-only core_consumed accounting Jun 16, 2026
Copilot AI requested a review from pelikhan June 16, 2026 17:59
@pelikhan pelikhan marked this pull request as ready for review June 16, 2026 18:05
Copilot AI review requested due to automatic review settings June 16, 2026 18:05

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

This PR improves the reliability and interpretability of GitHub API quota accounting in gh-aw run/audit reporting by making core_consumed provenance explicit and by restoring meaningful core_consumed estimates for runs where only rate_limit_api snapshots are present (no per-call response headers).

Changes:

  • Adds core_consumed_source to GitHubRateLimitUsage to tag how core_consumed was derived.
  • Extends parsing logic to derive core_consumed from rate_limit_api snapshot deltas (including a reset-safe fallback).
  • Updates/extends unit tests to cover snapshot-derived accounting and provenance.
Show a summary per file
File Description
pkg/cli/logs_github_rate_limit_usage.go Adds provenance tagging and snapshot-based core_consumed derivation logic.
pkg/cli/logs_github_rate_limit_usage_test.go Adds regression coverage for snapshot-only runs and reset behavior.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +201 to +205
state.snapshotCount++
if state.snapshotCount == 1 {
state.firstSnapshotUsed = entry.Used
}
state.lastSnapshotUsed = entry.Used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment in 0346fa7 to reflect that snapshots are also used to derive core_consumed via firstSnapshotUsed/lastSnapshotUsed.

assert.Equal(t, 10, usage.CoreConsumed, "core consumed should be derived from rate_limit_api snapshot delta")
assert.Equal(t, "rate_limit_api_delta", usage.CoreConsumedSource, "core consumed source should come from rate_limit_api snapshots")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestParseGitHubRateLimitsFileOnlyAPISnapshotSingle in 0346fa7, covering the exactly-one-snapshot case: asserts CoreConsumed==0 and CoreConsumedSource=="rate_limit_api_single_snapshot".

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan merged commit 266d1ad into main Jun 16, 2026
29 checks passed
@pelikhan pelikhan deleted the copilot/deep-report-investigate-github-api-calls branch June 16, 2026 20:54
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