gitbutlerapp/gitbutler · error

Failed to communicate with LM Studio server

Error message

Failed to communicate with LM Studio server: ${error instanceof Error ? error.message : String(error)}

What it means

The catch-all wrapper in evaluate(): any error thrown inside the try block (validation, network failure, JSON parse, errors 0-2) is rethrown with the prefix 'Failed to communicate with LM Studio server:' and the original message appended. It signals the LM Studio call failed, with the cause nested in the message.

Solutions

  1. Read the wrapped original message to identify the root cause.
  2. Verify LM Studio's local server is running and reachable (curl http://localhost:1234/v1/models).
  3. Check the endpoint URL and port in the app's AI settings.
  4. If in a browser context, confirm CORS is not blocking the local server.

Example fix

// before
const client = new LMStudioClient('http://localhost:9999/v1', model);
// after
const client = new LMStudioClient('http://localhost:1234/v1', model); // server actually running here
Defensive patterns

Strategy: try-catch

Validate before calling

// reachability pre-check
const res = await fetch(endpoint.replace(/\/$/, '') + '/models').catch(() => null);
if (!res || !res.ok) throw new Error('LM Studio server unreachable at ' + endpoint);

Try / catch

try {
  await client.evaluate(prompt);
} catch (e) {
  if (e.message.startsWith('Failed to communicate with LM Studio server:')) {
    const cause = e.message.replace('Failed to communicate with LM Studio server: ', '');
    // inspect cause: ECONNREFUSED => server not running; JSON errors => non-JSON response
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Any failure inside evaluate(): unreachable server / fetch TypeError, non-JSON response body passed to response.json(), or any of the earlier explicit throws.

Common situations: LM Studio server not started (ECONNREFUSED); wrong port; CORS blocking the request in the webview; server returning HTML error pages instead of JSON.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/d7a335d6ed058243. Report an issue: GitHub.

Appendix: source

Thrown at apps/desktop/src/lib/ai/lmStudioClient.ts:119

									result += token;
								}
							}
						} catch (e) {
							console.warn("Error parsing streaming JSON", e);
						}
					}
				}

				return result;
			}
			// Handle non-streaming response
			else {
				const json = await response.json();
				return json.choices[0]?.message?.content || "";
			}
		} catch (error) {
			console.error("Error calling LM Studio API:", error);
			throw new Error(
				`Failed to communicate with LM Studio server: ${error instanceof Error ? error.message : String(error)}`,
			);
		}
	}
}

View on GitHub (pinned to 58e5313667)