Pilot migration audit

Status log. Newest entry first. Last update: 2026-10-27 10:50 IST.

Summary

#IssueState
1The restart at the end of a migration times out after 90 s (the reported error).fixed, tested
2A migration starts while the site still has queued or running background jobs.fixed, tested
3Worker groups (for example 4 default, 3 short, 2 long) become one pool that listens to every queue (the reported settings issue).fixed, tested
4Every restart kills the running background jobs. An idle worker also often ignores the stop request and holds the restart for 90 s.fixed, tested
5When the final restart fails, the operation shows only "The task stopped before it finished".fixed
6Retry, Restore and Skip Patch can fail with "Another active task is already using resource 'bench:update'" if the task starts before the API saves its ID.fixed, tested
7Bench("benches/x") writes relative paths into systemd units, and systemd refuses those units.fixed
8Saving settings restarts the workload with its own fixed 120 s limit, which a draining job can exceed.fixed, tested
9Telemetry reads only worker_pool.log, so the logs of per-group pools would skip the worker parser.fixed
10Two worker groups with the same queues would give two pool units with the same name.fixed
11Maintenance mode took up to 60 s to take effect. At the start, web kept serving the sites (writes included). At the end, sites answered 503 for up to 60 s after "completed".fixed, tested
13Restore failed with "'origin' does not appear to be a git repository" for an app without a reachable remote. It always fetched the old commit, even when the commit was already local, so it also failed when the network or Git host was down.fixed, tested
14Lost updates on the operation record: a chain task that read the record before its own entry was saved dropped that entry, and the API saved a stale copy after it queued Retry or Restore.fixed
15An update or Restore stashed the uncommitted edits of an app it did not change, because it checked every app out again.fixed, tested
16A failed table import during Restore did not say why (for example, MariaDB down).fixed
17A failed background-job check put a Python traceback into the diagnosis.fixed, tested
18When a task could not save its own failure (disk full), the diagnosis said only "The task stopped before it finished".fixed
12On a 2 GB host, MariaDB started at 371 MB under a 384 MB MemoryHigh. It reached the limit, then stalled: no new connections, and a restore that takes 5 s took 2 h 20 min.fixed, tested
19An app install error showed the Python object instead of the app name.fixed
20After a backup failure, the sites became live again. Retry kept earlier backups. A later Restore erased writes made while the operation was paused.fixed, tested
21A missing or empty recovery table inventory made Restore treat every table as new and try to drop it. A missing table dump was silently skipped.fixed, tested
22A failed web restart during a maintenance change was ignored. Backup could proceed, or completion could be reported, even though web had not read the new settings.fixed, tested

Pull request: #704 — Fix worker restarts, maintenance and recovery bugs, against develop. Branch: fix/migration-reliability, 18 commits on top of develop 53b56124. All fixes are committed and pushed. The final focused suite has 88 passing tests. The full suite had 3877 passing tests and one failure: test_timeout_actually_terminates_the_process_group. This test also failed on clean develop. It checks for the text sleep 5 across all host processes, so unrelated processes can fail it. Ruff and the diff whitespace check passed.

Log

10:45 — Failure injection, round 4

Testing continues without network partition tests, as requested.

InjectionResult
First site migrates; second site fails; Restore bothpass Both settings and tables returned to the baseline. Both sites answered HTTP 200. Recovery snapshots were removed.
Kill the second site's backup; write a value to the first site while it is live; Retry; fail a patch; Restorepass after fix 20 Before the fix, Restore erased the value. Retry now takes fresh backups of every site. Restore preserved the value in the repeat test. Both sites answered HTTP 200.
Remove the recovery table inventory or a required table dumppass after fix 21 Restore paused with a specific error in each case. The site kept its migrated setting and marker table. After the files were put back, Restore returned the database to its baseline. The site answered HTTP 200.
Make the maintenance web restart failpass after fix 22 Two regression tests proved that the error was ignored. A real systemd start failure now paused the operation before backup: no snapshot, no migrated tables. After the web unit was repaired, Retry completed.

The three current fixes are deployed on the test host. Failure settings used in this round were removed. The test sites are live. These checks do not prove that Pilot has no remaining bugs.

10:13 — Failure injection, round 3

InjectionResult
SIGKILL the update during the asset step, then Retrypass A new update task ran, then both migrations. Completed.
SIGKILL the Admin process (it runs the task worker) during a migratepass after fix 15. The socket started Admin again on the next request. The running task continued, and the chain completed. (The first try found bug 15: the test app had lost its patch to a stash.)
Stop MariaDB during a migrate; Restore while it is down; start it; Restore againpass Paused, then revert_failed, then reverted. Web came back. Found bug 16.
Stop the Redis queue before a migration, then Retrypass Paused before the backup with maintenance off. Found bug 17.
Fill the disk during the backup, then free it and Retrypass Sites stayed live; Retry completed. Found bug 18.
Start a second migration while one runspass Refused: "still migrating - resolve it before starting another".
Reboot the server during a migrate, then Retrypass Back in 50 s. All units started. The task worker marked the task stopped, the operation paused with sites in maintenance, and Retry completed.
SIGKILL a Restore while it imports tables, then Restore againpass revert_failed with maintenance on, then reverted.
SIGKILL during the final service restart, then Retrypass Retry ran only the final step and did not migrate the site again.

09:18 — Failure injection, round 2

InjectionResult
SIGKILL the app update during the package install, then Restorefound bug 13, then pass. The kill left the new code and a half-installed environment, with both sites in maintenance. The first Restore failed on the test app, which has no remote. After the fix, Restore again resumed from its checkpoint: both apps back at their old commits, environment rebuilt, sites live, snapshots removed.

Bug 14 came from reading the code after this test. The window is small (the next task needs about a second to start), but a busy host can widen it, and the result is an operation stuck in its phase. Now a chain task waits until its entry is stored, and records itself if the task before it stopped. The API records the action ID by reading the stored record under a lock.

08:50 — Failure injection, round 1

Each test breaks the migration on purpose, then checks the operation state, the site data, maintenance mode, and recovery. A test app adds a patch that creates a table, changes a setting, commits, and then sleeps or fails.

InjectionResult
SIGKILL the migrate task during a patch, then Retrypass Operation paused in needs_attention. Both sites stayed in maintenance. No orphan frappe migrate process. Retry completed.
SIGKILL the migrate task, then Restorepass The touched-table list was incomplete, so Pilot restored the whole snapshot. Setting and tables back to the start state.
SIGKILL the backup task, then Retrypass Paused, and maintenance mode was turned off because nothing had changed. Retry made a new backup and completed.
Cancel the migrate task from the task API, then Restorepass after fix 12. The first Restore took 2 h 20 min because of the MariaDB stall below.

08:30 — MariaDB stalled on the 2 GB server (issue 12)

During the cancel test, the restore of one small site did not finish for over 2 hours. The load average was 14 to 18 on one CPU. MariaDB did not accept new connections.

Evidence: 18 of 24 MariaDB threads waited on disk reads. The disk did about 3,000 reads of 4 KB per second, all from MariaDB, but they were page faults on its own code, not table reads. The MariaDB service had MemoryHigh=384M and used 383 MB. Its "high" event counter passed one million. Memory_used_initial was 371 MB: MariaDB used almost all of its limit right after it started.

Cause: Pilot sizes the buffer pool (128 MB) and key buffer (32 MB), but not the Aria page cache. MariaDB's default for it is 128 MB, and MariaDB uses Aria for on-disk temporary tables (19,000 of them on this server). Without swap, the kernel can only take back MariaDB's code pages, so it reads them again and again.

Fix: Pilot sets aria-pagecache-buffer-size to the key buffer size (8, 32 or 128 MB by host size) and counts it in the budget. A new patch writes it into an existing my.cnf; it applies at MariaDB's next start. After a restart on the test server, Memory_used_initial went from 371 MB to 270 MB.

Note: an older patch already raises MemoryHigh, but it keeps 384 MB on a 512 MB limit, so it did not help here.

07:00 — Maintenance mode took up to 60 s (issue 11)

Frappe reads a site's config again only every 60 s in each web process. So web kept serving a site for up to a minute after Pilot turned maintenance mode on. At the end, web had restarted while maintenance mode was still on, so the sites answered 503 for up to a minute after the update completed.

Fix: Pilot restarts web once before the first step of a site, and once after it turns maintenance mode off. Web holds its socket during a restart, so requests wait instead of failing.

Measured with a ping every 0.5 s during a 2-site migration: 503 started 4 s after the start. The last 503 was 2 s before "completed". Before the fix, 503s went on for about 40 s after "completed".

05:25 — Groups with the same queues

With one pool per group, two groups that both list default would give two units with the same name. Rejecting such a config at load time could stop an existing bench from loading. So Pilot now gives these groups one pool with the sum of their counts. The branch is deployed on the test server, and its units and sites are healthy.

05:15 — More checks

04:55 — Full workflows tested on the test server

Setup: one bench under systemd, not in lite mode, with 2 default, 1 short and 1 long workers. Frappe was reset 200 merges back, so an update had real patches to run.

WorkflowResult on the branch
App update, 2 sites, a 100 s job queued on each siteEach backup waited for its site's job. Update, both migrations and the restart completed. The restart took 12 s (it took 90 s or more before). Maintenance mode was turned off at the end.
Site migration with a patch that fails on purpose (it creates a table and changes a setting)Operation went to needs_attention and named the patch. Restore put back the setting, dropped the new table, turned off maintenance mode and removed the snapshot.
The same failure, then Skip PatchThe migration continued on its own and completed.
Retry of the operation that failed on develop with the 90 s timeoutCompleted.
ready-for-migration on a lite-mode benchReports the jobs correctly (READY before a job, NOT READY during it), so the wait also works in lite mode.

04:40 — Why restarts killed jobs and why idle workers hung (issue 4)

systemd's default KillMode=control-group sends SIGTERM to every process of a unit, and also SIGCONT. For a worker pool, that includes:

Evidence:

TestResult
SIGTERM only, sent to an idle worker, 6 timesExited in 2 s, 6 of 6
SIGTERM + SIGCONT + SIGINT (what systemd and the pool send), 6 timesStuck after 15 s, 5 of 6
Restart with a 60 s job running, developRestart took 1 s. Job failed: Work-horse terminated unexpectedly; waitpid returned 15
Same test with KillMode=mixedRestart waited 51 s. Job completed: Job OK
5 idle restarts of pools that ran for 75 s, with KillMode=mixed1 to 3 s each (one took 91 s before)

Fix: worker pool units now set KillMode=mixed. systemd sends SIGTERM only to the pool. The pool asks each worker to stop once. A worker finishes its job, then exits. After 90 s, systemd still kills what remains. This is the same as Frappe's supervisor setup, which signals only the main process.

04:20 — Retry and Restore race (issue 6)

Restore failed with TaskConflictError ... 'bench:update' in a test. The action task reads its own ID from the operation record to hand its locks to the next task. The API writes that ID only after the task is queued. The task now uses its own running ID.

04:00 — First fixes tested

TestBefore (develop)After (branch)
Worker processesOne pool: --num-workers 4 --queue default,short,longThree pools: 2 default, 1 short, 1 long
Site migration with a 240 s job runningMigration ran next to the job. Restart failed: systemctl timed out after 90s. Operation stopped in needs_attention. This is the reported error.—
Site migration with a 150 s job running—Backup waited 150 s for the job, then ran. Migration completed.

03:30 — Root causes of the reported issues

Issues 1 and 2. Pilot puts the sites in maintenance mode and starts the backup, update and migrate at once. It does not wait for running jobs. At the end, Pilot restarts web and the workers. systemd lets a unit take 90 s to stop. Pilot gave the complete systemctl restart only 90 s, so one slow unit made the restart fail.

The Frappe Cloud agent puts the site in maintenance mode, then runs bench --site X ready-for-migration again and again for up to 300 s. It continues only when the site has no queued or running job.

Issue 3. Under systemd, Pilot runs Frappe's worker-pool. It merged all worker groups into one pool that listens to every queue. The counts per queue in the settings had no effect.

Changes on the branch

Open points