Skip to content

Fix gh aw logs discarding all processed runs due to variable shadowing - #49332

Merged
pelikhan merged 3 commits into
mainfrom
copilot/agentic-token-audit-2026-07-31
Jul 31, 2026
Merged

Fix gh aw logs discarding all processed runs due to variable shadowing#49332
pelikhan merged 3 commits into
mainfrom
copilot/agentic-token-audit-2026-07-31

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

The daily token-audit workflow reported zero runs despite gh aw logs visibly downloading artifacts for ~100 runs over 7 minutes. The collection window was fine — gh aw logs was silently dropping every processed run.

In collectProcessedWorkflowRuns, the batch results were assigned with := inside the for body. Since the loop body is its own scope, this declared a new processedRuns that shadowed the function-level accumulator, so each batch's results were discarded at the end of the iteration:

for iteration < MaxIterations {
    ...
    // shadows the outer processedRuns — results never accumulate
    processedRuns, batchProcessed, allRunsConsumed, timedOut := processWorkflowRunBatch(
        runtime.activeCtx, batch, processedRuns, ...)
}

The knock-on effects: len(processedRuns) stayed at 0, so the count cap never tripped and the loop paginated through every available run, then exited via handleEmptyProcessedRuns with No workflow runs with artifacts found matching the specified criteria and .runs == [] in JSON output.

Changes

  • pkg/cli/logs_orchestrator_download.go — pre-declare the batch outputs and assign with = so runs accumulate across iterations. The batch flag is renamed to batchTimedOut to avoid colliding with the timedOut already declared earlier in the same block.
  • Test seamslogsFetchWorkflowRunBatch and logsProcessWorkflowRunBatch package vars, following the existing forecastListWorkflowRunsPaginated pattern, so the collection loop can be exercised without the GitHub API.
  • pkg/cli/logs_orchestrator_unit_test.goTestCollectProcessedWorkflowRunsAccumulatesBatches drives two batches through the loop and asserts all three runs survive. It reproduces the bug on the pre-fix code (should have 3 item(s), but has 0).
  • Changeset — patch entry.

.github/workflows/agentic-token-audit.md is upstream-managed (source: githubnext/agentic-ops@…) and is deliberately untouched; the defect was in the CLI.

Worth noting for reviewers: the skip paths in shouldSkipProcessedWorkflowRun are verbose-gated, which is why the failure surfaced as a plausible-looking "empty window" rather than an error. No linter in .golangci.yml currently catches this class of shadowing.


Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.7 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 31, 2026 12:52
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix empty log collection for agentic token audit Fix gh aw logs discarding all processed runs due to variable shadowing Jul 31, 2026
Copilot AI requested a review from pelikhan July 31, 2026 12:55
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Category: bug (log-collection fix)
Risk: low
Priority: 25/100 (impact 10, urgency 5, quality 10)
Recommended action: defer

Rationale: PR is marked [WIP], is a draft, has 0 diff (no committed changes yet), and CI check copilot is still in_progress. No files changed yet, nothing to review. Revisit once the fix is pushed and CI completes.

Labels applied: pr-type:bug, pr-risk:low, pr-priority:low, pr-action:defer, pr-agent:copilot.

Generated by 🔧 PR Triage Agent · auto · 38.1 AIC · ⌖ 7.66 AIC · ⊞ 7.9K ·

@pelikhan
pelikhan marked this pull request as ready for review July 31, 2026 13:02
Copilot AI review requested due to automatic review settings July 31, 2026 13:02

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

Fixes gh aw logs dropping processed runs because of loop-scoped variable shadowing.

Changes:

  • Preserves accumulated runs across batches.
  • Adds injectable test seams and a regression test.
  • Adds a patch changeset.
Show a summary per file
File Description
pkg/cli/logs_orchestrator_download.go Corrects batch-result assignment.
pkg/cli/logs_orchestrator_unit_test.go Verifies multi-batch accumulation.
.changeset/fix-logs-processed-runs-shadowing.md Documents the user-facing fix.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill on this PR. The branch refresh was requested from sous-chef run https://github.com/github/gh-aw/actions/runs/30632990067. Then confirm whether any remaining follow-up is needed before merge.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 16.7 AIC · ⊞ 8.1K ·
Comment /souschef to run again

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #49332 does not have the implementation label and has only 59 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Ran the pr-finisher pass. No code changes were needed.

  • Branch is already current with main (behind=0 on 16f7657).
  • No unresolved review threads are present.
  • Local make fmt, make lint, make test-unit, and make test all passed.
  • The referenced sous-chef run had no failed jobs; the threat-detection note looks like a tooling-only failure.

Remaining follow-up before merge: let the current copilot check on this PR finish. If that completes successfully, I don’t see any other agent-actionable blocker.

Copilot AI requested a review from gh-aw-bot July 31, 2026 13:25

@github-actions github-actions Bot 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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

The fix is correct and the approach is clean.

  • The root cause (:= shadowing the outer processedRuns accumulator) is accurately identified and the fix (pre-declare + plain =) is the right minimal change.
  • The test seam pattern (logsFetchWorkflowRunBatch / logsProcessWorkflowRunBatch package vars with t.Cleanup restore) follows the existing convention and the regression test faithfully reproduces the bug.
  • batchTimedOut rename cleanly resolves the name collision.

No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 12.9 AIC · ⊞ 5.3K

@github-actions

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🎉 Great work! This PR looks ready for review. The variable shadowing bug is clearly identified and fixed, with a well-designed regression test that validates the batch accumulation across loop iterations. The changeset documentation is precise, and the refactoring (introducing test seams via logsFetchWorkflowRunBatch and logsProcessWorkflowRunBatch) follows the existing patterns in the codebase (like forecastListWorkflowRunsPaginated).

A few observations for maintainers:

  • Test design — The test effectively reproduces the original bug by verifying that runs from both batches accumulate (asserting len(runs) == 3 with specific DatabaseIDs from different batches).
  • Variable shadowing — Renaming timedOut to batchTimedOut avoids the collision and makes the code self-documenting.
  • Linter coverage — Worth noting that no existing linter in .golangci.yml catches this class of shadowing, which could be a future improvement.

The PR is small, focused, and ready to merge.

Generated by ✅ Contribution Check · auto · 56.6 AIC · ⊞ 8.7K ·

@github-actions

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test Quality Sentinel Report

Test Quality Score: 86/100 — Excellent

Analyzed 7 test(s): 7 design, 0 implementation, 0 violation(s).

📊 Metrics (7 tests)
Metric Value
Analyzed 7 (Go: 7, JS: 0)
✅ Design 7 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 6 (86%)
Duplicate clusters 0
Inflation YES (test +46 lines vs prod +13 lines = 3.5:1)
🚨 Violations 0
Test File Classification Issues
TestIsDeadlineExceeded logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestNoRunsMessage logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestParseFilterDate logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestBuildContinuationIfNeeded logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestComputeLogsBatchSize logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestHandleEmptyWorkflowRunBatch logs_orchestrator_unit_test.go behavioral_contract, design_test None
TestCollectProcessedWorkflowRunsAccumulatesBatches logs_orchestrator_unit_test.go behavioral_contract, design_test None
⚠️ Flagged (1 — inflation only)

Inflation (pkg/cli/logs_orchestrator_unit_test.go) — test file added 46 lines vs 13 in the production file (3.5:1). This exceeds the 2:1 threshold but is justified: the PR fixes a variable-shadowing bug and the tests cover multiple distinct behavioral contracts (deadline detection, message generation, date parsing, continuation cursor, batch sizing, pagination).

Verdict

passed. 0% implementation tests (threshold: 30%). The regression test TestCollectProcessedWorkflowRunsAccumulatesBatches directly verifies the fixed bug using injected function vars, confirming runs accumulate across pagination iterations. All 7 tests carry descriptive assertion messages and cover error/edge paths.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 45.9 AIC · ⊞ 8.4K ·
Comment /review to run again

@github-actions github-actions Bot 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.

✅ Test Quality Sentinel: 86/100. 0% implementation tests (threshold: 30%).

@github-actions github-actions Bot 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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: Approve — no blocking issues

Correct, minimal, well-tested fix for the := shadowing bug that discarded processedRuns on every batch.

Review notes
  • Fix: pre-declaring batchProcessed, allRunsConsumed, batchTimedOut and assigning with = correctly restores accumulation into the outer processedRuns. Verified no other := shadowing of this pattern exists elsewhere in the file.
  • Test seam: logsFetchWorkflowRunBatch / logsProcessWorkflowRunBatch package-level var indirection follows the existing forecastListWorkflowRunsPaginated convention in this package — consistent style, no other direct callers of fetchWorkflowRunBatch/processWorkflowRunBatch bypass it.
  • Regression test TestCollectProcessedWorkflowRunsAccumulatesBatches reproduces the bug pre-fix and passes post-fix. No t.Parallel() in this file, so the shared package-level var swap-and-restore via t.Cleanup is safe from cross-test races.
  • Renaming timedOut to batchTimedOut avoids the naming collision with the outer-scope timedOut, reducing future shadowing risk in this same function.

A background grumpy-coder sub-agent pass and my own independent review of the diff found no additional correctness, concurrency, or maintainability issues within the changed lines.

🔎 Code quality review by PR Code Quality Reviewer · auto · 54.7 AIC · ⊞ 7.8K
Comment /review to run again

@github-actions github-actions Bot 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.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — approving. The root cause is correctly identified and fixed, and the regression test faithfully reproduces the original failure.

📋 Key Themes & Highlights

Key Themes

  • Root cause fixed, not just the symptom — the := shadowing is eliminated by pre-declaring variables before the loop and using = assignment
  • Regression test covers the exact failure modeTestCollectProcessedWorkflowRunsAccumulatesBatches would have caught this before the bad code shipped
  • Test seams follow the established forecastListWorkflowRunsPaginated pattern — consistent and easy to navigate

Positive Highlights

  • ✅ Informative inline comment explaining why = is used (not :=) — prevents future contributors from reintroducing the bug
  • batchTimedOut rename avoids a collision with the outer timedOut; clearer scope separation
  • ✅ Changeset entry is accurate and user-facing
  • ✅ Test uses t.Cleanup to restore the package-level vars — safe for parallel future tests

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 38.7 AIC · ⊞ 7K
Comment /matt to run again

@pelikhan
pelikhan merged commit ccf88b8 into main Jul 31, 2026
86 of 96 checks passed
@pelikhan
pelikhan deleted the copilot/agentic-token-audit-2026-07-31 branch July 31, 2026 13:33
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[agentic-token-audit] 2026-07-31 — Empty log collection window, no AIC data to report

4 participants