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([med-migration-scripts-migrations-014-attribute]): address codex review iter 2

[._.]/ Adam Eivy72466e0e48bf
diff --git a/scripts/migrations/014-attribute-existing-annotations.js b/scripts/migrations/014-attribute-existing-annotations.js
index 4c856cb922..25db8d3a3e 100644
--- a/scripts/migrations/014-attribute-existing-annotations.js
+++ b/scripts/migrations/014-attribute-existing-annotations.js
@@ -51,10 +51,13 @@ async function ensureSelfIdentity(instancesPath) {
const data = await readJsonOr(instancesPath, { self: null, peers: [] });
// Strict: only reuse a real-looking identity. Reject the `'unknown'` sentinel
// (this is exactly the value we're trying to never persist), reject non-string
- // shapes, and reject empty strings — any of those would re-introduce the
- // phantom-author bug we're fixing. Fall through to fresh-identity creation.
- const existingId = data?.self?.instanceId;
- if (typeof existingId === 'string' && existingId && existingId !== 'unknown') {
+ // shapes, and reject empty / whitespace-only / padded-sentinel strings —
+ // any of those would re-introduce the phantom-author bug we're fixing.
+ // Trim before comparing so `' unknown '` is rejected the same as `'unknown'`.
+ // Fall through to fresh-identity creation when invalid.
+ const rawId = data?.self?.instanceId;
+ const normalizedId = typeof rawId === 'string' ? rawId.trim() : '';
+ if (normalizedId && normalizedId !== 'unknown') {
return data.self;
}
const self = { instanceId: crypto.randomUUID(), name: os.hostname() };
diff --git a/scripts/migrations/014-attribute-existing-annotations.test.js b/scripts/migrations/014-attribute-existing-annotations.test.js
index 915a5f2d42..9ff4a2c948 100644
--- a/scripts/migrations/014-attribute-existing-annotations.test.js
+++ b/scripts/migrations/014-attribute-existing-annotations.test.js
@@ -171,6 +171,29 @@ describe('migration 014 — attribute existing annotations', () => {
expect(instances.self.instanceId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-/);
});
+ it('rejects whitespace-only or padded "unknown" sentinel and creates a fresh identity', async () => {
+ // A hand-edited or whitespace-corrupted instances.json mustn't slip past
+ // the sentinel guard — `' unknown '` is the same phantom as `'unknown'`.
+ writeInstances({ self: { instanceId: ' unknown ', name: 'old' }, peers: [] });
+ writeAnnotations({
+ 'image:foo.png': { starred: true, updatedAt: '2025-01-01T00:00:00.000Z' },
+ });
+ await migration.up({ rootDir });
+ const instances = readInstances();
+ expect(instances.self.instanceId.trim()).not.toBe('unknown');
+ expect(instances.self.instanceId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-/);
+ });
+
+ it('rejects whitespace-only self.instanceId and creates a fresh identity', async () => {
+ writeInstances({ self: { instanceId: ' ', name: 'host' }, peers: [] });
+ writeAnnotations({
+ 'image:foo.png': { starred: true, updatedAt: '2025-01-01T00:00:00.000Z' },
+ });
+ await migration.up({ rootDir });
+ const instances = readInstances();
+ expect(instances.self.instanceId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-/);
+ });
+
it('rejects empty-string self.instanceId and creates a fresh identity', async () => {
writeInstances({ self: { instanceId: '', name: 'host' }, peers: [] });
writeAnnotations({