-
Notifications
You must be signed in to change notification settings - Fork 424
Clarify github_api_calls provenance and recover snapshot-only core_consumed accounting
#39623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelikhan
merged 5 commits into
main
from
copilot/deep-report-investigate-github-api-calls
Jun 16, 2026
+81
−14
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ac6dc6
Initial plan
Copilot a18d005
Improve github_api_calls provenance for snapshot-only runs
Copilot feaf2a6
Merge branch 'main' into copilot/deep-report-investigate-github-api-c…
pelikhan 09a4412
Merge branch 'main' into copilot/deep-report-investigate-github-api-c…
pelikhan 0346fa7
fix: update snapshot comment and add single-snapshot regression test
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ func TestParseGitHubRateLimitsFileBasic(t *testing.T) { | |
|
|
||
| // Core resource: 2 calls, consumed = lastUsed(120) - firstUsed(110) = 10 | ||
| assert.Equal(t, 10, usage.CoreConsumed, "core quota consumed should be 10") | ||
| assert.Equal(t, "response_headers_delta", usage.CoreConsumedSource, "core consumed source should come from response headers") | ||
| assert.Equal(t, 4880, usage.CoreRemaining, "core remaining should match last entry") | ||
| assert.Equal(t, 5000, usage.CoreLimit, "core limit should be 5000") | ||
|
|
||
|
|
@@ -103,6 +104,48 @@ func TestParseGitHubRateLimitsFileOnlyAPISnapshots(t *testing.T) { | |
| require.NotNil(t, usage, "usage should not be nil") | ||
|
|
||
| assert.Equal(t, 0, usage.TotalRequestsMade, "should count 0 API calls from response_headers") | ||
| 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") | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| // TestParseGitHubRateLimitsFileOnlyAPISnapshotsWindowReset verifies snapshot-only | ||
| // runs still produce a lower-bound consumption value when the window resets. | ||
| func TestParseGitHubRateLimitsFileOnlyAPISnapshotsWindowReset(t *testing.T) { | ||
| content := `{"timestamp":"2026-04-05T08:00:00.000Z","source":"rate_limit_api","operation":"startup","resource":"core","limit":5000,"remaining":100,"used":4900,"reset":"2026-04-05T09:00:00.000Z"} | ||
| {"timestamp":"2026-04-05T09:00:10.000Z","source":"rate_limit_api","operation":"shutdown","resource":"core","limit":5000,"remaining":4995,"used":5,"reset":"2026-04-05T10:00:00.000Z"} | ||
| ` | ||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "github_rate_limits.jsonl") | ||
| require.NoError(t, os.WriteFile(path, []byte(content), 0600), "should write test JSONL file") | ||
|
|
||
| usage, err := parseGitHubRateLimitsFile(path) | ||
| require.NoError(t, err, "should not return an error") | ||
| require.NotNil(t, usage, "usage should not be nil") | ||
|
|
||
| assert.Equal(t, 0, usage.TotalRequestsMade, "should count 0 API calls from response_headers") | ||
| assert.Equal(t, 5, usage.CoreConsumed, "window reset should fall back to last snapshot used value") | ||
| assert.Equal(t, "rate_limit_api_delta", usage.CoreConsumedSource, "core consumed source should come from rate_limit_api snapshots") | ||
| } | ||
|
|
||
| // TestParseGitHubRateLimitsFileOnlyAPISnapshotSingle verifies that a file containing | ||
| // exactly one rate_limit_api snapshot (no response_headers) produces CoreConsumed==0 | ||
| // with provenance tagged as rate_limit_api_single_snapshot. | ||
| func TestParseGitHubRateLimitsFileOnlyAPISnapshotSingle(t *testing.T) { | ||
| content := `{"timestamp":"2026-04-05T08:00:00.000Z","source":"rate_limit_api","operation":"startup","resource":"core","limit":5000,"remaining":4850,"used":150,"reset":"2026-04-05T09:00:00.000Z"} | ||
| ` | ||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "github_rate_limits.jsonl") | ||
| require.NoError(t, os.WriteFile(path, []byte(content), 0600), "should write test JSONL file") | ||
|
|
||
| usage, err := parseGitHubRateLimitsFile(path) | ||
| require.NoError(t, err, "should not return an error") | ||
| require.NotNil(t, usage, "usage should not be nil") | ||
|
|
||
| assert.Equal(t, 0, usage.TotalRequestsMade, "should count 0 API calls from response_headers") | ||
| assert.Equal(t, 0, usage.CoreConsumed, "single snapshot cannot compute a delta; consumed should be 0") | ||
| assert.Equal(t, "rate_limit_api_single_snapshot", usage.CoreConsumedSource, "provenance should be rate_limit_api_single_snapshot") | ||
| assert.Equal(t, 4850, usage.CoreRemaining, "core remaining should match snapshot value") | ||
| assert.Equal(t, 5000, usage.CoreLimit, "core limit should match snapshot value") | ||
| } | ||
|
|
||
| // TestFindGitHubRateLimitsFileAbsent verifies that findGitHubRateLimitsFile returns | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_consumedviafirstSnapshotUsed/lastSnapshotUsed.