Skip to content

Retry Copilot harness crashes before agent startup - #51792

Closed
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/aw-failures-fix-segfault
Closed

pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/aw-failures-fix-segfault

Conversation

Copilot AI commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

The Copilot Node harness can terminate with exit 139 during /reflect preflight, bypassing its in-process retry loop and failing the workflow before Copilot starts.

  • Crash recovery

    • Add a shell launcher around Copilot harness invocations.
    • Retry fresh harness processes for signal-style exits (134–139), with bounded retry count and backoff.
    "$node_executable" "$harness" "$@"
    # Signal-style exit → restart a fresh harness process.
  • Reflect diagnostics

    • Log Node heap, RSS, external memory, and cgroup memory usage immediately before and after /reflect fetches.
    • Keep diagnostics best-effort for runners without cgroup files.
  • Regression coverage

    • Cover recovery from an exit-139 harness process.
    • Cover resource snapshots around /reflect.
    • Verify generated Copilot commands route through the crash-retry launcher.

Copilot AI changed the title [WIP] Fix Copilot CLI harness segfault killing Agent Performance Analyzer Retry Copilot harness crashes before agent startup Aug 10, 2026
Copilot AI requested a review from pelikhan August 10, 2026 14:01
@pelikhan
pelikhan marked this pull request as ready for review August 10, 2026 15:35
Copilot AI balanced review requested due to automatic review settings August 10, 2026 15:35

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

Adds crash recovery around Copilot harness startup and resource diagnostics for /reflect.

Changes:

  • Retries harness exits 134–139 with bounded backoff.
  • Routes generated Copilot commands through the retry launcher.
  • Logs memory snapshots around reflect requests and adds regression coverage.
Show a summary per file
File Description
actions/setup/sh/copilot_harness_runner.sh Adds bounded crash retries.
actions/setup/js/awf_reflect.cjs Adds reflect memory diagnostics.
actions/setup/js/copilot_harness.cjs Re-exports the diagnostic helper.
actions/setup/js/copilot_harness.test.cjs Tests diagnostics and exit-139 recovery.
pkg/workflow/copilot_engine_execution.go Routes harness execution through the launcher.
pkg/workflow/copilot_engine_test.go Verifies generated launcher commands.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

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

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 10, 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 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #51792

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

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.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • api.individual.githubcopilot.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.individual.githubcopilot.com"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

✅ Test Quality Score: 82/100 — Excellent

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

📊 Metrics (4 tests)
Metric Value
Analyzed 4 (Go: 2, JS: 2)
✅ Design 4 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 3 (75%)
Duplicate clusters 0
Inflation ⚠️ Yes (copilot_harness.test.cjs +62 vs copilot_harness.cjs +2 — ratio ~31:1; contextually justified — see note below)
🚨 Violations 0
Test File Classification Issues
"retries a signal-style harness exit..." copilot_harness.test.cjs:2359 behavioral_contract · high_value · design_test —
"logs resource snapshots around the reflect fetch" copilot_harness.test.cjs:2330 behavioral_contract · high_value · design_test Happy-path only (no failure case for missing cgroup)
TestCopilotGeneratedHarnessCommandSupportsSpacedRunnerPaths (table-driven ×3) copilot_engine_test.go:2869 behavioral_contract · high_value · design_test —
TestCopilotEngineHarnessScript (modified — runner.sh assertion) copilot_engine_test.go:2725 behavioral_contract · high_value · design_test —
📝 Test Analysis

"retries a signal-style harness exit and returns the recovered status" (copilot_harness.test.cjs:2359)
Directly exercises the exit-139 crash-recovery contract using a real spawnSync against the shell runner script. The stub harness fails on attempt 1 then succeeds; the test asserts result.status === 0, that the harness was called twice, and that "retrying fresh harness 1/1" appears in stderr. This is the primary regression guard for the PR.

"logs resource snapshots around the reflect fetch" (copilot_harness.test.cjs:2330)
Verifies that awf-reflect emits before/after log lines and captures heapUsed, rss, external, cgroupCurrent, and cgroupMax in the snapshot object. Happy-path only — no assertion for cgroup-missing conditions. Low risk since the PR description states diagnostics are best-effort on runners without cgroup files.

TestCopilotGeneratedHarnessCommandSupportsSpacedRunnerPaths (copilot_engine_test.go:2869)
Table-driven (CLI / SDK / SDK-with-arbitrary-driver) test that executes the generated bash exec prefix via exec.Command("bash", "-c", ...) against a stub node binary, asserting that arguments with spaces are correctly preserved through the crash-retry runner. Robust integration-style coverage of the new runner invocation path.

TestCopilotEngineHarnessScript (modified) (copilot_engine_test.go:2725)
Adds a copilot_harness_runner.sh presence assertion to the existing harness-script test, ensuring generated execution steps route through the crash-retry launcher. Minimal but precise design-invariant guard.

i️ Inflation Note

copilot_harness.test.cjs added +62 lines against copilot_harness.cjs +2 lines (raw ratio ~31:1). The 10-point inflation penalty is applied to the score. However, this is contextually justified: the new tests cover behaviour spread across three production files that all surface through the harness entry point — copilot_harness.cjs (+2), awf_reflect.cjs (+37), and the new copilot_harness_runner.sh (+47). This is not a quality concern.

Verdict

✅ passed. 0% implementation tests (threshold: 30%). Score 82/100. No guideline violations. Inflation penalty applied but contextually justified by multi-file production coverage.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 61.9 AIC · ⌖ 7.23 AIC · ⊞ 7.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.

Test Quality Sentinel: 82/100. 0% implementation tests (threshold: 30%). No guideline violations.

@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 /diagnosing-bugs and /tdd — requesting changes on two correctness issues and two test-coverage gaps.

📋 Key Themes & Highlights

Issues

  • SIGKILL (exit 137) retry semantics — retrying an OOM-killed process wastes the budget silently; should log a distinct warning or be excluded from the retry range.
  • Retry budget exhaustion not tested — the regression test only covers the happy path (1 crash → success); the budget-exhausted path (all retries consumed → exit with crash code) is untested.
  • Backoff sleep path untested — GH_AW_HARNESS_CRASH_DELAY_MS=0 skips the printf -v sleep format; a 1ms test case would catch format regressions.
  • Three identical runner-path Sprintf calls — extracting a helper would guard against future quoting drift across the three call sites in copilot_engine_execution.go.

Positive Highlights

  • ✅ Shell retry script is clean, bounded, and safe (set -uo pipefail without -e is the right call here)
  • ✅ cgroup best-effort fallback pattern in getReflectResourceSnapshot is correct
  • ✅ Regression test correctly exercises the script as a subprocess via spawnSync, not a mock
  • ✅ Constant refactoring (nodeRuntimeResolutionSetupCommand) cleanly untangles the node-exec setup from the invocation

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 45.2 AIC · ⌖ 7.22 AIC · ⊞ 7.1K
Comment /matt to run again


case $status in
134 | 135 | 136 | 137 | 138 | 139)
;;

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.

[/diagnosing-bugs] Exit 137 (SIGKILL) is included in the crash-retry range, but it typically means the OOM killer or an external kill -9 terminated the process — retrying immediately will likely exhaust the retry budget without recovering.

💡 Suggested fix

Remove 137 from the retry set, or at least log a distinct warning when retrying a SIGKILL exit:

case $status in
  134 | 135 | 136 | 138 | 139)
    ;;
  137)
    echo "[copilot-harness-runner] harness killed (exit=137/SIGKILL); this may be OOM — retrying but success is unlikely" >&2
    ;;
  *)
    exit "$status"
    ;;
esac

This prevents silent budget exhaustion when the runner is out of memory.

@copilot please address this.

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Do not enable -e: signal-style harness exits must be inspected and retried.

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.

[/diagnosing-bugs] set -uo pipefail without -e is correct here, but the comment only says why -e is omitted. Consider also noting that set -u will cause the script to abort if GH_AW_HARNESS_CRASH_RETRIES or GH_AW_HARNESS_CRASH_DELAY_MS are unset and the ${VAR:-default} expansion is removed — the defaults below guard this, so it's fine, but a brief note would help future editors understand the contract.

Minor nit, no action required unless you agree it aids maintainability.

@copilot please address this.

printf -v delay_seconds '%d.%03d' "$((delay_ms / 1000))" "$((delay_ms % 1000))"
sleep "$delay_seconds"
fi
done

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.

[/diagnosing-bugs] The script is missing a final newline — done ends without a trailing \n. Most shells handle this fine, but some CI linters flag it and wc -l will under-count. Run echo '' >> copilot_harness_runner.sh or ensure your editor adds a trailing newline.

@copilot please address this.

}
});
});

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.

[/tdd] The crash-retry test uses GH_AW_HARNESS_CRASH_DELAY_MS: "0" to skip the sleep, which is great for speed. However it doesn't test the backoff path — a future change could accidentally break the sleep format string (printf -v delay_seconds) without being caught. Consider adding a second case with delay_ms=1 to exercise the sleep branch, even briefly.

💡 Example addition
it("completes with non-zero delay without hanging", () => {
  // Just ensure the sleep printf path doesn't crash the script
  const result = spawnSync("bash", [runnerPath, "/bin/bash", harnessPath, callsPath], {
    env: { ...process.env, GH_AW_HARNESS_CRASH_RETRIES: "1", GH_AW_HARNESS_CRASH_DELAY_MS: "1" },
    encoding: "utf8",
    timeout: 5000,
  });
  expect(result.status).toBe(0);
});

@copilot please address this.

external: expect.any(Number),
cgroupCurrent: expect.any(String),
cgroupMax: expect.any(String),
})

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.

[/tdd] The retry test only covers the happy path (1 crash → 1 retry → success). It doesn't cover budget exhaustion (all retries consumed → last crash exit code is forwarded). This is the other half of the recovery contract and a likely regression point.

💡 Suggested additional case
it("exits with crash code when retry budget is exhausted", () => {
  // harness always exits 139
  fs.writeFileSync(harnessPath, `#!/usr/bin/env bash\nexit 139\n`, { mode: 0o755 });
  const result = spawnSync("bash", [runnerPath, "/bin/bash", harnessPath], {
    env: { ...process.env, GH_AW_HARNESS_CRASH_RETRIES: "1", GH_AW_HARNESS_CRASH_DELAY_MS: "0" },
    encoding: "utf8",
  });
  expect(result.status).toBe(139);
  expect(result.stderr).toContain("crash retry budget exhausted");
});

@copilot please address this.

return fmt.Sprintf(`%s; "%s/copilot_harness_runner.sh" "$GH_AW_NODE_EXEC" %s %s`, runtimeResolutionCommand, SetupActionDestinationShell, harnessScriptPath, commandName)
}

func (e *CopilotEngine) buildCopilotSDKExecPrefix(workflowData *WorkflowData, commandName, harnessScriptPath, runtimeResolutionCommand string) string {

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 generated shell fragment now embeds copilot_harness_runner.sh via SetupActionDestinationShell in three separate Sprintf calls (lines 379, 394, 404). If the runner path or quoting convention needs to change, all three sites must be updated in sync. Extracting a small helper — e.g. buildHarnessRunnerPrefix(nodeExec, harnessPath string) string — would make the interface shallower and reduce future drift.

💡 Sketch
func buildHarnessRunnerPrefix(harnessRunnerPath, harnessScriptPath, commandName string) string {
    return fmt.Sprintf(`"%s" "$GH_AW_NODE_EXEC" %s %s`, harnessRunnerPath, harnessScriptPath, commandName)
}

The three call sites then become single-line delegations, and the quoting lives in one place.

@copilot please address this.

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

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 47.4 AIC · ⌖ 6.38 AIC · ⊞ 5.4K

set -uo pipefail

if (( $# < 3 )); then
echo "[copilot-harness-runner] usage: <node> <harness> <command> [args...]" >&2

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.

Minor: the usage message says <node> <harness> <command> [args...] but after shift 2 the script passes "$@" directly to node — there is no distinct <command> positional; it is just the first of the pass-through args. Consider usage: <node> <harness> [args...] to avoid confusion.

Non-blocking cosmetic fix. @copilot please address this.

@github-actions github-actions Bot mentioned this pull request Aug 10, 2026

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

Generated by ✂️ Ponytail Reviewer for #51792 · auto · 40.3 AIC · ⌖ 7.42 AIC · ⊞ 6.8K
Comment /ponytail to run again

extractModelIds,
fetchAWFReflect,
fetchModelsFromUrl,
getReflectResourceSnapshot,

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.

L71,1490: yagni: getReflectResourceSnapshot re-imported and re-exported here but never invoked in this file. Drop the import/export, keep it only in awf_reflect.cjs.

return e.buildCopilotSDKExecPrefix(workflowData, commandName, harnessScriptPath, runtimeResolutionCommand)
}
return fmt.Sprintf(`%s %s %s`, runtimeResolutionCommand, harnessScriptPath, commandName)
return fmt.Sprintf(`%s; "%s/copilot_harness_runner.sh" "$GH_AW_NODE_EXEC" %s %s`, runtimeResolutionCommand, SetupActionDestinationShell, harnessScriptPath, commandName)

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.

L376,394,404: yagni: same "%s/copilot_harness_runner.sh" "$GH_AW_NODE_EXEC" ... prefix duplicated 3x with varying trailing args. One helper runnerPrefix := fmt.Sprintf("%s; \"%s/copilot_harness_runner.sh\" \"$GH_AW_NODE_EXEC\"", runtimeResolutionCommand, SetupActionDestinationShell) then append args, 1 shared definition.

@github-actions
github-actions Bot deleted the copilot/aw-failures-fix-segfault branch August 18, 2026 02:24
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-failures] [P0] Fix Copilot CLI harness segfault (exit 139) killing Agent Performance Analyzer

3 participants