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): drop the caller fallback that misreported both causes (#4688)

[._.]/ Adam Eivyec7616e7d30e
diff --git a/client/src/components/cos/CoSCanvasGuard.jsx b/client/src/components/cos/CoSCanvasGuard.jsx
index f43f098619..671bbe49ea 100644
--- a/client/src/components/cos/CoSCanvasGuard.jsx
+++ b/client/src/components/cos/CoSCanvasGuard.jsx
@@ -16,12 +16,12 @@ import CoSAvatarFrame from './CoSAvatarFrame';
* is a real pre-gate and keeps the WebGL hint; anything thrown afterwards is an
* asset failure and says so.
*
- * `fallback` overrides the PRE-GATE only. A caught error deliberately outranks
- * it: the GLB-loading callers already probe for a missing model with a HEAD
- * request and render their own "no model, run setup" hint before mounting this
- * guard at all, so a failure that reaches HERE means the file answered and then
- * failed — a different cause, which that hint would misreport (it is what sent
- * a user chasing `npm run setup:data` for a server returning HTML).
+ * Both panels are the guard's own, with no caller override. The GLB-loading
+ * callers used to pass their "no model — run setup" hint as a `fallback`, but
+ * they reach this guard ONLY after a HEAD request proved the model is there, so
+ * that hint was wrong on both branches: it hid the asset-failure message for a
+ * server answering with HTML, and it told a user with no WebGL to go run
+ * `npm run setup:data`. Misdirecting the user is the bug #4688 is about.
*/
const panelClass = (background) =>
@@ -57,7 +57,6 @@ function AvatarAssetFailure({ background = false, error }) {
export default function CoSCanvasGuard({
label = 'Interactive 3D avatar. Drag to rotate.',
background = false,
- fallback = null,
resetKey = null,
children,
}) {
@@ -65,8 +64,7 @@ export default function CoSCanvasGuard({
const [supported] = useState(() => isWebGLAvailable());
// 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.
+ // `fallback={null}` and hands the error up here via `onError`.
//
// 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
@@ -76,7 +74,7 @@ export default function CoSCanvasGuard({
const [failure, setFailure] = useState(null);
const error = failure?.key === resetKey ? failure.error : null;
- if (!supported) return fallback || <WebGLUnavailableHint background={background} />;
+ if (!supported) return <WebGLUnavailableHint background={background} />;
if (error) return <AvatarAssetFailure background={background} error={error} />;
return (
diff --git a/client/src/components/cos/CoSCanvasGuard.test.jsx b/client/src/components/cos/CoSCanvasGuard.test.jsx
index c85dd29868..159ef498d4 100644
--- a/client/src/components/cos/CoSCanvasGuard.test.jsx
+++ b/client/src/components/cos/CoSCanvasGuard.test.jsx
@@ -89,30 +89,13 @@ describe('CoSCanvasGuard', () => {
expect(screen.getByTestId('avatar-canvas')).toBeInTheDocument();
});
- it('lets an explicit caller fallback override the WebGL pre-gate', () => {
- // `supported` comes from a `useState` INITIALIZER, which runs once at mount —
- // flipping the mock and rerendering would silently exercise some other
- // branch, so this needs a fresh mount.
+ // Both panels are the guard's own. The GLB-loading callers used to pass a
+ // "no model — run setup" hint here, but they only reach the guard after a HEAD
+ // request proved the model IS there, so that hint was wrong on both branches.
+ it('owns both panels, with no caller override', () => {
+ cleanup();
webgl.available = false;
- render(<CoSCanvasGuard fallback={<div data-testid="caller-fallback" />}><div /></CoSCanvasGuard>);
- expect(screen.getByTestId('caller-fallback')).toBeInTheDocument();
- expect(screen.queryByText(/This display has no WebGL/i)).not.toBeInTheDocument();
- });
-
- // ...but NOT an asset failure. The GLB-loading callers pass a "no model, run
- // setup" hint as their fallback, and they already probe for a missing model
- // with a HEAD request before mounting the guard — so a failure reaching here
- // means the file answered and then failed, which that hint misreports. This
- // is the exact path #4688 describes: the server hands back the SPA index, the
- // parser chokes on `<`, and the user gets sent to run setup for nothing.
- it('shows the asset failure even when the caller supplied a fallback', () => {
- render(
- <CoSCanvasGuard fallback={<div data-testid="caller-fallback" />}>
- <Boom error={new Error("Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON")} />
- </CoSCanvasGuard>,
- );
- expect(screen.getByTestId('cos-avatar-asset-error')).toBeInTheDocument();
- expect(screen.getByText(/web page instead of the mesh file/i)).toBeInTheDocument();
- expect(screen.queryByTestId('caller-fallback')).not.toBeInTheDocument();
+ render(<CoSCanvasGuard><div /></CoSCanvasGuard>);
+ expect(screen.getByText(/This display has no WebGL/i)).toBeInTheDocument();
});
});
diff --git a/client/src/components/cos/MiniCharacterCoSAvatar.jsx b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
index 99c2e65812..c9ea032a81 100644
--- a/client/src/components/cos/MiniCharacterCoSAvatar.jsx
+++ b/client/src/components/cos/MiniCharacterCoSAvatar.jsx
@@ -169,7 +169,6 @@ export default function MiniCharacterCoSAvatar({ state, speaking, background = f
<CoSCanvasGuard
label="Mini-character avatar. Drag to rotate."
background={background}
- fallback={<MissingModelHint background={background} bundled={bundled} />}
resetKey={url}
>
<Canvas
diff --git a/client/src/components/cos/MuseCoSAvatar.jsx b/client/src/components/cos/MuseCoSAvatar.jsx
index 7e0314c497..9889cf1199 100644
--- a/client/src/components/cos/MuseCoSAvatar.jsx
+++ b/client/src/components/cos/MuseCoSAvatar.jsx
@@ -305,7 +305,6 @@ export default function MuseCoSAvatar({ state, speaking, background = false }) {
<CoSCanvasGuard
label="Muse 3D avatar. Drag to rotate."
background={background}
- fallback={<MissingModelHint background={background} />}
>
<Canvas
camera={{ position: [0, 0, 3.3], fov: 45 }}
diff --git a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
index 7f669644af..02ff8faab1 100644
--- a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
+++ b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
@@ -853,6 +853,19 @@ describe('ThreejsModelPreview spec-render failures', () => {
expect(screen.queryByText(/Drag to orbit/)).not.toBeInTheDocument();
});
+ // The selected-part badge is the third piece of chrome gated on the failure,
+ // and it only mounts with a part in the URL — so the case above never reaches
+ // it. Same defect either way: it is a DOM peer that follows the panel, so it
+ // paints over the message and its Clear button drives an unmounted canvas.
+ it('hides the selected-part badge behind the failure too', () => {
+ canvasFailure.error = new Error('bad geometry');
+ renderPreview(<ThreejsModelPreview spec={knifeSpec()} />, '/?part=handle');
+
+ expect(screen.getByTestId('threejs-spec-error')).toBeInTheDocument();
+ expect(screen.queryByText('Handle')).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Clear part selection' })).not.toBeInTheDocument();
+ });
+
// 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', () => {
diff --git a/docs/PORTS.md b/docs/PORTS.md
index 677099d090..a6fe0eddc2 100644
--- a/docs/PORTS.md
+++ b/docs/PORTS.md
@@ -57,7 +57,7 @@ Rules of thumb:
- **A server-owned path must never be answered by an SPA fallback — and there are two of them.** Neither 404s. In dev, Vite answers an unproxied path with `index.html` and a `200`; in production the fallback in `server/index.js` skips a request only when its path carries a file extension, so an EXTENSIONLESS one falls through the same way. Either shape hands a binary loader HTML, which fails far from the cause (a missing `/data/image-to-3d` proxy entry surfaced as `Unexpected token '<' … is not valid JSON` from the GLB viewer, which took its whole route down), or hands an API client HTML with a success status.
- **Dev side:** `/data` is proxied as one wildcard prefix, so a new mount is covered the moment it is added.
- **Production side:** `server/lib/assetRoutePrefixes.js` lists the namespaces the server owns (`SERVER_OWNED_PREFIXES`) alongside the exact client routes inside them (`spaPaths` — `/data` itself is the Data Manager page), and `mountAssetRoutes` closes each one with a terminating 404 (#4688).
- - `scripts/dev-proxy-drift.test.js` fails if the proxy, the mounts, or the client's own routes (`NAV_COMMANDS`) drift apart — including when a new client page is added *under* a server-owned prefix, which the terminator would otherwise 404 silently.
+ - `scripts/dev-proxy-drift.test.js` fails if the proxy, the mounts, and the client's own routes drift apart. It reads both `NAV_COMMANDS` and `App.jsx`'s nested `<Route>` tree, so a new page under a server-owned prefix — which the terminator would otherwise 404 silently — fails the build even when only its `:id` detail route exists.
## Defining Ports in ecosystem.config.cjs
diff --git a/scripts/dev-proxy-drift.test.js b/scripts/dev-proxy-drift.test.js
index bd7f6778f7..bbac784325 100644
--- a/scripts/dev-proxy-drift.test.js
+++ b/scripts/dev-proxy-drift.test.js
@@ -63,17 +63,37 @@ const proxyMatches = (context, url) =>
const navPaths = NAV_COMMANDS.map((command) => command.path);
/**
- * Every path the client router declares.
+ * Every path the client router declares, with nesting resolved.
*
* NOT just `NAV_COMMANDS`: `client/src/CLAUDE.md` requires a selectable view to
* register only its BASE path in the nav manifest while its `:id` detail route
* lives in `App.jsx` alone. A convention-following `<Route path="data/:category">`
* would therefore be invisible to a nav-manifest-only check — and the terminator
* would 404 it in production with nothing failing near the new route.
+ *
+ * Nesting has to be resolved rather than read off each tag, because App.jsx
+ * nests (`<Route path="media"><Route path="image" …/></Route>` is `/media/image`).
+ * A depth-tracking scan is enough here and keeps the guard dependency-free — a
+ * real JSX parse would mean pulling a parser into the server test runner, whose
+ * CI job installs only the server's dependencies.
*/
function clientRoutePaths(source) {
- return [...source.matchAll(/<Route\s+path="([^"]+)"/g)]
- .map(([, path]) => (path.startsWith('/') ? path : `/${path}`));
+ const paths = [];
+ const stack = [];
+ const TAG = /<Route\b([^>]*?)(\/?)>|<\/Route>/g;
+ for (const [tag, attrs, selfClosing] of source.matchAll(TAG)) {
+ if (tag === '</Route>') { stack.pop(); continue; }
+ const path = attrs.match(/\bpath="([^"]*)"/)?.[1] ?? null;
+ // An index route (no `path`) resolves to its parent, and a layout route
+ // with no path adds no segment — both are represented by a null frame.
+ const segments = [...stack, path].filter((segment) => segment);
+ if (path !== null) {
+ const joined = segments.join('/').replace(/\/+/g, '/');
+ paths.push(joined.startsWith('/') ? joined : `/${joined}`);
+ }
+ if (!selfClosing) stack.push(path);
+ }
+ return paths;
}
describe('vite dev proxy vs the server and the client router', () => {
@@ -155,7 +175,11 @@ describe('server/index.js route registration order', () => {
it('registers every API router above the terminators', () => {
const mountIndex = source.indexOf('mountAssetRoutes(app)');
expect(mountIndex).toBeGreaterThan(0);
- const shadowed = [...source.matchAll(/app\.use\(\s*'(\/(?:api|sdapi)[^']*)'/g)]
+ const apiMounts = [...source.matchAll(/app\.use\(\s*'(\/(?:api|sdapi)[^']*)'/g)];
+ // A refactor to non-literal mounts would leave the regex matching nothing
+ // and the assertion below vacuously true.
+ expect(apiMounts.length).toBeGreaterThan(20);
+ const shadowed = apiMounts
.filter((match) => match.index > mountIndex)
.map(([, route]) => route);
expect(shadowed).toEqual([]);
diff --git a/server/lib/README.md b/server/lib/README.md
index b447a3d24c..3295d850ea 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -362,7 +362,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `apiRegistry.js` | Single source of truth for which PortOS services are externally-callable HTTP APIs (`voice`, `sdapi`). `API_REGISTRY` declares each API's `publicPrefixes` (read/compute-safe surface only) + defaults; `isRegistryPublic(settings, path)` tells `authGate` when an `exposed && !requireAuth` API re-opens its prefix; `resolveApiAccess(settings)` merges persisted `apiAccess` flags for the Settings UI + OpenAPI docs. |
| `arrayUtils.js` | `shuffle(arr)` — Fisher-Yates shuffle (new array, never mutates). The canonical uniform shuffle — never `arr.sort(() => Math.random() - 0.5)`, which is biased. Shared by `meatspacePostCognitive.js` (Schulte table / mental rotation) and `meatspacePostMemory.js` (memory drill generators). |
| `assetMounts.js` | `ASSET_MOUNTS` — every `/data/**` static mount as `{ route, dir, gate? }` (`dir` a thunk so a test that re-roots `PATHS.data` still steers it) — plus `mountAssetRoutes(app)`, which mounts them and then TERMINATES each `SERVER_OWNED_PREFIXES` namespace with a 404. The terminator matters: the SPA fallback only skips paths carrying a file extension, so an extensionless `/data/…` or a mistyped `/api/…` used to be answered with index.html and a 200 — a binary loader parsed HTML, an API client got HTML with a success status (#4688). |
-| `assetRoutePrefixes.js` | Import-free leaf holding the URL prefixes the server owns: `ASSET_ROUTE_PREFIXES` (every `/data/**` static mount) and `SERVER_OWNED_PREFIXES` (what must never reach the SPA fallback, each with the exact `spaPaths` that ARE client routes). `scripts/dev-proxy-drift.test.js` checks the dev proxy's `^/data/` wildcard against the mounts, and fails if a `NAV_COMMANDS` route is ever added under a server-owned prefix without being declared. |
+| `assetRoutePrefixes.js` | Import-free leaf holding the URL prefixes the server owns: `ASSET_ROUTE_PREFIXES` (every `/data/**` static mount) and `SERVER_OWNED_PREFIXES` (what must never reach the SPA fallback, each with the exact `spaPaths` that ARE client routes). `scripts/dev-proxy-drift.test.js` checks the dev proxy's `^/data/` wildcard against the mounts, pins the route-registration order in `server/index.js` (a router added below the terminators is shadowed), and fails if a client route — from `NAV_COMMANDS` or `App.jsx`'s nested `<Route>` tree — is ever added under a server-owned prefix without being declared. |
| `asyncMutex.js` | Promise-based async mutex. |
| `authGate.js` | Express + Socket.IO middleware that gates `/api/*` and `/data/*` behind the password set in `settings.secrets.auth`. No-op when auth is off; emits 401 `AUTH_REQUIRED` (or plain text for `/data/*`) when on and the request has no valid session token. Consults `apiRegistry.isRegistryPublic` so an exposed+passwordless API (voice/sdapi) bypasses the gate on its public prefix only. |
| `concurrencyGate.js` | `createConcurrencyGate(limit)` → `run(fn)` — cap on simultaneous async work for ONE module-scoped budget, released FIFO. Sibling to `mapWithConcurrency.js`, which caps in-flight work *within one array map*; a gate is shared state, so several call sites fanning out at the same remote respect one budget instead of each respecting its own while the host sees the sum. `createMutex` (`asyncMutex.js`) is this with `limit` fixed at 1 — prefer it for mutual exclusion. Note the budget is per-MODULE, not per-host: two modules calling one host each get their own gate. Used by `huggingFaceCatalog.js` (4) and `ollamaRegistryCatalog.js` (16), whose cold catalog-enrichment bursts otherwise arrive at a free public API as a thundering herd — which the Hub answers with an HTTP/2 GOAWAY that surfaces as a bare `fetch failed`. |
diff --git a/server/lib/assetRoutePrefixes.js b/server/lib/assetRoutePrefixes.js
index 148da133e8..acc04ac1a6 100644
--- a/server/lib/assetRoutePrefixes.js
+++ b/server/lib/assetRoutePrefixes.js
@@ -49,8 +49,9 @@ export const ASSET_ROUTE_PREFIXES = [
* must still reach the SPA — `/data` itself is the Data Manager page. Exact
* paths only, not prefixes: `nav.data` has no children (`/devtools/datadog` is
* a sibling, not a child), and `scripts/dev-proxy-drift.test.js` fails if a
- * NAV_COMMANDS route is ever added under one of these prefixes without being
- * listed here.
+ * client route is ever added under one of these prefixes without being listed
+ * here — reading both `NAV_COMMANDS` and `App.jsx`'s own nested `<Route>` tree,
+ * since a `:id` detail route is only ever declared in the latter.
*/
export const SERVER_OWNED_PREFIXES = [
{ prefix: '/data', spaPaths: ['/data'] },