Conversation
OllamaResourcesStartAndRespondOk waited for the ollama/ollama2 resources to reach the "Running" state before issuing an HTTP GET against them. "Running" only means the container/executable process has started; it does not mean the Ollama server inside is actually accepting connections yet. This is a genuine race: on a slow/contended CI runner the request can be issued before the server is listening, causing intermittent connection-refused failures. OllamaModelResource does not need any additional wait wiring for this: it implements IResourceWithParent<IOllamaResource> and has no "resource with its own lifetime" markers (it isn't a container, executable, project, etc.), so Aspire's ApplicationOrchestrator already propagates the parent's state/lifecycle to it automatically (see ResourceHasOwnLifetime/SetChildResourceAsync). No custom WaitAnnotation or WaitFor() is required or appropriate here. Fix: use ResourceNotificationService.WaitForResourceHealthyAsync instead of WaitForResourceAsync(..., KnownResourceStates.Running), the same pattern already used correctly by OllamaResourcesListAvailableModels. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1606Or
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1606" |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The readiness race is addressed with a focused, low-risk change.
Review effort: Lite
Findings: None
What changed in this PR
Fixes an Ollama AppHost test race by waiting for resource health before sending HTTP requests.
Changes:
- Replaces the
Runningstate wait withWaitForResourceHealthyAsync. - Aligns the test with the existing health-readiness pattern.
| File | Description |
|---|---|
tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AppHostTests.cs |
Waits for Ollama health before testing HTTP availability. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The race condition
AppHostTests.OllamaResourcesStartAndRespondOkwaited for theollama/ollama2resources to reach theRunningstate, then immediately issued an HTTPGET /against them:Runningonly means the container/executable process has started — it does not mean the Ollama server inside is actually listening and accepting HTTP connections yet. On a slow or contended CI runner, theGET /can race ahead of the server actually being ready, causing intermittentconnection refused/non-200 failures. This matches the resource-health guidance inOllamaResourcesListAvailableModelsin the same file, which already correctly usesWaitForResourceHealthyAsyncinstead.The fix
Use
ResourceNotificationService.WaitForResourceHealthyAsyncinstead ofWaitForResourceAsync(..., KnownResourceStates.Running), mirroring the pattern already used elsewhere in the same test class.Why no change was needed to
OllamaModelResource/AddModelI initially explored adding an explicit wait dependency (
WaitFor/WaitAnnotation) fromOllamaModelResourceonto its parent Ollama resource, and separately looked at catching the pre-download404inOllamaModelHealthCheck. Neither is necessary:OllamaModelResourcealready implementsIResourceWithParent<IOllamaResource>, and it isn't a container/executable/project/parameter/connection-string resource. Aspire'sApplicationOrchestrator.ResourceHasOwnLifetime/SetChildResourceAsyncexplicitly treats such "no owned lifetime"IResourceWithParentresources by propagating the parent's lifecycle state to them automatically, so no extra wiring is required or appropriate.404fromOllamaSharp.ShowModelAsyncinsideOllamaModelHealthCheckis already converted byMicrosoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckServiceinto anUnhealthyresult internally (it just logs a warning first), so the standard Aspire health-check retry/WaitForHealthypolling already handles it correctly today.Validation
dotnet buildon the hosting project and test project: succeeds.CommunityToolkit.Aspire.Hosting.Ollama.Tests(--filter-not-class "*AppHostTests*"): 69/69 passed.[RequiresDocker] AppHostTests(the class containing the fixed test): I was not able to get a clean run in this sandbox —tests-app-hosts/Ollama.AppHoststarts one resource viaAddOllamaLocal(a local executable resource requiring theollamaCLI binary onPATH), which is not installed in this environment, so that resource fails to start regardless of this change. This is a pre-existing environment limitation, not a regression. The change itself is a one-line swap to an existing, already-used API (WaitForResourceHealthyAsync), so risk is low.TypeScriptAppHostTestswas not run locally (requires theaspireCLI + Node/npm driving a real multi-container/model-pull scenario; out of scope for this fix and not verified here).Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com