{"record":{"id":"9b1879e85331add3","repo":"microsoft/aspire","slug":"timed-out-waiting-for-foundry-cli-server-startup-after-s","errorCode":null,"errorMessage":"Timed out waiting for Foundry CLI server startup after {s_serviceStartTimeout}.","messagePattern":"Timed out waiting for Foundry CLI server startup after (.+?)\\.","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/FoundryLocalService.cs","lineNumber":449,"sourceCode":"                // then stop draining instead of waiting forever for EOF from the daemon. If both\n                // streams close first, the CLI exited without producing the required endpoint.\n                await process.WaitForExitAsync(startCancellation.Token).ConfigureAwait(false);\n                var readersCompletionTask = Task.WhenAll(outputTask, errorTask);\n                var completedTask = await Task\n                    .WhenAny(outputCompletionSource.Task, readersCompletionTask)\n                    .WaitAsync(startCancellation.Token)\n                    .ConfigureAwait(false);\n                if (completedTask == readersCompletionTask && !outputCompletionSource.Task.IsCompleted)\n                {\n                    var incompleteOutput = await outputTask.ConfigureAwait(false);\n                    var incompleteError = await errorTask.ConfigureAwait(false);\n                    throw new InvalidOperationException(\n                        $\"Foundry CLI command '{command}' exited before producing required output with exit code {process.ExitCode}: {incompleteError}{incompleteOutput}\");\n                }\n            }\n            catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)\n            {\n                throw new TimeoutException($\"Timed out waiting for Foundry CLI server startup after {s_serviceStartTimeout}.\");\n            }\n            finally\n            {\n                readCancellation.Cancel();\n                await Task.WhenAll(outputTask, errorTask).ConfigureAwait(false);\n            }\n        }\n        else\n        {\n            await process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);\n        }\n\n        var output = await outputTask.ConfigureAwait(false);\n        var error = await errorTask.ConfigureAwait(false);\n\n        return new(process.ExitCode, output, error);\n    }\n","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/FoundryLocalService.cs#L431-L467","documentation":"When starting the Foundry CLI service, RunProcessAsync bounds the wait with s_serviceStartTimeout via a linked CancellationTokenSource (CancelAfter). If the foundry start command neither exits nor emits the expected endpoint within that timeout — and the caller's token was not cancelled — the OperationCanceledException is translated into this TimeoutException. It means the CLI server took too long to report startup.","triggerScenarios":"StartCliServerAsync -> RunFoundryCommandCoreAsync -> RunProcessAsync with stopReadingAfterProcessExit=true: WaitForExitAsync or the WhenAny wait throws OperationCanceledException from startCancellation (the internal s_serviceStartTimeout expired) while the external cancellationToken is still live.","commonSituations":"Slow or loaded machine where the foundry service takes longer than the fixed startup timeout to boot; the daemonized process inherits the streams and hangs without printing the endpoint; first-run initialization (model cache warm-up, downloads) exceeding the timeout; antivirus/EDR scanning the newly spawned binary.","solutions":["Start the Foundry service ahead of time (`foundry service start`) so the app host finds it already running instead of starting it within the timeout.","Retry the app host — transient slowness (first run, cold caches) often exceeds the fixed timeout once and succeeds afterwards.","Check machine load, antivirus scanning, and background processes delaying the CLI's startup.","Update the Foundry Local CLI; if startups legitimately need more time, file an issue with microsoft/aspire asking for a configurable startup timeout."],"exampleFix":"// before: cold-start exceeds the internal timeout during AppHost startup\n// after: warm the service up before launching the AppHost\n// $ foundry service start\n// $ foundry service status  # verify running\ndotnet run --project MyApp.AppHost","handlingStrategy":"retry","validationCode":"// Warm the service up before AppHost startup so the timeout path is avoided:\nvar psi = new ProcessStartInfo(\"foundry\", \"service start\") { UseShellExecute = false };\nusing var p = Process.Start(psi)!;\nawait p.WaitForExitAsync();\n// then confirm: foundry service status","typeGuard":null,"tryCatchPattern":"try\n{\n    await foundryResource.StartAsync();\n}\ncatch (TimeoutException ex) when (ex.Message.Contains(\"Timed out waiting for Foundry CLI server startup\"))\n{\n    logger.LogWarning(ex, \"Foundry service startup timed out; retrying after pre-warming.\");\n    // Pre-start the service with `foundry service start`, then retry once.\n}","preventionTips":["Pre-start the Foundry service (`foundry service start`) before running the AppHost, especially on cold or slow machines.","Retry once on timeout — first-run initialization often exceeds the fixed startup window.","Exclude the foundry binary from antivirus/EDR scanning if startup is consistently delayed.","Update the CLI; report persistently slow startups to microsoft/aspire if the fixed timeout is too tight for your hardware."],"tags":["foundry","cli","timeout","service-startup"],"backgroundTag":"request-timeout","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}