Skip to content

feat(updates): run backend, model and add-on updates as server-owned runs - #13447

Merged
mudler merged 98 commits into
mudler:masterfrom
mudler-agent:feat/upgrade-center
Nov 24, 2026
Merged

mudler merged 98 commits into
mudler:masterfrom
mudler-agent:feat/upgrade-center

Conversation

@mudler-agent

Copy link
Copy Markdown
Collaborator

This change makes every update of a backend, a gallery model or an add-on an
upgrade run that the server owns. One run updates a set of items in a
fixed order, follows each update to the end and keeps the result. A reload of
the page, a restart of the server or the loss of one frontend in a cluster does
not lose the run.

Before this change, the Updates page ran the selected rows one after another
from the browser, and each kind of update had its own path and its own
notifications.

What changes for users

  • Review before any change. Update N ready, and Update or
    Retry on a row, open a review dialog. The server makes the plan. The
    items are grouped by kind, each with a checkbox, its versions and a risk line
    when the server knows the risk (for example "Stops 2 loaded models on 2
    nodes while it switches"). Select all, Select none and the count
    ("6 of 8 selected") are at the top. Models start unselected, because a model
    update reloads the model. An item that cannot start shows the reason and
    cannot be selected.
  • Run panel with real states. The Updates page shows the active run: how
    many items are updated, running and waiting, a progress bar and Cancel
    remaining
    . Each item shows its state: queued (with the reason it waits),
    updating, updated, failed, rolled back, cancelled, skipped or not confirmed.
    An item is updated only when its operation ended without an error and a
    fresh check no longer lists it. When the run ends, the page gives the result
    ("5 updated, 1 needs attention"). Retry shows only on an item that the
    server can retry. /app/updates?run=<id> opens one run.
  • One Notifications item per run. While the run is active, one item shows
    its progress and is edited in place. It never sends a push. When the run
    ends, one end item replaces it and notifies once. The operations of a run do
    not write their own "installed", "upgraded" or "failed" items. The footer of
    the notification center has Open Updates with the number of updates,
    for administrators.
  • Rollback of a failed backend upgrade. After the swap, the server starts
    the new backend build once, with the readiness check of a model load. When
    it does not start, the previous build is put back and the item ends
    rolled_back with the cause (the last output of the process). This works on
    a single server and on each worker of a cluster.
  • Automatic updates are runs. Update backends automatically and
    Update add-ons automatically start a run with the source auto, with the
    same page, history and notifications. A release that already failed its
    start check is held back from automatic runs until the gallery lists another
    release. The Updates page shows it as "Held back: this release did not
    start", and a person can still start it by hand.
  • A single update is a run of one item. Upgrade on a model row, an
    approved add-on upgrade and the single upgrade routes start a run of one
    item, so they show in the same panel and notifications.

What changes for operators and API clients

  • New routes under /api/updates/runs (admin only, Swagger tag
    updates): POST /preview, POST / (start, answers 202), GET /,
    GET /{id}, POST /{id}/cancel, POST /{id}/items/{key}/cancel,
    POST /{id}/retry and DELETE /{id} (dismiss). A refusal has one shape on
    every route, {"code", "key", "message"}, with the codes invalid,
    not_found, no_update, stale, source_unchecked, run_active,
    held_back, not_cancellable, run_finished, run_not_finished,
    nothing_to_retry, not_human_surface and unavailable.
  • The single upgrade routes keep their fields.
    POST /api/backends/upgrade/{name}, POST /backends/upgrade/{name},
    POST /api/models/upgrade/{name} and POST /api/addons/{id}/upgrade answer
    as before and add run. The backend routes take an optional expected_to
    and answer 404 not_installed, 409 no_update or 409 stale before
    anything is queued. A failed backend job has an error_key (download,
    verify, swap, start, ...). GET /api/backends/updates adds heldBack.
  • One run at a time per cluster. While a run is active, a start and every
    single upgrade route answer 409 run_active. The per-node route
    POST /api/nodes/{id}/backends/upgrade stays direct, to repair one node.
  • Retention. Finished runs are removed after
    --upgrade-run-retention-days (LOCALAI_UPGRADE_RUN_RETENTION_DAYS,
    default 30) and beyond the newest --upgrade-run-keep
    (LOCALAI_UPGRADE_RUN_KEEP, default 200). -1 disables each limit.
  • Hard break for old workers. A frontend sends backend upgrades on
    backend.upgrade and never falls back to a forced install. The worker reply
    has new fields (code, rolled_back, verified, cause). Update the
    frontends and the workers together. A frontend reads a failed upgrade of an
    old worker as unknown.
  • New Assistant tools. upgrade_run_start (backends and models only),
    upgrade_run_status and upgrade_run_cancel. upgrade_backend and
    upgrade_model start a run of one item.

How it works

  • Server-owned run. A start request names the items and the
    expected_to of the preview. The server checks every item before it creates
    the run; one failed check refuses the whole request.
  • Planner order. Backends first (up to the backend operation limit, never
    two updates of the same backend at the same time), then models one at a
    time, then add-ons one at a time. A queued item says why it waits.
  • Executor over the existing jobs. Each item uses the operation that a
    single update uses (the backend operation queue, the model upgrade, the
    library install or the add-on upgrade). The operation shows in
    /api/operations as before, and the run reads its progress from it.
  • Stores. Runs and items are rows in the shared database in a cluster
    (PostgreSQL), in the authentication database on a single server with
    authentication, or in upgrade_runs.db under the data path. A server with
    none of these keeps no runs and queues single upgrades directly, as before.
  • Advisory lock. One frontend runs a run and holds its advisory lock.
    Other frontends set a cancel flag and broadcast on the bus. When the runner
    dies, the lock is freed and another frontend takes the run over as after a
    restart. A second lock admits one start at a time. After a restart, a
    running item becomes unconfirmed and a fresh check decides between
    updated and failed with interrupted. A server that is not part of a
    cluster removes the staged leftovers of an interrupted backend update at
    start, and never removes a previous build.
  • Notifications. The runner writes the live item (at most once every 1.5
    seconds) and the end item.
  • Rollback in a cluster. A worker keeps its backend build until the new
    build starts. The reply carries the outcome over NATS and over the tunnel on
    WebSocket or P2P. A reply that never arrives makes the node and the item
    unconfirmed, not failed.

Security notes

  • All run routes need an administrator. Any administrator can read and cancel
    any run; a retry is a new run of the administrator who retries.
  • Add-on items run as the administrator who started the run, through the
    add-on owner, with the installed and candidate digests pinned. They run only
    when the run came from that administrator's own browser session with the
    header X-LocalAI-Confirm: upgrade-run. A run from an API key, from the
    Assistant or without the header skips its add-on items with
    not_human_surface. upgrade_run_start refuses add-on items.
  • The automatic add-on run uses the system actor of the add-on owner on the
    owner itself. That actor never goes through the add-on gateway, which
    refuses it.
  • Errors and messages of items and nodes are cleaned where they enter the run:
    one line of at most 512 characters, no control characters or markup, paths
    cut to the file name, and URL credentials, bearer tokens and values such as
    token= or password= removed. The frontend keeps at most 512 bytes of each
    text that a worker sends and maps an unknown code to unknown.
  • The start check runs the new backend build once as the user LocalAI runs
    as. Without strict integrity, a build from a gallery entry with no SHA-256
    and no signature policy now runs at upgrade time, not only at the next model
    load.

Testing

Go (-tags nosqlite,purego_utp, PostgreSQL specs against postgres:16-alpine):

Package Specs passed
core/services/upgraderun 112
core/services/distributed (PostgreSQL store) 38
core/http/endpoints/localai 923
core/application 461
core/http/endpoints/addons (auth tag) 213
core/services/updatenotify 54
core/services/modelupdates 135
core/services/galleryop 219
core/gallery 637
core/services/nodes 1134
core/services/worker 466
core/services/workerctl 71
core/services/carrier 319
core/http/routes 280
core/config 1018
core/services/localaitools (with inproc 41 and httpapi 55) 410
core/services/addons/gateway (auth tag) 269
core/services/studio/session (auth tag) 174

upgraderun, updatenotify and distributed also pass with -race. The
add-on suite inventories in scripts/addons/suites.json match the real Ginkgo
reports of the gateway, endpoints, owner binding, session scope, runtime,
protocol and lifecycle packages. gofmt, golangci-lint (with and without
the auth tag) and make swagger (no diff) are clean.

End to end, on a real server with fixture galleries and fixture add-ons: the
review, a run, the rollback of a backend that does not start, the auth rules
for add-on items, an automatic pass, recovery after a restart and a cluster
with two frontends. All passed.

UI: Playwright on the real UI served by the UI test server, one worker, with
the spec files of the Updates page, the review dialog, the run panel, the
notification center, the nodes and placement pages, the backends and add-ons
pages and view-as: 571 passed, 14 skipped, 0 failed. ESLint, the inline style,
UI kit and colour gates, the i18n check (no new gaps) and 2049 unit cases
pass.

Known limits and follow-ups

  • A backend from a backend library has no start check.
  • Model rows keep their own dialog for configuration-only updates and for the
    choices about edited keys; a run makes no such choice.
  • The start check proves that the backend process starts and answers a health
    check. It does not prove that a model loads on the GPU.
  • The display of an add-on on a moving channel (a tag that moves to new
    content) needs more work: the run pins the digest, but the versions on the
    page can be less clear than for a fixed release.
  • StartOne (the run of one item behind the single upgrade routes) polls for
    the operation of its item.

Assisted-by: Claude:claude-opus-5-5

The update of backends, add-ons and models is driven by the browser,
one request per item, and the run lives in page state, so a reload
loses it. Start a server-owned run with its state machine as a pure
reducer: events in, the new run and the effects out, no I/O.

An item is updated only after its operation ended without an error and
a fresh check no longer lists it; a listed item fails as stale, an
unanswered check leaves it unconfirmed. A queued item is dropped on
cancel, a running one is cancelled only while its operation says it can
stop, retry queues again only retryable items, and a finished run takes
nothing but a dismiss. The scheduler runs backends first, up to the
backend limit and never two of one backend, then models one at a time,
then add-ons one at a time, and says why each queued item waits.

Assisted-by: Claude:claude-opus-5-5
…going stale

Add the upgrade_runs and upgrade_run_items tables, on SQLite standalone
and PostgreSQL in a cluster, and register the store in InitStores. The
runner writes the state of a run and of its items; any frontend sets
the cancel and dismiss flags, which a save of the runner never
overwrites. The progress of a running item is not stored: it is read
from the status of its operation.

Add GalleryStore.TouchActive. An operation that waits in the queue
behind a long download does not tick, so the 30-minute reaper failed it
although it was going to run. The runner of an upgrade run touches the
operations it follows; one whose frontend died still goes stale.

Assisted-by: Claude:claude-opus-5-5
Add a client for the update run routes (preview, start, list, read,
cancel, item cancel, retry, dismiss) and the useUpgradeRun hook. The
hook asks for the plan of a review, starts the run, reads it every two
seconds while it runs and sends the run actions. It keeps no run of its
own: a reload reads the active run, or the run in the address, again.

The state is a reducer in utils/upgradeRun.js, so the node unit tests
check the review selection, the start body, the polling guards and the
counts without a browser.

upgradeFailureWords is now the one failure-words map for every kind. It
words the backend steps (download, verify, swap, start) and the run
refusals, and says the server's own text for a key it does not know.

Assisted-by: Claude:claude-opus-5-5
"Update N ready" no longer starts anything. It opens a review that the
server plans: the items grouped by kind, a checkbox each, the versions,
the risks the server knows (models that stop, data that is migrated,
edited model keys), Select all, Select none and a live count. Models
start unselected. A row's Update or Retry opens the same review with
that row only.

The run shows on the page: the strip says how many items update, how
many are done, running and waiting, with an overall bar and Cancel
remaining. One group lists the items in run order with their state,
the reason a queued item waits, progress, and for a failure what
happened, which version the item is on and that its data is unchanged.
Retry shows only when the server marks the item retryable. When the run
ends the strip gives the result with Retry failed and Dismiss.

Remove the browser-side orchestration it replaces: useBulkUpgrade,
BulkUpgradeDialog, runConcurrent, the per-row runners of updateRun.js
and the row selection of the page. The node dialog keeps its own
node-by-node run and stays on the Nodes page of a backend.

Assisted-by: Claude:claude-opus-5-5
A run has one live item in the panel (code updates.run) with a progress
bar and "View progress", and a summary once it ended (updates.run.end)
with the counts and the first item that needs attention. Both lead to
the Updates page with the run in the address, also when the server
stored no link.

The panel footer gets "Open Updates" for administrators, with the number
of updates. UpdatesProvider now sits above InboxProvider so the panel
can read it.

Assisted-by: Claude:claude-opus-5-5
Take 121 for KeyUpgradeRuns. One frontend at a time starts an upgrade
run, so two frontends never start two runs at once. The runner of a run
holds a key of its own, derived from the run id.

Assisted-by: Claude:claude-opus-5-5
…paths

Add the planner: a preview orders the items with an update into
backends, models and add-ons, says what each update does and whether it
can start, and selects backends and add-ons but not models. A start
request is checked item by item (installed, an update, the target the
caller saw); a held model or one with edited keys becomes a skipped
item.

The candidates come from the existing update checks: the backend read
model and the model read model, behind a small Checker interface, and
the add-on owner through an implementation the caller hands in. Each
item starts through the path a single update uses: the backend
operation queue, the model upgrade queue after its request checks, the
library install, or an add-on upgrader. The state of an item is read
from the operation status in the gallery service, never kept twice.

Assisted-by: Claude:claude-opus-5-5
Add the runner and the in-process service API: Preview, Start, Get,
List, Cancel, CancelItem, Retry and Dismiss, with typed errors the HTTP
layer maps to status codes, and an Observer interface told of every
change.

The runner feeds the reducer with the operation statuses, the results
of the fresh checks and the cancel flags other frontends write, stores
the run before it shows it, and touches the operations it follows so
the stale reaper leaves them alone. It holds an advisory lock of its
run; every frontend sweeps for runs nobody runs, and the one that takes
the lock continues the run, with the items that were running
unconfirmed until a fresh check decides. A broadcast on the bus makes
the runner apply a cancel at once and tells the other frontends of a
change. One run runs at a time in the cluster.

The specs cover the executor with fakes of the job paths and the
checks, two frontends on the fake bus, a restart, and the reaper.

Assisted-by: Claude:claude-opus-5-5
What a run is, its stages, when an item counts as updated, cancel,
retry and dismiss, restarts, and how a run behaves with several
frontends: shared state in the database and a single runner per run
under an advisory lock.

Assisted-by: Claude:claude-opus-5-5
The Updates page no longer runs updates from the browser. Describe the
review (groups, risk lines, models unselected), the update run that the
server owns, its states and result, the notification item of a run and
the Open Updates link of the notification center.

Assisted-by: Claude:claude-opus-5-5
…cked

A start that names an item missing from a check that failed or never
ran was refused with no_update, which is not known. Refuse it with
source_unchecked so the caller checks again. Add a spec for it, and run
the two-frontend spec on PostgreSQL too when LOCALAI_TEST_POSTGRES_URL
is set, where the run locks are real session locks.

Assisted-by: Claude:claude-opus-5-5
The server runs one update run at a time, and a retry of a finished run
is a new run. The page follows them:

- A start refused with run_active says so in the review and the page
  shows the active run. While a run is active, the row actions that
  would start another one are off and say why.
- Retry failed and a row's Retry follow the new run, also in the
  address.
- An unconfirmed item of an active run is the server's check after the
  operation: it shows as in progress with the server's message. In a
  run that ended it asks for a new check.
- Words for every queued reason (after_backends, after_models,
  backend_limit, same_backend, one_model_at_a_time,
  one_addon_at_a_time), with a plain fallback, and for the run refusals
  in the one failure-words map.

Assisted-by: Claude:claude-opus-5-5
Add mockUpdateRuns and run fixtures to the Updates fixtures, and specs
for the review (selection, count, models unselected, risk lines, the
one-row review, refusals), the run (states in run order, polling to a
rolled-back item, reload, failure words, Retry only when retryable, a
retry that is a new run, an unconfirmed check, Dismiss) and the
Notifications panel (the live item and its bar, the summary, Open
Updates for administrators only).

Move the specs of the browser-side bulk run to the review: Update and
Retry open a review, a cluster row is part of it with its risk line,
and the page never posts an add-on upgrade itself.

Assisted-by: Claude:claude-opus-5-5
A failed backend upgrade only carried the raw Go error text, so a client
could not tell a refused signature from a broken download without
parsing words. Tag each step of gallery.UpgradeBackend with a stable
code (download, verify, swap, not_installed, no_update, stale, and the
reserved start) in an error that keeps the cause for errors.Is and
errors.As. The downloader now marks a checksum or signature refusal
with ErrIntegrity, so that case reads as verify and not as a failed
transfer.

backendHandler gives a failed upgrade without a code the code unknown,
and OpStatus carries the code as error_key next to the message, also
across the peer broadcast.

Assisted-by: Claude:claude-sonnet-5-5
An upgrade request for a backend that is not installed, or that has
nothing to upgrade to, was accepted with 200 and failed later in the
job. A client that starts an upgrade run only learned about it after
waiting. The three upgrade routes (the API, the UI route and the
per-node route) now answer 404 not_installed or 409 no_update before
they queue anything.

A request can also carry expected_to, the version or digest the caller
saw. When it is no longer the available build the answer is 409 stale.
A meta backend is checked through the concrete backend it points to,
and nothing is refused on the missing-update rule before the first
check has finished. Response shapes of the accepted requests are
unchanged.

Assisted-by: Claude:claude-sonnet-5-5
A worker that does not serve backend.upgrade used to get a forced
backend.install instead, from the distributed manager and from the
reconciler drain of queued upgrades. That path never confirmed what the
worker did with the upgrade, and it hid a worker that is too old. A
cluster upgrade now goes through the upgrade command only: a worker with
no route fails the upgrade, and a queued upgrade waits for a node that
serves it.

InstallBackendForce is removed from NodeControl, the NATS and tunnel
adapter and the carrier holder, with the specs that only tested it. The
docs say that old workers must be upgraded with the frontend.

Assisted-by: Claude:claude-sonnet-5-5
The early refusal decided no_update from the update list, which is
refreshed about every six hours. A user who clicked Update right after
a build was published was refused until the next check. When the guard
would answer no_update and the last successful check is older than five
minutes, or there is none, it now runs the check of Check now, shared
with one that already runs, and waits at most fifteen seconds. The
fresh list decides. A check that fails or times out lets the request
through, and the job reports the truth.

Assisted-by: Claude:claude-sonnet-5-5
OpStatus.ErrorKey lived in memory only, so a frontend that rebuilt its
statuses from the operation record read no key and the upgrade run saw
unknown. The key is now a column of gallery_operations (error_key,
added by the automatic migration), written with the failure by
UpdateStatusWithKey, restored by Hydrate and carried by the history
record. A panic in an upgrade handler now ends with the key unknown.

Assisted-by: Claude:claude-sonnet-5-5
An upgrade swaps a new backend build into place but nothing starts it,
so a build that fails at process start is only found at the next model
load, after the previous build is gone.

CheckBackendStart starts the build the way a model load does (the
loader's process start, on a free local port of its own), waits until
it answers a gRPC health check, and stops it again. It stops the process
on every path, also when the context ends. A failure is a
StartCheckError with the end of the process output, bounded to 512
bytes and on one line. The check loads no model: it proves that the
build starts and listens, not that a model loads on a GPU.

The backendtest package gives specs a run.sh that starts the test
executable as a backend that serves, exits with output, or never
listens, and records its PID so a spec can check that no process is
left running.

Assisted-by: Claude:claude-opus-5-5
…tart

A local backend upgrade swapped the new build in, wrote its metadata
(a failure was only logged), registered the backends (a failure was
only a warning) and deleted the previous build. A build that failed at
process start stayed in place, and the upgrade reported success.

After the swap and the metadata write, the upgrade now starts the new
build from its final path (model.CheckBackendStart) before it removes
the previous build. When the build does not start, the upgrade moves
it aside to <name>.failed, puts the previous build and its metadata
back, registers the backends again and fails with the code start and
the end of the process output. A metadata write or a registration that
fails after the swap rolls back the same way, with the code swap. When
the restore itself fails, the error says so and the failed build is
kept for diagnosis. A cancelled context stops the check and still
restores the previous build.

UpgradeError gets RolledBack, and UpgradeRolledBack reads it. A forced
install (InstallBackend with the new WithStartCheck option, passed by
the local backend manager when Force is set) keeps the replaced build
until the new one starts, with the same rollback. A first install
starts nothing. The library installs of the add-on backend installer do
not take the option. The failed-op cleanup no longer deletes a backend
whose forced reinstall rolled back.

OpStatus gets rolled_back (the previous build is back) and unconfirmed
(an upgrade whose reply was lost), and NodeProgress gets error_key and
the node statuses rolled_back and unconfirmed for the cluster upgrade.
UpgradeNodesError keeps the outcome of each node of a cluster upgrade.

Assisted-by: Claude:claude-opus-5-5
The routes that update one item at a time answer with the id of the
operation, but a run starts the operation on the goroutine of its
runner. StartOne starts a run of one item and waits until the item has a
job id, ended without one, or the wait runs out.

Add the package upgraderuntest with fakes of the job paths and the
checks, for the tests of the packages that wire and serve the runs.

Assisted-by: Claude:claude-opus-5-5
…ctor

An upgrade run upgrades an add-on through the path of POST
/api/addons/{id}/upgrade: the owner records the upgrade for the
administrator who started the run, with the pinned digests and every
check of the explicit upgrade, and the operation queue runs it for that
administrator. Nothing acts as a system identity.

The actor of a run carries the add-on identity of the caller and
whether the request came from the administrator's own browser session
with the confirmation header X-LocalAI-Confirm: upgrade-run. A run
without it skips its add-on items with not_human_surface, a run whose
actor is not an add-on administrator skips them with forbidden, and an
owner refusal fails the item with the owner's type. The credential
reference stays on the server: answers name the user only.

POST /api/addons/{id}/upgrade starts a run of one item with the
operation the caller recorded, and answers as before with the run
added. While another run runs it answers 409 run_active and drops the
record. Without the run service it queues as before.

The owner lists the update status of every installed add-on for the
run's check (Manager.UpdateStatuses); it is not routed.

List the new specs in the add-on case inventories.

Assisted-by: Claude:claude-opus-5-5
Build the upgrade run service at startup and close it on shutdown. Its
checks are the backend update check, the model update check and, on
the process of the add-on owner, the owner's add-on update status. Its
job paths are the backend queue, the model upgrade, the library install
for the run's actor and the add-on upgrade through the gateway.

In a cluster it uses the shared store, the bus and the gallery store to
keep its operations from going stale; standalone it keeps the runs in
the authentication database, or in a SQLite file of its own under the
data path. Without either it does not start and the single upgrade
routes keep their direct path. The HTTP layer hands it the cache of
/api/operations.

Assisted-by: Claude:claude-opus-5-5
Add the administrator routes of upgrade runs under /api/updates/runs:
preview, start, list (active=1 for the running run), read, cancel a run
or one item, retry and dismiss. The answers are the JSON of the run
service; a refusal is {code, key, message} with 400 for invalid, 404 for
not_found and 409 for the other codes. The preview adds
default_selected, risk and order to the plan.

POST /api/backends/upgrade/{name}, POST /backends/upgrade/{name} and
POST /api/models/upgrade/{name} start a run of one item and keep their
answer, with the run added. While another run runs they answer 409 with
code run_active; an expected_to that moved is 409 stale. When the run's
check does not list the item, or the server keeps no runs, they answer
through their direct path as before. A model upgrade with config_only
or choices stays direct: a run makes no such choice. The per-node
upgrade route does not change.

Assisted-by: Claude:claude-opus-5-5
…models

Add upgrade_run_start, upgrade_run_status and upgrade_run_cancel to the
admin tools, with both clients, the DTOs and a recipe for updating
several items at once. The two mutating tools are under safety rule 1.

The tools take backends and gallery models only and refuse an add-on
item before anything starts: an add-on upgrade needs the administrator's
own browser session, which the assistant does not have. A run the
in-process client starts has the acting user's id as its actor, which
carries no add-on identity.

upgrade_backend and upgrade_model stay; the in-process client starts
them as a run of one item, as the REST routes do. The preview, retry
and dismiss routes get no tool, with the reason in the coverage map.

Assisted-by: Claude:claude-opus-5-5
Extend the upgrade runs page with where the runs are kept, how add-on
items keep the owner's checks and the browser session rule, the routes
with their typed errors and examples, what the single upgrade routes add
to their answers, and the assistant tools. Point the model updates and
the add-on update pages at it, and regenerate the API reference.

Assisted-by: Claude:claude-opus-5-5
…y route

A worker upgrade stopped the processes of the backend, force-reinstalled
it (the install deleted the previous build at once) and never started
the new build. A build that failed at process start stayed in place, and
the failure reached the frontend as a plain string that ended with the
code unknown, flattened with the other nodes into one message.

The worker now passes a start check to the install: the new build runs
once under a process key of its own with startBackend (the worker's
port range, bind host, data token and 30 s readiness check), and the
previous build is removed only when it answers. When it does not, the
previous build is put back and registered. The worker then starts the
processes it stopped again, on the build in place, with no model loaded.
Nothing in the check or the restore talks to NATS, so a worker that
holds only a tunnel behaves the same.

BackendUpgradeReply gets code (the typed upgrade code), rolled_back,
verified, cause (the bounded end of the output of the failed start),
restarted_process_keys and restart_error. The fields travel as JSON on
the NATS, websocket and P2P routes alike. Frontend and workers update
together: there is no version negotiation.

On the frontend, UpgradeReplyError maps a reply to a typed UpgradeError.
A cluster upgrade that fails returns an UpgradeNodesError that keeps the
outcome of each node (updated, failed, rolled_back, unconfirmed or
queued) with its code, so errors.Is and UpgradeCodeOf still work through
the aggregation. The per-node status written to the operation is
rolled_back or unconfirmed for an upgrade, with error_key. A reply that
never arrives stays unconfirmed: it is never read as failed or updated,
and its intent stays queued. A rolled back upgrade is not retried by the
fan-out or the reconciler, because the same build would fail the same
way.

The mixed-fleet specs carry a rolled back answer and a lost reply from a
NATS, a websocket and a P2P worker to the frontend. Swagger is
regenerated for the new operation status fields.

Assisted-by: Claude:claude-opus-5-5
The backends page says what an upgrade does when the new build does not
start (the previous build comes back, error_key start, rolled_back), the
same for a forced reinstall, and the limits of the start check: it
proves that the build starts and listens, not that a model loads on the
GPU. The distributed mode page says that a worker keeps its build until
the new one starts, what its reply carries on every route, how a lost
reply ends unconfirmed, and that frontend and workers update together.

Assisted-by: Claude:claude-opus-5-5
An install or an upgrade keeps directories next to the backend while it
replaces it: the staged build, the previous build and, now, a failed
build moved aside. The backends are registered again while the previous
build is still kept, so the listing read those directories as backends:
it registered names like "x.backup" whose path is deleted a moment
later, and an unreadable metadata file in one failed the whole listing,
which now rolls the upgrade back. The listing skips them.

Assisted-by: Claude:claude-opus-5-5
The stale refusal of the single backend upgrade routes read the
message with a type assertion; use errors.As, as CodeOf does, so a
wrapped refusal cannot panic. Drop an unreachable branch of the add-on
upgrade route.

Assisted-by: Claude:claude-opus-5-5
The worker bounds the cause and the restart error of its backend.upgrade
reply, but the frontend used the error and the cause as they came. A
compromised or an older worker could send megabytes, markup or a
credential, which went into the operation status, the run item, the
database and the context of the assistant.

BackendUpgradeReply.Sanitize keeps the last CauseLimit bytes of the
error, the cause and the restart error and cleans them with
sanitize.Text. The control adapter, which all carriers use, applies it on
receipt, and UpgradeReplyError applies it again for any other adapter.

Assisted-by: Claude:claude-opus-5-5
Nothing removed a finished run: UpgradeRunStore.CleanOld had no caller,
and a dismiss only sets a flag, so the runs table grew with each run.

The store gets Prune, which removes the finished runs older than a
maximum age and those beyond the newest N, with their items, and never
a running run. The sweep loop of the run service calls it once an hour,
under a try of the admission lock, so one frontend at a time prunes and
no run starts meanwhile. Pruning is idempotent.

The defaults keep 30 days and 200 runs. --upgrade-run-retention-days
and --upgrade-run-keep change them; -1 turns a limit off.

Assisted-by: Claude:claude-opus-5-5
… path

The upgrade joined the requested name into the backends path. The name
can be an alias, and an alias can have the name of the directory of
another backend, so the upgrade replaced that other backend. A name with
a path separator or ".." built a path outside the backends path, and
the restore of a failed build removed name+".failed" from that path.

ValidateBackendName accepts only one plain path element. The upgrade
checks the requested name, resolves it to the directory of the run file
it names (the target of an alias), refuses a directory outside the
backends path, and upgrades that directory under its own name. The
install checks the gallery name before it creates any directory, and
the restore checks that it got a backend directory and its swap
directory before it moves or removes anything. A refused upgrade has
the code unknown.

A symbolic link is moved and removed as a link; a spec covers that the
restore never follows one.

Assisted-by: Claude:claude-opus-5-5
The pages said that an update "still goes to expected_to". The run
checks each item against expected_to just before its operation starts,
but a gallery backend or model operation installs what the gallery
lists when it runs. Say that, and that the integrity checks run before
the swap and that the add-on owner pins and checks add-on items at queue
time and at run time.

Add an access and trust section: every administrator can read and
cancel every run, the assistant's run tools rely on the confirm-first
rule of its safety prompt (add-on items are refused in code), and the
start check runs the downloaded build as the LocalAI user right after
the swap, which without strict integrity can be a build with no
checksum and no signature.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-5-5
The error keys of a run item were written in several places: the backend
step keys repeated the strings of gallery.UpgradeFailureCode, the add-on
keys were literals in the retry table, in the add-on starters and in the
automatic add-on starter, and the actor of the automatic runs repeated
the user id of the owner's automatic upgrade.

Define the step keys from the gallery failure codes and the add-on keys
as constants of upgraderun, make the RunErr constants of the add-on
routes refer to them, and take the automatic run actor from
addons.AutoUpgradeActor. Every value is the same as before, so the
stored keys, the JSON answers and the retry rules do not change.

Assisted-by: Claude:claude-opus-5-5
The start check of a new backend build (pkg/model) and the bound of the
cause of a failed worker upgrade (workerctl.BoundCause) each had the
same loop: drop control characters but a tab and invalid UTF-8, trim
each line, and join the lines that are not empty with "; ".

Move the loop to sanitize.JoinLines and call it from both. The output
is the same: BoundCause still keeps the last CauseLimit bytes, and the
start check output is still bounded by the bytes it reads. A spec
covers the new function.

Assisted-by: Claude:claude-opus-5-5
Use slices.Sorted(maps.Keys(...)) for the backends a pass hands to a
run, slices.SortStableFunc with cmp.Or for the order of the candidates,
slices.Contains for the checker of a kind and slices.ContainsFunc for
the node check of the backend upgrade guard, and reflect.Pointer for
reflect.Ptr. The order and the answers are the same as before.

Also drop the copy of the upgrade source into a second interface in
NewBackendUpgradeGuard (a nil interface converts to a nil interface),
and move Item.RetryEligible next to the retry table and retryablePhase
it reads.

Assisted-by: Claude:claude-opus-5-5
UpgradeRunStore.CleanOld was Prune(retention, -1) and only a spec of
the store called it: the service prunes with Prune and the retention
settings. Remove it; the spec now calls Prune(24h, -1), which is what
CleanOld did, so it checks the same behaviour.

Also unexport InstalledBackendsOf of the localai endpoints: only
NewBackendUpgradeGuard in the same file uses it.

Assisted-by: Claude:claude-opus-5-5
splitUpdate (and its otherOf helper) split a selection of the Updates
page into the node dialog and the plain updates; the server-owned
upgrade runs replaced that path, and only its unit tests still called
it. firstAttention had no caller at all. Remove both and the tests that
covered only them (three tests and one assertion). Nothing that the app
imports changes.

Assisted-by: Claude:claude-opus-5-5
An add-on item that the owner refused got its retryable flag from a
second list, retryableRefusal, which knew only stale_installed,
candidate_changed and check_failed. The retry table of the runs also
lists unavailable, upgrade_failed, interrupted and the unknown key as
retryable, so an owner that answered "unavailable", or an upgrade that
failed and kept the installed version, ended as a failed item with no
Retry, while the same key from any other path could be retried.

Drop retryableRefusal and set the flag of an owner refusal with
upgraderun.RetryableKey, so the retry table is the one source of truth.
Types that the table does not list (incompatible, recovery_required,
integrity_error, upgrade_conflict, approval_required, forbidden, ...)
stay not retryable.

A new table spec runs a refusal of each type through a run: before
this change the unavailable, upgrade_failed, interrupted and untyped
entries failed.

Assisted-by: Claude:claude-opus-5-5
When an automatic pass found another upgrade run running, autoRunner
started a goroutine for the family that tried again every minute, up to
30 times. Nothing owned it: it was in no WaitGroup and ended only with
the context of the pass, so it outlived the shutdown of the upgrade
runs and could call Start on a service that was closing.

Give autoRunner a stop path. Close closes a quit channel, waits for the
retry goroutines with a WaitGroup, and makes later passes start no new
waiter. The WaitGroup is added under the lock that Close takes, so a
retry that starts while the runner closes is either refused or waited
for. stopUpgradeRuns, which Shutdown calls, closes the runner before it
stops the run service. The retry timer is now a time.Timer that is
stopped when the goroutine ends.

A new spec leaves a retry waiting an hour, stops the upgrade runs and
checks that the stop returns, that the waiter and its goroutine are
gone (counted by the retryLater frames in the goroutine stacks, not by
the total count, which other specs change) and that no retry ran.
Before this change the waiter was still there after the stop.

Assisted-by: Claude:claude-opus-5-5
fromRecords ignored the error of json.Unmarshal for the nodes and the
extra data of an item row, and marshalOrEmpty ignored the error of
json.Marshal. A damaged row lost its node list or its pins with no
trace anywhere.

fromRecords now returns the partial run together with an error that
names each damaged row and column (never its content, which can hold
node names, digests and error text). A partial run is the right answer
for a read: one damaged row must not make the run or the list of runs
unreadable. The service logs each damaged column once, with the run id,
the item key and the column, so a run read on every poll of the Updates
page does not flood the log. toRecords returns the encode error: a new
run is not created, and the runner logs the failed save as it logs any
store error.

A new spec stores a finished run with a corrupt nodes and extra column
and reads it twice: before this change nothing was logged.

Assisted-by: Claude:claude-opus-5-5
Conflicts:

- core/http/react-ui/src/App.jsx: master wraps the shell in
  ViewAsProvider; this branch moved UpdatesProvider above InboxProvider.
  The order is now ViewAsProvider > UpdatesProvider > InboxProvider.
- scripts/addons/suites.json: both sides added cases to the same four
  inventories (the upgrade run cases here, the host grants cookie cases
  on master). Each inventory keeps both lists.

swagger/ takes master's files and is regenerated with swag init.

Assisted-by: Claude:claude-opus-5-5
A model upgrade that an upgrade run started still wrote its own
"Model X upgraded" row next to the end row of the run. The gallery
operation knew the upgrade belonged to a run, but the model upgrader
never got the mark, so its result went to the emitter as a lone upgrade.

Carry InRun from the operation into the upgrade request and its result,
and skip the row in ModelUpgradeResult when it is set, as Operation
already does for backends and add-ons.

Assisted-by: Claude:claude-opus-5-5
The spec "keeps one waiter for the family" read a.autoRuns.waiting
without a.autoRuns.mu while the retry goroutine writes the map, so a
-race run reported a data race. Read the length under the lock, as the
next spec does.

Assisted-by: Claude:claude-opus-5-5
A rolled-back backend item read "The new version did not start: the
new build did not start: the backend process exited ...". The gallery
put "the new build did not start:" before the cause, and the Updates
page and the inbox put their own sentence before the error again.

The error key start already says that the new build did not start, and
every reader words the key. The gallery now returns the bare cause with
the code, so the sentence is said once, by the reader.

On a worker, a backend process that died without output added an empty
"Last stderr:" label to the cause. The label is now written only when
the process wrote something.

The run row of the Updates page uses its "did not start" sentence only
for the key start; a rolled-back item with another key (a build that
could not be put in place) is said with the words of its key.

Assisted-by: Claude:claude-opus-5-5
After a crash, an item that was running is settled by the restart
recovery: it becomes unconfirmed, and a fresh check decides. When the
check still listed it, the item failed with the key stale and the text
"the operation ended but the update is still listed", which is wrong:
the operation did not end, the restart stopped it.

An item settled by the recovery now fails with the key interrupted and
"the update was interrupted by a restart". The key is retryable. The
Updates page words it "The update was interrupted by a restart. Check
again", in every locale.

Assisted-by: Claude:claude-opus-5-5
Three faults of the end item of an upgrade run in the inbox:

- The list put a capital on the body of every failure, so the end item
  read "E2e-bad is still on 1.0.0". Its body starts with the name of an
  item, which keeps its case now.
- The end item of a cancelled run said only "1 updated" while the page
  said "Update run cancelled, 1 updated". The params now carry
  state "cancelled" and the count of cancelled items, and the item says
  "Update run cancelled: 1 updated".
- The error of a backend whose new build did not start is now the bare
  cause. The params carry first_key, and the item says "the new version
  did not start" before the cause for the key start.

The new params are additive. The words are in every locale.

Assisted-by: Claude:claude-opus-5-5
…c runs

A backend release whose new build did not start was tried again by
every automatic pass: each scheduled pass and each check started a new
automatic run, ran the start check of the bad build, rolled it back and
wrote a new item that needs attention in the inbox.

An automatic run now leaves out an item whose target already ended
rolled_back, or failed with the key start, verify or swap, in the
newest attempt of that release in one of the last 20 runs (dismissed
runs included). Failures of the moment (download, unavailable, unknown,
interrupted, ...) are tried again. The hold ends when the gallery lists
another target. When every item is held back, the start is refused with
the new code held_back and the pass writes nothing. A manual run is
never held back.

With the automatic update on, GET /api/backends/updates marks such an
item with heldBack: true (additive), so the Updates page can say why
the automatic update skips it.

Assisted-by: Claude:claude-opus-5-5
…e at start

After a crash during a backend upgrade, an empty <backend>.upgrade-tmp
directory and the partial download (about 8.6 MB in the test) stayed on
disk until the next upgrade of the same backend, or for ever.

At start, in local mode and before any operation can run, the server
now removes the staged builds (.upgrade-tmp, .install-tmp) of the
backends directory and the download directories that a crash left in
the staging directory. It never removes a previous build (.backup,
.install-backup), which may be the only copy: without its backend
directory it is put back, next to it it is logged and kept. A .failed
build stays. A cluster frontend does not sweep, as a worker may share
its directories.

Assisted-by: Claude:claude-opus-5-5
Four faults of the Updates page found against a real server:

- A finished run disappeared on reload: without ?run= the page asked
  only for running runs. It now loads the newest run that is not
  dismissed (the list puts the running one first), so a finished run
  stays until Dismiss. The test fixture now answers ?active=1 with the
  running runs only, as the server does.
- The filter counted only the rows outside the run: "Updating 0" while
  an item updated, "Needs you 0" beside a rolled-back item. Items of
  the run are now counted, and shown by the filter, in their group:
  waiting and running ones as Updating, ones that need attention as
  Needs you, updated ones as Up to date.
- After the run, the same backend was listed under Needs you as
  "Failed" while the run said "Rolled back". /api/operations now gives
  rolledBack and errorKey of a failed operation (additive), and such a
  row reads "Rolled back" with the sentence of the run.
- An automatic run had no label on the page. Its banner now says
  "Automatic update".

A backend release that the automatic update holds back (heldBack in
the read model) says "Held back: this release did not start" on its
row and can still be updated by hand. The words are in every locale.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-5-5 swag
The table "is retryable exactly when the retry table says so" in
core/http/endpoints/addons/upgrade_run_test.go has 12 entries that the
four inventories of that package (gateway, proposals, artifacts, apps)
did not list, so the report had 213 cases and the inventories 201. Add
the 12 cases to each.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-sonnet-5-5
@mudler
mudler merged commit e00e621 into mudler:master Nov 24, 2026
108 of 110 checks passed
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.

2 participants