Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Users experiencing CLI startup or connection failures receive generic "JSON-RPC connection lost" errors with no actionable information about the root cause (missing CLI, authentication, configuration).

Changes

Error Detection & Reporting

  • Early failure detection: 50ms check after process start captures immediate crashes with exit codes and stderr
  • Synchronized stderr capture: Avoids race conditions between immediate checks and background logging
  • Specific exception handling: ConnectionLostException now includes troubleshooting link and context
  • Process startup errors: Wrapped Process.Start() to catch and report missing executable errors

Documentation

  • Troubleshooting guide (docs/troubleshooting-connection-errors.md): Covers CLI installation, authentication, version compatibility, port conflicts, permissions
  • Debug logging examples: Cross-language examples for enabling detailed diagnostics
  • Getting started integration: Link from main tutorial to troubleshooting

Testing

  • Platform-aware error tests: Verify detection of missing CLI and immediate process exits on Windows and Unix

Error Message Improvements

Before:

IOException: The JSON-RPC connection with the remote party was lost before the request could complete.

After:

InvalidOperationException: Copilot CLI process exited immediately with code 1.
This may indicate the CLI is not properly installed or configured.
Error output:
Error: Not authenticated. Please run 'copilot auth login' first.
IOException: Communication error with Copilot CLI: The connection was lost.
This usually means the CLI process crashed or exited unexpectedly.
See https://github.com/github/copilot-sdk/blob/main/docs/troubleshooting-connection-errors.md

Technical Notes

Stderr capture uses a synchronized list to ensure error output is available regardless of timing between immediate exit checks and background logging. The 50ms delay balances false positives (slow-starting but valid processes) against detection speed.

Original prompt

This section details on the original issue you should resolve

<issue_title>Communication error with Copilot CLI: The JSON-RPC connection with the remote party was lost before the request could complete.</issue_title>
<issue_description>I followed the getting started guide as mentioned here.

I created a new console app using .NET 10 and included the Github Copilot SDK(0.1.19).

When running the application, I gett the following error on the CreateSessionAsync line.

An exception of type 'System.IO.IOException' occurred in System.Private.CoreLib.dll but was not handled in user code
Communication error with Copilot CLI: The JSON-RPC connection with the remote party was lost before the request could complete.

Executing the CLI directly works without any problem.
</issue_description>

<agent_instructions>Investigate the issue and provide improvements and/or suggestions</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@patniko Would be helpful to have a repro. Mind sharing CLI and SDK version #? We'll investigate other ways this might occur in parallel.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 29, 2026 17:58
- Add early detection of CLI process crashes with exit code reporting
- Capture and include stderr output in error messages for better diagnostics
- Add process readiness check to detect immediate failures
- Handle ConnectionLostException separately with clearer error messages
- Improve timeout handling with more descriptive errors
- Add better error messages for CLI startup failures

Co-authored-by: patniko <26906478+patniko@users.noreply.github.com>
- Create comprehensive troubleshooting guide for connection errors
- Add link to troubleshooting from getting started guide
- Add error handling tests to verify improvements
- Document common error scenarios and solutions

Co-authored-by: patniko <26906478+patniko@users.noreply.github.com>
- Fix stderr capture race condition by using synchronized list
- Remove unused StderrCapture class
- Improve ConnectionLostException error message with troubleshooting link
- Make process exit detection more reliable (50ms instead of 100ms)
- Fix platform-specific test to work on both Windows and Unix
- Remove placeholder version numbers from documentation
- Simplify connection error test assertions

Co-authored-by: patniko <26906478+patniko@users.noreply.github.com>
Comment on lines +699 to +705
catch (Exception ex)
{
throw new InvalidOperationException(
$"Failed to start Copilot CLI process. " +
$"Please ensure the Copilot CLI is installed and accessible at '{cliPath}'. " +
$"Error: {ex.Message}", ex);
}
Comment on lines +40 to +47
if (OperatingSystem.IsWindows())
{
exitCommand = "cmd";
}
else
{
exitCommand = "false"; // Unix command that exits immediately with code 1
}
Copilot AI changed the title [WIP] Fix communication error with Copilot CLI during session creation Improve CLI communication error diagnostics Jan 29, 2026
Copilot AI requested a review from patniko January 29, 2026 18:07
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.

Communication error with Copilot CLI: The JSON-RPC connection with the remote party was lost before the request could complete.

2 participants