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

refactor([med-migration-scripts-migrations-014-attribute]): hoist unknown-author heal out of inner loop

[._.]/ Adam Eivy300161d46aab
diff --git a/PLAN.md b/PLAN.md
index 18e8b7bbd2..5ea884e321 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -27,6 +27,7 @@ _Nothing currently parked — pick the next item from the Backlog._
- [ ] [extract-readcertmeta-helper] **Extract a shared `readCertMeta()` helper from `data/certs/meta.json` readers.** Three independent readers exist: `server/lib/peerSelfHost.js:13-18` (hostname only), `server/services/certRenewer.js:30-31` (mode + hostname), `server/lib/networkExposure.js:25-29` (mode + hostname + ips). Each does its own `statSync({ throwIfNoEntry: false }) + readFileSync + safeJSONParse`. Consolidate into `server/lib/certMeta.js` exporting `readCertMeta() → { mode, hostname, ips } | null`. Surfaced by /simplify during `[codex5-network-exposure-ui]`; deferred to keep that PR scoped. Note `peerSelfHost.js` is in a hot path — verify perf when consolidating.
- [ ] [hoist-loopback-host-helper-to-client-lib] **Hoist `isLoopbackHost` to `client/src/lib/loopbackHost.js`.** `server/lib/networkExposure.js` exports `isLoopbackHost`, but `client/src/components/NetworkExposureWidget.jsx:22-30` re-declares the same `LOOPBACK_HOSTS` Set and `describeMicAvailability()` helper inline (server export isn't reachable from browser). Move the client copy into `client/src/lib/loopbackHost.js` + add a barrel entry so future secure-context callers (voiceClient, etc.) can reuse it. When hoisting, broaden the IPv4 check from a single literal `127.0.0.1` to the full `127.0.0.0/8` loopback range to match browser secure-context behavior — easy `/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/` regex. Surfaced by /simplify and the codex review during `[codex5-network-exposure-ui]`.
- [ ] [image-gen-mode-enum-unify] **Unify image-gen mode enum across server + client.** Server has `IMAGE_GEN_MODES = ['external','local','codex']` (a Zod-validator alphabet) at `server/services/imageGen/index.js:21`; client has `IMAGE_GEN_MODE` constants at `client/src/lib/imageGenBackends.js:3`. Code reads strings (`'codex'`, `'local'`, `'external'`) inline at ~10 sites across `server/services/imageGen/{codex,local,external}.js`, `server/routes/imageGen.js`, and several client pages. `IMAGE_GEN_MODES` is actively used (Zod enum + voice tool enum), so the choice is "export a typed enum object on the server (`IMAGE_GEN_MODE = Object.freeze({ CODEX: 'codex', ... })`) alongside `IMAGE_GEN_MODES` and adopt it at dispatch sites" — not "drop `IMAGE_GEN_MODES`". Surfaced by /simplify after the per-render checkbox PR.
+- [ ] [unknown-instance-id-sentinel-extract] **Extract the `'unknown'` instanceId sentinel to a named constant.** The literal string `'unknown'` appears at 7+ sites across `server/services/instances.js#getInstanceId` (the default), `server/services/mediaAnnotations.js` (heal check in `readAll`, peer-merge guard, `setAnnotation` precondition), and `server/services/sharing/annotationsSync.js#flushAll` (export-refusal guard). Promote to `export const UNKNOWN_INSTANCE_ID = 'unknown'` in `instances.js` and import where compared, so the contract is greppable and typo-proof. Surfaced by /simplify during `[med-migration-scripts-migrations-014-attribute]`.
### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)
diff --git a/server/services/mediaAnnotations.js b/server/services/mediaAnnotations.js
index 4be1bc21a1..9b3f6abf5d 100644
--- a/server/services/mediaAnnotations.js
+++ b/server/services/mediaAnnotations.js
@@ -101,19 +101,18 @@ async function readAll() {
const authors = {};
for (const [instanceId, sub] of Object.entries(lifted.authors)) {
if (typeof instanceId !== 'string' || !instanceId) continue;
+ if (instanceId === 'unknown' && healUnknownAuthor) continue; // re-keyed below
const sane = sanitizeAuthorEntry(sub);
- if (!sane) continue;
- if (instanceId === 'unknown' && healUnknownAuthor) {
- // Prefer a real local entry already present — it's the source of truth;
- // the unknown bucket is the phantom that needs to be dropped.
- if (!authors[localInstanceId]) {
- authors[localInstanceId] = sane.authorName
- ? sane
- : { ...sane, authorName: defaultAuthorName };
- }
- continue;
+ if (sane) authors[instanceId] = sane;
+ }
+ // Heal the phantom: re-key `unknown` → real local id. Skip when a real
+ // local entry already exists for this key — that's the source of truth
+ // (a later setAnnotation already wrote there) and the phantom is dropped.
+ if (healUnknownAuthor && lifted.authors.unknown && !authors[localInstanceId]) {
+ const sane = sanitizeAuthorEntry(lifted.authors.unknown);
+ if (sane) {
+ authors[localInstanceId] = { ...sane, authorName: sane.authorName || defaultAuthorName };
}
- authors[instanceId] = sane;
}
if (Object.keys(authors).length > 0) out[key] = { authors };
}