Skip to content

fix(watchdog): track models on address-based external backends - #12902

Open
bercedev wants to merge 1 commit into
mudler:masterfrom
bercedev:fix/watchdog-external-address
Open

bercedev wants to merge 1 commit into
mudler:masterfrom
bercedev:fix/watchdog-external-address

Conversation

@bercedev

@bercedev bercedev commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

A model on an address-based external backend (an address in external_backends.json) was never added to the watchdog's addressModelMap. Spawned backends get registered in StartProcess, but the address path builds the client with no process and skips that, so EnforceLRULimit and EnforceGroupExclusivity never saw the model as loaded and loaded the next one next to it.

spawnGRPCModel now registers the model at its address after LoadModel succeeds, when there is no process (spawned backends are already registered in StartProcess). Unloading already handles these: deleteProcess calls Free() and then wd.Untrack(address) for a model with no process.

This PR fixes #12900

Notes for Reviewers

Distributed mode goes through the model router before spawnGRPCModel, so it isn't affected.

With the idle watchdog on, these models are now also freed after the idle timeout, like spawned backends. Before, the watchdog never saw them.

One address still maps to one model, so two models on the same endpoint would overwrite each other's entry, as the issue says. I left that alone.

Tests: new spec in pkg/model/initializers_external_address_test.go starts a fake backend on a local port and checks the watchdog lists the model after spawnGRPCModel. It fails on master and passes here. go test ./pkg/model/ (203 specs) and go vet ./pkg/model/ pass, gofmt is clean.

AI disclosure: written with Claude Code (Assisted-by trailer on the commit). The commit has no Signed-off-by, since CONTRIBUTING.md leaves that to the human submitter.

Signed commits

  • Yes, I signed my commits.
  • Documentation updated (docs/content/) for user-facing changes, or not applicable

@localai-org-maint-bot

Copy link
Copy Markdown
Collaborator

@mudler Review at a966502c4: needs changes before merge.

The new registration in pkg/model/initializers.go:236 enables automatic eviction of address-based external backends, but the force shutdown path cannot stop them. deleteProcess skips Free() when forced, then deletes/untracks the processless model without contacting the external backend (pkg/model/process.go:131,166–168). LocalAI can then load another model while the original still occupies memory. The busy watchdog uses this path too; it is not limited to explicitly forced LRU eviction.

Reproduced with a local gRPC fake implementing Free: load the model, mark a request active, and enforce LRU with forced eviction. The model disappears from the loader without receiving Free. The same assertion passes against master 06c51e8b5 and fails with this PR. A correction needs to retain tracking when external resources cannot be released. Merely calling Free with a timeout is insufficient: its client mutex acquisition can wait behind the stuck request before the context is checked.

The original package suite and go vet ./pkg/model pass; race tests were unavailable because CGO is disabled. The new eviction behavior and single-model-per-address limitation also need user documentation. DCO currently requires the contributor's human sign-off.

A backend reached by address has no process, so StartProcess never registered it with the watchdog and LRU and group eviction never saw it loaded.

Fixes mudler#12900

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: berce <75228263+bercedev@users.noreply.github.com>
@bercedev
bercedev force-pushed the fix/watchdog-external-address branch from a966502 to a27bee8 Compare October 26, 2026 10:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Watchdog eviction does not work for address-based external backends (missing model registration)

3 participants