Skip to content

fix(aw-compat): gh aw fix returns exit code 2 and correct summary when guided-error codemod fires#43169

Merged
pelikhan merged 5 commits into
mainfrom
copilot/aw-compat-fix-gh-aw-reporting
Jul 4, 2026
Merged

fix(aw-compat): gh aw fix returns exit code 2 and correct summary when guided-error codemod fires#43169
pelikhan merged 5 commits into
mainfrom
copilot/aw-compat-fix-gh-aw-reporting

Conversation

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

gh aw fix was printing ✓ No fixes needed (exit 0) even when a guided-error codemod (e.g. top-level-env-secrets-guided-error) fired, because processing errors caused the file to be skipped before the fix counter was incremented — leaving the summary with zero fixes and a false success signal.

Changes

  • GuidedError sentinel type (fix_codemods.go) — new error type with Unwrap support; distinguishes manual-fix conditions from hard processing failures.
  • Guided bool field on Codemod — marks codemods whose Apply errors are advisory (not auto-correctable). getTopLevelEnvSecretsGuidedErrorCodemod is the first consumer.
  • processWorkflowFileWithInfo — wraps errors from Guided: true codemods as &GuidedError{Cause: ...} so the caller can identify them via errors.As.
  • runFixCommand summary logic:
    • Tracks totalGuidedErrors separately from auto-fix counts.
    • Suppresses ✓ No fixes needed when guided errors are present.
    • Prints ✗ N file(s) need a manual fix.
    • Returns &ExitCodeError{Code: 2} — distinct from the crash exit code (1) so automation can branch on this condition.

Before / After

# Before
✗ Error processing smoke.md: codemod top-level-env-secrets-guided-error failed: ...Manual fix required...
i ✓ No fixes needed
$ echo $?
0

# After
✗ Error processing smoke.md: codemod top-level-env-secrets-guided-error failed: ...Manual fix required...
✗ 1 file needs a manual fix
$ echo $?
2

Generated by 👨‍🍳 PR Sous Chef · 7.05 AIC · ⌖ 5.18 AIC · ⊞ 6.6K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 3, 2026 10:40
… message

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 gh aw reporting manual fixes needed incorrectly fix(aw-compat): gh aw fix returns exit code 2 and correct summary when guided-error codemod fires Jul 3, 2026
Copilot AI requested a review from pelikhan July 3, 2026 10:44
@github-actions github-actions Bot mentioned this pull request Jul 3, 2026
@pelikhan pelikhan marked this pull request as ready for review July 3, 2026 12:50
Copilot AI review requested due to automatic review settings July 3, 2026 12:50

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 gh aw fix’s behavior when a “guided/manual-fix” codemod fires (e.g., top-level env: secrets): instead of reporting “No fixes needed” with exit code 0, it now emits a manual-fix summary and returns an ExitCodeError{Code: 2} so automation can branch on “manual intervention required”.

Changes:

  • Introduces a GuidedError sentinel (with Unwrap) and a Codemod.Guided flag to classify advisory/manual-fix codemod failures.
  • Updates processWorkflowFileWithInfo to wrap Apply errors from Guided: true codemods as GuidedError.
  • Updates runFixCommand to count guided errors, suppress “✓ No fixes needed” when present, print a manual-fix summary line, and return exit code 2.
  • Adds tests covering exit code 2, suppression of “No fixes needed”, pluralization, and GuidedError wrapping.
Show a summary per file
File Description
pkg/cli/fix_command.go Tracks guided/manual-fix codemod errors, adjusts summary output, and returns exit code 2 when manual fixes are required.
pkg/cli/fix_command_test.go Adds regression tests for guided-error exit code + output behavior and for GuidedError wrapping.
pkg/cli/fix_codemods.go Adds Codemod.Guided and the GuidedError sentinel type.
pkg/cli/codemod_engine_env_secrets.go Marks the top-level env secrets codemod as Guided: true.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread pkg/cli/fix_command.go
Comment on lines 172 to +176
fmt.Fprintf(os.Stderr, "%s\n", console.FormatErrorMessage(fmt.Sprintf("Error processing %s: %v", filepath.Base(file), err)))
var guidedErr *GuidedError
if errors.As(err, &guidedErr) {
totalGuidedErrors++
}
Comment thread pkg/cli/fix_command.go
Comment on lines 246 to 250
if totalFixed > 0 {
fmt.Fprintf(os.Stderr, "%s\n", console.FormatSuccessMessage(fmt.Sprintf("✓ Fixed %d of %d workflow files", totalFixed, totalFiles)))
} else {
} else if totalGuidedErrors == 0 {
fmt.Fprintf(os.Stderr, "%s\n", console.FormatInfoMessage("✓ No fixes needed"))
}
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category bug
Risk 🟢 Low
Score 60/100 (Impact 28 + Urgency 18 + Quality 14)
Action fast_track
Batch pr-batch:safe-output-fixes (with #43168)

Score Breakdown

  • Impact (28/50): Fixes gh aw fix false success signal — important CLI correctness fix
  • Urgency (18/30): CI checks all skipped; no reviews; surgical 4-file change
  • Quality (14/20): Precise root-cause description, minimal scope, targeted fix

Batch candidate with #43168 (safe-output ingestion hardening). Both are small, clean bug fixes.

Generated by 🔧 PR Triage Agent · 92.3 AIC · ⌖ 6.73 AIC · ⊞ 5.5K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address unresolved review comments, and rerun checks once the branch is up to date.

Generated by 👨‍🍳 PR Sous Chef · 7.05 AIC · ⌖ 5.18 AIC · ⊞ 6.6K ·
Comment /souschef to run again

…nd return exit 1 on hard processing errors

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address unresolved review comments, and rerun checks once the branch is up to date.

...

Done — addressed both unresolved review threads in commit fix: count guided-error files in totalFiles; suppress false success and return exit 1 on hard processing errors:

  1. totalFiles denominator — guided-error files are now counted in totalFiles (incremented before the continue), so the "Fixed X of Y" summary is accurate when a mix of clean, guided-error, and hard-error files is processed.

  2. Hard processing errors — a new totalProcessingErrors counter tracks non-guided failures (read/parse/write errors). When non-zero, "✓ No fixes needed" is suppressed and the function returns ExitCodeError{Code: 1}, giving automation a clear non-zero signal distinct from the guided-error code 2.

Three new tests were added: exit code 1 for hard errors, suppression of "No fixes needed" for hard errors, and a mixed-file test verifying totalFiles includes guided-error files. Local make fmt and make test-unit are green.

Copilot AI requested a review from gh-aw-bot July 3, 2026 14:42
@pelikhan pelikhan merged commit 068e5ab into main Jul 4, 2026
29 checks passed
@pelikhan pelikhan deleted the copilot/aw-compat-fix-gh-aw-reporting branch July 4, 2026 03:04
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.3

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.

[aw-compat] gh aw fix: reports "✓ No fixes needed" (exit 0) while a guided-error codemod says "Manual fix required"

4 participants