Skip to content

fix(apps): a failed restore holds what it broke until it heals or its owner accepts it - #1921

Merged
MorningLightMountain713 merged 49 commits into
developmentfrom
fix/backup-restore-run-authority
Nov 25, 2026
Merged

MorningLightMountain713 merged 49 commits into
developmentfrom
fix/backup-restore-run-authority

Conversation

@MorningLightMountain713

@MorningLightMountain713 MorningLightMountain713 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Why

A restore that fails part way through its clear leaves a component's data neither the old copy nor the restored one. FluxOS then started that component on what was left, and for a synced component its folder sent the damage — the deletions included — to every other instance. On a lab node a lone g: app restarted on its leftovers after a failed restore.

A failed restore now holds what it broke, in every sync mode, until a restore finishes, the owner starts the component (accepting its data as it is), or the copy heals from a connected peer that holds the data.

What changes

  • The restore record. Written before a restore clears any component, g:, r:, s: or unsynced, and removed once the unpack succeeds. It carries the time it was set, which identifies it. While it stands nothing runs the component and nothing makes its folder send: the reconciler keeps it stopped, changeSyncthingFolderType refuses sendreceive, the election records no running opinion and does not resume it as primary, a soft install does not start it, and the syncthing monitor writes its folder receive-only. A record that cannot be read holds every refusal, and the folder deciders act on none: the folder is left as it is for the pass, so a running copy keeps sending and nothing is reverted or healed. No unpause makes a held folder send.
  • A restore is finished once its record is cleared. A clear that fails after a good unpack is a failed restore: the component is held as any component left mid-replacement, and the error line says so and how it is released.
  • What releases it. A restore that unpacks; the owner's start; a new volume (hard redeploy, hard update reinstall, install); or, for an r:/g:/s: folder, healing from its peers. A held folder is reverted or released only on counts syncthing has scanned since the restore: syncthing counts local changes only in a receiving folder it has scanned, and scans no paused folder. So the first pass that finds the folder receiving, unpaused and idle asks syncthing to scan it and goes on; syncthing answers once the scan is done, and the answer marks that record scanned (restore:scanned; a record set again since stays unscanned). The status the heal decides on is read after the record says scanned. Then, synced with no receive-only local changes left while a connected peer other than this node holds the data (findSyncedPeer), the record is cleared. A lone copy is never healed that way, and a record that carries no time is released only by a restore or the owner.
  • What does not. An owner's stop or kill; a backup (refused for a held component, before anything stops, so the last good archive survives); the restore's restart of the other instances (/apps/apprestart/<app>?unlessstopped=true restarts only what their owners have not stopped and changes no record or lock).
  • A folder pass reads the record once. The monitor reads a folder's record once per pass, before the state machine, and every decision of the pass is made on that answer; the state machine reports whether the record still holds the folder once the pass is done.
  • A node taking an app's folder on deletes none of its data. A fresh install's volume is newly formatted and its container is not started, so its folder is created receive-only and syncs from the peers; files the peers do not have are reverted or kept by the check that runs before any folder sends. A first run that finds no syncthing folder decides from the container, as it does with one: a running app keeps running, a stopped one receives first. The sync layer's local appdata clear is gone (requestStopAndClearData, volumeService.clearAppVolumeData, the reconciler:beforeDataClear checkpoint), so nothing deletes a component's data while a backup or restore holds it.
  • The restore says so. Its error line names each held component and how it is released; /apps/componentstates/:appname (owner and Flux team) gives each component's run state and the reason it is stopped.
  • Receive-only deletions are local changes. A receive-only folder whose only local changes are deletions reads synced to syncthing; it is reverted like any other local change, so a standby missing files is never read as clean.
  • Backup and restore hold the app through the reconciler, and take the answer of the pass the hold causes. Every component down, or the operation is refused, naming each component and why: the node is starting, docker is not answering, another app operation on the node held the pass aside, or the container is still up. Nothing waits past that pass; the operator retries. Once the operation ends it releases exactly the components its stop held — the release reads nothing, so a database that cannot answer does not leave the app stopped — and starting the app is the reconciler's. The election decides from recorded intent.
  • What FDM routes to. listRunningApps lists everything running plus each container a backup or restore took down (globalState.operationStoppedContainers), which was running when the operation began. A container that was already stopped — a standby's g: component, one its owner stopped, one that crashed — is not listed, whatever operation its app is under.
  • /flux/info needs the database. It answers 503 while the database is not available (requireDatabase).
  • A holder that leaves ready says so. The monitor publishes syncthing:folderNotReady, the counterpart of syncthing:folderReady, when a ready holder stops being ready.
  • A requested stop is not a death. A stop that outlasts its timeout ends in SIGKILL (137), which the reconciler read as a crash, so backups, restores and elections climbed the restart backoff to a quarter of an hour. containerEventsConsumer (renamed from containerCrashRecovery) records Docker's stop events, and the start after a run something asked Docker to stop begins with a clear ladder, as an owner's start does. An OOM kill, and a stop the event stream missed, are judged as deaths.

The PR stacked on this one (#1922), which lands in the same release, sends every operation on an app through that app's manager: an owner's start while a restore is running is refused, and the heal of a held folder is an operation on its app. It also decides an r: copy by its folder alone, every pass, and refuses a global restart with unlessstopped, which would restart one node.

Follows v9

  • Backup and restore stop and start containers through the reconciler, which stays the only thing that starts or stops an app's containers: v9's in-memory hold operationDesired, which the reconciler reads as operationHold and a restart drops. The entry points differ: holdStopped/releaseHold answer from the pass the hold causes, where v9's drive waits for the containers to settle.
  • The reconciler keeps acting while a backup or restore holds an app, as v9's hasBlockingLease leaves both out.

Testing

  • Unit: the full suite at this head 577ab690ec, 13,506 passing, 0 failing, 2 pending; eslint clean. Each guard and release above has tests that are red without it and green with it:
    • the heal: held while the folder sends, is paused or scanning, while no scan asked for since the restore has finished, with a record without a time or one that cannot be read; it asks syncthing for one scan and marks the record when it finishes, asks again when that scan did not finish, reverts on the pass after, and decides on the counts read after the record says scanned, not the pass's earlier reading. Against a heal that compares syncthing's last-scan time with the record's, 7 fail;
    • a fresh install, a first run with no folder (stopped and running) and the skipped-app path: red against the clearing state machine at their own assertions;
    • the single read: a g: folder whose record cannot be read is not passed to the state machine and gets no designation; red with the second read;
    • the release: backup and restore each release their components when the spec read fails at the end; red with the release reading the spec.
  • Harness, suites on real syncthing:
    • 4401, a lone g: app and a mixed one;
    • 4402, g: with standbys; a restore that deleted nothing is cleared by the pass under way when its scan is recorded, or the next;
    • 4403, unsynced;
    • 4404, r: and s:, and an s: copy whose demotion syncthing refused (the daemon down between the restore's pause and its demotion): it reports none of the restore's deletions while paused and sending, and heals from its peers only once it receives and has been scanned;
    • 4406, a record that cannot be read, g:, r: and s: each with a running copy holding writes its peers lack;
    • 2260, a fresh install receives the primary's data unpaused and keeps it, with the app stopped on the new holder.
  • Suites that install a synced app wait for the first pass that writes the new folder (waitForFolderTakenOn).
  • Full gate: on tester at the head of the stack this PR is the base of (fix(apps): each app's operations go through one manager, one at a time #1922 aa6bd4cb42, which carries this PR's 577ab690ec), on development 396cc107bd: 341 of 341 suites passed (MAXN 6, about 4 h).
  • Lab, on isotest20 (an ArcaneOS lab node, one holder):
    • a failed local restore held the g: component stopped and its folder receive-only through election passes and a FluxOS restart;
    • the owner's start released it, and it ran, as primary, about 40 s later.

🤖 Generated with Claude Code

@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.

Request changes (small), at head ed956019e, reviewed against development 9a8b3ab92.

Merges cleanly onto the current development tip (which already has #1884, #1919, #1920). Unit suite on the merged result: 13500 passing, 0 failing. eslint clean on all changed ZelBack files. The design is sound: the record is written before the clear, the holds are consistent across reconciler, election, folder writes and soft install, and the releases are narrow. Released nodes tolerate apprestart?unlessstopped=true (no rejectQueryParameters on that route), and stop precedes die in real docker events, so the 137 handling holds.

Must fix

An unreadable restore record reverts a healthy app's folder.

  • restoreHolds() (syncthingFolderWrites.js) returns true when the Mongo read rejects.
  • healHeldFolder (syncthingFolderStateMachine.js) does not re-read the record. With a synced peer and receive-only local changes it calls dbRevert.
  • For a healthy r:/g:/s: folder with no restore: on the first failing pass the monitor forces the folder receiveonly while the container keeps running, so its writes become local changes. From the second pass on, each pass reverts them and discards the running app's data.
  • Reproduced with a throwaway test (real syncthingFolderWrites, isRestoreUnfinished rejecting): pass 1 no revert, pass 2 one, pass 3 two, for r:, g: and s:.
  • No existing test covers it. The state-machine tests stub restoreHolds itself, so the catch never reaches the state machine.

Fix: treat an unreadable record as hold-only (stay receive-only, never revert or heal); revert only when the record was positively read as set. Add a unit test with a rejecting isRestoreUnfinished.

Non-blocking

  1. appStart clears restoreUnfinished and never checks restoreInProgress. An owner start mid-restore followed by a restore failure leaves an unsynced component with no durable hold. Same gap exists on development, so not a regression.
  2. If clearing the record after a successful unpack fails, the component stays held (safe), but the error line does not say so.
  3. The new /apps/componentstates route sits under the comment that belongs to appstart.
  4. Eight fixup! commits: please autosquash.
  5. drive() waits up to 15 min per component; backup/restore previously gave up after ~60 s, so a stuck container now holds the app's lease much longer.

Before an ACK

  • Re-run the harness gate on the merged result: 329/329 was at ed956019e on the old base, and #1884/#1919/#1920 have landed since, plus this PR reorders the fixture ring.
  • I ran the unit tests but only skimmed the new harness suites 4401-4404, so their "red without the fix" claims are not independently verified.

@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Each item, at head d80a758e52:

Must fix: an unreadable record reverts a healthy app's folder. Fixed in 130cd0905f, in a different shape from the one suggested. Staying receive-only on an unreadable record still harms a running copy: its folder stops sending, so writes its peers do not have yet stay on that node, and nothing sends them while the read keeps failing. So the record now has three answers, held, not held and unknown. On unknown, the state machine and the monitor leave the folder as it is for that pass: no type change, no revert, no heal. The refusals (restoreHolds) still hold on unknown, and no unpause makes a held folder send. Unit tests use a rejecting isRestoreUnfinished, as you asked.

Harness suite 4406 covers it with real syncthing. A g:, an r: and an s: app each have a running copy holding a write its peers lack; that node's reads of the record fail for three folder passes. With the fix, the folder keeps sending and the write reaches every peer (3/3, three runs). Without it, all three are red at "folder stopped sending". Breaking the rule in one decider alone is red at its own assertion: the state machine for g: and r:, the monitor for s:. The state machine's case needed a new event, syncthing:folderNotReady (2a89ec318d), the counterpart of syncthing:folderReady.

1. appStart mid-restore. Agreed. It belongs with one operation per app, a separate PR stacked on this one, and will be fixed there.

2. A failed record clear after a good unpack. That is now a failed restore (d20561e4df): the component is held like any component left mid-replacement, and the error line says it is kept stopped and how it is released. The operator retries the restore; the archive is kept.

3. The route under appstart's comment. Moved above it (69865aa8a7). The comment now states its rule in two lines (de69f6e468).

4. Autosquash. We keep pushed history as it is, so the fixup! commits stay.

5. The 15-minute wait. Gone (5d04c9cc78). A backup or restore holds the app and takes the answer of the pass the hold causes. Either every component is down, or the operation is refused, naming each component and why: the node is starting, docker is not answering, another app operation on the node held the pass aside, or the container is still up. Nothing waits past that pass; a stuck container frees the app as soon as its stop fails, and the operator retries. Lifting the hold returns at once, and the reconciler starts the app. Suite 44 now restarts docker once the hold has stopped the app (d80a758e52).

The 4401–4404 "red without the fix" claims. Each suite was run against development before the fix: H7 is red at its own assertion, every other case at "the restore recorded the component held". Each rule was also broken alone in a copy of the branch, and each was red at its own case.

Before an ACK. Unit at the head: 13,441 passing, 0 failing. Every suite that backs up or restores (35, 44, 86–93, 2005, 2209, 4401–4404, 4406) is green at the head. The full gate on this branch merged with development 396cc107bd (merge b267520eea) is green: 331/331 suites, 0 failing.

@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.

Request changes (small) — 2nd pass at head d80a758e5, against current development (396cc107b).

Verified

  • Merges clean into development; unit suite 13514 passing / 0 failing on the merged tree; eslint clean on the changed files.
  • My previous must-fix is closed: an unreadable restore record now decides nothing, so it no longer triggers dbRevert on a healthy folder (test asserts dbRevert is not called).
  • No stale containerCrashRecovery references, no duplicate harness suite numbers.

Must-fix

  1. A pending data clear can wipe appdata while a backup/restore holds the app. isManagedElsewhere no longer covers backup/restore (they hold through operationDesired), and the dataDesired === 'clear' branch (appReconciler.js ~l.971) runs before effectiveDesiredRunning, so the hold never guards it. The base deferred the whole pass. If a clear is already pending/retrying when a backup starts, holdStopped returns stopped: true and the clear still runs: the backup archives an empty appdata/ and reports success; a retried clear can also land mid-unpack of a restore. Reproduced with a throwaway test (one failed clear, then holdStopped → 2 clear calls). Fix: skip the clear while the component is held by an operation, with a test that is red without it.

  2. healHeldFolder can clear the record on a stale reading. It trusts isSynced + zero receive-only counts without checking the folder is receiveonly or has been scanned since the restore. Syncthing only counts receive-only changes for a receive-only folder, after a scan. If the restore's demote fails (an expected case), an s: folder stays sendreceive/paused over a stale index; the next monitor pass reads zeros, clears the record, and the s: path then makes the folder send — the deletions go to every peer. The same stale read is possible right after a successful demote, before the first scan. Not yet confirmed against a real daemon. Fix: heal only a folder that is receiveonly, idle, and scanned since the restore.

Non-blocking

  • syncthingMonitor.js bare return on a second unreadable record read: the state machine may already have set designationPending/restarted, and the later loop still sets designatedLeader = true for a folder that was never written.
  • startApplication re-reads the spec to release the hold and swallows errors; a DB blip leaves the app held stopped until FluxOS restarts. Release with the ids captured at stop time.
  • Still open from last pass: an owner's appstart during a running restore clears the record, so the "is kept stopped" message is untrue if the restore then fails.
  • PR body does not mention the /flux/info requireDatabase 503 guard or the listRunningApps semantics change; 8 fixup! commits still to autosquash.

Conditions for ACK: fixes 1 and 2 with tests, a full harness gate at the new head (the claimed 331/331 is at the previous head), and the polish above.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.12894% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.77%. Comparing base (f979ae9) to head (0b71f21).
⚠️ Report is 76 commits behind head on development.

Files with missing lines Patch % Lines
...ack/src/services/appLifecycle/advancedWorkflows.js 95.69% 4 Missing ⚠️
.../services/appMonitoring/containerEventsConsumer.js 73.33% 4 Missing ⚠️
...elBack/src/services/appManagement/appController.js 91.42% 3 Missing ⚠️
ZelBack/src/services/appLifecycle/appInstaller.js 84.61% 2 Missing ⚠️
ZelBack/src/routes.js 66.66% 1 Missing ⚠️
...ack/src/services/appManagement/appsRuntimeState.js 96.29% 1 Missing ⚠️
...vices/appMonitoring/syncthingFolderStateMachine.js 98.46% 1 Missing ⚠️
ZelBack/src/services/serviceManager.js 50.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@               Coverage Diff               @@
##           development    #1921      +/-   ##
===============================================
+ Coverage        85.43%   85.77%   +0.33%     
===============================================
  Files              280      287       +7     
  Lines            42082    42442     +360     
===============================================
+ Hits             35953    36404     +451     
+ Misses            6128     6037      -91     
  Partials             1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The API answers as FluxOS starts and the MongoDB connection follows
moments later; a /flux/info landing in between read installed apps
through a client that did not exist yet and threw "Cannot read
properties of null (reading 'db')". requireDatabase answers 503 with
Retry-After through serviceUnavailable, before the route's cache as the
other readiness guards are, so the cache never keeps a refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the election decides from recorded intent

A failed restore set its folder receiveonly and its component's intent to
stopped, and the election pass that read the running list while the
restore still held the app - a list that reports a backed-up or restored
app's stopped containers as running - then made the folder send over the
half-replaced data (gate red, suite 2209).

- appReconciler: drive(ids, state) and operationDesired. A backup or
  restore holds its components stopped through the reconciler and lifts
  the hold on every exit; the reconciler no longer stands aside for the
  operation's claim. drive waits for each component to settle, outlasting
  a pass deferred by another operation on the node.
- backup and restore stop and start only through drive
  (stopApplication/startApplication): an operator-stopped component stays
  down, and an elected one starts as its election decides.
- restoreUnfinished: a durable record, written before a restore clears a
  component that does not sync and removed when its unpack succeeds. The
  reconciler keeps the component stopped on it, across a FluxOS restart,
  until a restore succeeds or the owner starts it. It survives a soft
  removal and the boot twin-merge.
- the election reads, per app, the reconciler's recorded intent, and the
  container only where none is recorded; an app docker cannot answer for
  is skipped that pass. holdAsPrimary writes nothing while an intent other
  than running is recorded or a backup or restore holds the app.
- listRunningApps adds back only the containers an operation took down
  (globalState.operationStoppedContainers), not every stopped container of
  an app under backup or restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt a decision to leave a component stopped

The read moves from before the decision checkpoint and the FDM call to
after them, so what an app's decisions use is read where they are made.
A reconcile pass that finds a stopped component where it belongs counts
reconciler:held with the reason, the only record of that decision.

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

The restore case declared the primary's folder a cold start (data on disk,
nothing ever advertised) while its standbys held the synced copy - a state
syncthing cannot produce, and the one in which the folder state machine
seeds without a sync check. Its clear also failed before removing anything.
The restore now fails part-way through the clear, removing one file and not
the next, and syncthing reports the primary's folder short of the copy the
standbys hold by a local change.

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

- 2209: an election pass held at its decision while a restore of its app
  fails decides from the stop FluxOS recorded, and the half-replaced
  folder never sends.
- 44 (renamed for its claim): a reconnect sweep mid-backup starts nothing
  the backup holds; an operator-stopped component is not started by a
  backup, read from the container's start time; FDM is routed to the
  container the backup took down and not to the operator-stopped one.
- 88: a component that does not sync, whose restore did not finish, stays
  stopped across a FluxOS restart until its owner starts it.
- 91: the unsynced component of a failed restore is held by the
  reconciler, which never starts it.
- container.js: containerStartedAt; node-client: reconciler:operationHold
  on the allow list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omotion's start has run

The case means the volume to go during the scans that cover the promoted
folder's restart, after the promotion started the component. It waited
only for the scan, so a slow start could still be in flight when the
volume went; the start then completed after the node had recorded the
stop, and read as a start over the unsafe volume.

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

Discovery orders nodes that joined in the same block by txhash, highest
first, and every fixture node joins in one block. With random txhashes the
ring ran in an order no suite was designed for: suite 1502's stub peer
landed just before node 1, which then had no inbound peer, since a stub
never dials. Each txhash now leads with a byte that falls with the index,
so the ring runs in index order, the order suites place nodes and stubs by.

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

Test 2 patches caseSensitiveFS off on both holders and reads the patch back
before waiting for FluxOS to correct it. A syncthing pass that reads the
folder after the patch queues it and writes caseSensitiveFS on; under load
that write landed before the read back, and the fixture check failed. Each
holder's write of the folder is now held at syncthing:beforeFolderWrite, the
read back waits until a pass is held there, and the holds are released after,
in every case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…until it heals or its owner accepts it

A restore that stops part way through replacing a component's data leaves a
directory that is neither copy. With no peer holding the data, syncthing
calls such a folder synced, and the first-start path made a lone g:
component primary again on it. The durable restoreUnfinished record now
covers every sync mode:

- written before any component's data is cleared, removed once it unpacks;
- while it stands the reconciler keeps the component stopped, no folder
  write makes its folder send (syncthingFolderWrites, every writer), the
  election records no running opinion, a standby is not resumed as
  primary, the monitor writes its folder receive-only, a soft install
  does not start it, and a backup of it is refused;
- r:, g: and s: folders heal from a peer that holds the data: local
  changes, deletions included, are reverted to the peers' copy, and the
  record is cleared once the folder is synced and clean. A held folder
  claims no holdings;
- an operator start clears it (a restart, which a restore sends every
  other instance, does not), and so does a new volume;
- the restore refuses to clear a synced folder no longer paused, and its
  error line says which component it left held and how it is released;
- /apps/componentstates/:appname (owner and Flux team) answers, per
  component here, whether it runs and the reconciler's reason when not.

Unit: each rule red without it (25 mutations, each in a throwaway copy).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A restore record's every write publishes restore:record {identifier,
unfinished}; restore:beforeClear holds a restore after it has recorded the
component held and before it clears anything; dbClient reads the record.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… from standbys that hold the data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ata, its owner or healing

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

syncthing reports such a folder idle, with inSyncBytes equal to globalBytes
and only receiveOnlyChangedDeletes set, so it read as synced and clean: a
standby missing files could be promoted on them. Every receive-only change
counts - files, directories, symlinks and deletions - and the kept and
reverted logs and events carry the deletions.

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

A restore of an r: or s: component asks every other instance to restart, so
its containers read the restored data. That request arrived as an owner's
restart, which lifts the stop lock: an instance its owner had stopped was
started again. The restore now sends /apps/apprestart/<app>?unlessstopped=true,
which restarts each component its owner has not stopped and changes no stop
lock and no restore record; a component whose lock cannot be read is not
restarted. An instance on an earlier release ignores the query and restarts as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nce, by a framework helper

dropConnections (syncthing-real.js) pauses and resumes each peer device on the
node's own syncthing, which closes the link, and returns once none is connected;
a traffic block set first keeps it closed. 4402 uses it, and 4404's held
instance no longer waits out syncthing's five-minute receive timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The case holds both standbys at masterSlave:beforeDecision past their start
slots; released together after FDM's master is cleared, each found no primary
and both started (tester, 2026-11-18: nodes 1 and 3 at 09:10:46.5). One
standby is released first and the other once a single holder runs, as the
product's spacing between standbys orders them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and no unpause makes a held folder send

A read of the restore record that failed answered held everywhere. The folder
writes refuse on it, which is right; but the state machine and the monitor
acted on it, making a healthy running app's folder receive-only and, from the
next pass, reverting the app's own writes as an unfinished restore's leftovers.

restoreRecord answers held, not held, or unknown. The state machine and the
monitor leave a folder whose record is unknown as it is for the pass
(skipProcessing; the monitor keeps an unprocessed folder), so nothing is turned,
reverted or healed on a record nobody read. restoreHolds, for the refusals, still
holds on an unknown record. The folder writes also refuse an unpause that would
make a held folder send - one set to send, or one whose config cannot be read -
so no write path sends a held copy whatever the deciders do.

Tests: six new tests, each red against the previous code and green with this
(the unpause refused, the unknown record, r: and g: passes reverting nothing, the
monitor leaving the folder and healing nothing); a mutation of each rule turns
only its own tests red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The monitor publishes syncthing:folderNotReady on the pass that takes a ready
holder out of ready, the counterpart of syncthing:folderReady: from then the
election no longer reads it as eligible and its folder's health is not watched.

Tests: a ready holder taken out of ready publishes it (red without the
publish); one that stays ready, or was not ready, does not.

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

A g:, an r: and an s: app on three holders with real syncthing. The running
copy's node is cut from the other holders' syncthing and its app writes
appdata/written-<mode>.txt, which only that copy then holds. That node's reads
of its runtime-state collection fail (failCommands, finds on
zelappsruntimestate only) for three folder passes; through every poll its
folder sends, its container runs and it publishes no syncthing:folderNotReady.
Once the cut is undone the file reaches every other holder.

The state machine and the monitor count each pass that meets an unreadable
record (syncthing:restoreUnfinished, unknown); the window ends at three.

Proved on chud: green 3/3 with the fix, three runs; red 3/3 at "folder stopped
sending" on e8dd3dc; the record read as held in the state machine alone is
red for g: and r: at "copy stopped being ready"; in the monitor alone, red for
s: at "folder stopped sending".

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

A component is restored once its restore record is cleared. A clear that fails
leaves it failed as any component left mid-replacement is: kept stopped, its
folder demoted, and the error line saying so and how it is released.

Tests: a clear that rejects fails the restore with the component kept stopped and
the held error line (red without the change).

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

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

holdStopped writes the operation's hold and answers from the pass it
enqueues: every component down, or the operation is refused, naming each
component and why - the node is starting, docker cannot answer, another
operation on the node held the pass aside, or the container is still up.
Nothing waits past that pass, so a stuck container frees its app as soon as
its stop fails. releaseHold lifts the hold and returns; starting the
component is the reconciler's, retried as any start is. driveSettleMs is
gone.

Tests: each refusal reason, and the busy one without a wait; a mutation of
each (busy read as running, no boot refusal, a wait for the container, the
busy wording) is red alone.

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

The backup goes on only once the pass its hold causes has stopped the app, so
the reconnect sweep comes after that stop, inside the backup's window, and the
backup is not refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fresh install's volume is newly formatted and its container is not
started, so there is nothing on it to clear. The folder is created
receive-only and syncs from the peers; files the peers do not have are
reverted or kept by the existing check before the folder sends.

A first run with no syncthing folder decides from the container, as it
does with one: a running app keeps running, a stopped one receives first.

Removed: requestStopAndClearData, dataClearPending, the reconciler's data
clear, volumeService.clearAppVolumeData, the cleared event and the
reconciler:beforeDataClear checkpoint. A backup or restore can no longer
meet a pending clear.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
waitForFolderTakenOn waits for the first pass that writes a newly
installed component's folder. 2260 proves a fresh install receives the
primary's data unpaused and keeps it, with the app stopped on the new
holder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Syncthing counts local changes only in a receiving folder it has scanned,
and scans no paused folder. A folder an unfinished restore holds is
reverted or released only while it is receiving, unpaused and idle, and
its last scan finished after the restore record was set. Until then the
record stands and the folder receives.

The record carries the time it was set (restoreUnfinishedSince);
syncthingService.folderLastScan reads syncthing's last scan of a folder.

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

On real syncthing: the restore's demotion is refused (the daemon is down
between the restore's pause and its demotion), so the folder is left
paused and sending. Syncthing counts none of the restore's deletions in
it; the copy heals from its peers only once it receives and syncthing has
scanned it since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The monitor reads a folder's restore record once per pass, before the
state machine, and every decision of the pass is made on that answer. A
record that cannot be read leaves the folder out of the pass before
anything is decided for it, so no designation is made for a folder the
pass does not write. The state machine takes the record as read and
reports whether it still holds the folder once the pass is done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stopApplication hands the component identifiers to its caller before it
holds them, and a backup or restore releases exactly those on every exit.
The release reads nothing, so a database that cannot answer at the end of
an operation no longer leaves its app held stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Syncthing records a folder's last scan to the whole second, so a scan that
finished in the second the restore record was set read as older than the
record, and the held folder waited for the next periodic scan.

The first pass that finds a held folder receiving, unpaused and idle asks
syncthing to scan it and moves on; syncthing answers once the scan is done,
and the answer marks that record scanned (setRestoreScanned, matched on the
record's time, so a record set again since stays unscanned) and publishes
restore:scanned. The heal reads the folder's status after the record says
scanned.

Harness 4402: a restore that deleted nothing is cleared by the pass under
way when its scan is recorded or the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MorningLightMountain713
MorningLightMountain713 force-pushed the fix/backup-restore-run-authority branch from 0b71f21 to 09742c1 Compare November 20, 2026 20:21
@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the second pass. Each item, at head 09742c1b3c (the branch is now rebased onto development 396cc107bd; its tree is identical to the old head merged with it):

Must fix 1: a pending data clear can wipe appdata under a backup/restore hold. The clear is gone rather than guarded (ebda429ddc). It was the sync layer's requestStopAndClearData, for a folder taken on fresh: a first run with no syncthing folder, a new app, a skipped app's second encounter. A fresh install's volume is newly formatted and its container is not started, so it deleted nothing there; the one case it acted on, FluxOS starting with an installed app whose syncthing folder is gone, is already handled by the check that runs before any folder sends, which reverts files the peers hold and keeps the ones only this node has. Now a first run with no folder decides from the container (running keeps running, stopped receives first), the new-app and skipped paths set the folder receive-only and the component stopped, and nothing deletes a component's data. requestStopAndClearData, volumeService.clearAppVolumeData and the reconciler:beforeDataClear checkpoint are removed. Unit: a fresh install, a first run with no folder (stopped and running) and the skipped-app path are red against the clearing state machine at their own assertions. Harness suites that install a synced app wait for the first pass that writes the new folder (cf0c80ce31).

Must fix 2: healHeldFolder clears the record on a stale reading. A held folder is reverted or released only on counts syncthing has scanned since the restore (fb36a8049c, 09742c1b3c). The first pass that finds it receive-only, unpaused and idle asks syncthing to scan it and goes on; syncthing answers once the scan is done, and that answer marks the record scanned (matched on the record's time, so a record set again since stays unscanned). The heal reads the folder's status after the record says scanned. A comparison of syncthing's lastScan with the record's time does not work: syncthing stores lastScan to the whole second, so the scan after the restore's unpause, finishing in the record's own second, reads as older than it. The gate found that through 4402. Confirmed against a real daemon in 4404 (11b6c3aeb8): an s: copy whose demotion syncthing refused (the daemon down between the restore's pause and its demotion) reports none of the restore's deletions while paused and sending, and heals from its peers only once it receives and has been scanned.

Non-blocking: the monitor's bare return on a second unreadable read. The monitor reads a folder's record once per pass, before the state machine, and every decision of the pass uses that answer (387c957a83).

Non-blocking: startApplication re-reads the spec to release. An operation releases exactly the ids its stop held, captured at stop time; the release reads nothing (af8e1b1fd7).

Still open: appstart during a running restore. Fixed in the PR stacked on this one, #1922 (fd238acadf): an owner's start, stop or restart is refused while an operation holds the app.

PR body. It now covers the /flux/info requireDatabase 503 and what listRunningApps lists, and the heal as above.

The fixup! commits. We keep the commits as they are and do not squash them.

Conditions for ACK.

  • Unit: the full suite, 13,433 passing, 0 failing; eslint clean.
  • Full gate at the head of the stack merged with development 396cc107bd: 333 of 334. The red was 4402, the lastScan rounding above, fixed here; 4401 to 4408, 88 and 91 all pass on the fix.
  • A full gate at the rebased head of the stack is running; I will post its result here.

@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

The full integration gate at the head of the stack is green: 334/334 suites passed (MAXN=6, about 3 h 20 min), at #1922's head 355eb9d36d, which carries this PR's 09742c1b3c beneath it, both rebased onto development 396cc107bd. That run includes 4402, the suite the previous gate failed, plus 4401–4408.

CI is green on both PRs at those heads.

… it asked for

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.

Third pass at head 577ab690e: ACK on the code, with conditions below.

The PR sits directly on the current development tip (396cc107b), so there is nothing to merge or rebase. CI is green. I ran it in a clean worktree: unit suite 13,506 passing, 0 failing, 2 pending, and eslint is clean on ZelBack/src. (The PR body still says 13,433.)

Earlier must-fixes: both closed

  1. A pending data clear wiping appdata under a backup/restore hold. The clear is removed outright (requestStopAndClearData, dataDesired, clearAppVolumeData and the checkpoint have no leftover references), and backup/restore now hold the app through the reconciler (holdStopped / releaseHold).
  2. The heal clearing the record on a stale reading. The heal now acts only on counts read after syncthing finished a scan it was asked for, matched to the record by its time. An unreadable record decides nothing.

I also checked that no other path clears an owner stop through setAppOperatorStopped(…, false), that a backup of a held component is refused before anything stops, and that "a requested stop is not a death" does not hide a crash after a restart.

Findings

1. Narrow race in the heal (should-fix, not blocking). healHeldFolder clears the record with an unconditional setRestoreUnfinished(appId, false) (appsRuntimeState.js:358), after awaiting the status read and findSyncedPeer. Nothing serialises that against a new restore setting its own record. The window is milliseconds against more than 5 s of restore prelude, and it only hurts if the owner retries the restore, the heal is stalled at that moment, and the retried restore then fails. The catch block does not re-assert the record, and its in-memory stop is lost on a FluxOS restart. The fix is one line: clear only when the record's at still matches. I would take it in the same push.

2. Policy change that needs maintainer sign-off. Development wiped and stopped an r:/g: component on a first run with no syncthing folder. Now an r: component whose container is running, with no folder, goes sendreceive, so its local-only files are offered to peers (no deletions are sent). This only happens when FluxOS starts with the container up and syncthing has lost its config, and the data is live, so I think it is acceptable. g: is not affected. No harness suite covers this case (2260 covers a fresh install with the app stopped).

3. Owner appstart during a running restore still clears the record. Deferred to #1922. #1922 should land in the same release.

4. Minor. unlessstopped=true on apprestart returns before the global branch, so a global call with that flag restarts locally only. Peers on older versions ignore the flag and do a plain restart, as before.

Conditions

  • Harness gate on the affected suites (4404 at minimum) at this head, or #1921 and #1922 merged together and gated at the tip. The 334/334 run was at #1922's head over 09742c1b3; the only commit since is a +7-line change to suite 4404.
  • #1922 lands in the same release.
  • Sign-off on finding 2.
  • Finding 1, which I would not block on.

This supersedes my earlier CHANGES_REQUESTED reviews.

@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the third pass. Each item, at this head 577ab690ec; the fixes are on #1922, which lands in the same release, at its head 1c0121cd41:

1. The heal-clear race. Fixed in 8d0e24386e, in a different shape from the one suggested. Every writer of the restore record runs under the app's manager except the heal, which was the one path that read and cleared the record without holding the app. The heal is now an operation on the app (heal), from its first read of the record to the clear: a restore cannot set its record while the heal holds the app, and the heal is refused, and tried again on a later pass, while a restore or any other operation holds it. A compare-and-clear would have kept two kinds of writer, one of them racing; with the heal held there is one rule for every writer.

2. An r: copy running with no folder: sign-off. Decided, and the rule is now narrower than the one you reviewed (224808e788). An r: copy is decided by its folder alone, every pass: a folder that sends is caught up; a folder that receives, or is missing, means the copy is stopped and catches up from its peers before it runs again. So a running copy with no folder no longer goes sendreceive and offers nothing to its peers; handleFirstRun is gone. A g: copy is the election's: running, it is the primary and its copy is the source; stopped, it is a standby. The monitor never stops a g: component.

3. Owner appstart during a restore. Closed by #1922: an owner start is an operation on the app, refused while a restore holds it (appController.test.js).

4. unlessstopped=true with global. Refused with an error (cd4d1095a8): the restart would reach one node only, so the route says so rather than doing less than it was asked. A restart across the app's nodes that keeps owner-stopped components needs an instruction the owner signs, which is separate work.

Conditions. Unit suite at this head: 13,506 passing, 0 failing, 2 pending (the body is updated). #1922 lands in the same release.

Gate. The full integration gate is running on tester at the head of the stack, #1922 1c0121cd41 (which carries 577ab690ec), on development 396cc107bd; its result goes in this PR's Testing section.

@Cabecinha84

Copy link
Copy Markdown
Member

Review, 4th pass at head 577ab690ec (on development 396cc107bd)

Verdict: code ACK stands, conditional on #1922 landing in the same release, at a reviewed and gated head. #1921 alone is not safe to ship.

Verified today

  • Head and development tip are unchanged since my last pass; merge-base equals the dev tip, no rebase needed. CI green, mergeable.
  • Unit suite in a clean worktree: 13,506 passing, 0 failing, 2 pending. ESLint clean on every changed file.
  • Production diff re-read against the body's claims:
    • Every start path (docker restart policy no, reconciler, election promotion, soft install, hard redeploy) consults the restore record; a hard redeploy clears it by design with a new volume.
    • patchNow, putFolders and changeSyncthingFolderType all refuse sendreceive while the record stands; an unreadable record is treated as held and the monitor decides nothing.
    • No leftovers of requestStopAndClearData, clearAppVolumeData, beforeDataClear or containerCrashRecovery.
    • The record is persisted (survives a FluxOS restart); operationStoppedContainers is released in each operation's finally.
    • /apps/componentstates checks authorisation before any lookup.
  • fix(apps): each app's operations go through one manager, one at a time #1922 spot-check (not a full review): 577ab690ec is an ancestor of its head, and 8d0e24386e, 224808e788, cd4d1095a8 exist and touch what the reply says.

Still open at this head (fixed only on #1922 per the author)

  1. Heal-clear race: healHeldFolder clears the record unconditionally after an await, so a new restore's record can be cleared; if that restore then fails, an s: folder can send its deletions to peers.
  2. Owner appstart clears the record during a running restore; same consequence if the restore then fails.
  3. r: with no folder and a running container goes sendreceive (policy change).
  4. apprestart?unlessstopped=true on a global app restarts one node and reports success.

Notes (non-blocking)

  • Backup and restore of the same app do not exclude each other, and releaseHold deletes the hold unconditionally (no owner or count). A backup finishing mid-restore can let the reconciler start the container during the restore's clear/untar. Not a regression (development's backup also ends with appDockerStart and never checked restore), so a follow-up is fine: tryStartBackup/tryStartRestore should check each other.
  • A soft redeploy keeps restoreUnfinished but drops restoreUnfinishedAt/restoreScanned (SURVIVES_SOFT_REMOVAL), so a held standby can never heal from peers. Fail-safe, availability only.
  • The restore error line says an owner's start on an r: component sends its data to the other instances; in fact the restore's deletions are reverted to the peers' copy. Safe outcome, wrong wording.
  • requireDatabase only covers "not connected yet", not a database that goes down afterwards. I could not verify how FDM, HomeUI or FluxBench treat a 503 from /flux/info.

Conditions

  1. fix(apps): a failed restore holds what it broke until it heals or its owner accepts it #1921 and fix(apps): each app's operations go through one manager, one at a time #1922 merge together, same release.
  2. Full harness gate at the final fix(apps): each app's operations go through one manager, one at a time #1922 head. The author's gate was at 1c0121cd41; the PR is now at f3e9567715, so it is stale.
  3. fix(apps): each app's operations go through one manager, one at a time #1922 gets a fresh review (my last verdict there is still request-changes at f4db86b09).

@MorningLightMountain713

Copy link
Copy Markdown
Collaborator Author

Thanks for the fourth pass. The four notes, in order:

Backup and restore of one app. Closed by #1922: a backup and a restore each take the app through its per-app lease (takeAppFor), so while one holds the app the other is refused, and only one of them ever holds a component; releaseHold lifts nothing another operation set. Harness 4405 "refuses a restore of an app a backup holds, and the backup finishes whole".

A soft redeploy dropping the restore record's time. On #1922 a soft redeploy replaces the app in place and nothing calls removeControllerState, so it and SURVIVES_SOFT_REMOVAL are removed. The one other place the record could be split, the merge of same-identifier twins, takes the record whole (held, its time, scanned) from the twin that holds it (4c4e63f776); its unit test is red with the old merge.

The restore's error line. It reads "The restore of did not finish, so it is stopped to protect your data. Run the restore again." for every kind of component (803f871042): what an owner's start does to a held synced component depends on whether another instance has the data, so the line names the one step that releases it in every case. Separately, for the clients' owners: FluxCloud clears the restore's last line and shows "Restore from FluxDrive complete" whether it failed or not, and the node UI's upload restore shows a success toast after a failure.

requireDatabase and the 503. The guard covers the boot window, before the database client exists: /flux/info answers 503 with Retry-After, uncached. A database lost after boot is answered as every route answers a fault, 200 with {status: 'error'}, as on development. Every caller treats the two alike: FDM's version check fails the node for that pass either way, fluxstats skips it, flux-network-history reads it as not Arcane, the node UI shows an error, and FluxBench does not call /flux/info on any branch (it calls /flux/nodetier, /flux/version, /flux/backendfolder, /flux/enterpriseappowners).

Conditions. #1921 and #1922 merge together, #1921 first. The full gate at #1922 aa6bd4cb42 (its head ebd35671b1 adds one unit-test-only commit), on development 396cc107bd: 341 of 341 suites passed. #1922's second pass is answered on #1922.

@Cabecinha84

Copy link
Copy Markdown
Member

Review, 5th pass at head 577ab690ec (on development 396cc107bd)

Verdict: code ACK stands, unchanged. #1921 alone is still not safe to ship: merge it only together with #1922, after #1922 has a fresh review and a gate at its final head.

Verified today

Still present at this head (re-confirmed in code)

  1. Heal-clear race: healHeldFolder clears the record after several awaits without holding the app.
  2. Owner appstart clears the record while a restore is running.
  3. r: with no folder and a running container goes sendreceive on first run.
  4. apprestart?unlessstopped=true on a global app restarts only this node and reports success.

#1922 at ebd35671b (spot-check, not a full review)

  • All four are fixed there: the heal holds the app through a lease, owner start goes through the per-app operation guard, handleFirstRun is gone, and unlessstopped with global is refused. Backup and restore exclude each other. Solo unit run: 13,649 passing, 0 failing. ebd35671b is one unit-test-only commit above your gate head aa6bd4cb4 (341/341, your number, I did not run it).
  • New finding for fix(apps): each app's operations go through one manager, one at a time #1922: healHeldFolder takes its lease under appId.split('_')[1] || appId. For a legacy (spec v3 or lower) app the folder id is flux<app>, so the key is flux<app>, while backup and restore lock on <app>. Heal and restore never exclude each other there, so item 1 stays open for legacy apps. dockerService.getBaseAppName gives the right key (the reconciler uses it). I did not check whether the validator still accepts g:/r: flags on a new legacy spec; restore does support legacy apps.
  • releaseHold still deletes unconditionally. It is safe only because backup and restore share one lock key, so it depends on the key fix above. Lock keys are the raw request app name while spec lookups ignore case, so MYAPP and myapp get different locks (pre-existing).

Conditions

  1. fix(apps): a failed restore holds what it broke until it heals or its owner accepts it #1921 and fix(apps): each app's operations go through one manager, one at a time #1922 merge together, same release, fix(apps): a failed restore holds what it broke until it heals or its owner accepts it #1921 first.
  2. fix(apps): each app's operations go through one manager, one at a time #1922 gets a fresh review at its final head (my last verdict there is still request-changes) and the legacy lease key is fixed.
  3. Full harness gate at that final head.

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.

3 participants