fix(distributed): detach cold-load staging from the request context#10438
Merged
Conversation
A model not yet loaded on a worker is staged lazily on the inference request path. Staging a multi-GB model takes minutes - far longer than any client keeps its HTTP request open - so a browser refresh, an ingress/LB idle-timeout, or a round-robined retry landing on another frontend replica cancels the request context and aborts the upload with "context canceled" mid-transfer. Large models then never finish staging, so they never load (observed in a 2-replica deployment: both frontends repeatedly failed to stage a 15.7 GB GGUF, each attempt dying at a different offset). Bind the cold load (staging + LoadModel + the per-model advisory lock) to context.WithoutCancel(ctx): it keeps the request's values (prefix chain) but drops cancellation/deadline. Each long step keeps its own bound (the file stager's resume budget, LoadModel's 5m timeout), and the advisory lock still de-dupes concurrent loaders across replicas. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-8 [Claude Code]
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.
Problem
In distributed mode, a model not yet loaded on a worker is staged lazily on the inference request path (
SmartRouter.Route→scheduleAndLoad→stageModelFiles). The staging upload is bound to the triggering request'scontext. Staging a multi-GB model takes minutes - far longer than any client keeps its HTTP connection open - so a browser refresh, an ingress/LB idle-timeout, or a round-robined retry landing on another frontend replica cancels the request context and aborts the upload withcontext canceledmid-transfer. Large models then never finish staging, so they never load.Observed in a 2-replica deployment: both frontends repeatedly failed to stage a 15.7 GB GGUF, each attempt dying at a different offset:
(
context canceled, not deadline exceeded → the caller's context was cancelled, i.e. the request was abandoned.)Fix
Bind the cold load (staging +
LoadModel+ the per-model advisory lock) tocontext.WithoutCancel(ctx): it preserves the request's values (prefix-cache chain, etc.) but drops its cancellation/deadline. Each long step keeps its own bound - the file stager's resume budget andLoadModel's 5-minute timeout - so nothing leaks, and the per-model Postgres advisory lock still de-dupes concurrent loaders across replicas.Test
router_staging_context_test.goreproduces the outage: the fake stager cancels the request context the moment staging begins and asserts the context the stager receives is not cancelled. Red before the fix (context canceled), green after. Fullcore/services/nodessuite passes;golangci-lint --new-from-merge-base=origin/masterreports 0 issues.Assisted-by: Claude:claude-opus-4-8 [Claude Code]