github/copilot-sdk · error · InvalidOperationException
Elicitation is not supported by the host. Check…
Error message
Elicitation is not supported by the host. Check session.Capabilities.Ui?.Elicitation before calling UI methods.
What it means
AssertElicitation is a precondition check: it throws InvalidOperationException when the host did not advertise UI elicitation capability (Capabilities.Ui?.Elicitation != true) but an elicitation API (showing input dialogs to the user) was called. The message points you to verify the capability flag first.
Solutions
- Check session.Capabilities.Ui?.Elicitation == true before calling any elicitation API.
- Fall back to a non-UI flow (CLI prompts, defaults, or config values) when elicitation is unsupported.
- Upgrade the host/CLI to a version that supports elicitation.
- If you control the host, declare the ui.elicitation capability in its initialize response.
Example fix
// before
var answer = await session.Ui.RequestInputAsync(new() { Message = "Name?" });
// after
if (session.Capabilities.Ui?.Elicitation == true)
var answer = await session.Ui.RequestInputAsync(new() { Message = "Name?" });
else
var answer = PromptFallback("Name?"); Defensive patterns
Strategy: type-guard
Validate before calling
if (session.Capabilities.Ui?.Elicitation != true)
return await FallbackPromptAsync(message); Type guard
static bool SupportsElicitation(Session s) => s.Capabilities?.Ui?.Elicitation == true;
Try / catch
try { return await session.Ui.RequestInputAsync(req); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Elicitation is not supported"))
{ return await FallbackPromptAsync(req.Message); } Prevention
- Check Capabilities.Ui?.Elicitation before every elicitation call
- Design non-UI fallbacks for headless/CI environments
- Upgrade the host/CLI if elicitation support is required
When it happens
Trigger: Calling session UI elicitation methods (e.g. RequestInput/ShowForm style APIs) against a host — CLI, CI runner, IDE — whose capabilities response lacks ui.elicitation or sets it false.
Common situations: Running a Copilot SDK app inside headless/CI environments; older CLI versions without elicitation support; embedding the session in a custom host that never declares the Ui capability.
Related errors
- Cannot connect because TCP host or port are not available
- CLI process exited unexpectedly. stderr
- Client is not started. Call StartAsync first.
- Communication error with Copilot CLI
- ConnectionToken must be a non-empty string or null.
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/729896822ce0262b.
Report an issue: GitHub.
Appendix: source
Thrown at dotnet/src/Session.cs:1532
{
Action = UIElicitationResponseAction.Cancel
});
}
catch (Exception innerEx) when (innerEx is IOException or ObjectDisposedException)
{
// Connection lost — nothing we can do
}
}
}
/// <summary>
/// Throws if the host does not support elicitation.
/// </summary>
private void AssertElicitation()
{
if (Capabilities.Ui?.Elicitation != true)
{
throw new InvalidOperationException(
"Elicitation is not supported by the host. " +
"Check session.Capabilities.Ui?.Elicitation before calling UI methods.");
}
}
/// <summary>
/// Implements <see cref="ISessionUiApi"/> backed by the session's RPC connection.
/// </summary>
private sealed class SessionUiApiImpl(CopilotSession session) : ISessionUiApi
{
// Parses a JSON string and returns a detached JsonElement. Using `using`
// ensures the pooled buffers backing the JsonDocument are released
// promptly; the cloned RootElement is independent of the document.
private static JsonElement ParseJsonElement(string json)
{
using var doc = JsonDocument.Parse(json);
return doc.RootElement.Clone();
}View on GitHub (pinned to cd8cf15dc3)