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

CopilotAI 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:

constwithCleanupTimeout=p=>{lettimedOut=false;constdeadline=newPromise(resolve=>setTimeout(()=>{timedOut=true;resolve(false);},CLEANUP_TIMEOUT_MS));returnPromise.race([p.then(()=>true,()=>true),deadline]).then(settled=>{if(!settled&&timedOut)log(`warning: cleanup operation timed out after ${CLEANUP_TIMEOUT_MS}ms`);returnsettled;});};

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

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 ·

CopilotAIand 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>
CopilotAI changed the title [WIP] Fix timeout issue for Impeccable Skills Reviewer in Copilot CLIfix: reduce post-completion idle watchdog and add cleanup timeouts to prevent Copilot CLI hang on exitJul 8, 2026
CopilotAI requested a review from pelikhanJuly 8, 2026 09:56
@pelikhan
pelikhan marked this pull request as ready for review July 8, 2026 10:00
CopilotAI review requested due to automatic review settings July 8, 2026 10:00

CopilotAI 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
FileDescription
actions/setup/js/copilot_sdk_session.cjsShortens the post-completion watchdog and adds timeout-bounded best-effort cleanup in the finally block.
actions/setup/js/copilot_sdk_driver.test.cjsAdds 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 threadactions/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

CopilotAIand 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>

CopilotAI commented Jul 8, 2026

Copy link
Copy Markdown
ContributorAuthor

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

@pelikhan

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

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.7

Sign up for freeto 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

@gh-aw-bot@pelikhan