-
Notifications
You must be signed in to change notification settings - Fork 39
Fix logs command not finding all runs when no workflow name is specified #2045
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ce94a73
Initial plan
Copilot 773111f
Fix logs command filtering issue for all workflows
Copilot 75e6f6c
Add documentation for logs command filtering fix
Copilot abb9288
Complete fix for logs command filtering issue - all validations pass
Copilot 10bc9bf
Add changeset for logs command filtering fix
github-actions[bot] 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Logs Command Filtering Fix | ||
|
|
||
| ## Problem Description | ||
|
|
||
| The `logs` command was not finding all workflow runs when no workflow name was specified. | ||
|
|
||
| **Reproduction:** | ||
| ```bash | ||
| ./gh-aw logs tidy -c 10 # Returns 10 runs | ||
| ./gh-aw logs -c 10 # Returns fewer than 10 runs (inconsistent) | ||
| ``` | ||
|
|
||
| ## Root Cause | ||
|
|
||
| The issue was in the pagination logic in `pkg/cli/logs.go`: | ||
|
|
||
| 1. `listWorkflowRunsWithPagination()` fetches workflow runs from GitHub API | ||
| 2. When no workflow name is specified, it filters results to only agentic workflows | ||
| 3. The iteration loop checked if `len(filteredRuns) < batchSize` to detect end of data | ||
| 4. This caused premature termination when few agentic workflows were in a batch | ||
|
|
||
| **Example scenario:** | ||
| - Request 10 agentic workflow runs | ||
| - First batch: Fetch 250 runs from API → Only 5 are agentic workflows after filtering | ||
| - **Bug**: `len(filteredRuns)=5 < batchSize=250` → Stop iteration ❌ | ||
| - **Expected**: Continue iterating to find more agentic workflows ✓ | ||
|
|
||
| ## Solution | ||
|
|
||
| Modified `listWorkflowRunsWithPagination()` to return two values: | ||
| 1. Filtered workflow runs (agentic only when no workflow name specified) | ||
| 2. Total count fetched from GitHub API (before filtering) | ||
|
|
||
| Changed the end-of-data check from: | ||
| ```go | ||
| if len(runs) < batchSize { // WRONG: uses filtered count | ||
| break | ||
| } | ||
| ``` | ||
|
|
||
| To: | ||
| ```go | ||
| if totalFetched < batchSize { // CORRECT: uses API response count | ||
| break | ||
| } | ||
| ``` | ||
|
|
||
| This ensures iteration continues until: | ||
| - We have enough agentic workflow runs, OR | ||
| - We truly reach the end of GitHub data (API returns fewer than requested) | ||
|
|
||
| ## Files Changed | ||
|
|
||
| 1. **pkg/cli/logs.go** | ||
| - Modified `listWorkflowRunsWithPagination()` signature to return `([]WorkflowRun, int, error)` | ||
| - Added `totalFetched` tracking before filtering | ||
| - Updated end-of-data check to use `totalFetched` | ||
| - Added comprehensive comments explaining the fix | ||
|
|
||
| 2. **pkg/cli/logs_test.go** | ||
| - Updated test to handle new return value from `listWorkflowRunsWithPagination()` | ||
|
|
||
| 3. **pkg/cli/logs_filtering_test.go** (new) | ||
| - Added documentation tests explaining the expected behavior | ||
| - Tests are skipped (network-dependent) but serve as documentation | ||
|
|
||
| ## Testing | ||
|
|
||
| All existing unit tests pass: | ||
| ```bash | ||
| make test-unit # ✓ All tests pass | ||
| make lint # ✓ No issues | ||
| make build # ✓ Compiles successfully | ||
| ``` | ||
|
|
||
| ## Impact | ||
|
|
||
| This fix ensures consistent behavior: | ||
| - `./gh-aw logs -c 10` now returns 10 agentic workflow runs (not fewer) | ||
| - `./gh-aw logs tidy -c 10` behavior unchanged (still returns 10 runs) | ||
| - No performance impact (still uses efficient batch fetching) | ||
| - No breaking changes (CLI interface unchanged) | ||
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestListWorkflowRunsWithPagination_ReturnsTotalFetchedCount verifies that | ||
| // the function returns both the filtered runs and the total count fetched from API | ||
| func TestListWorkflowRunsWithPagination_ReturnsTotalFetchedCount(t *testing.T) { | ||
| t.Skip("Skipping network-dependent test - this verifies the fix for filtering issue") | ||
|
|
||
| // This test would require actual GitHub CLI access to work properly | ||
| // The key insight is that the function should return: | ||
| // 1. Filtered runs (e.g., 5 agentic workflows) | ||
| // 2. Total fetched count (e.g., 250 total runs from API) | ||
| // | ||
| // This allows the caller to properly detect when it has reached the end | ||
| // of available runs by checking totalFetched < batchSize, not len(runs) < batchSize | ||
|
|
||
| // Example scenario that would fail with old code: | ||
| // - Request 250 runs from GitHub API | ||
| // - API returns 250 runs (mix of agentic and non-agentic) | ||
| // - Only 5 are agentic workflows after filtering | ||
| // - Old code: checks len(runs)=5 < batchSize=250, stops iteration incorrectly | ||
| // - New code: checks totalFetched=250 < batchSize=250 is false, continues iteration | ||
| } | ||
|
|
||
| // TestDownloadWorkflowLogs_IteratesUntilEnoughRuns demonstrates the fixed behavior | ||
| func TestDownloadWorkflowLogs_IteratesUntilEnoughRuns(t *testing.T) { | ||
| t.Skip("Skipping network-dependent test - this would verify end-to-end behavior") | ||
|
|
||
| // This test would verify that when calling: | ||
| // ./gh-aw logs -c 10 (no workflow name) | ||
| // | ||
| // The function: | ||
| // 1. Fetches batches of runs until it has 10 agentic workflow runs | ||
| // 2. Continues iterating if first batch has few agentic workflows | ||
| // 3. Only stops when totalFetched < batchSize (reached end of GitHub data) | ||
| // 4. Returns the same number of results as: | ||
| // ./gh-aw logs tidy -c 10 (specific workflow name) | ||
| } |
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
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.
@copilot remove file
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.
Removed in abb9288