{"record":{"id":"cc9375178f88085d","repo":"LykosAI/StabilityMatrix","slug":"client-is-not-connected-inferencegenerationviewmodelbase","errorCode":null,"errorMessage":"Client is not connected","messagePattern":"Client is not connected","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs","lineNumber":256,"sourceCode":"        return Enumerable.Empty<ImageSource>();\n    }\n\n    protected async Task UploadInputImages(ComfyClient client)\n    {\n        foreach (var image in GetInputImages())\n        {\n            await ClientManager.UploadInputImageAsync(image);\n        }\n    }\n\n    public async Task RunCustomGeneration(\n        InferenceQueueCustomPromptEventArgs args,\n        CancellationToken cancellationToken = default\n    )\n    {\n        if (ClientManager.Client is not { } client)\n        {\n            throw new InvalidOperationException(\"Client is not connected\");\n        }\n\n        var generationArgs = new ImageGenerationEventArgs\n        {\n            Client = client,\n            Nodes = args.Builder.ToNodeDictionary(),\n            OutputNodeNames = args.Builder.Connections.OutputNodeNames.ToArray(),\n            Project = InferenceProjectDocument.FromLoadable(this),\n            FilesToTransfer = args.FilesToTransfer,\n            Parameters = new GenerationParameters(),\n            ClearOutputImages = true,\n        };\n\n        await RunGeneration(generationArgs, cancellationToken);\n    }\n\n    /// <summary>\n    /// Runs a generation task","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait RunCustomGeneration(args); // throws if not connected\n// after\nif (ClientManager.Client is null)\n{\n    Dialogs.ShowDialog(\"Not connected\", \"Start the inference server first.\");\n    return;\n}\nawait RunCustomGeneration(args);","handlingStrategy":"validation","validationCode":"if (ClientManager.Client is null)\n{\n    NotifyUser(\"Inference server is not connected. Start it before generating.\");\n    return;\n}","typeGuard":"if (ClientManager.Client is not { } client) return; // narrows to non-null client","tryCatchPattern":"try { await RunCustomGeneration(args, ct); }\ncatch (InvalidOperationException) { Dialogs.ShowDialog(\"Not connected\", \"Start the inference server first.\"); }","preventionTips":["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."],"tags":["state","network","inference","avalonia"],"backgroundTag":"invalid-state-transition","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}