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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([med-sharing-server-services-sharing-version-js]): inbox-promote gate for legacy-canon pending
[._.]/ Adam Eivy98110674433c
diff --git a/PLAN.md b/PLAN.mdindex e908398fc0..c6363ef50e 100644--- a/PLAN.md+++ b/PLAN.md@@ -53,6 +53,8 @@ The 2026-04-25 CODEX 5.5 review's concrete bugs (Brain Feeds nav, Time Capsule n### Deferred from better/2026-05-19+- [ ] [legacy-series-canon-orphan-universe-leak-on-throw] **[LOW][SHARING]** `server/services/pipeline/migrateSeriesCanon.js#applyLegacySeriesCanonToUniverse` — when the helper hits a transient I/O failure between `createUniverse(...)` and `updateUniverse(universeId, patch)` (or any subsequent write), the orphan universe is persisted on disk but the helper throws. On retry the manifest reprocesses, sees `s.universeId` still unset (bucket record isn't mutated), and mints a SECOND auto-migrated universe. Canon data isn't lost (the manifest stays retryable via `legacyCanonPendingFailures`), but empty `"<series-name> (auto-migrated)"` universes accumulate per retry pass. Fix needs a deterministic universe id derived from the importing series (e.g. `uni-import-<seriesHash>` or persisting the chosen id back to the bucket sidecar) so the second creation hits `ERR_DUPLICATE` and the helper reuses the existing universe. Deferred from `[med-sharing-server-services-sharing-version-js]` because the fix touches the universe identity model — out of scope for the importer-side migration salvage PR. Surfaced 2026-05-20 in codex review iter 4.+- [ ] [universebuilder-collection-hook-flaky-batch-enrich] **[MED][TESTS]** `server/services/universeBuilderCollectionHook.test.js > "enriches every sidecar in a batch — all N images get tagged"` still fails intermittently when the full server suite runs in parallel, even after the 2026-05-19 fix that migrated `enrichSidecar` to `atomicWrite` (`[imagegen-local-defer-module-load-side-effects]` PR). Passes 100% in isolation (`vitest run services/universeBuilderCollectionHook.test.js` — 8/8). Suggests a cross-file race that survives the temp+rename atomicity — likely shared `PATHS.data` Proxy / mocked `mediaCollections` state colliding with a sibling test that drains the same hook queue concurrently. Reproduce by running the full server `vitest run` 10× and grepping for FAIL; instrument the batch enrich path to log timing and identify the contending writer. Surfaced 2026-05-20 during the legacy-series-canon import PR.- [ ] [ansistrip-osc-alternative-unreachable] **[MED][TUI]** `server/lib/ansiStrip.js:14` — the OSC alternative in `ANSI_PATTERN` (`\][^\x07]*(?:\x07|\x1B\\)`) is dead code. Alternation order matches the single-byte alternative `[@-Z\\-_]` against `\x1B]` (0x5D is in 0x5C-0x5F) before the OSC alt is tried. Effect: only `\x1B]` is stripped from OSC sequences; the body+terminator leak into the cleaned stream (e.g. `\x1B]0;title\x07after` → `0;title\x07after`). Callers (`tuiPromptRunner.js:237`, `agentTuiSpawning.js:292`) consume the result without further filtering. Fix by either reordering alternatives (OSC before single-byte) or excluding `]` from the single-byte class (`[@-Z\\^_]` or similar). The new `ansiStrip.test.js` pins the current buggy behavior so a fix has an unambiguous before/after baseline. Surfaced 2026-05-20 during the test-coverage PR for med-tests-no-tests-for-server-lib-ansistrip-js; deferred to keep that PR scoped to tests.diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.jsindex 8b360b5095..f28ae7bcd4 100644--- a/server/services/sharing/importer.js+++ b/server/services/sharing/importer.js@@ -911,6 +911,23 @@ export async function promoteInboxItem(bucketId, manifestId) {pendingCollectionSeries: outcome.collectionPendingSeries,});}+ // Same gate for the legacy-canon migration: a pre-B.4 series whose linked+ // universe isn't local or whose helper threw transiently must keep the+ // inbox row so the user can re-promote after fixing the missing universe+ // or the transient I/O issue. Without this, the user's "promote" click+ // would consume the inbox row while the series merge silently skipped.+ if (outcome.legacyCanonPendingUniverses) {+ throw Object.assign(new Error(`Legacy series canon waiting on universe ${outcome.legacyCanonPendingUniverses.join(', ')} to be imported first`), {+ code: 'SHARING_LEGACY_CANON_UNIVERSE_PENDING',+ pendingLegacyCanonUniverses: outcome.legacyCanonPendingUniverses,+ });+ }+ if (outcome.legacyCanonPendingFailures) {+ throw Object.assign(new Error(`Legacy series canon migration failed for ${outcome.legacyCanonPendingFailures.join(', ')} — retry after resolving the underlying error`), {+ code: 'SHARING_LEGACY_CANON_FAILED',+ pendingLegacyCanonFailures: outcome.legacyCanonPendingFailures,+ });+ }// Drop from inbox.inbox.items.splice(idx, 1);await writeInbox(bucketId, inbox);diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.jsindex 070c62d932..ad5ead7561 100644--- a/server/services/sharing/integration.test.js+++ b/server/services/sharing/integration.test.js@@ -1446,6 +1446,65 @@ describe('sharing round-trip', () => {expect(autoMigrated).toHaveLength(1);});+ it('promoteInboxItem keeps the inbox row when legacy canon needs a missing universe', async () => {+ // Without the gate in promoteInboxItem the user's "promote" click would+ // splice the inbox row even though the series merge skipped — same+ // silent-data-loss shape as the auto-merge path before this PR.+ const bucket = await buckets.createBucket({ name: 'InboxLegacyBucket', path: tempBucket, mode: 'inbox' });++ const missingUniverseId = 'uni-inbox-not-bundled';+ const seriesId = 'ser-inbox-legacy';+ const legacySeries = {+ id: seriesId,+ name: 'Inbox Legacy Series',+ logline: 'inbox-pending test',+ premise: 'links to a universe not in the bundle',+ universeId: missingUniverseId,+ characters: [{ name: 'Phantom', physicalDescription: 'inbox-pending' }],+ createdAt: '2026-05-01T00:00:00.000Z',+ updatedAt: '2026-05-01T00:00:00.000Z',+ };+ mkdirSync(join(tempBucket, 'records', 'series'), { recursive: true });+ writeFileSync(+ join(tempBucket, 'records', 'series', `${seriesId}.json`),+ JSON.stringify(legacySeries),+ );+ const manifest = {+ id: 'mfst-inbox-legacy',+ schemaVersion: 1,+ sharingSchemaVersion: 1,+ producedByVersion: '1.0.0',+ createdAt: new Date().toISOString(),+ kind: 'series',+ senderInstanceId: 'inbox-legacy-peer',+ source: 'Inbox Legacy Peer',+ sourceBio: null,+ bucketId: bucket.id,+ bucketName: bucket.name,+ recordIds: [seriesId],+ assetRefs: [],+ note: null,+ };+ const filename = `2026-05-01T00-00-00-000Z-inbox-legacy-peer-${manifest.id}.json`;+ writeFileSync(join(tempBucket, 'manifests', filename), JSON.stringify(manifest));++ // First: queue as an inbox item (the bucket is inbox mode).+ const r1 = await importer.processManifest(bucket.id, filename);+ expect(r1.outcome.mode).toBe('inbox');+ expect((await importer.listInbox(bucket.id))).toHaveLength(1);++ // Promote — should throw because the linked universe is missing, AND the+ // inbox row must NOT be removed.+ let promoteErr = null;+ await importer.promoteInboxItem(bucket.id, manifest.id).catch((err) => { promoteErr = err; });+ expect(promoteErr).toBeTruthy();+ expect(promoteErr.code).toBe('SHARING_LEGACY_CANON_UNIVERSE_PENDING');+ expect(promoteErr.pendingLegacyCanonUniverses).toEqual([missingUniverseId]);+ expect((await importer.listInbox(bucket.id))).toHaveLength(1);+ const stillMissing = await series.getSeries(seriesId).catch(() => null);+ expect(stillMissing).toBeNull();+ });+it('leaves the manifest pending and retries when the missing universe later arrives', async () => {// Without this guard, the importer would fall through to insertSeriesWithId// and `sanitizeSeries` would silently drop the legacy canon arrays — the