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

fix: reset PortOS app repoPath when it is not an existing directory (#12483)

[._.]/ Adam Eivyaccc6ae2325f
diff --git a/server/services/apps.js b/server/services/apps.js
index a4a326c9d1..0306a4aeb7 100644
--- a/server/services/apps.js
+++ b/server/services/apps.js
@@ -1,4 +1,5 @@
import { join } from 'path';
+import { statSync } from 'fs';
import { v4 as uuidv4 } from '../lib/uuid.js';
import EventEmitter from 'events';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
@@ -20,6 +21,11 @@ import { certPaths } from '../../lib/certPaths.js';
const DATA_DIR = PATHS.data;
const APPS_FILE = join(DATA_DIR, 'apps.json');
+function isExistingDirectory(p) {
+ if (typeof p !== 'string' || !p) return false;
+ try { return statSync(p).isDirectory(); } catch { return false; }
+}
+
// Stable ID for the PortOS app — always present, never deletable. Defined in
// `lib/appIdentity.js` so a caller that only needs to name PortOS (a CoS task's
// target app, a scope check) can import it without this whole service graph;
@@ -157,6 +163,15 @@ async function loadApps() {
data.apps[PORTOS_APP_ID].repoPath = baseline.repoPath;
dirty = true;
}
+ // A restored snapshot from another checkout carries that checkout's absolute
+ // path. A repoPath that is not an existing directory cannot be a working
+ // override, so rebind to the running checkout (#12483).
+ const storedRepoPath = data.apps[PORTOS_APP_ID].repoPath;
+ if (storedRepoPath !== baseline.repoPath && !isExistingDirectory(storedRepoPath)) {
+ console.warn(`⚠️ PortOS app repoPath ${storedRepoPath} is not a directory; resetting to ${baseline.repoPath}`);
+ data.apps[PORTOS_APP_ID].repoPath = baseline.repoPath;
+ dirty = true;
+ }
if (dirty) {
await atomicWrite(APPS_FILE, data);
console.log(placeholderDirty
diff --git a/server/services/apps.test.js b/server/services/apps.test.js
index eeec0ed1ee..6939c028cf 100644
--- a/server/services/apps.test.js
+++ b/server/services/apps.test.js
@@ -1,4 +1,5 @@
import { readFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('fs/promises', () => ({
@@ -419,12 +420,33 @@ describe('__PORTOS_ROOT__ placeholder expansion on load', () => {
expect(JSON.stringify(persisted)).not.toContain('__PORTOS_ROOT__');
});
- it('preserves a concrete user-overridden repoPath', async () => {
+ it('resets a PortOS repoPath that is not an existing directory (restored from another checkout)', async () => {
readJSONFile.mockResolvedValue({
apps: {
[PORTOS_APP_ID]: {
name: 'PortOS',
- repoPath: '/custom/portos/checkout',
+ repoPath: '/nonexistent/source/checkout',
+ type: 'express',
+ pm2ProcessNames: ['portos-server'],
+ },
+ 'other-app': { name: 'Other', repoPath: '/nonexistent/other-app' },
+ },
+ });
+
+ const apps = await getAllApps();
+ expect(apps.find((app) => app.id === PORTOS_APP_ID).repoPath).toBe('/mock/root');
+ const persisted = atomicWrite.mock.calls.at(-1)[1];
+ expect(persisted.apps[PORTOS_APP_ID].repoPath).toBe('/mock/root');
+ expect(persisted.apps['other-app'].repoPath).toBe('/nonexistent/other-app');
+ });
+
+ it('preserves a concrete user-overridden repoPath that exists', async () => {
+ const override = tmpdir();
+ readJSONFile.mockResolvedValue({
+ apps: {
+ [PORTOS_APP_ID]: {
+ name: 'PortOS',
+ repoPath: override,
type: 'express',
pm2ProcessNames: ['portos-server'],
},
@@ -433,7 +455,7 @@ describe('__PORTOS_ROOT__ placeholder expansion on load', () => {
const apps = await getAllApps();
const portos = apps.find((app) => app.id === PORTOS_APP_ID);
- expect(portos.repoPath).toBe('/custom/portos/checkout');
+ expect(portos.repoPath).toBe(override);
});
it('expands placeholders on non-PortOS app records too', async () => {