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: bound approved voice references before export buffers accumulate
[._.]/ Adam Eivy3f13b45610b4
diff --git a/server/services/fableLoom/exports.js b/server/services/fableLoom/exports.jsindex b2e9146243..e45273e809 100644--- a/server/services/fableLoom/exports.js+++ b/server/services/fableLoom/exports.js@@ -278,6 +278,7 @@ async function build(job, snapshot, episodes, history, universe, signal) {});}const voicePlans = [];+ const media = createMediaStore();if (job.options.includeVoice) {const universeId = typeof universe?.id === 'string' && universe.id? universe.id@@ -330,8 +331,8 @@ async function build(job, snapshot, episodes, history, universe, signal) {continue;}voicePlans.push({- characterId: character.id, bytes, sha256,- extension: asset.filename.slice(asset.filename.lastIndexOf('.') + 1).toLowerCase(),+ characterId: character.id,+ ...media.add({ bytes, extension: asset.filename.slice(asset.filename.lastIndexOf('.') + 1).toLowerCase(), durationMs: null }),consentConfirmed: asset.consentConfirmed, licensePosture: asset.licensePosture,sourcePolicy: character.approval?.sourcePolicy || null,});@@ -348,7 +349,6 @@ async function build(job, snapshot, episodes, history, universe, signal) {await ensureDir(directory);const cache = new Map();const prepare = await createFableLoomMediaCache(join(root(), 'media-cache'), job.options, signal);- const media = createMediaStore();const nodeAssets = new Map();const provenance = [];for (const request of requests) {@@ -396,9 +396,8 @@ async function build(job, snapshot, episodes, history, universe, signal) {await save(job);}const voiceProvenance = voicePlans.map(plan => {- const prepared = media.add({ bytes: plan.bytes, extension: plan.extension, durationMs: null });return {- characterId: plan.characterId, file: prepared.file, sha256: prepared.sha256, bytes: prepared.bytes,+ characterId: plan.characterId, file: plan.file, sha256: plan.sha256, bytes: plan.bytes,approved: true, draftFlags: [], consentConfirmed: plan.consentConfirmed,licensePosture: plan.licensePosture, sourcePolicy: plan.sourcePolicy,};diff --git a/server/services/fableLoom/exports.test.js b/server/services/fableLoom/exports.test.jsindex 3ea4f735d8..7cb824c42c 100644--- a/server/services/fableLoom/exports.test.js+++ b/server/services/fableLoom/exports.test.js@@ -20,6 +20,14 @@ import { execFileSync } from '../../lib/childProcess.js';vi.mock('../../lib/paths.js', async original => makePathsProxy(await original(), {dataRoot: () => lazyTempDataRoot('portos-fableloom-export-'),}));+const exportBudget = vi.hoisted(() => ({ maxPackageBytes: null }));+vi.mock('../../lib/fableLoomExport.js', async original => {+ const module = await original();+ return { ...module, FABLELOOM_EXPORT_LIMITS: {+ ...module.FABLELOOM_EXPORT_LIMITS,+ get maxPackageBytes() { return exportBudget.maxPackageBytes ?? module.FABLELOOM_EXPORT_LIMITS.maxPackageBytes; },+ } };+});vi.mock('./records.js', () => ({ getLoom: vi.fn() }));vi.mock('../videoGen/history.js', () => ({ loadHistory: vi.fn() }));vi.mock('../universeBuilder.js', () => ({ getUniverse: vi.fn() }));@@ -33,6 +41,7 @@ import { loadHistory } from '../videoGen/history.js';import { getUniverse } from '../universeBuilder.js';import { listVoiceProfiles } from '../voice/profiles.js';import * as media from './exportMedia.js';+import * as voiceReferences from './exportVoice.js';import {__testing, startFableLoomExport, getFableLoomExport, getFableLoomExportDownload,} from './exports.js';@@ -222,7 +231,7 @@ beforeEach(async () => {jobIds.length = 0;await rm(join(PATHS.data, 'cache/fableloom-exports'), { recursive: true, force: true });});-afterEach(async () => { await __testing.drain(); vi.restoreAllMocks(); });+afterEach(async () => { await __testing.drain(); vi.restoreAllMocks(); exportBudget.maxPackageBytes = null; });afterAll(async () => { await owned.drain(); await __testing.drain(); cleanupTempDataRoots(); });describe('portable FableLoom export boundary', () => {@@ -678,6 +687,57 @@ describe('portable FableLoom export boundary', () => {expect(listVoiceProfiles).not.toHaveBeenCalled();});+ it('refuses an oversized voice package before reading its remaining references', async () => {+ useCast();+ const assets = [];+ for (let index = 0; index < 4; index++) {+ const filename = `reference-${index}.wav`;+ const sha256 = await writeVoiceReference(Buffer.from(`voice-reference-${index}`), filename);+ assets.push({ filename, sha256, licensePosture: 'generated-original-voice' });+ }+ listVoiceProfiles.mockResolvedValue([voiceProfile({ sourceAssets: assets })]);+ // A small budget exercises the same public worker boundary without large allocations.+ exportBudget.maxPackageBytes = 25;+ const readReference = vi.spyOn(voiceReferences, 'readFableLoomVoiceReference');+ const result = await terminal(await begin({+ episodeIds: ['episode-one'], includeCharacters: true, includeVoice: true,+ }));+ expect(result).toMatchObject({ status: 'failed', error: { code: 'EXPORT_PACKAGE_SIZE' } });+ expect(readReference).toHaveBeenCalledTimes(2);+ expect(result).not.toHaveProperty('downloadUrl');+ await expect(stat(join(PATHS.data, 'cache/fableloom-exports', jobIds.at(-1), 'package.zip')))+ .rejects.toMatchObject({ code: 'ENOENT' });+ });++ videoIt('deduplicates approved voice bytes across the cast within the package budget', async () => {+ useCast([approvedCharacter(), approvedCharacter({ id: 'example-support' })]);+ loom.episodes[0].nodes[0].visualCanon.characterAppearances = [{ characterId: 'example-support' }];+ const bytes = Buffer.alloc(32 * 1024, 7);+ const digest = await writeVoiceReference(bytes);+ const supportRoot = join(PATHS.voiceProfiles, 'support-voice', 'source');+ await mkdir(supportRoot, { recursive: true });+ await writeFile(join(supportRoot, 'reference.wav'), bytes);+ const protagonist = voiceProfile({ sha256: digest });+ const support = { ...voiceProfile({ sha256: digest, id: 'support-voice' }),+ binding: { universeId: 'example-universe', characterId: 'example-support' } };+ listVoiceProfiles.mockImplementation(async ({ characterId }) => [protagonist, support]+ .filter(profile => profile.binding.characterId === characterId));+ const options = { episodeIds: ['episode-one'], includeCharacters: true, includeVoice: true };+ const firstId = await begin(options);+ const first = await archive(firstId);+ const { sizeReport } = await getFableLoomExport(loom.id, firstId);+ // Enough for the actual package, but not another copy of the shared reference.+ exportBudget.maxPackageBytes = sizeReport.archiveBytes + 1;+ expect(exportBudget.maxPackageBytes).toBeLessThan(bytes.length * 2);+ const repeated = await archive(await begin(options));+ expect(repeated.bytes.equals(first.bytes)).toBe(true);+ expect([...repeated.files.keys()].filter(name => name.endsWith('.wav'))).toEqual([`media/${digest}.wav`]);+ expect(JSON.parse(repeated.files.get('provenance.json')).voices).toEqual([+ expect.objectContaining({ characterId: 'example-character', file: `media/${digest}.wav` }),+ expect.objectContaining({ characterId: 'example-support', file: `media/${digest}.wav` }),+ ]);+ });+videoIt('exports approved voice references with provenance and stable hashes', async () => {useCast();const bytes = Buffer.from('approved-reference-audio');