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 (codex): let both new failure panels recover (#4688)

[._.]/ Adam Eivye6bb6985e22a
diff --git a/client/src/components/cos/CoSCanvasGuard.jsx b/client/src/components/cos/CoSCanvasGuard.jsx
index f0fc13e421..7d263da834 100644
--- a/client/src/components/cos/CoSCanvasGuard.jsx
+++ b/client/src/components/cos/CoSCanvasGuard.jsx
@@ -51,6 +51,7 @@ export default function CoSCanvasGuard({
label = 'Interactive 3D avatar. Drag to rotate.',
background = false,
fallback = null,
+ resetKey = null,
children,
}) {
// Probe once on mount — availability doesn't flip mid-session.
@@ -59,14 +60,21 @@ export default function CoSCanvasGuard({
// 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);
+ //
+ // The failure is stored WITH the `resetKey` it belongs to. Without that it
+ // would stick forever: once the panel is up the boundary is unmounted, so
+ // nothing can ever re-try. A caller whose avatar can change model — the
+ // mini-character wrappers switch `variant`, and with it the GLB URL — passes
+ // that URL as `resetKey` so one variant's dead model can't blank the next.
+ const [failure, setFailure] = useState(null);
+ const error = failure?.key === resetKey ? failure.error : null;
if (!supported) return fallback || <WebGLUnavailableHint background={background} />;
if (error) return fallback || <AvatarAssetFailure background={background} error={error} />;
return (
<CoSAvatarFrame label={label} background={background}>
- <ErrorBoundary fallback={null} onError={setError}>
+ <ErrorBoundary fallback={null} onError={(caught) => setFailure({ key: resetKey, error: caught })}>
{children}
</ErrorBoundary>
</CoSAvatarFrame>
diff --git a/client/src/components/cos/CoSCanvasGuard.test.jsx b/client/src/components/cos/CoSCanvasGuard.test.jsx
index f35655aba0..40ebade4ac 100644
--- a/client/src/components/cos/CoSCanvasGuard.test.jsx
+++ b/client/src/components/cos/CoSCanvasGuard.test.jsx
@@ -66,6 +66,26 @@ describe('CoSCanvasGuard', () => {
expect(screen.getByText('something went sideways')).toBeInTheDocument();
});
+ // Without the resetKey the panel sticks forever: once it is up the boundary
+ // is unmounted, so nothing can retry. The mini-character wrappers switch
+ // `variant` (and with it the GLB URL) on the same guard instance.
+ it('clears a failure when the caller points the guard at another model', () => {
+ const { rerender } = render(
+ <CoSCanvasGuard resetKey="/api/avatar/a.glb">
+ <Boom error={new Error('Could not load /api/avatar/a.glb: 404 Not Found')} />
+ </CoSCanvasGuard>,
+ );
+ expect(screen.getByTestId('cos-avatar-asset-error')).toBeInTheDocument();
+
+ rerender(
+ <CoSCanvasGuard resetKey="/api/avatar/b.glb">
+ <div data-testid="avatar-canvas" />
+ </CoSCanvasGuard>,
+ );
+ expect(screen.queryByTestId('cos-avatar-asset-error')).not.toBeInTheDocument();
+ expect(screen.getByTestId('avatar-canvas')).toBeInTheDocument();
+ });
+
it('lets an explicit caller fallback override both panels', () => {
const fallback = <div data-testid="caller-fallback" />;
const { rerender } = render(
diff --git a/client/src/components/cos/MiniCharacterCoSAvatar.jsx b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
index 8b446c8bb3..99c2e65812 100644
--- a/client/src/components/cos/MiniCharacterCoSAvatar.jsx
+++ b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
@@ -170,6 +170,7 @@ export default function MiniCharacterCoSAvatar({ state, speaking, background = f
label="Mini-character avatar. Drag to rotate."
background={background}
fallback={<MissingModelHint background={background} bundled={bundled} />}
+ resetKey={url}
>
<Canvas
camera={{ position: [0, 0.2, 3.0], fov: 40 }}
diff --git a/client/src/components/threejsModels/ThreejsModelPreview.jsx b/client/src/components/threejsModels/ThreejsModelPreview.jsx
index d78cb1893a..f1c24d102f 100644
--- a/client/src/components/threejsModels/ThreejsModelPreview.jsx
+++ b/client/src/components/threejsModels/ThreejsModelPreview.jsx
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
import { useSearchParams } from 'react-router';
-import { AlertTriangle } from 'lucide-react';
+import { AlertTriangle, RefreshCw } from 'lucide-react';
import { Canvas, useFrame, useThree } from '@react-three/fiber';
import { Bounds, OrbitControls, useBounds } from '@react-three/drei';
import * as THREE from 'three';
@@ -483,7 +483,7 @@ function useClipPlayback({ clip, cuesById, onCue }) {
// a NaN radius or a missing vertex array. Without a boundary that throw escapes
// to the router and blanks the whole page; this is the same inline panel
// GlbViewer shows for a mesh that cannot load, for the same reason.
-function SpecRenderFailure({ error }) {
+function SpecRenderFailure({ error, onRetry }) {
return (
// `.port-media-overlay` (not a hardcoded `bg-black/NN`) because the panel
// floats over a surface whose backdrop is a user-picked colour — a day theme
@@ -500,6 +500,17 @@ function SpecRenderFailure({ error }) {
<p className="max-w-full break-all font-mono text-[10px] leading-snug text-port-text-muted">
{String(error?.message || error || '')}
</p>
+ {/* The boundary catches a lost WebGL context just as readily as a bad
+ spec, and that one can come back — but only a NEW spec clears the
+ panel on its own, so without this the preview is stuck until the model
+ is regenerated. Dropping the failure is what remounts the canvas. */}
+ <button
+ type="button"
+ onClick={onRetry}
+ className="port-media-overlay-item mt-1 inline-flex items-center gap-1.5 rounded-md border border-port-border px-3 py-1.5 text-xs font-medium"
+ >
+ <RefreshCw className="h-3.5 w-3.5" /> Retry
+ </button>
</div>
);
}
@@ -623,7 +634,7 @@ export default function ThreejsModelPreview({ spec, family = null, className = '
style={transparent ? checkerboardStyle : undefined}
>
{specError ? (
- <SpecRenderFailure error={specError} />
+ <SpecRenderFailure error={specError} onRetry={() => setFailure(null)} />
) : (
/* Anything thrown inside an r3f `<Canvas>` is caught by the Canvas and
re-thrown from its OWN render, so with no boundary here the nearest one
diff --git a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
index 63e2ef9def..cdc5de20fd 100644
--- a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
+++ b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
@@ -847,6 +847,20 @@ describe('ThreejsModelPreview spec-render failures', () => {
expect(logged).toHaveBeenCalledWith(expect.stringContaining('💥 React Error'), expect.anything());
});
+ // A lost WebGL context throws the same way a bad spec does, but it can come
+ // back — and the spec signature never changes, so nothing else would clear it.
+ it('recovers from a failure the spec signature can never clear', () => {
+ canvasFailure.error = new Error('THREE.WebGLRenderer: Error creating WebGL context.');
+ renderPreview(<ThreejsModelPreview spec={SPEC} />);
+ expect(screen.getByTestId('threejs-spec-error')).toBeInTheDocument();
+
+ canvasFailure.error = null;
+ fireEvent.click(screen.getByRole('button', { name: /Retry/i }));
+
+ expect(screen.queryByTestId('threejs-spec-error')).not.toBeInTheDocument();
+ expect(screen.getByTestId('threejs-canvas')).toBeInTheDocument();
+ });
+
// The failure is remembered against the spec that produced it, so a
// regeneration is not stuck behind the previous spec's bad geometry.
it('clears the panel when a different spec arrives', () => {