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

address review (claude): error boundary + bundled hint + HEAD variant test

Adam Eivy9c66c21498a2
diff --git a/client/src/components/cos/MiniCharacterCoSAvatar.jsx b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
index bc3a033656..11b132313a 100644
--- a/client/src/components/cos/MiniCharacterCoSAvatar.jsx
+++ b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
@@ -1,4 +1,4 @@
-import { useRef, useMemo, useEffect, useState, Suspense } from 'react';
+import { useRef, useMemo, useEffect, useState, Suspense, Component } from 'react';
import { Canvas, useFrame } from '@react-three/fiber';
import { useGLTF, useAnimations } from '@react-three/drei';
import * as THREE from 'three';
@@ -27,6 +27,11 @@ const FALLBACK = { clip: 'idle', rot: 0.2, timeScale: 1.0 };
// the whole avatar down in frame (~210px per world unit at this camera).
const GROUND_Y = -1.4;
+// Variants shipped in data.reference/avatar/ and seeded into data/avatar/ by
+// `npm run setup:data`. For these the "missing model" case means the seed
+// hasn't run yet — not that the user must supply their own GLB.
+const BUNDLED_VARIANTS = new Set(['mini-male-c', 'mini-female-d']);
+
function buildModelUrl(variant) {
return variant ? `/api/avatar/model.glb?variant=${encodeURIComponent(variant)}` : '/api/avatar/model.glb';
}
@@ -131,16 +136,45 @@ function Scene({ state, speaking, background, variant }) {
);
}
-function MissingModelHint({ background = false }) {
+function MissingModelHint({ background = false, bundled = false }) {
return (
<div className={`${background ? 'relative w-full h-full min-h-full' : 'relative w-full max-w-[8rem] lg:max-w-[12rem] aspect-[5/6]'} flex flex-col items-center justify-center rounded-lg border border-port-border bg-port-card/60 text-center p-3`}>
<div className="text-3xl mb-2">🧍</div>
- <div className="text-xs font-semibold text-slate-200 mb-1">No mini-character model</div>
- <code className="text-[9px] text-port-accent break-all leading-tight">data/avatar/&lt;variant&gt;.glb</code>
+ {bundled ? (
+ <>
+ <div className="text-xs font-semibold text-slate-200 mb-1">Model not yet seeded</div>
+ <div className="text-[10px] text-slate-400 mb-1.5">Run</div>
+ <code className="text-[9px] text-port-accent break-all leading-tight">npm run setup:data</code>
+ </>
+ ) : (
+ <>
+ <div className="text-xs font-semibold text-slate-200 mb-1">No mini-character model</div>
+ <code className="text-[9px] text-port-accent break-all leading-tight">data/avatar/&lt;variant&gt;.glb</code>
+ </>
+ )}
</div>
);
}
+// Error boundary so a corrupt/missing GLB or a GET that returns a non-GLTF
+// body (the HEAD probe only confirms r.ok, not valid GLTF) degrades to the
+// missing-model hint instead of white-screening the whole CoS page.
+class AvatarErrorBoundary extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { failed: false };
+ }
+ static getDerivedStateFromError() {
+ return { failed: true };
+ }
+ componentDidCatch(err) {
+ console.warn(`⚠️ Mini-character avatar failed to load: ${err?.message || err}`);
+ }
+ render() {
+ return this.state.failed ? this.props.fallback : this.props.children;
+ }
+}
+
function LoadingPlaceholder({ background = false }) {
return (
<div className={`${background ? 'relative w-full h-full min-h-full' : 'relative w-full max-w-[8rem] lg:max-w-[12rem] aspect-[5/6]'} flex items-center justify-center`}>
@@ -162,20 +196,23 @@ export default function MiniCharacterCoSAvatar({ state, speaking, background = f
return () => { cancelled = true; };
}, [url]);
+ const bundled = BUNDLED_VARIANTS.has(variant);
if (modelPresent === null) return <LoadingPlaceholder background={background} />;
- if (!modelPresent) return <MissingModelHint background={background} />;
+ if (!modelPresent) return <MissingModelHint background={background} bundled={bundled} />;
return (
<CoSAvatarFrame label="Mini-character avatar. Drag to rotate." background={background}>
- <Canvas
- camera={{ position: [0, 0.2, 3.0], fov: 40 }}
- style={{ width: '100%', height: '100%', background: 'transparent' }}
- gl={{ alpha: true, antialias: true }}
- >
- <Suspense fallback={null}>
- <Scene state={state} speaking={speaking} background={background} variant={variant} />
- </Suspense>
- </Canvas>
+ <AvatarErrorBoundary fallback={<MissingModelHint background={background} bundled={bundled} />}>
+ <Canvas
+ camera={{ position: [0, 0.2, 3.0], fov: 40 }}
+ style={{ width: '100%', height: '100%', background: 'transparent' }}
+ gl={{ alpha: true, antialias: true }}
+ >
+ <Suspense fallback={null}>
+ <Scene state={state} speaking={speaking} background={background} variant={variant} />
+ </Suspense>
+ </Canvas>
+ </AvatarErrorBoundary>
</CoSAvatarFrame>
);
}
diff --git a/server/lib/testHelper.js b/server/lib/testHelper.js
index 2302756d29..240de9921f 100644
--- a/server/lib/testHelper.js
+++ b/server/lib/testHelper.js
@@ -92,6 +92,7 @@ class RequestBuilder {
export function request(app) {
return {
get: (path) => new RequestBuilder(app, 'GET', path),
+ head: (path) => new RequestBuilder(app, 'HEAD', path),
post: (path) => new RequestBuilder(app, 'POST', path),
put: (path) => new RequestBuilder(app, 'PUT', path),
delete: (path) => new RequestBuilder(app, 'DELETE', path),
diff --git a/server/routes/avatar.test.js b/server/routes/avatar.test.js
index 652dd5fe1b..7abadf31b5 100644
--- a/server/routes/avatar.test.js
+++ b/server/routes/avatar.test.js
@@ -11,7 +11,6 @@ vi.mock('fs', () => ({
}));
vi.mock('../lib/fileUtils.js', () => ({
-tryReadFile: vi.fn().mockResolvedValue(null),
PATHS: { data: '/mock/data' }
}));
@@ -111,5 +110,17 @@ describe('avatar routes', () => {
}
}
});
+
+ // The client probes with HEAD before GET, so the HEAD handler runs the
+ // same resolveVariant() guard — pin it independently of the GET path.
+ it('HEAD honors a valid variant and rejects traversal', async () => {
+ existsSync.mockReturnValue(true);
+ statSync.mockReturnValue({ size: 5 });
+ const ok = await request(buildApp()).head('/api/avatar/model.glb?variant=mini-male-c');
+ expect(ok.status).toBe(200);
+ expect(ok.headers['content-type']).toBe('model/gltf-binary');
+ const bad = await request(buildApp()).head('/api/avatar/model.glb?variant=../secret');
+ expect(bad.status).toBe(404);
+ });
});
});