LykosAI/StabilityMatrix · error · InvalidOperationException
Client is not connected
Error message
Client is not connected
What it means
RunCustomGeneration requires an active inference server connection. It reads ClientManager.Client and, when it is null (no connected client), throws InvalidOperationException because generation cannot proceed without a client. This is a state precondition check, not a bug in the method itself.
Solutions
- Check ClientManager.Client is not null (and the server is running) before starting generation; prompt the user to connect/start the backend otherwise.
- Start the inference server and await a connected ClientGained/Connected event before enabling generation.
- Handle the InvalidOperationException in the queue-processing path and surface a 'not connected' notification instead of crashing.
Example fix
// before
await RunCustomGeneration(args); // throws if not connected
// after
if (ClientManager.Client is null)
{
Dialogs.ShowDialog("Not connected", "Start the inference server first.");
return;
}
await RunCustomGeneration(args); Defensive patterns
Strategy: validation
Validate before calling
if (ClientManager.Client is null)
{
NotifyUser("Inference server is not connected. Start it before generating.");
return;
} Type guard
if (ClientManager.Client is not { } client) return; // narrows to non-null client Try / catch
try { await RunCustomGeneration(args, ct); }
catch (InvalidOperationException) { Dialogs.ShowDialog("Not connected", "Start the inference server first."); } Prevention
- Disable the Generate button until the client/connection is established.
- Listen for ClientManager connect/disconnect events to update UI state.
- Re-check connectivity after server restarts before queueing work.
When it happens
Trigger: Invoking RunCustomGeneration (directly or via the custom-prompt queue event) before connecting to an inference server, after the server disconnected/crashed, or while ClientManager.Client hasn't been assigned following startup.
Common situations: User hits Generate before the backend (ComfyUI/A3) finished starting; the server process died mid-session and ClientManager.Client was cleared; a queued InferenceQueueCustomPrompt event fires after shutdown; swap-model or restart flows that drop the client.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Failed to parse parameters
- Sampler not selected
- : Model not selected
- Scheduler not selected
- BaseClipVision not set
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/cc9375178f88085d.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs:256
return Enumerable.Empty<ImageSource>();
}
protected async Task UploadInputImages(ComfyClient client)
{
foreach (var image in GetInputImages())
{
await ClientManager.UploadInputImageAsync(image);
}
}
public async Task RunCustomGeneration(
InferenceQueueCustomPromptEventArgs args,
CancellationToken cancellationToken = default
)
{
if (ClientManager.Client is not { } client)
{
throw new InvalidOperationException("Client is not connected");
}
var generationArgs = new ImageGenerationEventArgs
{
Client = client,
Nodes = args.Builder.ToNodeDictionary(),
OutputNodeNames = args.Builder.Connections.OutputNodeNames.ToArray(),
Project = InferenceProjectDocument.FromLoadable(this),
FilesToTransfer = args.FilesToTransfer,
Parameters = new GenerationParameters(),
ClearOutputImages = true,
};
await RunGeneration(generationArgs, cancellationToken);
}
/// <summary>
/// Runs a generation taskView on GitHub (pinned to af93d6ef57)