Skip to content

fix: reduce post-completion idle watchdog and add cleanup timeouts to prevent Copilot CLI hang on exit#44254

Merged
pelikhan merged 9 commits into
mainfrom
copilot/aw-fix-impeccable-skills-reviewer-timeout
Jul 8, 2026
Merged

fix: reduce post-completion idle watchdog and add cleanup timeouts to prevent Copilot CLI hang on exit#44254
pelikhan merged 9 commits into
mainfrom
copilot/aw-fix-impeccable-skills-reviewer-timeout

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The Impeccable Skills Reviewer was completing its review successfully but the Copilot CLI process never exited, causing every run to be killed by the 15-minute hard step timeout — a false failure on otherwise successful reviews.

Root cause

Two compounding issues in copilot_sdk_session.cjs:

  1. Watchdog too slow: SDK_POST_COMPLETION_IDLE_MS_DEFAULT was 5 minutes. If the agent finishes at T+10min with a 15-min step, the watchdog fires at T+15min — racing the timeout instead of beating it.

  2. client.stop() can hang: After sendAndWait times out, the finally block calls await client.stop(). When the SDK server is unresponsive this never settles, blocking the process until the step timeout kills it.

Changes

actions/setup/js/copilot_sdk_session.cjs

  • Reduce SDK_POST_COMPLETION_IDLE_MS_DEFAULT from 5 * 60 * 100030 * 1000. The watchdog guards against false positives via three conditions (output collected, no in-flight tool calls, not mid-inference turn), so 30 s is safe in practice.

  • Add 5-second cleanup timeout to session.disconnect() and client.stop() in the finally block. Uses Promise.race so a hung server unblocks the driver within a bounded window, with a warning logged on timeout:

const withCleanupTimeout = p => {
  let timedOut = false;
  const deadline = new Promise(resolve =>
    setTimeout(() => { timedOut = true; resolve(false); }, CLEANUP_TIMEOUT_MS)
  );
  return Promise.race([p.then(() => true, () => true), deadline]).then(settled => {
    if (!settled && timedOut)
      log(`warning: cleanup operation timed out after ${CLEANUP_TIMEOUT_MS}ms`);
    return settled;
  });
};

actions/setup/js/copilot_sdk_driver.test.cjs

  • Adds regression test "cleanup timeout prevents hang when client.stop() never resolves"client.stop() returns a promise that never settles; asserts exitCode: 0 and wall-clock completion under 10 s.

Generated by 👨‍🍳 PR Sous Chef · 14.3 AIC · ⌖ 7.84 AIC · ⊞ 7.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · 5.89 AIC · ⌖ 8.02 AIC · ⊞ 7.1K ·
Comment /souschef to run again

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Hey @copilot 👋 — thanks for picking up the Impeccable Skills Reviewer timeout fix! The problem statement is well scoped (post-completion hang preventing clean CLI exit) and the PR is correctly rooted in the failure-investigator issue trail.

A couple of things to address before this is ready for review:

  • No diff yet — the PR currently has 0 changed files. Once the fix lands (engine exit signal, MCP/stdio handle cleanup, or idle-timeout addition), make sure the implementation is committed and the description is updated to reflect what changed and why.
  • Tests are missing — the fix will touch process-lifecycle or MCP-server teardown paths. Add tests (or extend existing ones) that confirm the CLI exits cleanly after the final assistant turn, without requiring the full 15-minute hard timeout to fire.

When you're ready to fill in the implementation, here's a prompt you can use:

Fix the post-completion hang in the Copilot CLI that causes the process to stay alive after the agent emits its final assistant turn.

Steps:
1. Identify the MCP server(s) and safe-output stdio bridge(s) that remain open after the last turn — trace from the engine's shutdown path.
2. Ensure all child processes (MCP servers, safe-output bridge) receive a close/terminate signal when the engine decides it is done.
3. Add an inactivity/idle timeout (shorter than the 15-minute hard step timeout) so a finished-but-hung agent exits with success when output was produced.
4. Write a test (unit or integration) that starts a minimal agent run, asserts it completes, and verifies the process exits within a short deadline after the final turn — no manual kill required.
5. Update the PR description with: what was hanging, what was changed to fix it, and how to verify the fix locally.

Generated by ✅ Contribution Check · 160.8 AIC · ⌖ 33.9 AIC · ⊞ 6.2K ·

Copilot AI and others added 2 commits July 8, 2026 09:54
… prevent Copilot CLI hang on exit

- Reduce SDK_POST_COMPLETION_IDLE_MS_DEFAULT from 5 minutes to 30 seconds
  so the watchdog fires quickly after the agent completes, well before the
  step timeout fires
- Add 5-second cleanup timeout to session.disconnect() and client.stop()
  in the finally block so the driver does not hang when the SDK server is
  unresponsive after sendAndWait times out
- Add regression test verifying the cleanup timeout prevents a hung
  client.stop() from blocking the exit path

Closes #44243

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ess and log warning

Address code review feedback: the cleanup helper now returns a boolean
(true = settled in time, false = timed out) and logs a warning message
when the timeout fires, making timeout conditions observable in logs.
The `catch` blocks remain for best-effort semantics.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix timeout issue for Impeccable Skills Reviewer in Copilot CLI fix: reduce post-completion idle watchdog and add cleanup timeouts to prevent Copilot CLI hang on exit Jul 8, 2026
Copilot AI requested a review from pelikhan July 8, 2026 09:56
@pelikhan
pelikhan marked this pull request as ready for review July 8, 2026 10:00
Copilot AI review requested due to automatic review settings July 8, 2026 10:00

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 prevents successful Copilot SDK-driven runs from being reported as failures due to the Copilot CLI hanging on exit, by tightening the post-completion watchdog and bounding cleanup operations that can otherwise block forever.

Changes:

  • Reduced the default post-completion idle watchdog from 5 minutes to 30 seconds to beat typical GitHub Actions step timeouts.
  • Added a per-cleanup 5s timeout wrapper around session.disconnect() and client.stop() to avoid indefinite hangs in the finally block.
  • Added a regression test covering the “client.stop() never resolves” hang scenario.
Show a summary per file
File Description
actions/setup/js/copilot_sdk_session.cjs Shortens the post-completion watchdog and adds timeout-bounded best-effort cleanup in the finally block.
actions/setup/js/copilot_sdk_driver.test.cjs Adds a regression test ensuring cleanup timeout prevents hangs when client.stop() never resolves.

Review details

Tip

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

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

Comment thread actions/setup/js/copilot_sdk_session.cjs
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

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

Generated by 👨‍🍳 PR Sous Chef · 14.3 AIC · ⌖ 7.84 AIC · ⊞ 7.1K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 8, 2026 11:02
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

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

Addressed in bbe84f5: the cleanup timeout helper now clears and unreferences its deadline timer when cleanup settles, and the JS regression tests cover the prompt-cleanup path. Local make fmt, make lint, make test-unit, make test, make recompile, and make agent-report-progress passed. Checks on the new head still need a maintainer re-trigger because agent pushes do not start CI.

Copilot AI requested a review from gh-aw-bot July 8, 2026 11:15
@pelikhan

pelikhan commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

@copilot revert lock files

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

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

Generated by 👨‍🍳 PR Sous Chef · 5.89 AIC · ⌖ 8.02 AIC · ⊞ 7.1K ·
Comment /souschef to run again

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category bug
Risk 🟡 medium
Score 74 / 100
Recommended action fast_track

Score breakdown: Impact 38 + Urgency 22 + Quality 14

Assessment: Fixes Copilot CLI hang on exit — every successful run is marked as failed due to a watchdog timing race and blocking client.stop(). High urgency. AI reviewer approved. CI status unknown (sandbox restriction).

Next step: Confirm CI green, then fast-track merge.

Generated by 🔧 PR Triage Agent · 64.6 AIC · ⌖ 20.4 AIC · ⊞ 5.4K ·

@pelikhan

pelikhan commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

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

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Done. I ran the pr-finisher pass on the current head, replied on the unresolved Copilot review thread, and revalidated locally with make fmt, make lint, make test-unit, make test, and make recompile. The branch is clean locally; CI on the latest agent head still needs a maintainer re-trigger.

@pelikhan
pelikhan merged commit 3d68dc9 into main Jul 8, 2026
14 checks passed
@pelikhan
pelikhan deleted the copilot/aw-fix-impeccable-skills-reviewer-timeout branch July 8, 2026 14:05
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.7

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] [aw-fix] Impeccable Skills Reviewer times out at 15m after completing its review — Copilot CLI hangs on exit

4 participants