Skip to content

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

Coordinate backup publication cuts across local processes

[._.]/ Adam Eivy848cab6b9e05
diff --git a/docs/BACKUP_PUBLICATION_ADMISSION.md b/docs/BACKUP_PUBLICATION_ADMISSION.md
new file mode 100644
index 0000000000..87d100c8bf
--- /dev/null
+++ b/docs/BACKUP_PUBLICATION_ADMISSION.md
@@ -0,0 +1,51 @@
+# Shared backup publication admission
+
+The server and `portos-cos` are separate processes that share one install data
+root. `withBackupAssetPublication` registers a short durable lease in
+`data/backup-admission/publications/` before changing an asset and its owning
+record. Model execution and transfers into unreferenced staging files remain
+outside the lease. Hold it through the final record write and failure rollback.
+Nested calls reuse the existing lease. Synchronous completion listeners receive
+separate leases while their parent remains admitted.
+
+A snapshot or live restore atomically creates `data/backup-admission/cut/`, then
+drains every registered publication before reading or replacing either store.
+New publications wait until the cut owner releases it. Readers register before
+checking the cut; the cut registers before checking readers. This ordering closes
+the cross-process admission race. A preliminary gate check avoids registering
+and deleting leases repeatedly during a long snapshot. Directory creation and
+removal work on Windows and POSIX; ownership files are fsynced, with directory
+fsync on POSIX (Windows does not support opening a directory that way).
+
+Every owner has a random ID, process generation, PID, kind, and timestamp. Only
+the matching owner may release its directory. Neither elapsed time nor a missing
+PID permits automatic removal: a dead publication may have left an incomplete
+file/record pair, and a dead restore may have installed only part of its snapshot.
+A cut that cannot drain refuses with `BACKUP_SNAPSHOT_BUSY` and includes the
+blocking ownership records. The read-only `backupPublicationAdmissionStatus()`
+returns both cut and publication ownership, including unreadable records.
+
+The control directory is machine-local authority. Backup excludes it
+unconditionally, and all full or selective restores preserve it. Upgrade and
+restart both the server and CoS runner before relying on coordination between
+them; an older runner does not participate. Admission still only covers owners
+listed as admitted in the backup inventory, not arbitrary shell commands or
+external tools that write the data tree.
+
+## Interrupted ownership recovery
+
+An interrupted owner is a recovery blocker, not evidence that its data is safe.
+Keep the recorded ID, PID, generation, timestamp, and directory path in the
+incident record. Stop both PortOS processes and any tool writing the affected
+data before examining it. Correlate the owner with logs, inspect the affected
+file/record pair, and finish or roll back that domain's interrupted publication.
+For a restore, also complete its cache/index and database recovery before
+reopening publication admission. A failed snapshot must remain failed.
+
+Only after the affected data has been verified may an operator explicitly retire
+that exact ownership directory while all writers remain stopped. Preserve its
+owner record with the recovery evidence; do not delete the entire control tree,
+clear ownership merely because its PID exited, or remove a record from a running
+process. Restart both processes after recovery. If the record is unreadable or
+the affected data cannot be established, retain the blocker and restore from a
+verified source with a deliberate recovery plan.
diff --git a/server/lib/backupSharedAdmission.js b/server/lib/backupSharedAdmission.js
new file mode 100644
index 0000000000..a550537cda
--- /dev/null
+++ b/server/lib/backupSharedAdmission.js
@@ -0,0 +1,114 @@
+/** Cross-process publication admission on the install's shared local filesystem. */
+import * as fs from 'node:fs';
+import { randomUUID } from 'node:crypto';
+import { dirname, join } from 'node:path';
+import { PATHS } from './paths.js';
+import { assertNotRealDataWrite } from './testDataIsolation.js';
+
+const busy = (message, details = {}) => Object.assign(new Error(message), {
+ status: 503, code: 'BACKUP_SNAPSHOT_BUSY', ...details,
+});
+
+/**
+ * Atomic directory creation is available on Windows as well as POSIX. Readers
+ * register BEFORE checking the cut gate; the cutter creates its gate BEFORE
+ * checking readers. A reader racing the cutter therefore either gets drained
+ * or observes the gate and never starts its mutation. No PID/age reclamation:
+ * a crashed writer may have left half a publication behind.
+ */
+export function createBackupSharedAdmission(directory, { io = fs, makeId = randomUUID, assertWrite = assertNotRealDataWrite } = {}) {
+ const readers = join(directory, 'publications');
+ const cutPath = join(directory, 'cut');
+ const generation = makeId();
+ const exists = path => {
+ try { io.lstatSync(path); return true; }
+ catch (error) { if (error.code === 'ENOENT') return false; throw error; }
+ };
+ const syncDir = path => {
+ if (process.platform === 'win32') return;
+ const fd = io.openSync(path, 'r');
+ try { io.fsyncSync(fd); } finally { io.closeSync(fd); }
+ };
+ const prepare = () => {
+ assertWrite(directory, 'backup publication admission');
+ const firstCreated = io.mkdirSync(readers, { recursive: true, mode: 0o700 });
+ // Persist the entire newly created ancestry, including the parent entry
+ // naming its first directory, before any asset mutation can start. Also
+ // sync the normal control/data parents when another process won mkdir.
+ const highest = firstCreated ? dirname(firstCreated) : dirname(directory);
+ for (let path = readers; ; path = dirname(path)) {
+ syncDir(path);
+ if (path === highest || dirname(path) === path) break;
+ }
+ };
+ const describe = path => {
+ try {
+ const owner = JSON.parse(io.readFileSync(join(path, 'owner.json'), 'utf8'));
+ if (owner.version !== 1 || typeof owner.id !== 'string' || typeof owner.generation !== 'string'
+ || !Number.isInteger(owner.pid) || !['publication', 'snapshot'].includes(owner.kind)) throw new Error('Invalid ownership record');
+ return { ...owner, path };
+ } catch { return { path, unreadable: true }; }
+ };
+ const writeOwner = (path, kind) => {
+ const owner = { version: 1, id: makeId(), generation, pid: process.pid, kind, startedAt: new Date().toISOString() };
+ const fd = io.openSync(join(path, 'owner.json'), 'wx', 0o600);
+ try { io.writeFileSync(fd, JSON.stringify(owner) + '\n'); io.fsyncSync(fd); }
+ finally { io.closeSync(fd); }
+ syncDir(path);
+ syncDir(kind === 'publication' ? readers : directory);
+ let active = true;
+ return {
+ owner, path,
+ get active() { return active; },
+ release() {
+ if (!active) return;
+ if (describe(path).id !== owner.id) throw busy(`Backup admission ownership changed at ${path}; reconcile the recorded owner before retrying.`, { recoveryPath: path });
+ // Only our nonce-checked directory. Failure leaves an explicit blocker.
+ io.unlinkSync(join(path, 'owner.json'));
+ io.rmdirSync(path);
+ syncDir(kind === 'publication' ? readers : directory);
+ active = false;
+ },
+ };
+ };
+ const tryPublication = ({ parent } = {}) => {
+ // Avoid durable registration churn while a long snapshot owns the gate.
+ // The second check AFTER registration below still closes the race.
+ const joinsParent = parent?.active && exists(parent.path);
+ if (!joinsParent && exists(cutPath)) return null;
+ prepare();
+ const path = join(readers, makeId());
+ io.mkdirSync(path, { mode: 0o700 });
+ const lease = writeOwner(path, 'publication');
+ // A synchronous fan-out may join its live parent while a cut drains it.
+ // Registration completes before the parent can relinquish its own lease.
+ if (!joinsParent && exists(cutPath)) {
+ lease.release();
+ return null;
+ }
+ return lease;
+ };
+ const reserveCut = () => {
+ prepare();
+ try { io.mkdirSync(cutPath, { mode: 0o700 }); }
+ catch (error) {
+ if (error.code !== 'EEXIST') throw error;
+ throw busy(`Backup snapshot cut already owned at ${cutPath}. If its process stopped, reconcile the interrupted backup or restore before removing its ownership record.`, { recoveryPath: cutPath, owner: describe(cutPath) });
+ }
+ return writeOwner(cutPath, 'snapshot');
+ };
+ const publications = () => {
+ try { return io.readdirSync(readers).map(name => describe(join(readers, name))); }
+ catch (error) { if (error.code === 'ENOENT') return []; throw error; }
+ };
+ return { tryPublication, reserveCut, publications, cutPending: () => exists(cutPath),
+ status: () => ({ cut: exists(cutPath) ? describe(cutPath) : null, publications: publications() }) };
+}
+
+let shared;
+export const backupSharedAdmission = new Proxy({}, {
+ get(_target, key) {
+ shared ??= createBackupSharedAdmission(join(PATHS.data, 'backup-admission'));
+ return shared[key];
+ },
+});
diff --git a/server/lib/backupSharedAdmission.test.js b/server/lib/backupSharedAdmission.test.js
new file mode 100644
index 0000000000..e596016fe7
--- /dev/null
+++ b/server/lib/backupSharedAdmission.test.js
@@ -0,0 +1,177 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { spawn } from 'node:child_process';
+import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
+import * as syncFs from 'node:fs';
+import { existsSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { once } from 'node:events';
+import { createBackupSharedAdmission } from './backupSharedAdmission.js';
+
+const roots = [];
+const children = [];
+const boundaryUrl = new URL('./backupSnapshotBoundary.js', import.meta.url).href;
+const childSource = `
+ import { writeFile, mkdir } from 'node:fs/promises';
+ import { join } from 'node:path';
+ const { withBackupAssetPublication, acquireBackupSnapshotCut } = await import(${JSON.stringify(boundaryUrl)});
+ let finish;
+ const done = new Promise(resolve => { finish = resolve; });
+ process.on('message', message => { if (message === 'finish') finish(); });
+ const root = process.env.PORTOS_DATA_ROOT;
+ const mode = process.env.ADMISSION_TEST_MODE;
+ process.send({ type: 'starting' });
+ try {
+ if (mode === 'publication' || mode === 'unadmitted') {
+ const publish = mode === 'unadmitted' ? work => work() : withBackupAssetPublication;
+ await publish(async () => {
+ await writeFile(join(root, 'data', 'output.txt'), process.env.ADMISSION_TEST_VALUE);
+ process.send({ type: 'entered' });
+ await done;
+ await writeFile(join(root, 'data', 'metadata.json'), JSON.stringify({ output: process.env.ADMISSION_TEST_VALUE }));
+ });
+ } else {
+ const release = await acquireBackupSnapshotCut({ timeoutMs: Number(process.env.ADMISSION_TEST_TIMEOUT || 5000) });
+ process.send({ type: 'entered' });
+ await done;
+ release();
+ release(); // stale duplicate releases must be harmless
+ }
+ process.send({ type: 'finished' });
+ } catch (error) { process.send({ type: 'rejected', code: error.code, message: error.message, blockers: error.blockers }); }
+`;
+async function root() {
+ const path = await mkdtemp(join(tmpdir(), 'backup-shared-race-'));
+ roots.push(path);
+ await mkdir(join(path, 'data'));
+ return path;
+}
+function worker(path, mode, value = '', timeout = 5000) {
+ const env = { ...process.env, PORTOS_DATA_ROOT: path, ADMISSION_TEST_MODE: mode,
+ ADMISSION_TEST_VALUE: value, ADMISSION_TEST_TIMEOUT: String(timeout) };
+ // These are real Node children, not Vitest workers; keep their filesystem
+ // rooted at the private install above and do not inherit a runner identity.
+ delete env.VITEST; delete env.VITEST_WORKER_ID; delete env.VITEST_POOL_ID;
+ const proc = spawn(process.execPath, ['--input-type=module', '-e', childSource], { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });
+ children.push(proc);
+ const messages = [];
+ let stderr = '';
+ proc.stderr.on('data', data => { stderr += data; });
+ proc.on('message', message => messages.push(message));
+ return { proc, messages,
+ async next(type) {
+ await vi.waitFor(() => {
+ if (proc.exitCode !== null) throw new Error(`Child exited ${proc.exitCode}: ${stderr}`);
+ expect(messages.some(message => message.type === type), stderr).toBe(true);
+ }, { timeout: 10000, interval: 10 });
+ return messages.find(message => message.type === type);
+ },
+ finish: () => proc.send('finish'),
+ async crash() { const exited = once(proc, 'exit'); proc.kill('SIGKILL'); await exited; },
+ };
+}
+afterEach(async () => {
+ await Promise.all(children.splice(0).map(async proc => {
+ if (proc.exitCode !== null || proc.signalCode !== null) return;
+ const exited = once(proc, 'exit'); proc.kill('SIGKILL'); await exited;
+ }));
+ await Promise.all(roots.splice(0).map(path => rm(path, { recursive: true, force: true })));
+});
+
+describe('shared snapshot admission between real server and runner processes', () => {
+ it('drains the file/metadata pair and excludes a later process through the cut', async () => {
+ const path = await root();
+ const first = worker(path, 'publication', 'first');
+ await first.next('entered');
+ const cut = worker(path, 'cut');
+ await cut.next('starting');
+ await vi.waitFor(() => expect(existsSync(join(path, 'data/backup-admission/cut/owner.json'))).toBe(true));
+ expect(cut.messages.some(message => message.type === 'entered')).toBe(false);
+ const later = worker(path, 'publication', 'later');
+ await later.next('starting');
+ first.finish();
+ await first.next('finished');
+ await cut.next('entered');
+ expect(await readFile(join(path, 'data/output.txt'), 'utf8')).toBe('first');
+ expect(JSON.parse(await readFile(join(path, 'data/metadata.json'), 'utf8'))).toEqual({ output: 'first' });
+ expect(later.messages.some(message => message.type === 'entered')).toBe(false);
+ cut.finish();
+ await cut.next('finished');
+ await later.next('entered');
+ later.finish();
+ await later.next('finished');
+ expect(JSON.parse(await readFile(join(path, 'data/metadata.json'), 'utf8'))).toEqual({ output: 'later' });
+ });
+
+ it('negative control: a nonparticipating process can change the copied pair under a cut', async () => {
+ const path = await root();
+ const writer = worker(path, 'unadmitted', 'uncoordinated');
+ await writer.next('entered');
+ const cut = worker(path, 'cut');
+ await cut.next('entered');
+ expect(existsSync(join(path, 'data/metadata.json'))).toBe(false);
+ writer.finish();
+ await writer.next('finished');
+ expect(JSON.parse(await readFile(join(path, 'data/metadata.json'), 'utf8'))).toEqual({ output: 'uncoordinated' });
+ cut.finish();
+ await cut.next('finished');
+ });
+
+ it('persists newly created control ancestors before admitting a first publication', async () => {
+ const path = await root();
+ const directory = join(path, 'data/backup-admission');
+ const opened = new Map();
+ const synced = [];
+ const io = { ...syncFs,
+ openSync(path, ...args) { const fd = syncFs.openSync(path, ...args); opened.set(fd, path); return fd; },
+ fsyncSync(fd) { synced.push(opened.get(fd)); syncFs.fsyncSync(fd); },
+ };
+ const admission = createBackupSharedAdmission(directory, { io });
+ const lease = admission.tryPublication();
+ try {
+ expect(synced).toContain(join(lease.path, 'owner.json'));
+ if (process.platform !== 'win32') {
+ expect(synced).toEqual(expect.arrayContaining([join(directory, 'publications'), directory, join(path, 'data')]));
+ expect(synced.indexOf(join(path, 'data'))).toBeLessThan(synced.indexOf(join(lease.path, 'owner.json')));
+ }
+ } finally { lease.release(); }
+ });
+
+ it('keeps a killed writer as a durable blocker across coordinator restarts', async () => {
+ const path = await root();
+ const writer = worker(path, 'publication', 'half pair');
+ await writer.next('entered');
+ await writer.crash();
+ for (let attempt = 0; attempt < 2; attempt++) {
+ const cut = worker(path, 'cut', '', 50);
+ const rejected = await cut.next('rejected');
+ expect(rejected).toMatchObject({ code: 'BACKUP_SNAPSHOT_BUSY', blockers: [expect.objectContaining({ kind: 'publication', pid: writer.proc.pid })] });
+ expect(rejected.message).toContain('must not be removed by age or PID');
+ }
+ expect(existsSync(join(path, 'data/metadata.json'))).toBe(false);
+ expect(existsSync(join(path, 'data/backup-admission/cut'))).toBe(false);
+ });
+
+ it('preserves a crashed cut instead of letting another process steal it', async () => {
+ const path = await root();
+ const owner = worker(path, 'cut');
+ await owner.next('entered');
+ await owner.crash();
+ const contender = worker(path, 'cut');
+ expect(await contender.next('rejected')).toMatchObject({ code: 'BACKUP_SNAPSHOT_BUSY', message: expect.stringContaining('reconcile the interrupted backup or restore') });
+ const gate = JSON.parse(await readFile(join(path, 'data/backup-admission/cut/owner.json'), 'utf8'));
+ expect(gate.pid).toBe(owner.proc.pid);
+ });
+
+ it('fails closed on unreadable ownership and refuses a stale release', async () => {
+ const path = await root();
+ const directory = join(path, 'data/backup-admission');
+ const admission = createBackupSharedAdmission(directory);
+ const cut = admission.reserveCut();
+ await writeFile(join(directory, 'cut/owner.json'), '{broken');
+ expect(() => cut.release()).toThrow('ownership changed');
+ expect(() => admission.reserveCut()).toThrow('already owned');
+ expect(admission.tryPublication()).toBe(null);
+ expect(admission.status().cut).toMatchObject({ unreadable: true });
+ });
+});
diff --git a/server/lib/backupSnapshotBoundary.js b/server/lib/backupSnapshotBoundary.js
index 22cf6dd782..256d685e97 100644
--- a/server/lib/backupSnapshotBoundary.js
+++ b/server/lib/backupSnapshotBoundary.js
@@ -1,6 +1,7 @@
import { maintenance } from './maintenanceAdmission.js';
+import { backupSharedAdmission } from './backupSharedAdmission.js';
/**
- * Process-local admission for durable file-plus-row publications during backup.
+ * Cross-process admission for durable file-plus-row publications during backup.
* Callers hold one mutation lease across BOTH stores, not around individual
* filesystem or SQL operations. The backup closes admission before rsync and
* keeps it closed through the database dump and manifest write.
@@ -8,7 +9,8 @@ import { maintenance } from './maintenanceAdmission.js';
* Database maintenance shares the boundary. A cut is refused while a maintenance
* fence is up, and maintenance that must not observe or replace a half-published
* pair takes the same cut around its own destructive step. Publication itself is
- * never refused here: under a fence the database already rejects the row write.
+ * waits for a snapshot; unreadable ownership fails closed. Under a database
+ * fence the database already rejects the row write.
* Every retryable refusal carries BACKUP_SNAPSHOT_BUSY.
*/
import { AsyncLocalStorage } from 'node:async_hooks';
@@ -43,12 +45,17 @@ async function withAdmittedBackupAssetPublication(work) {
while (!joinsAdmitted && (cutRequested || cutActive)) {
await new Promise(resolve => publicationWaiters.push(resolve));
}
+ let sharedLease;
+ while (!(sharedLease = backupSharedAdmission.tryPublication({ parent: joinsAdmitted ? scope.spawnedBy.sharedLease : null }))) {
+ await new Promise(resolve => setTimeout(resolve, 25));
+ }
admitted += 1;
- const lease = { active: true };
+ const lease = { active: true, sharedLease };
try {
return await publicationScope.run(lease, work);
} finally {
lease.active = false;
+ sharedLease.release();
admitted -= 1;
if (admitted === 0) {
const waiters = drainWaiters;
@@ -67,12 +74,17 @@ export function holdsBackupAssetPublication() {
return publicationScope.getStore()?.active === true;
}
+/** Read-only ownership evidence for interrupted-publication recovery. */
+export function backupPublicationAdmissionStatus() {
+ return backupSharedAdmission.status();
+}
+
/**
* Whether a backup cut is requested or active. Optional housekeeping that would
* otherwise wait out the whole snapshot can defer to its next pass instead.
*/
export function backupSnapshotCutPending() {
- return cutRequested || cutActive;
+ return cutRequested || cutActive || backupSharedAdmission.cutPending();
}
/** Wait for already admitted workflows to settle, or reject when they do not. */
@@ -121,11 +133,19 @@ export async function acquireBackupSnapshotCut({ timeoutMs = DEFAULT_DRAIN_TIMEO
if (publicationScope.getStore()?.active) throw new Error('Backup snapshot cut cannot be acquired inside an asset publication');
if (cutRequested || cutActive) throw busyError('Backup snapshot cut already owned');
assertDatabaseAdmission();
+ const sharedCut = backupSharedAdmission.reserveCut();
cutRequested = true;
+ const deadline = Date.now() + timeoutMs;
try {
if (admitted > 0) await awaitDrain(timeoutMs);
+ let blockers;
+ while ((blockers = backupSharedAdmission.publications()).length > 0) {
+ if (Date.now() >= deadline) throw Object.assign(busyError('Timed out draining asset publications for backup. Reconcile interrupted publications before retrying; ownership records must not be removed by age or PID.'), { blockers });
+ await new Promise(resolve => setTimeout(resolve, Math.min(25, Math.max(1, deadline - Date.now()))));
+ }
assertDatabaseAdmission();
} catch (error) {
+ sharedCut.release();
cutRequested = false;
releasePublications();
throw error;
@@ -135,6 +155,7 @@ export async function acquireBackupSnapshotCut({ timeoutMs = DEFAULT_DRAIN_TIMEO
let released = false;
return () => {
if (released) return;
+ sharedCut.release();
released = true;
cutActive = false;
releasePublications();
diff --git a/server/services/backup.js b/server/services/backup.js
index 0e5e5699c1..79aeae6a13 100644
--- a/server/services/backup.js
+++ b/server/services/backup.js
@@ -162,6 +162,7 @@ const queueStateWrite = createFileWriteQueue();
// matches any `loras/` directory anywhere under data/ (e.g. a user's
// brain/.../loras/ collection), which would silently exclude unrelated user data.
export const DEFAULT_EXCLUDES = [
+ { path: '/backup-admission/', reason: 'Machine-local publication ownership and snapshot fences', overridable: false },
{ path: '/image-thumbnails/', reason: 'Regenerable image grid previews', overridable: false },
{ path: '/python/laya-mlx/', reason: 'Rebuildable Laya-MLX experiment runtime and pinned model weights', overridable: false },
{ path: '/browser-profile/', reason: 'Browser CDP profile — cache/cookies, can be several GB', overridable: false },
@@ -1339,7 +1340,7 @@ const OS_METADATA_RSYNC_EXCLUDES = [...OS_METADATA_FILES, '._*'].map(name => `--
* verification and execution cannot disagree.
*/
const RESTORE_PRESERVED_FILES = Object.freeze([
- 'database-authority.json', 'peer-execution', 'peer-execution-catalog.json', 'peer-execution-grants.json', 'peer-execution-authority.json', 'peer-execution-recovery.jsonl', 'workflow-maintenance',
+ 'database-authority.json', 'peer-execution', 'peer-execution-catalog.json', 'peer-execution-grants.json', 'peer-execution-authority.json', 'peer-execution-recovery.jsonl', 'workflow-maintenance', 'backup-admission',
]);
// Matched case-insensitively (rsync has no such flag, so each letter becomes a
// `[xX]` class): on a case-insensitive volume a `Database-Authority.json` entry
@@ -1519,7 +1520,7 @@ export async function restoreSnapshot(destPath, snapshotId, { dryRun = true, sub
// never promises a restore that execution would silently skip.
if (restoreScopeIsPreservedFile(subdirFilter)) {
throw new ServerError(
- 'These machine-local authority and recovery records (database-authority.json, peer-execution-authority.json, peer-execution-recovery.jsonl and workflow-maintenance) are never restored from a snapshot. Restore application records with a data or database restore; existing local authority and unresolved owners must be reconciled on this machine (see docs/STORAGE.md).',
+ 'These machine-local authority and recovery records (database-authority.json, peer-execution-authority.json, peer-execution-recovery.jsonl workflow-maintenance and backup-admission) are never restored from a snapshot. Restore application records with a data or database restore; existing local authority and unresolved owners must be reconciled on this machine (see docs/STORAGE.md).',
{ status: 400, code: 'BACKUP_RESTORE_MACHINE_LOCAL' },
);
}
diff --git a/server/services/backup.test.js b/server/services/backup.test.js
index 29e7579e50..117df99b57 100644
--- a/server/services/backup.test.js
+++ b/server/services/backup.test.js
@@ -2413,7 +2413,7 @@ describe('restoreSnapshot manifest verification', () => {
});
});
- it.for(['peer-execution-grants.json', 'peer-execution-catalog.json', 'peer-execution/fixture-operation/evidence.json', 'peer-execution-authority.json', 'peer-execution-recovery.jsonl', 'workflow-maintenance/state.json', 'Workflow-Maintenance/state.json'])
+ it.for(['peer-execution-grants.json', 'peer-execution-catalog.json', 'peer-execution/fixture-operation/evidence.json', 'peer-execution-authority.json', 'peer-execution-recovery.jsonl', 'workflow-maintenance/state.json', 'Workflow-Maintenance/state.json', 'backup-admission/cut/owner.json', 'Backup-Admission/publications/owner.json'])
('preserves non-rewound execution authority and ownership at %s (#10127)', async (path, context) => {
await withRealRsync(context, async () => {
const localPath = joinPath(PATHS.data, path);
@@ -3077,6 +3077,7 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>
'--exclude=/[pP][eE][eE][rR]-[eE][xX][eE][cC][uU][tT][iI][oO][nN]-[aA][uU][tT][hH][oO][rR][iI][tT][yY].[jJ][sS][oO][nN]',
'--exclude=/[pP][eE][eE][rR]-[eE][xX][eE][cC][uU][tT][iI][oO][nN]-[rR][eE][cC][oO][vV][eE][rR][yY].[jJ][sS][oO][nN][lL]',
'--exclude=/[wW][oO][rR][kK][fF][lL][oO][wW]-[mM][aA][iI][nN][tT][eE][nN][aA][nN][cC][eE]',
+ '--exclude=/[bB][aA][cC][kK][uU][pP]-[aA][dD][mM][iI][sS][sS][iI][oO][nN]',
'--dry-run',
// Leading `/` is load-bearing: rsync matches an unanchored pattern
// against the end of every path, so `brain/***` would also restore
@@ -3110,6 +3111,7 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>
'--exclude=/[pP][eE][eE][rR]-[eE][xX][eE][cC][uU][tT][iI][oO][nN]-[aA][uU][tT][hH][oO][rR][iI][tT][yY].[jJ][sS][oO][nN]',
'--exclude=/[pP][eE][eE][rR]-[eE][xX][eE][cC][uU][tT][iI][oO][nN]-[rR][eE][cC][oO][vV][eE][rR][yY].[jJ][sS][oO][nN][lL]',
'--exclude=/[wW][oO][rR][kK][fF][lL][oO][wW]-[mM][aA][iI][nN][tT][eE][nN][aA][nN][cC][eE]',
+ '--exclude=/[bB][aA][cC][kK][uU][pP]-[aA][dD][mM][iI][sS][sS][iI][oO][nN]',
]);
});
diff --git a/server/vitest.setup.js b/server/vitest.setup.js
index a2ca2e0676..905325be09 100644
--- a/server/vitest.setup.js
+++ b/server/vitest.setup.js
@@ -113,3 +113,17 @@ vi.mock('./lib/maintenanceAdmission.js', async (importOriginal) => {
if (entry.closed || path !== join(root, 'workflow-maintenance')) throw new Error('Unexpected maintenance test path');
} }) };
});
+
+// Publication admission remains real, but never shares ownership with the install
+// or another test file. Use real fs/UUIDs even when domain suites mock them.
+vi.mock('./lib/backupSharedAdmission.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ const io = await vi.importActual('node:fs');
+ const { randomUUID } = await vi.importActual('node:crypto');
+ const root = io.mkdtempSync(join(tmpdir(), 'backup-admission-workflow-'));
+ const entry = { io, root, closed: false };
+ maintenanceTestRoots.push(entry);
+ return { ...actual, backupSharedAdmission: actual.createBackupSharedAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
+ if (entry.closed || path !== root) throw new Error('Unexpected backup admission test path');
+ } }) };
+});