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

address review (gemini): atomicWrite in new migrations (043-046), clarify PORTOS_SCHEMA_VERSIONS docstring vs storage-layout version

[._.]/ Adam Eivy93377a171662
diff --git a/scripts/migrations/043-story-builder-prompts.js b/scripts/migrations/043-story-builder-prompts.js
index ab027dc4c9..9347032f8e 100644
--- a/scripts/migrations/043-story-builder-prompts.js
+++ b/scripts/migrations/043-story-builder-prompts.js
@@ -10,8 +10,9 @@
* idea-expand generation would throw "Stage not found".
*/
-import { access, copyFile, mkdir, readFile, writeFile, constants } from 'fs/promises';
+import { access, copyFile, mkdir, readFile, constants } from 'fs/promises';
import { dirname, join } from 'path';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
// Each prompt file's basename doubles as its stage-config key (sans `.md`).
const STAGES = [
@@ -78,7 +79,7 @@ export default {
return;
}
await mkdir(dirname(installedConfigPath), { recursive: true });
- await writeFile(installedConfigPath, JSON.stringify(installed, null, 2) + '\n', 'utf8');
+ await atomicWrite(installedConfigPath, `${JSON.stringify(installed, null, 2)}\n`);
const action = installedExists ? 'merged' : 'created';
console.log(`📝 story-builder stage-config (${action}): ${added} added`);
} catch (err) {
diff --git a/scripts/migrations/044-hunyuan-fp32-deprecated.js b/scripts/migrations/044-hunyuan-fp32-deprecated.js
index 7fbb24fe56..5b5fd8a084 100644
--- a/scripts/migrations/044-hunyuan-fp32-deprecated.js
+++ b/scripts/migrations/044-hunyuan-fp32-deprecated.js
@@ -25,8 +25,9 @@
* changed) and exits without writing.
*/
-import { readFile, writeFile } from 'fs/promises';
+import { readFile } from 'fs/promises';
import { join } from 'path';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
const REL_PATH = 'data/media-models.json';
@@ -85,7 +86,7 @@ export default {
}
if (changed) {
- await writeFile(path, `${JSON.stringify(config, null, 2)}\n`);
+ await atomicWrite(path, `${JSON.stringify(config, null, 2)}\n`);
console.log(`📝 ${REL_PATH}: pinned HunyuanVideo to fp32 + marked deprecated (MPS matmul fp16/bf16 broken)`);
} else {
console.log(`✅ ${REL_PATH}: HunyuanVideo entry already pinned to fp32 + deprecated, no changes`);
diff --git a/scripts/migrations/045-flux2-klein-9b-kv-tokenizer.js b/scripts/migrations/045-flux2-klein-9b-kv-tokenizer.js
index 82281b553e..c4cdd4aa01 100644
--- a/scripts/migrations/045-flux2-klein-9b-kv-tokenizer.js
+++ b/scripts/migrations/045-flux2-klein-9b-kv-tokenizer.js
@@ -19,7 +19,8 @@
* without writing.
*/
-import { readFile, writeFile } from 'fs/promises';
+import { readFile } from 'fs/promises';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
import { join } from 'path';
const REL_PATH = 'data/media-models.json';
@@ -61,7 +62,7 @@ export default {
if (entry.tokenizerRepo === OLD_TOKENIZER_REPO) {
entry.tokenizerRepo = NEW_TOKENIZER_REPO;
- await writeFile(path, `${JSON.stringify(config, null, 2)}\n`);
+ await atomicWrite(path, `${JSON.stringify(config, null, 2)}\n`);
console.log(`📝 ${REL_PATH}: pinned flux2-klein-9b tokenizerRepo → ${NEW_TOKENIZER_REPO} (enables multi-reference editing)`);
} else {
console.log(`✅ ${REL_PATH}: flux2-klein-9b tokenizerRepo is "${entry.tokenizerRepo}" (not the pre-change default) — leaving alone`);
diff --git a/scripts/migrations/046-reference-watch-readonly-false.js b/scripts/migrations/046-reference-watch-readonly-false.js
index 848a3e0a76..a83a009760 100644
--- a/scripts/migrations/046-reference-watch-readonly-false.js
+++ b/scripts/migrations/046-reference-watch-readonly-false.js
@@ -29,8 +29,9 @@
* without writing.
*/
-import { readFile, writeFile } from 'fs/promises';
+import { readFile } from 'fs/promises';
import { join } from 'path';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
const REL_PATH = 'data/task-schedule.json';
@@ -72,7 +73,7 @@ export default {
}
meta.readOnly = false;
- await writeFile(path, `${JSON.stringify(config, null, 2)}\n`);
+ await atomicWrite(path, `${JSON.stringify(config, null, 2)}\n`);
console.log(`📝 ${REL_PATH}: flipped 'reference-watch' taskMetadata.readOnly true → false (v2 prompt needs write access to PLAN.md)`);
},
};
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index 97861b1d6e..604491cf61 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -7,14 +7,20 @@
* upgraded sender silently corrupts a downstream peer whose code doesn't
* yet understand a new storage layout.
*
- * `PORTOS_SCHEMA_VERSIONS` is the per-sync-category contract. Each entry is
- * the type-level storage layout version the running code expects to read +
- * write. When a category bumps its version (e.g. universes 4→5 splitting
- * out of the monolithic JSON), update the number here AND ship the
- * corresponding `scripts/migrations/NNN-…js`. The number flows through
- * every outbound payload's `portosMeta.schemaVersions`; receivers compare
- * incoming vs local and reject ahead-mismatches (sender too new) or
- * behind-mismatches (sender too old to satisfy a forward-only field).
+ * `PORTOS_SCHEMA_VERSIONS` is the per-sync-category WIRE contract — distinct
+ * from the storage-layout version stamped on `data/{type}/index.json` (see
+ * each service's local `TYPE_SCHEMA_VERSION` const). Bump the wire contract
+ * for either:
+ * (a) a storage layout change (e.g. universes 4→5 splitting out of the
+ * monolithic JSON), OR
+ * (b) an additive record-shape change that a not-yet-upgraded peer would
+ * silently strip on round-trip (e.g. pipelineSeries 1→2 for the
+ * `series.arc.readerMap` field).
+ * For (a) ship the corresponding `scripts/migrations/NNN-…js` to update the
+ * stamped storage version too; for (b) the local storage layout stays put.
+ * The number flows through every outbound payload's `portosMeta.schemaVersions`;
+ * receivers compare incoming vs local and reject ahead-mismatches (sender too
+ * new) or behind-mismatches (sender too old to satisfy a forward-only field).
*
* Absent categories default to 0 — the comparator treats 0 as "no check"
* so historical / un-versioned data categories pass through unchanged.