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: address review — migrations dir for fresh install, robust update marker handling

Adam Eivya05eced2d44a
diff --git a/scripts/setup-data.js b/scripts/setup-data.js
index 967f585eb7..912d26e40c 100644
--- a/scripts/setup-data.js
+++ b/scripts/setup-data.js
@@ -47,12 +47,12 @@ if (!existsSync(dataDir)) {
ensureSubdirs(sampleDir, dataDir);
- // Ensure migrations directory exists (not in data.sample)
- const migrationsDir = join(dataDir, 'migrations');
- if (!existsSync(migrationsDir)) {
- console.log('📁 Creating missing directory: migrations');
- mkdirSync(migrationsDir, { recursive: true });
- }
-
console.log('✅ Data directory already exists, ensured subdirectories');
}
+
+// Ensure migrations directory exists (not in data.sample, needed for both fresh and existing installs)
+const migrationsDir = join(dataDir, 'migrations');
+if (!existsSync(migrationsDir)) {
+ console.log('📁 Creating missing directory: migrations');
+ mkdirSync(migrationsDir, { recursive: true });
+}
diff --git a/server/index.js b/server/index.js
index cced4dac99..721fb05313 100644
--- a/server/index.js
+++ b/server/index.js
@@ -255,11 +255,40 @@ startBackupScheduler().catch(err => console.error(`❌ Backup scheduler init fai
// Check for update completion marker from a previous update cycle
const updateMarkerPath = join(__dirname, '..', 'data', 'update-complete.json');
readFile(updateMarkerPath, 'utf-8').then(raw => {
- const marker = JSON.parse(raw);
+ const parsed = JSON.parse(raw);
+ return { marker: parsed, parseError: null };
+}, err => {
+ // ENOENT = no marker file = no recent update, nothing to do
+ if (err?.code === 'ENOENT') return null;
+ // Unexpected read error — log and remove the problematic marker
+ console.error(`❌ Failed to read update marker: ${err?.message ?? err}`);
+ return { marker: null, parseError: err };
+}).then(result => {
+ if (!result) return; // No marker file
+ if (!result.marker) {
+ // Read failed with unexpected error — remove corrupted marker to avoid reprocessing
+ return unlink(updateMarkerPath).catch(unlinkErr => {
+ if (unlinkErr?.code !== 'ENOENT') console.error(`❌ Failed to remove problematic update marker: ${unlinkErr.message}`);
+ });
+ }
+ const marker = result.marker;
console.log(`✅ Update to v${marker.version} completed at ${marker.completedAt}`);
return recordUpdateResult({ version: marker.version, success: true, completedAt: marker.completedAt, log: '' })
- .then(() => unlink(updateMarkerPath));
-}).catch(() => {}); // No marker file = no recent update
+ .then(() => unlink(updateMarkerPath))
+ .catch(recordErr => {
+ console.error(`❌ Failed to record update result: ${recordErr.message}`);
+ // Still remove marker to avoid reprocessing on next startup
+ return unlink(updateMarkerPath).catch(unlinkErr => {
+ if (unlinkErr?.code !== 'ENOENT') console.error(`❌ Failed to remove update marker after record failure: ${unlinkErr.message}`);
+ });
+ });
+}).catch(err => {
+ // JSON.parse failure — corrupted marker file
+ console.error(`❌ Corrupted update marker (invalid JSON): ${err?.message ?? err}`);
+ unlink(updateMarkerPath).catch(unlinkErr => {
+ if (unlinkErr?.code !== 'ENOENT') console.error(`❌ Failed to remove corrupted update marker: ${unlinkErr.message}`);
+ });
+});
// Start periodic update checker (checks GitHub releases every 30 min)
startUpdateScheduler();