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: standardize error envelopes and redact store paths in youtube, avatar, identity routes (#11771)
[._.]/ Adam Eivyaab1f97a5bea
diff --git a/server/routes/avatar.js b/server/routes/avatar.jsindex ba3dc39751..a17c55ed5d 100644--- a/server/routes/avatar.js+++ b/server/routes/avatar.js@@ -10,7 +10,7 @@ import {parseRiggedVariant,riggedVariantForId,} from '../lib/avatarVariants.js';-import { ServerError, getErrorCode } from '../lib/errorHandler.js';+import { ServerError, asyncHandler, getErrorCode } from '../lib/errorHandler.js';import { buildClipCoverage } from '../services/rigging/clipCapabilities.js';import { retargetRunPaths } from '../services/rigging/retarget.js';import { getModel, listModels } from '../services/imageTo3d/db.js';@@ -71,13 +71,15 @@ router.head('/model.glb', async (req, res) => {return res.status(200).end();});-router.get('/model.glb', async (req, res) => {+router.get('/model.glb', asyncHandler(async (req, res) => {const path = await resolveAvatarPath(req.query.variant);if (!path || !(await pathExists(path))) {+ // A missing model is the normal pre-generation state, not a server fault.+ const severity = 'warning';if (isRiggedSpelling(req.query.variant)) {- throw new ServerError('That animated character is not available. Rig and animate the record first.', { status: 404 });+ throw new ServerError('That animated character is not available. Rig and animate the record first.', { status: 404, severity });}- throw new ServerError('No avatar model configured. Drop a GLB at data/avatar/model.glb', { status: 404 });+ throw new ServerError('No avatar model configured. Drop a GLB at data/avatar/model.glb', { status: 404, severity });}res.set('Content-Type', 'model/gltf-binary');res.set('Cache-Control', 'public, max-age=60');@@ -102,7 +104,7 @@ router.get('/model.glb', async (req, res) => {}});stream.pipe(res);-});+}));// One selector entry for a ready animated record: the `?variant=` spelling// that selects it, the avatar-route URL that serves it (variant-guarded and@@ -125,10 +127,10 @@ const riggedAvatarEntry = (record) => {// The animated records the avatar selectors may offer. Read-only: a DB list// filtered to verified retargets, each carrying its coverage — an empty list// (no records, none animated yet) is the normal fresh-install answer, not an error.-router.get('/rigged', async (_req, res) => {+router.get('/rigged', asyncHandler(async (_req, res) => {const records = await listModels();const ready = records.filter(isAnimatedRecordReady).map(riggedAvatarEntry).filter((entry) => entry.variant);res.json({ records: ready });-});+}));export default router;diff --git a/server/routes/avatar.test.js b/server/routes/avatar.test.jsindex 9ffdd2299e..23e7efd57b 100644--- a/server/routes/avatar.test.js+++ b/server/routes/avatar.test.js@@ -50,6 +50,20 @@ describe('avatar routes', () => {expect(res.body.error).toMatch(/avatar model/i);});+ it('emits the standard envelope and no server-error log for the expected pre-generation 404', async () => {+ pathExists.mockResolvedValue(false);+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});+ try {+ const res = await request(buildApp()).get('/api/avatar/model.glb');+ expect(res.status).toBe(404);+ expect(res.body.code).toBe('NOT_FOUND');+ expect(res.body.timestamp).toEqual(expect.any(Number));+ expect(errorSpy).not.toHaveBeenCalled();+ } finally {+ errorSpy.mockRestore();+ }+ });+it('streams model.glb content with correct headers', async () => {pathExists.mockResolvedValue(true);const fakeStream = Readable.from([Buffer.from('GLB-FAKE-CONTENT')]);diff --git a/server/routes/brainYoutube.js b/server/routes/brainYoutube.jsindex 0b9e6ed7ed..d56086bfd3 100644--- a/server/routes/brainYoutube.js+++ b/server/routes/brainYoutube.js@@ -27,11 +27,12 @@ router.post('/ingest', asyncHandler(async (req, res) => {}));/** GET /api/brain/youtube/ingest/:jobId/events — SSE progress stream. */-router.get('/ingest/:jobId/events', (req, res) => {+router.get('/ingest/:jobId/events', asyncHandler(async (req, res) => {+ // Throw before SSE headers are written so the standard error envelope applies.if (!ingest.attachIngestSseClient(req.params.jobId, res)) {- res.status(404).json({ error: 'Ingest job not found' });+ throw new ServerError('Ingest job not found', { status: 404, code: 'NOT_FOUND' });}-});+}));/** POST /api/brain/youtube/ingest/:jobId/cancel */router.post('/ingest/:jobId/cancel', asyncHandler(async (req, res) => {diff --git a/server/routes/brainYoutube.test.js b/server/routes/brainYoutube.test.jsindex 2553b6e887..fdc1ed1813 100644--- a/server/routes/brainYoutube.test.js+++ b/server/routes/brainYoutube.test.js@@ -5,7 +5,9 @@ import { errorMiddleware } from '../lib/errorHandler.js';const listIngests = vi.fn();-vi.mock('../services/youtubeIngest.js', () => ({ listIngests }));+const attachIngestSseClient = vi.fn();++vi.mock('../services/youtubeIngest.js', () => ({ listIngests, attachIngestSseClient }));const { default: routes } = await import('./brainYoutube.js');@@ -21,6 +23,22 @@ beforeEach(() => {vi.clearAllMocks();});+describe('GET /api/brain/youtube/ingest/:jobId/events', () => {+ it('answers an unknown job with the standard NOT_FOUND envelope before any SSE headers', async () => {+ attachIngestSseClient.mockReturnValue(false);++ const response = await request(makeApp()).get('/api/brain/youtube/ingest/job-missing/events');++ expect(response.status).toBe(404);+ expect(response.body).toEqual({+ error: 'Ingest job not found',+ code: 'NOT_FOUND',+ timestamp: expect.any(Number),+ });+ expect(attachIngestSseClient).toHaveBeenCalledWith('job-missing', expect.anything());+ });+});+describe('GET /api/brain/youtube/ingests', () => {it('returns the legacy full-history array for a query-less request', async () => {listIngests.mockResolvedValue([{ videoId: 'v1' }, { videoId: 'v2' }]);diff --git a/server/services/identity/store.js b/server/services/identity/store.jsindex 430a7f246b..b0661ec1fe 100644--- a/server/services/identity/store.js+++ b/server/services/identity/store.js@@ -142,7 +142,11 @@ export async function loadJSON(filePath, defaultVal, { strict = false } = {}) {// costs no goals, so reporting Strategist "unavailable" off it would be a lie in// the opposite direction: the goals were right there and readable.if (strict && !ok && !mlGoals) {- throw Object.assign(new Error(`Unreadable identity file: ${filePath}`), { code: 'UNREADABLE_STORE' });+ throw Object.assign(new Error(`Unreadable identity file: ${filePath}`), {+ code: 'UNREADABLE_STORE',+ // Host path stays in server logs; the HTTP envelope uses this message.+ responseMessage: 'Durable data store is unreadable',+ });}return data;}diff --git a/server/services/identity/store.test.js b/server/services/identity/store.test.jsindex 92b08a7369..981f607f10 100644--- a/server/services/identity/store.test.js+++ b/server/services/identity/store.test.js@@ -91,6 +91,14 @@ describe('loadJSON — { strict: true } (#2726)', () => {.rejects.toThrow(/Unreadable identity file/);});+ it('keeps the host path in the error message but redacts the HTTP-facing responseMessage', async () => {+ writeFileSync(GOALS_FILE, '{"goals": [{');+ const err = await loadJSON(GOALS_FILE, DEFAULT_GOALS, { strict: true }).catch((e) => e);+ expect(err.code).toBe('UNREADABLE_STORE');+ expect(err.message).toContain(GOALS_FILE);+ expect(err.responseMessage).toBe('Durable data store is unreadable');+ });+it('throws for a file truncated to zero bytes (a partial write, not an empty list)', async () => {writeFileSync(GOALS_FILE, '');await expect(loadJSON(GOALS_FILE, DEFAULT_GOALS, { strict: true }))