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

stop the CoS avatar guard reporting a model 404 as "no WebGL" (#4688)

[._.]/ Adam Eivyc3594a34ed9f
diff --git a/client/src/components/ErrorBoundary.jsx b/client/src/components/ErrorBoundary.jsx
index a90c47c744..8d28602ec0 100644
--- a/client/src/components/ErrorBoundary.jsx
+++ b/client/src/components/ErrorBoundary.jsx
@@ -19,8 +19,8 @@ export default class ErrorBoundary extends Component {
// `onError` lets a caller that owns chrome AROUND the failed subtree react
// to the failure — an r3f `<Canvas>` can only degrade to `fallback={null}`
// inside the scene, so the DOM-side message has to be rendered by the
- // parent from its own state (GlbViewer's mesh-load panel). Not called on
- // the stale-chunk path above: that reloads the page.
+ // parent from its own state (ThreejsModelPreview's spec-render panel).
+ // Not called on the stale-chunk path above: that reloads the page.
this.props.onError?.(error);
}
diff --git a/client/src/components/cos/CoSCanvasGuard.jsx b/client/src/components/cos/CoSCanvasGuard.jsx
index 48fd4d03cb..f0fc13e421 100644
--- a/client/src/components/cos/CoSCanvasGuard.jsx
+++ b/client/src/components/cos/CoSCanvasGuard.jsx
@@ -1,37 +1,28 @@
-import { Component, useState } from 'react';
+import { useState } from 'react';
import { isWebGLAvailable } from '../../lib/webglSupport';
+import { glbErrorText, glbFailureHint } from '../../lib/glbFailure';
+import ErrorBoundary from '../ErrorBoundary';
import CoSAvatarFrame from './CoSAvatarFrame';
/**
* Gate CoS 3D avatar canvases on WebGL availability and catch render-time
* failures so a missing GPU never leaves an unhandled promise rejection or a
* blank panel. Callers pass the r3f `<Canvas>…</Canvas>` as children.
+ *
+ * The two causes are reported SEPARATELY. Every caught error used to show the
+ * WebGL hint, but these avatars load remote GLBs (`MuseCoSAvatar` →
+ * `/api/avatar/model.glb`, `MiniCharacterCoSAvatar` → `useClonedGltf(url)`), so
+ * a model 404 told the user to go change an unrelated setting. `isWebGLAvailable`
+ * is a real pre-gate and keeps the WebGL hint; anything thrown afterwards is an
+ * asset failure and says so.
*/
-class AvatarErrorBoundary extends Component {
- constructor(props) {
- super(props);
- this.state = { failed: false };
- }
-
- static getDerivedStateFromError() {
- return { failed: true };
- }
-
- componentDidCatch(err) {
- console.warn(`⚠️ CoS avatar failed: ${err?.message || err}`);
- }
-
- render() {
- return this.state.failed ? this.props.fallback : this.props.children;
- }
-}
+const panelClass = (background) =>
+ `${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`;
function WebGLUnavailableHint({ 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 flex-col items-center justify-center rounded-lg border border-port-border bg-port-card/60 text-center p-3`}
- >
+ <div className={panelClass(background)}>
<div className="text-2xl mb-2" aria-hidden="true">🖥️</div>
<div className="text-xs font-semibold text-gray-200 mb-1">3D unavailable</div>
<div className="text-[10px] text-gray-400 leading-snug">
@@ -41,6 +32,21 @@ function WebGLUnavailableHint({ background = false }) {
);
}
+function AvatarAssetFailure({ background = false, error }) {
+ // `null` from the shared hint table means "we don't recognize this" — fall
+ // back to the raw message rather than inventing a cause.
+ const hint = glbFailureHint(error);
+ return (
+ <div className={panelClass(background)} data-testid="cos-avatar-asset-error" role="alert">
+ <div className="text-2xl mb-2" aria-hidden="true">⚠️</div>
+ <div className="text-xs font-semibold text-gray-200 mb-1">Avatar failed to load</div>
+ <div className="text-[10px] text-gray-400 leading-snug">
+ {hint || glbErrorText(error) || 'The avatar model could not be loaded.'}
+ </div>
+ </div>
+ );
+}
+
export default function CoSCanvasGuard({
label = 'Interactive 3D avatar. Drag to rotate.',
background = false,
@@ -49,15 +55,20 @@ export default function CoSCanvasGuard({
}) {
// Probe once on mount — availability doesn't flip mid-session.
const [supported] = useState(() => isWebGLAvailable());
- const resolvedFallback = fallback || <WebGLUnavailableHint background={background} />;
+ // The r3f `<Canvas>` re-throws from its own render, and the message belongs in
+ // the DOM chrome around it — so the shared boundary degrades the scene with
+ // `fallback={null}` and hands the error up here via `onError`. An explicit
+ // caller `fallback` still overrides both panels.
+ const [error, setError] = useState(null);
- if (!supported) return resolvedFallback;
+ if (!supported) return fallback || <WebGLUnavailableHint background={background} />;
+ if (error) return fallback || <AvatarAssetFailure background={background} error={error} />;
return (
<CoSAvatarFrame label={label} background={background}>
- <AvatarErrorBoundary fallback={resolvedFallback}>
+ <ErrorBoundary fallback={null} onError={setError}>
{children}
- </AvatarErrorBoundary>
+ </ErrorBoundary>
</CoSAvatarFrame>
);
}
diff --git a/client/src/components/cos/CoSCanvasGuard.test.jsx b/client/src/components/cos/CoSCanvasGuard.test.jsx
new file mode 100644
index 0000000000..f35655aba0
--- /dev/null
+++ b/client/src/components/cos/CoSCanvasGuard.test.jsx
@@ -0,0 +1,80 @@
+import { render, screen } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+// The guard's whole job is deciding WHICH failure the user is looking at, and
+// the two inputs to that decision are the WebGL pre-gate and whatever the
+// canvas throws. Both are mocked so each case can be driven independently.
+const webgl = vi.hoisted(() => ({ available: true }));
+vi.mock('../../lib/webglSupport', () => ({ isWebGLAvailable: () => webgl.available }));
+
+import CoSCanvasGuard from './CoSCanvasGuard';
+
+const Boom = ({ error }) => { throw error; };
+
+describe('CoSCanvasGuard', () => {
+ let logged;
+ beforeEach(() => {
+ webgl.available = true;
+ logged = vi.spyOn(console, 'error').mockImplementation(() => {});
+ });
+ afterEach(() => { vi.restoreAllMocks(); });
+
+ it('renders the canvas when WebGL is available and nothing throws', () => {
+ render(<CoSCanvasGuard><div data-testid="avatar-canvas" /></CoSCanvasGuard>);
+ expect(screen.getByTestId('avatar-canvas')).toBeInTheDocument();
+ expect(screen.queryByTestId('cos-avatar-asset-error')).not.toBeInTheDocument();
+ });
+
+ it('still shows the WebGL hint on a display that cannot render 3D', () => {
+ webgl.available = false;
+ render(<CoSCanvasGuard><div data-testid="avatar-canvas" /></CoSCanvasGuard>);
+ expect(screen.getByText(/This display has no WebGL/i)).toBeInTheDocument();
+ expect(screen.queryByTestId('avatar-canvas')).not.toBeInTheDocument();
+ });
+
+ // The reported bug: these avatars load remote GLBs, so a model 404 was
+ // reported as "no WebGL" and sent the user to change an unrelated setting.
+ it('reports an asset failure as an asset failure, not as missing WebGL', () => {
+ render(
+ <CoSCanvasGuard>
+ <Boom error={new Error('Could not load /api/avatar/model.glb: 404 Not Found')} />
+ </CoSCanvasGuard>,
+ );
+
+ expect(screen.getByTestId('cos-avatar-asset-error')).toBeInTheDocument();
+ expect(screen.getByText(/no longer on disk/i)).toBeInTheDocument();
+ expect(screen.queryByText(/This display has no WebGL/i)).not.toBeInTheDocument();
+ // The private AvatarErrorBoundary is gone; the shared one logs this.
+ expect(logged).toHaveBeenCalledWith(expect.stringContaining('💥 React Error'), expect.anything());
+ });
+
+ // A WebGL context that dies at RUNTIME (rather than failing the pre-gate) is
+ // still a WebGL problem, and the shared hint table is what says so.
+ it('names a runtime WebGL context failure for what it is', () => {
+ render(
+ <CoSCanvasGuard>
+ <Boom error={new Error('THREE.WebGLRenderer: Error creating WebGL context.')} />
+ </CoSCanvasGuard>,
+ );
+ expect(screen.getByText(/cannot create a WebGL context/i)).toBeInTheDocument();
+ });
+
+ // Nothing in the shared table recognizes this, so the raw message is better
+ // than inventing a cause.
+ it('falls back to the raw message for an unrecognized failure', () => {
+ render(<CoSCanvasGuard><Boom error={new Error('something went sideways')} /></CoSCanvasGuard>);
+ expect(screen.getByText('something went sideways')).toBeInTheDocument();
+ });
+
+ it('lets an explicit caller fallback override both panels', () => {
+ const fallback = <div data-testid="caller-fallback" />;
+ const { rerender } = render(
+ <CoSCanvasGuard fallback={fallback}><Boom error={new Error('boom')} /></CoSCanvasGuard>,
+ );
+ expect(screen.getByTestId('caller-fallback')).toBeInTheDocument();
+
+ webgl.available = false;
+ rerender(<CoSCanvasGuard fallback={fallback}><div /></CoSCanvasGuard>);
+ expect(screen.getByTestId('caller-fallback')).toBeInTheDocument();
+ });
+});
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 175ed5877b..4cf19243f0 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -44,6 +44,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `creativeDirectorPlan.js` | Pure presentation helpers for the CD studio Plan board (CDO Phase 4) — annotate `plan.steps[]` with tool cost-class/timing/approval flags, cost/status summaries, owning-surface deep links, status/cost badge tone maps. |
| `creativeDirectorPreview.js` | `selectProjectPreview(project)` → `{ kind: 'video'\|'image'\|'audio'\|'none', jobId?, src?, poster?, label, durationSec? }` — picks a CD project's representative produced asset (finalVideoId → last rendered scene → last done plan video/image step → `musicBed` audio → startingImageFile) for the list cards + Overview tab (#2702, audio #2772). Pure, computed off the already-returned project payload (no fetch). Plus `previewAspectClass(aspectRatio)` (literal Tailwind classes — a computed `aspect-[w/h]` never lands in the build), `startingImageSrc()` (client mirror of `localImageFilename`), and the `videoSrcForJob`/`videoPosterForJob`/`imageSrcForJob`/`musicBedSrc` path builders — the one client-side definition of the `<jobId>`-named asset convention, shared with `ScenePreview.jsx`. |
| `editorialRoadmap.js` | `projectAnalyzedPoints` (aggregate roadmap → analyzed chart points with arc-position `frac`) + `dominant` (most-frequent string). Shared by EditorialRoadmapPanel and the Reader Map page. |
+| `glbFailure.js` | Turns a 3D asset failure into an actionable sentence. `glbFailureHint(error)` matches the message against a shared table (an HTML body reaching the glTF parser, a WebGL context failure, a 404) and returns `null` when nothing recognizes it — so a caller can tell "we know the cause" from "we don't" and fall back to the raw text. `glbErrorText(error)` reads a message off whatever shape was thrown. Shared because the CoS avatars load remote GLBs too: every caught error there used to be reported as "this display has no WebGL", sending the user to change an unrelated setting (#4688). Consumed by `media/GlbViewer.jsx` and `cos/CoSCanvasGuard.jsx`. |
| `grokVideoClip.js` | Mirror of `server/lib/grokVideoClip.js` — `GROK_VIDEO_DURATIONS` (`[6, 10]`) + `GROK_VIDEO_DEFAULT_DURATION`, the clip lengths grok's `image_to_video` actually delivers. |
| `imageCleaners.js` | Mirror of `resolveCleanersFromConfig` from `server/lib/imageClean.js`. Reads `{cleanC2PA, denoise}` off a per-mode settings record. `cleanC2PA` defaults are mode-aware (on for `codex` + `external` — the backends that emit C2PA chunks today — off otherwise, as an allow-list rather than a deny-list); `denoise` defaults off everywhere (lossy, opt-in only). |
| `reviewerModels.js` | `reviewerModelsFromDefaults` / `reviewerModelsToDefaults` / `reviewerEffortsFromDefaults` / `reviewerEffortsToDefaults` — adapt the Code Review Defaults' per-reviewer SCALARS (`codexModel`, `ollamaModel`, `claudeEffort`, …) to and from the token-keyed maps `ReviewerPicker`'s Model and Effort columns take. Mirrors `reviewerModelsFromDefaults` / `reviewerEffortsFromDefaults` in `server/lib/cosValidation.js`. |
diff --git a/client/src/lib/glbFailure.js b/client/src/lib/glbFailure.js
new file mode 100644
index 0000000000..e5a3132cf8
--- /dev/null
+++ b/client/src/lib/glbFailure.js
@@ -0,0 +1,33 @@
+/**
+ * Turning a 3D asset failure into something a person can act on.
+ *
+ * The raw messages are useless on their own: the glTF parser JSON.parses
+ * whatever bytes it is handed, so a 200 HTML body (an SPA fallback answering a
+ * path that isn't really served) surfaces as a JSON syntax error naming a `<`
+ * token. Shared rather than private to the GLB viewer because the CoS avatars
+ * load remote GLBs too, and a model 404 there used to be reported as "this
+ * display has no WebGL" — sending the user to change an unrelated setting.
+ */
+
+// One table so every recognized cause reads the same way everywhere.
+const FAILURE_HINTS = [
+ [
+ /Unexpected token '<'|<!DOCTYPE/i,
+ 'The server answered with a web page instead of the mesh file — the asset may be missing or the server may still be restarting.',
+ ],
+ [/webgl/i, 'This display cannot create a WebGL context, so 3D previews cannot render here.'],
+ [/\b404\b|not found/i, 'The mesh file is no longer on disk.'],
+];
+
+/** The error's message, whatever shape the thrower used. */
+export const glbErrorText = (error) => String(error?.message || error || '');
+
+/**
+ * A sentence naming the cause, or `null` when nothing here recognizes it —
+ * deliberately not a generic catch-all string, so a caller can tell "we know
+ * what went wrong" from "we don't" and render accordingly.
+ */
+export function glbFailureHint(error) {
+ const message = glbErrorText(error);
+ return FAILURE_HINTS.find(([pattern]) => pattern.test(message))?.[1] || null;
+}
diff --git a/client/src/lib/glbFailure.test.js b/client/src/lib/glbFailure.test.js
new file mode 100644
index 0000000000..9720f6a7a5
--- /dev/null
+++ b/client/src/lib/glbFailure.test.js
@@ -0,0 +1,31 @@
+import { describe, expect, it } from 'vitest';
+import { glbErrorText, glbFailureHint } from './glbFailure';
+
+describe('glbFailureHint', () => {
+ // `null` is load-bearing: a caller shows the raw message only when nothing
+ // here recognized the cause, so a generic catch-all string would hide that.
+ it('only names a cause it can actually recognize', () => {
+ expect(glbFailureHint(new Error('something went sideways'))).toBeNull();
+ expect(glbFailureHint(new Error('<!DOCTYPE html>'))).toMatch(/web page/i);
+ expect(glbFailureHint(new Error('responded with 404'))).toMatch(/no longer on disk/i);
+ expect(glbFailureHint(new Error('Error creating WebGL context'))).toMatch(/WebGL/i);
+ });
+
+ // The reported failure shape: a server answering an asset path with the SPA
+ // index, so the glTF parser JSON.parses HTML and blames a `<` token.
+ it('recognizes an HTML body reaching the glTF parser', () => {
+ const error = new Error(
+ "Could not load /data/image-to-3d/abc/model.glb: Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON",
+ );
+ expect(glbFailureHint(error)).toMatch(/web page instead of the mesh file/i);
+ });
+});
+
+describe('glbErrorText', () => {
+ it('reads a message off whatever shape the thrower used', () => {
+ expect(glbErrorText(new Error('boom'))).toBe('boom');
+ expect(glbErrorText('plain string')).toBe('plain string');
+ expect(glbErrorText(null)).toBe('');
+ expect(glbErrorText(undefined)).toBe('');
+ });
+});
diff --git a/client/src/lib/index.js b/client/src/lib/index.js
index e72a125691..8c4989fe24 100644
--- a/client/src/lib/index.js
+++ b/client/src/lib/index.js
@@ -26,6 +26,7 @@ export * from './catalogTypes.js';
export * from './creativeDirectorPlan.js';
export * from './creativeDirectorPreview.js';
export * from './editorialRoadmap.js';
+export * from './glbFailure.js';
export * from './grokVideoClip.js';
export * from './imageCleaners.js';
export * from './imageGenBackends.js';