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
address review (claude): drop now-redundant mixed-root skip, add symmetric override-worktree guard
[._.]/ Adam Eivy45fb44f78361
diff --git a/scripts/run-migrations.js b/scripts/run-migrations.jsindex 692cc9471e..b520197e01 100644--- a/scripts/run-migrations.js+++ b/scripts/run-migrations.js@@ -5,13 +5,13 @@ import { fileURLToPath, pathToFileURL } from 'url';import { resolveInstallRoot, isWorktreeRoot } from '../server/lib/dataRoot.js';const __dirname = dirname(fileURLToPath(import.meta.url));-// The install this migration CODE ships with (the checkout that loaded this-// file), independent of any env override — used to detect a mixed-root run.-const CHECKOUT_ROOT = join(__dirname, '..');// Prefer an explicit PORTOS_DATA_ROOT env var over the executing-file location// so a process booted from inside a CoS agent git worktree still resolves to-// the real install (#1947). Falls back to the derived path when unset.-const DEFAULT_ROOT_DIR = resolveInstallRoot(CHECKOUT_ROOT);+// the real install (#1947). resolveInstallRoot refuses the pin when the derived+// path is itself a worktree, so a worktree launch falls through to its own path+// and the isWorktreeRoot backstop below skips. Falls back to the derived path+// when the env var is unset.+const DEFAULT_ROOT_DIR = resolveInstallRoot(join(__dirname, '..'));const DEFAULT_MIGRATIONS_DIR = join(__dirname, 'migrations');const appliedFilePath = (rootDir) => join(rootDir, 'data', 'migrations.applied.json');@@ -99,20 +99,6 @@ export async function runMigrations({return 0;}- // Mixed-root backstop (#1947): the migrations being scanned ship with THIS- // checkout (DEFAULT_MIGRATIONS_DIR), but rootDir points at a DIFFERENT- // install's data tree — e.g. a worktree process with PORTOS_DATA_ROOT pinned- // to the real install. Applying this checkout's migrations to a foreign data- // tree can mark a worktree-only migration applied without ever copying its- // shipped data (seed migrations only warn when their data.reference sample is- // absent), corrupting the real install's applied-list. Only enforce when the- // default migrations dir is in use — an explicit migrationsDir (tests, a- // deliberate cross-install run) means the caller owns the code/data pairing.- if (migrationsDir === DEFAULT_MIGRATIONS_DIR && resolve(rootDir) !== resolve(CHECKOUT_ROOT)) {- console.warn(`⚠️ Skipping migrations: data root (${rootDir}) differs from the executing checkout (${CHECKOUT_ROOT}) — refusing to apply this checkout's migrations to a foreign install (mixed-root)`);- return 0;- }-const appliedFile = appliedFilePath(rootDir);// Ensure data/ exists so we can persist applied state (migrationsDirdiff --git a/scripts/run-migrations.test.js b/scripts/run-migrations.test.jsindex fa4f5983c1..42cb9ac1ee 100644--- a/scripts/run-migrations.test.js+++ b/scripts/run-migrations.test.js@@ -166,20 +166,6 @@ export default {expect(existsSync(join(realRoot, 'data', 'fixture-marker.txt'))).toBe(true);});- it('skips when the data root differs from the executing checkout (mixed-root, default migrationsDir)', async () => {- // No migrationsDir override → the runner uses its OWN checkout's- // DEFAULT_MIGRATIONS_DIR. A rootDir pointing at a different install must not- // get this checkout's migrations applied to it (returns before any FS write- // to the foreign root, so this is safe to run against the real repo).- const foreignRoot = join(baseDir, 'some-other-install');- mkdirSync(join(foreignRoot, 'data'), { recursive: true });-- const ran = await runMigrations({ rootDir: foreignRoot });-- expect(ran).toBe(0);- expect(existsSync(join(foreignRoot, 'data', 'migrations.applied.json'))).toBe(false);- expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('mixed-root'));- });});describe('listPendingMigrations', () => {diff --git a/server/lib/dataRoot.js b/server/lib/dataRoot.jsindex 7d47f1e5ec..304710072a 100644--- a/server/lib/dataRoot.js+++ b/server/lib/dataRoot.js@@ -56,7 +56,13 @@ export function resolveInstallRoot(fallbackRoot) {const override = process.env[DATA_ROOT_ENV];if (typeof override === 'string' && override.trim() !== '') {const trimmed = override.trim();- return isAbsolute(trimmed) ? trimmed : resolvePath(trimmed);+ const resolved = isAbsolute(trimmed) ? trimmed : resolvePath(trimmed);+ // Symmetric leak-safety: never let the data root resolve INTO a worktree,+ // whether the worktree path came from the executing location (above) or a+ // misconfigured override. A worktree has no runtime data/ tree, so honoring+ // such an override would strand the real process on an empty tree.+ if (isWorktreeRoot(resolved)) return fallbackRoot;+ return resolved;}return fallbackRoot;}diff --git a/server/lib/dataRoot.test.js b/server/lib/dataRoot.test.jsindex f41ef28f9c..579c5bac01 100644--- a/server/lib/dataRoot.test.js+++ b/server/lib/dataRoot.test.js@@ -32,6 +32,11 @@ describe('resolveInstallRoot', () => {expect(out).not.toBe(REAL_ROOT);});+ it('IGNORES an override that itself points at a worktree checkout (symmetric leak safety)', () => {+ process.env[DATA_ROOT_ENV] = join(REAL_ROOT, 'data', 'cos', 'worktrees', 'agent-xyz');+ expect(resolveInstallRoot(REAL_ROOT)).toBe(REAL_ROOT);+ });+it('IGNORES the pin when the fallback is a worktree checkout (leak safety #1947)', () => {// A worktree-executing process must never honor a (possibly-leaked) pin —// resolving its data root to the live install would let worktree code