github/copilot-sdk · error · IllegalStateException
Interrupted while starting in-process runtime host.
Error message
Interrupted while starting in-process runtime host.
What it means
runHostStartOnBlockingThread submits the native hostStart call to a single-use executor and blocks on future.get(). If the calling thread is interrupted while waiting, the library restores the interrupt flag and throws IllegalStateException.
Solutions
- Avoid interrupting threads performing FFI startup; use a dedicated startup thread not subject to cancellation.
- Increase startup timeouts so watchdogs don't interrupt mid-start.
- Retry initialization on a fresh (non-interrupted) thread with a new FfiRuntimeHost.
- Catch IllegalStateException, check Thread.interrupted(), and handle shutdown gracefully.
Example fix
// before executor.submit(() -> client.start(e, o)).cancel(true); // interrupts mid-FFI // after initFuture = CompletableFuture.runAsync(() -> client.start(e, o), initExecutor); // don't cancel(true) during native start; await completion
Defensive patterns
Strategy: try-catch
Type guard
if (Thread.currentThread().isInterrupted()) { /* defer init to a fresh thread */ } Try / catch
try { host.start(e, o); } catch (IllegalStateException ex) { if (ex.getCause() instanceof InterruptedException || Thread.interrupted()) { /* reschedule init on new thread */ } else throw ex; } Prevention
- Run FFI startup on a dedicated thread not subject to cancel(true)
- Size startup timeouts generously so watchdogs don't interrupt
- Preserve and check interrupt status before retrying
When it happens
Trigger: Thread.interrupt() delivered to the thread blocked in start()/runHostStartOnBlockingThread — e.g. task cancellation, executor shutdown, or application shutdown interrupting worker threads.
Common situations: Cancelling a FutureTask/CompletableFuture wrapping client init; servlet container interrupting a slow request thread; test framework timeouts interrupting the test thread during slow native startup.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
Related errors
- FfiRuntimeHost was closed during startup.
- Interrupted while waiting for callback data
- FfiRuntimeHost has already been started.
- copilot_runtime_host_start failed (library '').
- copilot_runtime_connection_open failed.
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/a57493f843bb4b84.
Report an issue: GitHub.
Appendix: source
Thrown at java/sdk/src/main/java/com/github/copilot/ffi/FfiRuntimeHost.java:253
synchronized (callbackDrainMonitor) {
callbackDrainMonitor.notifyAll();
}
}
}
};
}
private int runHostStartOnBlockingThread(byte[] argvJson, byte[] envJson) {
ReaderThreadFactory readerThreadFactory = new ReaderThreadFactory();
ExecutorService executor = Executors
.newSingleThreadExecutor(runnable -> readerThreadFactory.create(runnable, "copilot-ffi-host-start"));
try {
Future<Integer> future = executor.submit(() -> nativeBinding.hostStart(argvJson, argvJson.length, envJson,
envJson == null ? 0 : envJson.length));
return future.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted while starting in-process runtime host.", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new IllegalStateException("Failed to start in-process runtime host.", cause);
} finally {
executor.shutdownNow();
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
private static byte[] buildArgvJson(String entrypointPath, CopilotClientOptions options) {
List<String> argv = new ArrayList<>();View on GitHub (pinned to cd8cf15dc3)