Skip to content

trial: fail and report rejected safe-output errors instead of always reporting success - #50723

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-issue-with-trial-output
Aug 6, 2026
Merged

trial: fail and report rejected safe-output errors instead of always reporting success#50723
pelikhan merged 6 commits into
mainfrom
copilot/fix-issue-with-trial-output

Conversation

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

gh aw trial unconditionally printed "All trials completed successfully" and exited 0 even when a workflow's safe-outputs artifact contained a non-empty errors array from rejected messages, silently masking partial failures from CI gates and automation.

Detection

  • Added extractSafeOutputErrors helper to parse the errors array out of a workflow's safe-outputs artifact.

Result reporting

  • Added Success and SafeOutputErrors fields to WorkflowTrialResult, and Success to CombinedTrialResult, so the --json output exposes an explicit pass/fail signal instead of requiring consumers to inspect nested errors arrays.
  • Per-workflow rejected messages are now printed to stderr as they're encountered.

Exit behavior

  • After the per-workflow loop, executeTrialRun now aggregates results across all workflows. If any workflow has safe-output errors, it returns a nonzero error reporting the total rejected count and the first error message, instead of the unconditional success message.
{
  "workflow_name": "example",
  "success": false,
  "safe_output_errors": [
    "Line 1: set_issue_field requires at least one of: 'field_name', 'field_node_id' fields"
  ]
}

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Run: https://github.com/github/gh-aw/actions/runs/31062758914> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 20.1 AIC · ⊞ 8.3K ·

Comment /souschef to run again

Copilot AI and others added 2 commits August 6, 2026 00:43
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 trial command exit code when errors are present trial: fail and report rejected safe-output errors instead of always reporting success Aug 6, 2026
Copilot AI requested a review from pelikhan August 6, 2026 00:44
@pelikhan
pelikhan marked this pull request as ready for review August 6, 2026 00:50
Copilot AI balanced review requested due to automatic review settings August 6, 2026 00: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

Detects rejected safe-output messages during gh aw trial and reports failed trials explicitly.

Changes:

  • Extracts safe-output errors and records success status.
  • Aggregates failures and returns a nonzero error.
  • Adds unit tests for error extraction and status fields.
Show a summary per file
File Description
pkg/cli/trial_types.go Adds status fields and error extraction.
pkg/cli/trial_helpers.go Reports and aggregates rejected messages.
pkg/cli/trial_safe_output_errors_test.go Tests extraction and result fields.

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: 4
  • Review effort level: Balanced

Comment thread pkg/cli/trial_helpers.go
Comment on lines +134 to +135
Success: len(safeOutputErrors) == 0,
SafeOutputErrors: safeOutputErrors,

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.

Fixed in latest commit: when --json is set, executeTrialRun now marshals the full WorkflowTrialResult (and CombinedTrialResult for multi-workflow runs) to stdout instead of the raw safe-outputs artifact, so success/safe_output_errors are exposed.

Comment thread pkg/cli/trial_helpers.go Outdated
if len(safeOutputErrors) > 0 {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("=== %d Safe Output Message(s) Rejected from %s ===", len(safeOutputErrors), parsedSpec.WorkflowName)))
for _, msg := range safeOutputErrors {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(msg))

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 sanitizeControlChars which escapes control characters (e.g. ANSI escapes, newlines) before rejected messages are written to stderr.

Comment on lines +64 to +67
Success: false,
}
if result.Success {
t.Error("expected Success to be false when SafeOutputErrors is non-empty")

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.

Factored the aggregation logic into aggregateTrialResults(results []WorkflowTrialResult) (bool, int, string), now used by executeTrialRun, and added TestAggregateTrialResults covering success/failure counts and first-error ordering across multiple workflows.

Comment thread pkg/cli/trial_helpers.go Outdated

if !overallSuccess {
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(fmt.Sprintf("Trial completed with %d rejected safe-output message(s)", totalRejected)))
return fmt.Errorf("trial completed with %d rejected safe-output message(s); first error: %s", totalRejected, firstErrorMessage)

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.

firstErrorMessage is now passed through sanitizeControlChars before being embedded in the returned error.

@pelikhan

pelikhan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Copilot AI and others added 2 commits August 6, 2026 01:18
…d aggregation tests

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Great work on this fix, Copilot! 🎯 This PR directly addresses the critical issue where gh aw trial was masking partial failures from safe-output rejections.

The implementation is solid:

  • DetectionextractSafeOutputErrors cleanly parses the errors array from safe-outputs artifacts
  • Result reporting — Adding explicit Success and SafeOutputErrors fields to result types gives consumers (CI gates, automation) a clear pass/fail signal without JSON parsing gymnastics
  • Exit behavior — Aggregating errors across all workflows and returning nonzero when any workflow fails is the right call for CI integration

The diff is focused, well-scoped to the single issue, and the PR body clearly explains detection, reporting, and exit behavior changes. Tests appear to be included. This looks ready for review and merge!

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

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please resolve the remaining review threads, refresh this branch if needed, then run the pr-finisher skill and push any follow-up fixes.

Run: https://github.com/github/gh-aw/actions/runs/31062758914

Generated by PR Sous Chef

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

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

...

All four flagged review threads are already addressed in the current HEAD (0fb05e0): --json now serializes the full WorkflowTrialResult/CombinedTrialResult shape, sanitizeControlChars sanitizes rejected messages written to stderr, aggregateTrialResults is factored out and covered by TestAggregateTrialResults, and the returned first-error message is sanitized too. Verified with go build ./... and the trial-related tests (all pass), and make fmt produced no diff. I don't have a tool in this environment to mark the review threads resolved, so they remain open pending a maintainer/reviewer resolving them — no further code changes are needed here.

Copilot AI requested a review from gh-aw-bot August 6, 2026 01:39
@pelikhan
pelikhan merged commit 5ca9076 into main Aug 6, 2026
31 checks passed
@pelikhan
pelikhan deleted the copilot/fix-issue-with-trial-output branch August 6, 2026 02:24
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.85.4

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.

trial: reports "All trials completed successfully" and exits 0 when safe-output results contain errors

4 participants