Skip to content

fix(health): ignore evidence-confirmed PR lifecycle interruptions - #70915

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan-shiny-guacamole
Oct 21, 2026
Merged

pelikhan merged 3 commits into
mainfrom
pelikhan-shiny-guacamole

Conversation

@pelikhan

Copy link
Copy Markdown
Collaborator

Summary

  • Exclude PR-review cancellations only when exact-commit/branch PR evidence places merge, closure, or head deletion during the attempt and before a cancelled job completed. Require complete job evidence; preserve genuine failed jobs/steps and unrelated cancellations.
  • Exclude failure-conclusion checkout interruptions only with the exact closed-PR checkout diagnostic and matching closure timestamp; accept only the known subsequent Handle agent failure conclusion aftermath. Other checkout failures remain failures.
  • Filter both failure inventory and chronological sampling before metrics, revision/recovery status, clusters, and investigation targets. Ignored runs are not successes and do not consume the sample minimum.
  • Cache lifecycle responses, including errors, within the collection; cap lifecycle requests at 40 and branch-event listings at two pages under the overall API budget. Reuse complete typed job inventories for presence checks. Expose explicit per-run ignored / retained / unknown classifications in JSON/text, and update CLI docs/release notes.
  • No workflow source/lock changes or workflow dispatches.

Validation

  • Passed make build, make fmt, and go test ./pkg/cli -run '^TestHealth' -count=1 -timeout=180s.
  • Regression coverage: merged/closed/deleted/restored heads, open PRs, closure after cancellation, genuine job/step failures, exact/wrong/missing checkout diagnostics, failure aftermath, missing/incomplete/unavailable evidence, request/cache bounds, continued sampling, and metrics/revision/clustering/inventory consistency.
  • Passed custom change-scoped linters, schema freshness, impacted unit tests, and make check-workflow-drift (346 workflows in sync).
  • Ran the required make agent-report-progress: aggregate status is blocked by a pre-existing nolint_filter warning about unknown custom linters. Direct golangci-lint reports only unchanged-file findings: add_workflow_resolution.go:1040,1090,1194 (modernize) and spec_test.go:251 (testifylint). No changed-file lint diagnostics; unrelated baseline issues were not modified.

Live evidence

Read-only check:

./gh-aw health mattpocock-skills-reviewer --repo github/gh-aw \
  --start-date 2026-10-21T14:39:00Z --end-date 2026-10-21T14:40:00Z --json

Run 39618696466, whose checkout failed after PR #70898 merged at 14:39:05Z, is explicitly ignored / pr_merged. Result: total_runs=0, success_count=0, failure_count=0, no clusters/investigation, and status=no_recent_runs rather than healthy. This used 10 total API requests, including two lifecycle requests.

pelikhan and others added 2 commits October 21, 2026 09:25
Correlate PR merge, closure, and head-deletion events with cancelled runs. Require explicit closed-PR checkout diagnostics for failure-conclusion interruptions, preserve genuine failures, and bound/cache lifecycle evidence requests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use promoted fields in JobInfoWithDuration literals to satisfy modernize/embedlit without changing the test fixtures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review October 21, 2026 16:59
Copilot AI max review requested due to automatic review settings October 21, 2026 16:59
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · sonnet50 · 13.3 AIC · ⌖ 15.2 AIC · ◇ 6.66 AIC · ⊞ 12.7K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #70915

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Commit pushed: 7adfc2a

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@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.

L967: delete: duplicate statement that filtered runs do not consume the minimum sample. Nothing replaces it; L965 already says this.

net: -1 lines possible.

Generated by ✂️ Ponytail Reviewer for #70915 · codex · gpt56 · 11.1 AIC · ⌖ 5.39 AIC · ⊞ 14.8K
Comment /ponytail to run again


Ignored runs do not count as successes or consume the minimum sample. They are excluded from rates, durations, token averages, revision/recovery evidence, failure candidates, clusters, and investigation targets. JSON `collection.pr_lifecycle_evidence` and text `[health_pr_lifecycle]` entries report `ignored`, `retained`, or `unknown` classifications and reasons. Missing, ambiguous, incomplete, or unavailable evidence leaves a run unfiltered by this check. Lifecycle API responses (including errors and targeted checkout-job logs) are cached within the collection, use the configured repository and host, and share its API budget. `collection.lifecycle_requests` is capped at 40 additional requests; branch-event listings are limited to two pages. Health downloads no artifacts.

Filtered runs do not consume the minimum sample. Health searches backward for five completed first-attempt runs per current-revision scope, stopping at the requested time boundary or API budget rather than a fixed page count. It narrows the search window to continue beyond GitHub's 1,000-run search limit, overlapping boundary timestamps and deduplicating runs. If timestamp ties prevent further progress, the report explicitly marks collection as partial.

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.

L967: delete: duplicate statement that filtered runs do not consume the minimum sample. Nothing replaces it; L965 already says this.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-10-21T17:02:29Z
review_event: REQUEST_CHANGES
top_themes: [incomplete lifecycle job evidence can suppress genuine failed runs]
files_reviewed: [pkg/cli/health_pr_lifecycle.go, pkg/cli/health_sampling.go, pkg/cli/health_collection.go, pkg/cli/health_failures_first.go, pkg/cli/health_job_evidence.go, pkg/cli/health_command.go, docs/src/content/docs/setup/cli.md]
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · 2.33 AIC · ⌖ 0.679 AIC · ⊞ 1.6K · ◷
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.

Request changes

The lifecycle filter can ignore failed PR runs without proving the required downstream Handle agent failure conclusion job exists. That permits incomplete job evidence to suppress genuine failures from health metrics and investigation. Require a valid post-checkout aftermath before classifying the run as ignored.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · 2.33 AIC · ⌖ 0.679 AIC · ⊞ 1.6K
Comment /review to run again

evidence.Status, evidence.Reason = "unknown", "missing_failed_checkout_job"
return evidence
}
if !healthValidClosureAftermath(aftermath, checkoutCompleted) {

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.

This accepts a failed PR run as lifecycle-ignored even when no subsequent conclusion job with the Handle agent failure step exists, so a truncated or otherwise incomplete job inventory can erase a real failure from metrics and investigation.

💡 Require the documented aftermath

aftermath is allowed to remain empty, and healthValidClosureAftermath([]JobInfoWithDuration{}, ...) returns true. Require at least one valid conclusion aftermath job (and validate it occurs after checkout) before setting ignored; otherwise retain or mark the evidence unknown.

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR changes core business logic in pkg/cli/ (733 new lines, more than the 100-line threshold) and does not link an Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/70915-ignore-evidence-confirmed-pr-lifecycle-interruptions-in-health.md. Review and complete it before merging.

The draft records this decision: gh aw health classifies pull_request runs that ended cancelled/failure as ignored, retained or unknown. A run is dropped from failure inventory and sampling only when timestamped PR merge/closure/head-deletion evidence and complete job evidence confirm it. For failures, the exact closed-PR checkout diagnostic is also required. Lifecycle requests are capped at 40.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.
  2. Complete the missing sections: confirm the deciders (marked [TODO: verify]), refine the rationale, and check the alternatives (ignore all PR cancellations / keep counting them as failures / treat them as successes).
  3. Commit the finalized ADR to docs/adr/ on your branch.
  4. Reference the ADR in this PR body, for example:

    ADR: ADR-70915: Ignore Evidence-Confirmed PR Lifecycle Interruptions in gh aw health

Once an ADR is linked in the PR body, this gate will re-run and check that the implementation matches the decision.

❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors, including your future self, can see the reasoning behind each decision.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · opus55 · 29.2 AIC · ⌖ 40.6 AIC · ⊞ 1.9K · ◷
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.

Skills-Based Review 🧠

Applied /codebase-design (triage unavailable — used fallback heuristic against pr-meta.json/pr-diff.patch; largest-diff files health_pr_lifecycle.go and health_pr_lifecycle_test.go prioritized) and /tdd. The new PR-lifecycle filter is impressively well-specified and the 374-line regression suite (health_pr_lifecycle_test.go) covers an unusually thorough matrix of evidence/edge cases — merged/closed/deleted/restored heads, genuine vs. aftermath failures, malformed/incomplete/unavailable evidence, request-budget caps, and shared caching. Two non-blocking design suggestions posted inline; nothing here blocks merge.

📋 Key Themes & Highlights

Key Themes

  • Hardcoded job/step vocabulary: "agent" / "conclusion" job-name literals in health_pr_lifecycle.go duplicate values already exposed as constants.AgentJobName / constants.ConclusionJobName, which pkg/cli imports elsewhere.
  • Duplicated PR-lookup logic: fetchHealthLifecyclePR re-implements the same /commits/{sha}/pulls lookup as fetchObsoletePREvidence (logs_pr_lifecycle.go), but without its --paginate/--slurp handling for commits linked to >99 PRs — a narrow case, but one the two copies will now diverge on if changed independently.

Positive Highlights

  • ✅ Evidence requirements are conservative by design: unknown/ambiguous evidence always falls back to retained, never a silent success.
  • ✅ Request budget (healthMaximumLifecycleRequests, 2-page branch-event cap) and response caching are both enforced and directly tested (TestHealthLifecycleRequestBudgetAndSharedCache).
  • ✅ Docs (cli.md) and the changeset clearly describe the new ignored/retained/unknown semantics and their exclusion from metrics/sampling.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 122.1 AIC · ⌖ 15.1 AIC · ⊞ 10.2K
Comment /matt to run again

}
continue
}
if run.Conclusion == "failure" && job.Name == "conclusion" && healthOnlyFailedStep(job, "Handle agent failure") {

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.

[/codebase-design] The job names "agent" and "conclusion" (and "Checkout PR branch" / "Handle agent failure" step names below) are hardcoded string literals, but pkg/constants.AgentJobName / ConclusionJobName already exist and pkg/cli imports pkg/constants elsewhere in the package.

💡 Suggestion
if run.Conclusion == "failure" && job.Name == string(constants.ConclusionJobName) && healthOnlyFailedStep(job, "Handle agent failure") {

and similarly at line 264 with string(constants.AgentJobName). This keeps the lifecycle filter resilient to any future rename of the generated job names and matches the existing vocabulary used throughout pkg/workflow.

@copilot please address this.

return classifyHealthHeadDeletion(run, start, evidence, collection)
}

func fetchHealthLifecyclePR(run WorkflowRun, collection *HealthCollection) (healthLifecyclePR, error) {

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.

[/codebase-design] fetchHealthLifecyclePR duplicates most of fetchObsoletePREvidence in pkg/cli/logs_pr_lifecycle.go (same /commits/{sha}/pulls endpoint, same head-ref disambiguation idea), but with subtly different logic: this version does not paginate past the first 100 PRs (logs_pr_lifecycle.go uses --paginate --slurp), so a commit shared by >99 PRs silently becomes missing_or_ambiguous_pull_request here instead of being handled across pages.

💡 Suggestion

Consider extracting a shared helper (e.g. fetchCommitPullRequests(ctx, headSha, headBranch)) used by both the logs and health lifecycle paths so the pagination/disambiguation rule is defined once and the two call sites only differ in caching/budget behavior. This reduces the risk of the two copies drifting further apart as PR-lifecycle heuristics evolve.

@copilot please address this.

@pelikhan
pelikhan merged commit 3f6775f into main Oct 21, 2026
5 checks passed
@pelikhan
pelikhan deleted the pelikhan-shiny-guacamole branch October 21, 2026 17:21

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.

🔵 Needs a closer look

Failure suppression still requires fixes and human validation of lifecycle timing and evidence assumptions.

4 open issues
What changed in this PR

Updates gh aw health to exclude evidence-confirmed PR lifecycle interruptions without counting them as successes.

Changes:

  • Correlates PR events, job evidence, and checkout diagnostics.
  • Applies exclusions consistently across sampling and failure reporting.
  • Adds bounded caching, explicit classifications, tests, and documentation.
File Description
pkg/​cli/​health_sampling.go Filters samples and reuses complete job inventories.
pkg/​cli/​health_pr_lifecycle.go Adds lifecycle classification and bounded lookups.
pkg/​cli/​health_pr_lifecycle_test.go Covers classification, budgets, and sampling consistency.
pkg/​cli/​health_job_evidence.go Clarifies the shared job-evidence comment.
pkg/​cli/​health_failures_first.go Filters interruptions before counting failure candidates.
pkg/​cli/​health_command.go Updates help and capability metadata.
pkg/​cli/​health_collection.go Exposes lifecycle classifications and request counts.
docs/​src/​content/​docs/​setup/​cli.md Documents exclusions, evidence requirements, and limits.
.changeset/​patch-health-pr-lifecycle.md Adds the patch release note.

Review effort: Max

}
}
if len(events) < 100 {
if evidence.Reason == "pr_head_deleted" && !restoredAt.After(evidence.EventAt) {
var aftermath []JobInfoWithDuration
var checkoutCompleted time.Time
for _, job := range jobs.details {
if job.Status != "completed" || job.Conclusion == "" {

func healthClosedCheckoutLog(jobID int64, prNumber int, collection *HealthCollection) (bool, error) {
data, err := healthLifecycleAPI(collection, fmt.Sprintf("%s/actions/jobs/%d/logs",
healthRepositoryEndpoint(collection.repoOverride), jobID), "--allow-escape-sequences")
}
evidence, checked := collection.PRLifecycleEvidence[run.DatabaseID]
if !checked || evidence.Attempt != run.Attempt || !evidence.UpdatedAt.Equal(run.UpdatedAt) {
evidence = classifyHealthPRLifecycle(run, collection)
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.93.0

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants