Skip to content

fix(cloudui): an update switches CloudUI atomically, gives up on a download that stops moving, and the installed release tag is in /flux/info - #1884

Merged
MorningLightMountain713 merged 16 commits into
developmentfrom
fix/cloudui-atomic-swap
Nov 18, 2026

Conversation

@MorningLightMountain713

@MorningLightMountain713 MorningLightMountain713 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What changes

scripts/update-cloudui.sh installs each build into its own folder under .cloudui/, and CloudUI becomes a symlink to the installed build. An update renames a new symlink over the old one, so CloudUI always resolves to a complete build, the old one or the new one.

  • First run on a node (CloudUI is still a folder): swapped for the symlink in one step with mv --exchange where mv has it (coreutils 9.5+); where it does not, the folder is moved aside and the symlink renamed into its place. Every later update is a symlink-over-symlink rename on every system.
  • Cleanup: everything a run creates (release JSON, tarball, unpacked build, the new symlink, the previous build) lives in .cloudui/. When a run exits, for any reason, it removes everything there except the installed build. A run killed outright with SIGKILL leaves its files for the next run to remove.
  • Stopped by a service manager: systemd and pm2 signal every process in the service, more than once, and the reader of the run's output may stop with it. The script catches SIGTERM, SIGINT and SIGHUP, ignores any further ones and exits through its cleanup; it catches SIGPIPE, so a write to a reader that has gone fails instead of ending bash; the cleanup ignores those signals, and the commands it runs inherit that, and it removes the files before it logs.
  • One run at a time: runs take a flock on .cloudui/.lock and wait their turn. With --if-idle a run does not wait: when another run holds the lock it exits 75 and changes nothing. The downloads close the lock descriptor, so a download that outlives its killed shell does not block the next run.
  • A release already installed: a run whose release's sha256 is the one in CloudUI/version downloads nothing and exits 0, so a run that waited for another finds that run's release installed and stops there. --force installs it again.
  • A download that stops moving: both curl calls give up when the transfer stays under 1 KB/s for two minutes or the connection does not open within 30 seconds. The run then fails and keeps the installed build. A slow transfer that keeps moving has no time limit.
  • The download goes to .cloudui/ on disk rather than /tmp.
  • CloudUI/version, CloudUI/index.html and every other path readers use are unchanged; express.static, sendFile, existsSync and readdirSync all follow the symlink.
  • .gitignore and .eslintignore: /CloudUI (no trailing slash, so it matches the symlink as well as a folder) and /.cloudui/, anchored to the project root.
  • The script now needs flock and GNU mv -T (Linux).

FluxOS's own update (nodes without the watchdog)

At boot FluxOS starts the CloudUI check in the background (startCloudUIUpdateCheck), so a slow download holds up nothing that starts after it. The script runs with no time limit, since it gives up on a download that stops moving, and only the end of its output is kept for the log.

When CloudUI is missing or holds only version and tag, the boot check runs the script with --force, since that version still names the release the script would otherwise find installed.

The rebuild route (/flux/rebuildui) runs the script with --if-idle --force through rebuildIfIdle: it installs the release whatever CloudUI/version holds, so it repairs a damaged UI, and while another update is in progress, in FluxOS or in another process, it answers at once that one is in progress rather than holding the request behind it. The boot check and the watchdog wait their turn.

The installed release tag

The script writes the release tag to tag beside version in the build it installs, so the tag switches with the build. version still holds the release asset's sha256, which the watchdog and FluxOS compare with the release. /flux/info reports cloudUI: { tag, sha256 }, each null where the script has not written it. cloudUIExists treats a CloudUI holding only version and tag as empty.

The watchdog

The watchdog runs this script (RunOnFlux/fluxnode-watchdog#54) in the background, one run at a time, and stops a run it has given up on with SIGTERM, which this script answers by removing its files.

Tests

tests/unit/updateCloudUiScript.test.js runs the real script against a local server standing in for the GitHub API, in a throwaway project root (Linux only): fresh install, flat archive, folder → symlink with and without --exchange, symlink → symlink with and without --exchange, an installed release left alone with nothing downloaded, its reinstall with --force and with --if-idle --force, a dangling CloudUI symlink, a symlink outside the store; the tag and version files of the installed build; every failure path (release fetch, missing asset/URL/digest, checksum mismatch, archive that does not unpack, failure with a folder still in place); a download and a release fetch that stop moving; a slow download that keeps moving; no API URL; no flock; SIGTERM mid-download, once, twice at once, and repeatedly until the run exits; SIGTERM or SIGPIPE arriving as the cleanup starts; a stop during a failed run's cleanup; a write and a stop after the output's reader has gone; SIGKILL mid-download and the next run's cleanup; leftovers of every kind; a run killed between the two fallback renames; an orphaned download not holding the lock; two concurrent runs, the second finding the first's release installed; --if-idle exiting 75 at once against a held lock and installing when idle; an unknown option. The signal cases are produced at the point they test (a BASH_ENV DEBUG trap, a readlink on PATH), so they do not depend on timing.

cloudUIUpdateService.test.js covers the background start, the absent time limit, a script ended by a signal, the bounded output, reading the tag file, the boot check forcing its install over a CloudUI holding only version and tag, and rebuildIfIdle: its options, its installed, failed and busy answers, busy without a run while one is in flight, and an update joining a rebuild in flight; fluxService.test.js covers the cloudUI field and the rebuild route's three answers; its getFluxInfo tests stub Docker and MongoDB, and its chain streaming preparation tests stub the app networks, so they pass or fail on the code under test alone. Harness suite 2803 sends its registration once the shaped node holds the policy, which the node needs before it resolves a repotag.

Run on Ubuntu 22.04 (bash 5.1, coreutils 8.32), Debian bookworm (bash 5.2, coreutils 9.1), Ubuntu 25.04 (bash 5.2, coreutils 9.5, where the --exchange case runs) and Ubuntu 26.04 (bash 5.3). Each branch was broken separately and each turned the suite red; the three parts of the signal handling were each broken on bash 5.1, 5.2 and 5.3.

Also run on an ArcaneOS node (systemd, watchdog) and a legacy node (pm2, FluxOS's own update): install over a real CloudUI folder by both paths, slow and stalled downloads, FluxOS answering while its boot download ran past five minutes, the released watchdog and FluxOS updating at once, and systemd and pm2 stopping a run mid-download, each leaving only the installed build. --if-idle, --force and the installed-release check have run in the unit tests only.

Unit (chud, tests/images/run-unit.sh): fluxService, cloudUIUpdateService and updateCloudUiScript: 317 passing, 1 pending, 0 failing. --if-idle made to wait, the installed-release check removed, and the boot check's --force removed, each turn the new tests red.

Harness gate (tester, MAXN=6) at 112c9271c7, this branch on development 54cd524684: 324 of 325 suites passed. 2803 sent its registration 2 ms before the shaped node adopted the policy; with the suite's fix it passes alone on chud (4 of 4). The branch was then rebased onto development f17f802717, which adds #1918 (networkStateManager.js and its test, no file of this PR); every commit applies unchanged.

🤖 Generated with Claude Code

@MorningLightMountain713 MorningLightMountain713 changed the title fix(cloudui): an update switches CloudUI to the new build atomically, and a failed or killed run leaves only the installed build fix(cloudui): an update switches CloudUI atomically, gives up on a download that stops moving, and the installed release tag is in /flux/info Oct 25, 2026

@Cabecinha84 Cabecinha84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditions before merge

  1. Rebase onto current development with the resolution above.
  2. Run the harness gate at the rebased head.

Non-blocking notes

  • .eslintignore: it still has /CloudUI/, which does not match a symlink. The PR changed .gitignore for this reason, so
    it should do the same here.
  • Rebuild route: rebuildUi now has no time limit. It can also queue behind a watchdog run holding the flock, leaving
    an HTTP request open for hours on a slow link.
  • Second waiting run: a run that waited on the lock downloads again after the first finishes, without checking whether
    it is already current.
  • Platform: the script now requires flock and GNU mv -T, which is fine on Linux nodes.

… and a failed or killed run leaves only the installed build

Each build is unpacked into its own folder under .cloudui/, and CloudUI is a
symlink to it, moved to a new build by renaming a new symlink over the old one.
A CloudUI that is still a folder is swapped for the symlink with mv --exchange
where mv has it, and moved aside then replaced where it does not.

Every run removes everything in .cloudui/ but the installed build when it exits;
runs take a lock so one never removes another's download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getFluxInfo asks Docker and MongoDB for their versions. The tests now stub both
and check the versions reported, so they pass or fail on getFluxInfo alone,
whether or not a Docker daemon is running where they run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…flux/info

The update script writes the release tag to `tag` beside `version` in the build
it installs, so the tag switches with the build. `version` keeps the release
asset's sha256, which the watchdog and FluxOS compare with the release.

/flux/info reports `cloudUI: { tag, sha256 }`, each null where the script has not
written it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ow one runs to the end

Both curl calls give up when the transfer stays under 1 KB/s for two minutes or
the connection does not open within 30 seconds. The run then fails and removes
its files, keeping the installed build. A slow transfer that keeps moving has no
time limit, so callers need not set one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A service manager stopping a service signals every process in it until no new
ones appear, which includes the processes the cleanup starts. The cleanup ignores
SIGTERM, SIGINT and SIGHUP, and the processes it starts inherit that. The reader
of the run's output may have stopped with the service, so the cleanup also
ignores SIGPIPE and removes the files before it logs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… no time limit

On a node without the watchdog, FluxOS checks CloudUI at boot. The check now
starts in the background, so a slow download holds up nothing that starts after
it. The script runs with no time limit, since it gives up on a download that stops
moving, and only the end of its output is kept for the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…files

bash dies outright on a second terminating signal that arrives while it handles
the first, before its EXIT trap runs, and a service manager sends SIGTERM more
than once. The script catches SIGTERM, SIGINT and SIGHUP, ignoring further ones,
and exits through the EXIT trap. It catches SIGPIPE too, so a write to a reader
that has stopped fails instead of killing bash; the commands it runs start with
the signal at its default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on its own

A signal sent as the cleanup starts, a stop during a failed run's cleanup, and a
write after the output's reader has gone are each produced at that point, so the
tests do not depend on timing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it on

within() clears its timer once the run or the timeout settles, so the file leaves no timer pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The preparation asks docker which app networks exist before it lets a private caller through. The tests answer with one network the caller is not on, so they pass or fail on the preparation alone, with or without a docker daemon where they run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…whatever CloudUI is

Both ignore files name the two paths the update script owns, anchored to the project root. /CloudUI has no trailing slash, so it matches the symlink as well as a folder, and .cloudui/ is listed rather than left to eslint's dot-folder default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in progress

The update script takes --if-idle: a run started with it does not wait for the run that holds the lock, and exits 75 having changed nothing. The rebuild route runs the script that way, through rebuildIfIdle, and answers that an update is in progress, rather than holding the request until the other run and then its own download finish. While this process has a run in flight, rebuildIfIdle answers busy without starting one. The boot check and the watchdog still wait their turn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uild installs it again

The update script does not download a release whose sha256 CloudUI/version already holds, and exits 0. --force installs it again. A run that waited for another to finish finds that run's release installed and stops there. The rebuild route passes --force, so it still repairs a damaged CloudUI whose version file names the release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… as it is

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the policy

The node refuses a registration before resolving its repotag until it holds the policy, so test 1 waits for the shaped node's policy:bundleChanged as well as its lookup of the policy host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MorningLightMountain713

MorningLightMountain713 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Both conditions and the four notes:

Rebase: the branch is on current development (f17f802717). The two conflicts resolved to development's side plus this PR's: serviceManager.js keeps startRouterAddressUpkeep() beside startCloudUIUpdateCheck(), and fluxService.test.js keeps the kernel assertion beside cloudUI, dockerVersion (development's 27.5.1 stub) and mongoDbVersion. Development's root hook that fails a file leaving a timer pending found one in the script tests (within() now clears its timer), and its chain streaming preparation tests now stub the app networks, which they read from docker.

Gate: tester, MAXN=6, at 112c9271c7 (this branch on development 54cd524684): 324 of 325 suites passed. 2803 sent its registration 2 ms before the shaped node adopted the policy, and the node refuses a registration before resolving its repotag until then; the suite now waits for the node's policy:bundleChanged first (a5496d080d) and passes alone on chud, 4 of 4. Since the gate the branch moved onto f17f802717, which adds only #1918 (networkStateManager.js and its test); every commit applies unchanged, so the gate stands for this head.

  1. .eslintignore: ESLint 8 follows the symlink and matches /CloudUI/ (a CloudUI link to a build with lint errors leaves npm run lint clean). Both ignore files now name /CloudUI and /.cloudui/, anchored to the root, rather than leaving .cloudui/ to ESLint's dot-folder default, which flat config does not have (aeb04d35eb).
  2. Rebuild route: it no longer waits behind another run. It runs the script with --if-idle; while another update is in progress, in FluxOS or in the watchdog, the script exits 75 at once and the route answers that an update is in progress (8b59a2521a).
  3. Second waiting run: the script downloads nothing when CloudUI/version already holds the release's sha256, so a run that waited finds the first run's release installed and exits 0. The rebuild route passes --force, so it still repairs a damaged UI (54a2834b23). The boot check passes --force as well when CloudUI is missing or holds only version and tag, since that version still names the release (2a9002c41e).
  4. Platform: agreed; nodes are Linux, and the script's header lists both requirements.

Units on chud (fluxService, cloudUIUpdateService, updateCloudUiScript): 317 passing, 1 pending, 0 failing; the PR description has the detail.

… version and tag

The boot check counts a CloudUI with nothing but its version and tag files as
missing, and that version file still names the latest release, so the script's
already-installed check would stand down. The boot check's install passes
--force.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Cabecinha84 Cabecinha84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK at head 2a9002c (2nd pass)

I test-merged the head onto current development (8c8d3bf, which includes #1919 and #1920). It merges cleanly, and the PR is mergeable with CI green.

Verified

  • Full unit suite on the merge: 13425 passing, 0 failing, 2 pending. One pending is the new mv --exchange test, which skips itself on coreutils 9.4 (my machine), so the folder-to-symlink swap via --exchange was not run here; the fallback path is covered and passes.
  • eslint is clean on the touched files, and bash -n passes on the script.
  • Serving through the symlink: I pointed express.static and the sendFile SPA fallback at a CloudUI -> .cloudui/build.x link. /version, assets, / and an SPA route all return 200.
  • The boot check is fire-and-forget, and checkAndUpdateCloudUI has an outer try/catch, so there is no unhandled rejection. app.js has no boot-time gate on CloudUI.

My earlier points are all closed: the rebase, .eslintignore, the rebuild route's --if-idle (it answers "in progress" at once), the skip-if-installed check, and the platform note.

Left, none blocking

  1. Harness gate at this head. The author's gate was at 112c9271c, before 2a9002c. That commit is JS and unit tests only, and no harness suite references CloudUI.
  2. On hosts without mv --exchange, a catchable SIGTERM between the two fallback mvs runs the cleanup with CloudUI absent, and the cleanup also deletes previous.*. The window is microseconds and happens once per node, and the boot check reinstalls a missing CloudUI. Ignoring signals across the pair would close it.
  3. remove_unused_builds assumes a relative CloudUI symlink. A hand-made absolute link into .cloudui/ would leave the installed build unprotected. The script itself always creates relative links.
  4. Watchdog follow-up, not for this PR: a watchdog run while version still matches is now a silent exit 0, so any content repair there needs --force.

@Cabecinha84 Cabecinha84 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at head 2a9002c, per the ACK review above. The harness gate at this head is still outstanding (non-blocking).

@MorningLightMountain713
MorningLightMountain713 merged commit 9a8b3ab into development Nov 18, 2026
3 checks passed
@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the second pass. The four notes:

  1. Gate at this head: the harness does not exercise CloudUI. Its stub serves a release with no dist.tar.gz, so on every harness node the boot check's script stops at "dist.tar.gz not found" before any download, and no suite checks the result. A gate at 2a9002c41e would run the same failing path as the gated commit. The script and service unit tests are what cover this PR.
  2. SIGTERM between the two fallback renames: no change. The two renames run only on a node's first update with this script, where CloudUI is still a folder and mv has no --exchange; every later update is a single atomic rename. The window is microseconds, once per node, and the node recovers by itself: the watchdog's periodic check and FluxOS's boot check both reinstall a missing CloudUI. Ignoring signals across the pair would change the signal handling the rest of the run depends on to close that window.
  3. Absolute CloudUI symlink: no change. The script only ever creates relative links, so an absolute one could only be made by hand on the node, which the script does not support; its outcome is a reinstall, not lost data.
  4. Watchdog: no follow-up needed. The watchdog runs the script only when CloudUI is missing or version differs from the release, so the installed-release check never stops one of its runs. A repair step added there later would pass --force.

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