Skip to content

fix(vm): VMs missing from the stored order go last, the same on every page - #2845

Open
luuvasara wants to merge 3 commits into
unraid:masterfrom
luuvasara:fix/vm-unlisted-last
Open

luuvasara wants to merge 3 commits into
unraid:masterfrom
luuvasara:fix/vm-unlisted-last

Conversation

@luuvasara

@luuvasara luuvasara commented Nov 16, 2026 •

Copy link
Copy Markdown

Related pull requests

Summary

VMs that the stored VM order (/boot/config/plugins/dynamix.vm.manager/userprefs.cfg) does not list go after the listed ones, in name order. This is the same on the VMs tab, the Dashboard, CPU pinning, and Start/Stop all. Start all starts in tab order; Stop all stops in reverse.

Why

It is the same bug as the Docker order PR, #2844. Each reader sorts with array_search($vm, $prefs) ?? 999. array_search returns false for a VM that is not listed (https://www.php.net/manual/en/function.array-search.php), and ?? only replaces null, so ?? 999 never fires. PHP compares false with an integer as booleans (https://www.php.net/manual/en/language.operators.comparison.php), so the VM ties with position 0 and goes to the top. The readers:

Example data: the stored order is win11, homeassistant, and you add pfsense. Today pfsense shows above both. Start all also starts it first, because Start/Stop all sorts the same way. The order is not cosmetic: what starts first and stops last has to be what others need, the rule systemd, Docker Compose and Kubernetes apply (sources in #2844).

Same principle as the Docker order

Unraid owns the order; a plugin such as FolderView Plus only groups it. With folders removed, the VMs stay in the same order as one flat list. That needs every VM to have a defined place, and unlisted ones at the end is the place that changes nothing for the VMs the user already arranged.

Why last, and why by name here

Containers go last in creation order because an app is set up after the database it needs, and a dependency has to start first and stop last (see #2844 for the sources). libvirt keeps no creation time for a domain: virDomainInfo holds state, memory, CPU count and CPU time only (https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInfo). So there is no creation order to use, and unlisted VMs go last in name order, which is the order the tab already uses when no order is stored.

Unlike containers, VMs are not written into the stored order automatically. The VM order file is only written when you drag, as today; this PR changes how it is read.

Testing

Tested on an Unraid 7.4 test server:

  • 4 VMs; a stored order with a removed name at position 0, 2 VMs listed, 2 unlisted.
  • Before: the unlisted VMs show first on the tab and the Dashboard.
  • After: listed VMs first in their order, then the unlisted ones by name, the same on the tab, the Dashboard, Start all and (reversed) Stop all.
  • With every VM listed, the order is unchanged.

This change was written with the help of frontier AI. I reviewed and tested it.

Summary by CodeRabbit

  • New Features
    • Container and virtual machine lists now follow saved user ordering, with naturally sorted defaults when no custom order is set.
    • Newly listed containers are placed after saved entries, ordered by creation time.
    • Renaming a container preserves its position and autostart setting when possible.
  • Updates
    • Container and virtual machine start and stop actions now use consistent ordering rules.
    • Autostart entries are sorted consistently with the saved container order.

…st first

Containers missing from userprefs.cfg sorted as position 0 (array_search returns false, so '?? 999' never applied) and went to the top of the Docker tab, Dashboard, CPU pinning and autostart file, each in its own order. All readers now use one sort; a container without a stored position is appended once, oldest first by Docker's creation time, and its autostart line moves with it. Writes to userprefs.cfg take a lock; renames keep the position.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Docker container ordering now uses persisted manual order and shared sorting methods across container actions, lists, and autostart entries. VM lists use a shared preference-ordering helper after natural sorting.

Changes

Docker Container Ordering

Layer / File(s) Summary
Docker order state and sorting
emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
DockerUtil adds manual-order storage and sorting methods. Container records now include their creation timestamp.
Docker order updates and actions
emhttp/plugins/dynamix.docker.manager/include/UserPrefs.php, emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php, emhttp/plugins/dynamix.docker.manager/include/ContainerManager.php
Preference submissions and resets use DockerUtil order methods. Renames update stored order and applicable autostart entries. Container actions use the resulting order.
Docker ordering consumers
emhttp/plugins/dynamix.docker.manager/include/DockerContainers.php, emhttp/plugins/dynamix.docker.manager/include/UpdateConfig.php, emhttp/plugins/dynamix/include/CPUset.php, emhttp/plugins/dynamix/include/DashboardApps.php
Container lists and autostart entries use DockerUtil sorting methods.

VM Ordering

Layer / File(s) Summary
VM preference ordering
emhttp/plugins/dynamix/include/Wrappers.php, emhttp/plugins/dynamix.vm.manager/include/VMManager.php, emhttp/plugins/dynamix.vm.manager/include/VMMachines.php, emhttp/plugins/dynamix/include/CPUset.php, emhttp/plugins/dynamix/include/DashboardApps.php
The new sort_by_order helper ranks items by preference position. VM lists are naturally sorted before preference ordering. VM actions reverse the order when the action is not start.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant UserPrefs
  participant DockerUtil
  participant OrderFile
  participant DockerContainers
  UserPrefs->>DockerUtil: saveUserOrder(names)
  DockerUtil->>OrderFile: write indexed names
  DockerContainers->>DockerUtil: sortContainers(containers)
  DockerUtil->>OrderFile: read manual order
  DockerUtil-->>DockerContainers: return ordered containers
Loading

Possibly related PRs

Suggested reviewers: bergware

Merge Risk: Minimal · up to efec4

The change makes VM and Docker ordering consistent across pages, with unlisted VMs placed after listed ones. No actionable merge-blocking risk remains in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: VMs missing from the stored order are now placed last, and the same order applies on every page. The raw summary shows changes to VM ordering in VMMachines.php, VMMana…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: VMs missing from the stored order are now placed last, and the same order applies on every page. The raw summary shows changes to VM ordering in VMMachines.php, VMManager.php, DashboardApps.php, CPUset.php, and the new sort_by_order helper in Wrappers.php, which matches the objectives. The title uses the conventional fix(vm) prefix and is concise, though it is long at 74 characters.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit sorts the names in rows
The oldest joins where order flows
The autostart list falls in line
A renamed burrow keeps its sign
VM names find their place anew
Then off the rabbit hops—eek, thump, woo!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e8b9b5f9-2978-4cf1-84d6-490efbb90ed1
Commits

Reviewing files that changed from the base of the PR and between 97beb1c and efec46e.

Files selected for processing: 1

  • emhttp/plugins/dynamix.docker.manager/include/ContainerManager.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

dev added 2 commits November 17, 2026 08:56
…ned no details for

The tab-order sort kept only containers listed by getDockerContainers(), which
skips a container whose inspect fails. Such a running container was then left
out of Stop all and Pause all. It is now kept, after the ordered ones; Start all
still skips it, as before.
… page

array_search returns false for a VM not in the VM userprefs.cfg, so '?? 999' never applied and the VM sorted as position 0 (top) on the VMs tab, Dashboard, CPU pinning and Start/Stop all. All four now use sort_by_order(): listed VMs in their order, then unlisted ones by name. Start all follows the tab order, Stop all the reverse.
@luuvasara
luuvasara force-pushed the fix/vm-unlisted-last branch from 97beb1c to efec46e Compare November 17, 2026 07:06
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.

1 participant