Repository navigation
Account for threat detection outcomes in audit and health reports - #75691
Conversation
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
|
🚀 PR Specification Reviewer has started processing this pull request |
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check. Warning Threat detection engine error Threat detection could not complete its analysis due to a tooling error. This is not a security finding. What happenedThe threat detection results could not be parsed. Review the workflow run logs to troubleshoot the error.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Ponytail Reviewer completed successfully!
|
|
Warning Threat detection engine error Threat detection could not complete its analysis due to a tooling error. This is not a security finding. What happenedThe threat detection results could not be parsed. Review the workflow run logs to troubleshoot the error. Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). 📄 Draft ADR committed:
📋 Gate evidence
📋 What to do next
Once the ADR is linked in the PR body, this gate will re-run and verify that the implementation matches the decision. 📋 Michael Nygard ADR format referenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
What this change does: It carries threat-detection outcomes into audit findings and health degradation, including recovery from older conclusion-job logs. The new tests cover audit classification, health rollups, raw job evidence, and output.
Should fix:
-
Duplicate stale-cache matrix (
pkg/cli/health_detection_test.go:L105-L138)- What this is: The new test repeats the 11-field cache-compatibility matrix already in
pkg/cli/health_subagents_test.go. - Problem: Both paths call
loadHealthRunSummary, so these cases exercise shared validation rather than detection logic. Every cache-field change now needs two copies. - Fix: Keep one detection-specific stale-cache assertion and move the full matrix to a shared
loadHealthRunSummarytest. - If we skip it: The matrices can drift and add about 35 lines of maintenance-only test code.
- What this is: The new test repeats the 11-field cache-compatibility matrix already in
Verdict: fix 1 first.
Lean: -35 lines possible.
Generated by ✂️ Ponytail Reviewer for #75691 · codex · routed: gpt56 max · ~7 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| } | ||
|
|
||
| func TestHealthDetectionFailuresRejectStaleCache(t *testing.T) { | ||
| for _, field := range []string{"run-id", "summary-id", "url", "repository", "attempt", "revision", "workflow", "updated", "status", "conclusion", "version"} { |
There was a problem hiding this comment.
What this is: This 11-case matrix duplicates the same stale-cache field checks in pkg/cli/health_subagents_test.go, while both paths call loadHealthRunSummary. Problem: These subtests exercise shared cache validation, not detection handling, so every cache-field change now requires two copies and adds about 35 test lines without new coverage. Fix: Keep one detection-specific incompatible-cache case and move the full field matrix to a shared loadHealthRunSummary test (or delete this duplicate). If we skip it: The two matrices can drift and make cache changes needlessly expensive to maintain.
There was a problem hiding this comment.
Removed the duplicate detection cache-field matrix; shared loader validation remains in health_subagents_test.go, and raw-job tests retain detection-specific cache coverage. Addressed in a060845.
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Found correctness and robustness issues that should be addressed before merge.
Findings
- Mixed detection and sub-agent failures overwrite each other in workflow and revision status, and the concise status output hides one warning.
- Legacy detection recovery trusts spoofable log text and reads unbounded log content on a fleet-health path.
Review was static per the review instructions; no tests or repository code were executed.
Comments that could not be inline-anchored
pkg/cli/health_detection.go:42
This overwrites the existing workflow status whenever detection findings exist, so a run with both detection and sub-agent failures no longer reports the sub-agent degradation in its primary status. <details><summary>💡 Preserve independent degradation signals</summary> `applyHealthSubagentFailures` runs immediately before this function, and this assignment discards its `subagent_failures_observed` status (and can also replace other evidence states). Keep the existing status unless it is a low...
pkg/cli/health_detection.go:49
This similarly replaces the revision status with `detection_failures_observed`, hiding that the current revision also has sub-agent failures. <details><summary>💡 Do not erase revision-level failure signals</summary> The revision status is rendered as the compact per-revision health summary, so this assignment makes mixed failures look like detection-only failures even though `SubagentFailures` remains nonzero. Compose the status or retain both dimensions in the revision data instead of overwr...
pkg/cli/audit_threat_detection_logs.go:38
This fallback trusts any conclusion-job step that prints a matching `env:` block, so a user-controlled step can forge a successful detection outcome and suppress the only available warning or threat result for older artifacts. <details><summary>💡 Require trustworthy provenance for recovered outcomes</summary> The parser checks formatting and enum values but cannot distinguish runner-emitted detection environment from workflow output that echoes the same text. Restrict recovery to a compiler/r...
pkg/cli/audit_threat_detection_logs.go:31
This fallback reads entire conclusion log files into memory for every run without a byte or line limit, creating avoidable memory and latency growth when health scans many runs or encounters a large log. <details><summary>💡 Bound legacy-log recovery</summary> The JSON path is capped at 1 MiB, but `readLogLines` and `readJobLogLines` are unbounded here and this code is now on the missing-result path used by fleet health. Read only a bounded prefix or stream until the relevant block is found, w...
pkg/cli/health_command.go:330
This `else if` suppresses the sub-agent warning whenever detection failures are present, so the detailed status line no longer reports all observed degradation types. <details><summary>💡 Emit independent warnings</summary> A workflow can have both failure classes, and the rest of the change intentionally preserves both counts. Use separate `if` statements (or combine both facts in one message) so operators are not told only about detection while missing a delegation failure. </details>
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~5 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /grill-with-docs. Requesting changes on status precedence and on docs that contradict the new degraded_workflows behaviour.
📋 Key Themes & Highlights
Key Themes
- Status precedence:
applyHealthDetectionFailuresoverwrites the sub-agent status, so sub-agent failures are hidden at the top level and in the text report (health_detection.go:44,health_command.go:319). - Docs drift:
degraded_workflowsnow counts detection failures, butcli.md:1129and ADR 70885 still say it is sub-agent-only.
Positive Highlights
- ✅ Cache identity checks in
loadHealthRunSummarycover run, attempt, SHA, workflow, and update time. Stale evidence is rejected. - ✅ Audit error and warning counts use
max()against the detection-derived counts, so they are not double-counted. - ✅ Targeted
go test ./pkg/clipasses.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again
| if health.SubagentFailureCount > 0 { | ||
| if health.DetectionFailureRuns > 0 { | ||
| fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("%d run(s) have threat-detection failures or threats; Actions success rate does not establish successful threat detection", health.DetectionFailureRuns))) | ||
| } else if health.SubagentFailureCount > 0 { |
There was a problem hiding this comment.
[/diagnosing-bugs] This else if means a workflow with both detection and sub-agent failures prints only the detection warning, so the sub-agent warning is dropped from the text report. These are independent problems, so print both lines instead of choosing one.
@copilot please address this.
There was a problem hiding this comment.
Detection and sub-agent warnings now print independently, with success/threshold messaging suppressed when either is present. Addressed in a060845.
|
|
||
| Health also reads matching `run_summary.json` files from `--logs-dir` (default: `.github/aw/logs`) for failed sub-agent invocations, including workflows whose Actions conclusion is `success`. An affected current revision has status `subagent_failures_observed` and is excluded from `healthy_workflows`; its Actions success/failure counts and success rate remain unchanged. JSON reports include `subagent_failure_count` (invocations), `subagent_failure_runs` (distinct runs), and per-workflow `subagent_failures` with run URLs, agent names, and requested models. Fleet JSON also includes `degraded_workflows`. | ||
|
|
||
| Threat-detection failures, warnings, and detected threats also degrade the current revision, with status `detection_failures_observed`. JSON includes `detection_failure_runs` and per-workflow `detection_failures` with run URLs and findings; text reports include `[detection_failures]`. Actions success rates remain unchanged, and a workflow with both detection and sub-agent failures counts only once in `degraded_workflows`. Audit reports expose detection outcomes in findings and error or warning counts. Detection engine errors such as `parse_error` are tooling failures, not security findings. When older usage artifacts omit the outcome, audit and health can recover it from downloaded conclusion-job environment logs. |
There was a problem hiding this comment.
[/grill-with-docs] This new paragraph says degraded_workflows now includes detection failures, which matches health_metrics.go:222 (if wh.SubagentFailureCount > 0 || wh.DetectionFailureRuns > 0). But line 1129 of this same file still says degraded_workflows "remains the sub-agent-only count", and docs/adr/70885-reuse-raw-cached-jobs-across-cli-versions-for-health.md line 21 says the same. Update all three so the docs match the code, or narrow the code if sub-agent-only was the intent.
@copilot please address this.
There was a problem hiding this comment.
Updated the CLI documentation and ADR: degraded_workflows includes either sub-agent or detection failures, counting each workflow once. Addressed in a060845.
| if health.DetectionFailureRuns == 0 { | ||
| return | ||
| } | ||
| health.Status = "detection_failures_observed" |
There was a problem hiding this comment.
[/diagnosing-bugs] This line overwrites the top-level status that applyHealthSubagentFailures set to subagent_failures_observed (health_subagents.go:38). Nothing reads that value after this point, so a workflow with both sub-agent and detection failures reports only detection_failures_observed, and the sub-agent signal disappears from the top-level status. The revision loop at lines 45-54 has the same overwrite. Keep both signals, for example by preserving the existing status and reporting detection failures in their own field, or by ranking the statuses explicitly.
@copilot please address this.
There was a problem hiding this comment.
Detection counters remain independent; existing sub-agent and insufficient-evidence statuses are preserved for workflows and revisions. Added regression coverage. Addressed in a060845.
There was a problem hiding this comment.
🟡 Changes recommended
A new test does not compile, the cache-schema regression fails unconditionally, and detection handling can omit failures or incorrectly include insufficient-evidence samples in health summaries.
7 open issues
Update cache schema version regression test · New Inspect every conclusion job invocation · New Match qualified detection job names · New Preserve insufficient-evidence status with detection warnings · New Fix embedded JobInfo composite literal in test · New Avoid inflating detection failure counts · New Retain failed detection results as fallback evidence · New
What changed in this PR
Extends gh-aw audit and health reports to surface threat-detection problems even when GitHub Actions reports success.
Changes:
- Adds detection error and warning counts, distinguishes tooling errors from threats, and suppresses unqualified success findings.
- Recovers historical detection outcomes from conclusion-job logs and invalidates older audit caches.
- Adds detection-based health degradation and per-run details without changing Actions success rates, with regression coverage and documentation.
| File | Description |
|---|---|
pkg/cli/health_revisions.go |
Tracks detection failures in revision summaries. |
pkg/cli/health_metrics.go |
Adds detection counters and updates health rollups. |
pkg/cli/health_detection.go |
Collects and renders per-run detection findings. |
pkg/cli/health_detection_test.go |
Covers detection evidence, cache compatibility, output, and rollups. |
pkg/cli/health_command.go |
Displays detection counts, warnings, and details. |
pkg/cli/audit_threat_detection.go |
Classifies detection issues and updates audit counts. |
pkg/cli/audit_threat_detection_logs.go |
Recovers outcomes from conclusion-job environment logs. |
pkg/cli/audit_threat_detection_logs_test.go |
Covers historical recovery and evidence validation. |
pkg/cli/audit_report.go |
Integrates detection issues into audit data. |
pkg/cli/audit_report_analysis.go |
Suppresses success findings and adds detection recommendations. |
pkg/cli/audit_cache.go |
Bumps the audit cache schema version. |
docs/src/content/docs/setup/cli.md |
Documents detection reporting and health semantics. |
Review effort: Max (auto)
| type auditCacheSource string | ||
|
|
||
| const auditSchemaVersion = 12 | ||
| const auditSchemaVersion = 13 |
| job := JobInfo{Name: "conclusion"} | ||
| location := locateJobLogs(workflowLogsDir, job) | ||
| if location.file == "" && location.dir == "" { | ||
| name, ok := uniqueQualifiedConclusionLog(workflowLogsDir) |
| processed.JobDetails = jobs.details | ||
| } | ||
| } | ||
| for _, finding := range generateThreatDetectionFindings(processed) { |
| if health.DetectionFailureRuns == 0 { | ||
| return | ||
| } | ||
| health.Status = "detection_failures_observed" |
| // The same failure may already have been counted from job or agent logs. | ||
| data.Metrics.ErrorCount = max(data.Metrics.ErrorCount, len(data.Errors)) | ||
| data.Metrics.WarningCount = max(data.Metrics.WarningCount, len(data.Warnings)) |
| case inHeader && strings.TrimSpace(line) == "env:": | ||
| inEnv = true | ||
| case line == "##[endgroup]": | ||
| if inEnv && validDetectionJobResult(block.JobResult) && validDetectionConclusion(block.Conclusion) { |
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: 108b5b3
|
…health-tools-detection-results Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |


Audit and health could report success despite a threat-detection tooling error. Detection warnings and failures need to remain visible even when Actions succeeds.
detection_failures_observed, expose per-run findings, and exclude them from healthy totals without changing Actions success rates.