Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: retain deployed LoRA adapter weights in backups (#8833)
[._.]/ Adam Eivy00a3a149ddb2
diff --git a/client/src/components/settings/BackupTab.test.jsx b/client/src/components/settings/BackupTab.test.jsxindex 4b8f1d13a0..6713f5393c 100644--- a/client/src/components/settings/BackupTab.test.jsx+++ b/client/src/components/settings/BackupTab.test.jsx@@ -702,18 +702,18 @@ describe('BackupTab', () => {// Regression: wildcard rules must survive edits and reload without the UI// promising that disabling a default includes the matching files.it('preserves independent custom rules through default toggles, save, and reload', async () => {- const loraPath = '/loras/*.safetensors';+ const checkpointPath = '/training-runs/**/checkpoints/';const custom = ['*.safetensors', '/lo*/', 'loras/'];- const backup = { destPath: '/backups', enabled: false, cronExpression: '0 2 * * *', retentionCount: null, excludePaths: custom, disabledDefaultExcludes: [loraPath, '/cache'] };+ const backup = { destPath: '/backups', enabled: false, cronExpression: '0 2 * * *', retentionCount: null, excludePaths: custom, disabledDefaultExcludes: [checkpointPath, '/cache'] };getSettings.mockResolvedValue({ backup });- getBackupStatus.mockResolvedValue({ defaultExcludes: [EXCLUDES[0], { path: loraPath, reason: 'LoRA weights', overridable: true }] });+ getBackupStatus.mockResolvedValue({ defaultExcludes: [EXCLUDES[0], { path: checkpointPath, reason: 'Intermediate LoRA checkpoints', overridable: true }] });updateSettings.mockImplementation(async payload => { getSettings.mockResolvedValue(payload); return {}; });await renderTab();expect(screen.getByText(/Additional rules still apply/)).toBeTruthy();expect(screen.getByRole('button', { name: /Default exclusions/ }).textContent).toMatch(/1 enabled, 1 disabled/);fireEvent.click(screen.getByRole('button', { name: /Default exclusions/ }));- const toggle = screen.getByRole('switch', { name: `Disable default exclusion ${loraPath}` });+ const toggle = screen.getByRole('switch', { name: `Disable default exclusion ${checkpointPath}` });expect(toggle.getAttribute('aria-checked')).toBe('true');expect(screen.getByText('(Default exclusion disabled)')).toBeTruthy();expect(screen.queryByText(/re-included|\(included\)|paths? skipped/)).toBeNull();@@ -732,14 +732,14 @@ describe('BackupTab', () => {await act(async () => { fireEvent.click(screen.getByRole('button', { name: /^Save$/ })); });// Anchored on the way in (#7241): `loras/**` is a path, not a wildcard-led// any-depth pattern, so it becomes `/loras/**`.- expect(updateSettings).toHaveBeenLastCalledWith({ backup: { ...backup, disabledDefaultExcludes: ['/cache', loraPath], excludePaths: [...custom, '/loras/**'] } }, { silent: true });+ expect(updateSettings).toHaveBeenLastCalledWith({ backup: { ...backup, disabledDefaultExcludes: ['/cache', checkpointPath], excludePaths: [...custom, '/loras/**'] } }, { silent: true });expect(toast.error).not.toHaveBeenCalled();cleanup();await renderTab();for (const pattern of [...custom, '/loras/**']) expect(screen.getByText(pattern)).toBeTruthy();fireEvent.click(screen.getByRole('button', { name: /Default exclusions/ }));- expect(screen.getByRole('switch', { name: `Disable default exclusion ${loraPath}` }).getAttribute('aria-checked')).toBe('true');+ expect(screen.getByRole('switch', { name: `Disable default exclusion ${checkpointPath}` }).getAttribute('aria-checked')).toBe('true');expect(screen.getByText('(Default exclusion disabled)')).toBeTruthy();expect(screen.getByText(/Disabling a default does not guarantee/)).toBeTruthy();});diff --git a/docs/BACKUP.md b/docs/BACKUP.mdindex 4eccd59af7..1de159656e 100644--- a/docs/BACKUP.md+++ b/docs/BACKUP.md@@ -74,7 +74,9 @@ A backup run (`runBackup` in `server/services/backup.js`) writes to:`DEFAULT_EXCLUDES` (in `backup.js`) skips ephemeral/cache data and large re-downloadable assets — all anchored with a leading `/` (rsync filter syntax). Two tiers:- **Non-overridable** (`overridable: false`): browser CDP profile, agent worktrees, cached jev training embeddings — caches with no irreplaceable user data; never backed up.-- **Overridable** (`overridable: true`): LoRA weight files, cloned repos, reference repos, browser downloads, jev training corpora — re-downloadable or rebuildable; the user can disable these built-in exclusion rules from the Backup settings UI via `disabledDefaultExcludes`.+- **Overridable** (`overridable: true`): intermediate LoRA training checkpoints, cloned repos, reference repos, browser downloads, jev training corpora — re-downloadable or rebuildable; the user can disable these built-in exclusion rules from the Backup settings UI via `disabledDefaultExcludes`.++Deployed LoRA weights in `data/loras/` and their metadata sidecars are included by default, whether trained locally or downloaded. Promoting an earlier checkpoint copies its selected bytes there, so a backup preserves that adapter independently of excluded torch and mflux intermediate checkpoint directories. This deliberately accepts the storage cost of deployed weights. Old `disabledDefaultExcludes` entries for `/loras/*.safetensors` remain harmless; the removed default no longer needs a toggle.#### jev project heads — excluded bulk, retained artifact@@ -102,7 +104,7 @@ The same rule applies to **user-entered** Additional Exclude Paths, which is theThe two `overridable` tiers are enforced, not advisory. A hand-edited `settings.json` that lists a non-overridable path in `disabledDefaultExcludes` is silently dropped server-side; `computeEffectiveExcludes()` enforces both the overridable allow-list and `Array.isArray` guards for hand-edited settings. The Backup tab switches describe default rule state: switching on disables that default exclusion, and switching off re-enables it. The summary counts enabled and disabled default rules, not included files.-Additional Exclude Paths is independent: toggling a default never removes custom patterns, and custom rsync patterns remain accepted even when they overlap defaults. Additional rules still apply when a default is disabled, so disabling `/loras/*.safetensors` does not guarantee weights will be backed up: `*.safetensors` or `/lo*/` can still exclude them. `computeEffectiveExcludes()` produces the filter list; rsync alone decides which paths match. The UI does not predict snapshot contents.+Additional Exclude Paths is independent: toggling a default never removes custom patterns, and custom rsync patterns remain accepted even when they overlap defaults. Additional rules still apply when a default is disabled, so deployed LoRA weights can still be omitted by explicit custom patterns: `*.safetensors` or `/lo*/` can still exclude them. `computeEffectiveExcludes()` produces the filter list; rsync alone decides which paths match. The UI does not predict snapshot contents.## The Postgres dump is mandatory, not optionaldiff --git a/server/services/backup.js b/server/services/backup.jsindex 10c3cbf736..09c82f27f4 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -161,11 +161,10 @@ export const DEFAULT_EXCLUDES = [{ path: '/cos/worktrees/', reason: 'Ephemeral agent git worktrees — recreated on demand', overridable: false },{ path: '/cos/slashdo-resolved/', reason: 'Resolved slashdo command bodies staged for agent prompts — derived from the bundled submodule, regenerated on demand', overridable: false },{ path: '/cos/feature-agents/*/worktree/', reason: 'Per-feature-agent git worktrees — recreated on demand', overridable: false },- { path: '/loras/*.safetensors', reason: 'LoRA adapter weight files — large, re-downloadable. .metadata.json sidecars (Civitai metadata, user-editable name/notes) ARE backed up.', overridable: true },// `**` (not `*`) so both engines' checkpoint dirs match: the torch trainer// writes training-runs/<id>/checkpoints/, mflux writes// training-runs/<id>/mflux/checkpoints/.- { path: '/training-runs/**/checkpoints/', reason: 'LoRA training checkpoints — large intermediate adapter state, resumable-but-regenerable. Final trained adapters land in data/loras/ (weights excluded there too); run samples + configs ARE backed up.', overridable: true },+ { path: '/training-runs/**/checkpoints/', reason: 'LoRA training checkpoints — large intermediate adapter state, resumable-but-regenerable. Deployed adapters in data/loras/, including promoted checkpoints, ARE backed up along with run samples + configs.', overridable: true },{ path: '/training-runs/*/cache/', reason: 'Precomputed latent/text-embedding training cache — regenerated from the dataset on the next run', overridable: false },{ path: '/training-runs/*/data/.mflux_cache/', reason: 'mflux low_ram disk-backed encode cache (written inside the staged training data dir) — regenerable', overridable: false },{ path: '/repos/', reason: 'Cloned git repositories — large, re-cloneable from origin', overridable: true },diff --git a/server/services/backup.test.js b/server/services/backup.test.jsindex 0b5d4d80f0..84c42ee66c 100644--- a/server/services/backup.test.js+++ b/server/services/backup.test.js@@ -197,6 +197,61 @@ describe('DEFAULT_EXCLUDES anchoring', () => {});});+describe('deployed LoRA backup recovery', () => {+ it('restores selected adapter bytes while excluding both runtimes checkpoints and honoring custom filters', async context => {+ if (process.platform === 'win32' && spawnSync('rsync', ['--version']).error?.code === 'ENOENT') {+ context.skip('Windows runner has no rsync executable; real rsync remains required on Linux/macOS.');+ }+ const root = await fs.mkdtemp(joinPath(tmpdir(), 'portos-lora-backup-'));+ const source = joinPath(root, 'source');+ const snapshot = joinPath(root, 'snapshot');+ const restored = joinPath(root, 'restored');+ const customSnapshot = joinPath(root, 'custom');+ const selected = Buffer.from('selected checkpoint step 250');+ const final = Buffer.from('different final checkpoint step 500');+ const sidecar = JSON.stringify({ name: 'Example trained adapter', step: 250 });+ const files = {+ 'loras/selected.safetensors': selected,+ 'loras/selected.metadata.json': sidecar,+ 'training-runs/torch-run/checkpoints/step-250.safetensors': selected,+ 'training-runs/mflux-run/mflux/checkpoints/step-250.safetensors': selected,+ 'training-runs/torch-run/final.safetensors': final,+ };+ try {+ for (const [relative, bytes] of Object.entries(files)) {+ const file = joinPath(source, relative);+ await fs.mkdir(joinPath(file, '..'), { recursive: true });+ await fs.writeFile(file, bytes);+ }+ for (const dest of [snapshot, restored, customSnapshot]) await fs.mkdir(dest);+ // A legacy disabled default is accepted without rewriting settings; it+ // cannot resurrect the removed exclusion or disable checkpoint filtering.+ const legacy = ['/loras/*.safetensors'];+ const copy = (from, to, excludes = []) => {+ const result = spawnSync(resolveRsyncBinary(), ['-a', ...excludes.flatMap(path => ['--exclude', path]), `${from}/`, `${to}/`], { encoding: 'utf8' });+ expect(result.error).toBeUndefined();+ expect(result.status, result.stderr).toBe(0);+ };+ copy(source, snapshot, computeEffectiveExcludes({ disabledDefaultExcludes: legacy }));+ copy(snapshot, restored);+ expect(await fs.readFile(joinPath(restored, 'loras/selected.safetensors'))).toEqual(selected);+ expect(await fs.readFile(joinPath(restored, 'loras/selected.metadata.json'), 'utf8')).toBe(sidecar);+ expect(await fs.readFile(joinPath(restored, 'training-runs/torch-run/final.safetensors'))).toEqual(final);+ for (const path of ['training-runs/torch-run/checkpoints', 'training-runs/mflux-run/mflux/checkpoints']) {+ expect(existsSync(joinPath(restored, path))).toBe(false);+ }+ const custom = ['/loras/*.safetensors'];+ copy(source, customSnapshot, computeEffectiveExcludes({ excludePaths: custom, disabledDefaultExcludes: legacy }));+ expect(existsSync(joinPath(customSnapshot, 'loras/selected.safetensors'))).toBe(false);+ expect(await fs.readFile(joinPath(customSnapshot, 'loras/selected.metadata.json'), 'utf8')).toBe(sidecar);+ expect(custom).toEqual(['/loras/*.safetensors']);+ expect(legacy).toEqual(['/loras/*.safetensors']);+ } finally {+ await fs.rm(root, { recursive: true, force: true });+ }+ });+});+describe('computeEffectiveExcludes', () => {it('includes every DEFAULT_EXCLUDES path when nothing is disabled', () => {const result = computeEffectiveExcludes({ excludePaths: [], disabledDefaultExcludes: [] });