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): dispose landscape GPU resources, guard galaxy texture, real building heights

[._.]/ Adam Eivy5ea9a6766dc9
diff --git a/client/src/components/ErrorBoundary.jsx b/client/src/components/ErrorBoundary.jsx
index defc3d0251..62f0c3cfde 100644
--- a/client/src/components/ErrorBoundary.jsx
+++ b/client/src/components/ErrorBoundary.jsx
@@ -20,6 +20,10 @@ export default class ErrorBoundary extends Component {
render() {
if (this.state.hasError) {
+ // Callers can supply a custom fallback (including `null`) — used to degrade
+ // gracefully inside non-DOM trees like the R3F Canvas, where the default
+ // full-screen DOM error UI can't render.
+ if (this.props.fallback !== undefined) return this.props.fallback;
return (
<div className="min-h-screen bg-port-bg flex items-center justify-center p-4">
<div className="bg-port-card border border-port-border rounded-xl p-8 max-w-md w-full">
diff --git a/client/src/components/city/CityLandscape.jsx b/client/src/components/city/CityLandscape.jsx
index 2dc15e44e0..e171724be2 100644
--- a/client/src/components/city/CityLandscape.jsx
+++ b/client/src/components/city/CityLandscape.jsx
@@ -1,4 +1,4 @@
-import { useMemo } from 'react';
+import { useEffect, useMemo } from 'react';
import * as THREE from 'three';
import { CITY_COLORS, cityDayMix, mixHex, seededRand, smoothstepRange } from './cityConstants';
@@ -75,6 +75,10 @@ function TerrainPlane({ dayMix }) {
depthWrite: true,
}), [dayMix]);
+ // R3F doesn't dispose a material handed in via the `material` prop, so free the
+ // prior one when dayMix flips (Day/Night toggle) and on unmount.
+ useEffect(() => () => material.dispose(), [material]);
+
return (
<mesh
rotation={[-Math.PI / 2, 0, 0]}
@@ -111,6 +115,10 @@ function Mountain({ mountain, dayMix }) {
return geom;
}, [dayMix, mountain.height, mountain.light, mountain.radius, mountain.sides, mountain.snow]);
+ // Attached via <primitive object={geometry}>, which R3F never auto-disposes —
+ // free the prior cone when dayMix rebuilds it, and on unmount.
+ useEffect(() => () => geometry.dispose(), [geometry]);
+
return (
<group position={mountain.position} rotation={[0, mountain.rotation, 0]} scale={mountain.scale}>
<mesh position={[0, mountain.height / 2 - 0.08, 0]}>
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index 2e430190e2..084ec695a4 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -44,6 +44,7 @@ import PlayerController from './PlayerController';
import CameraTransition from './CameraTransition';
import CityPhotoCamera from './CityPhotoCamera';
import { cityDayMix } from './cityConstants';
+import ErrorBoundary from '../ErrorBoundary';
export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, activityCalendar, goals, character, chronotype, memoryGraph, inboxDepth, jiraTickets, photoMode, photoPresetId, onPhotoCaptureReady, settings, playSfx, keysRef, dimmedAppIds, background }) {
const [positions, setPositions] = useState(null);
@@ -106,12 +107,15 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
{showGradientBackground && <color attach="background" args={[background || '#030308']} />}
{/* Mount the galaxy dome only at night — keeps its 2.8MB texture from being
fetched/decoded in full daylight, where it's fully faded out anyway.
- Wrapped in Suspense so the useLoader texture fetch can't suspend the
- whole canvas tree while it streams in. */}
+ Suspense keeps the useLoader fetch from suspending the whole canvas while
+ it streams in; the error boundary degrades to the plain dark sky if the
+ texture is missing/corrupt (e.g. a partial checkout) instead of crashing. */}
{!showGradientBackground && (
- <Suspense fallback={null}>
- <CityGalaxySky settings={settings} />
- </Suspense>
+ <ErrorBoundary fallback={null}>
+ <Suspense fallback={null}>
+ <CityGalaxySky settings={settings} />
+ </Suspense>
+ </ErrorBoundary>
)}
<CitySky settings={settings} />
<CityClouds settings={settings} />
diff --git a/client/src/components/city/cityLayout.js b/client/src/components/city/cityLayout.js
index 2195673643..a4e3e994ed 100644
--- a/client/src/components/city/cityLayout.js
+++ b/client/src/components/city/cityLayout.js
@@ -1,4 +1,4 @@
-import { BUILDING_PARAMS, DISTRICT_PARAMS } from './cityConstants';
+import { BUILDING_PARAMS, DISTRICT_PARAMS, getBuildingHeight } from './cityConstants';
import { autoColumns, gridIndexToPosition } from '../../utils/cityDistrictLayout';
const STATUS_ORDER = { online: 0, stopped: 1, not_started: 2, not_found: 3 };
@@ -27,7 +27,7 @@ export const computeCityLayout = (apps) => {
active.forEach((app, i) => {
const [x, , z] = gridIndexToPosition(i, { columns: activeCols, spacing, rowCount: activeRows });
- positions.set(app.id, { x, z, district: 'downtown' });
+ positions.set(app.id, { x, z, district: 'downtown', height: getBuildingHeight(app) });
});
// Warehouse district (archived apps): X-centered grid offset along +Z from downtown.
@@ -41,7 +41,7 @@ export const computeCityLayout = (apps) => {
spacing,
base: [0, 0, warehouseZ],
});
- positions.set(app.id, { x, z, district: 'warehouse' });
+ positions.set(app.id, { x, z, district: 'warehouse', height: getBuildingHeight(app) });
});
}
diff --git a/client/src/components/city/cityLayout.test.js b/client/src/components/city/cityLayout.test.js
index fd55d4ba81..5ae8050278 100644
--- a/client/src/components/city/cityLayout.test.js
+++ b/client/src/components/city/cityLayout.test.js
@@ -8,15 +8,19 @@ describe('computeCityLayout', () => {
it('lays active apps in a square grid centered on the origin', () => {
const pos = computeCityLayout([online('a'), online('b'), online('c'), online('d')]);
// 4 apps → 2 cols, 2 rows; X & Z both centered at offset (2-1)*12/2 = 6
- expect(pos.get('a')).toEqual({ x: -6, z: -6, district: 'downtown' });
- expect(pos.get('b')).toEqual({ x: 6, z: -6, district: 'downtown' });
- expect(pos.get('c')).toEqual({ x: -6, z: 6, district: 'downtown' });
- expect(pos.get('d')).toEqual({ x: 6, z: 6, district: 'downtown' });
+ expect(pos.get('a')).toMatchObject({ x: -6, z: -6, district: 'downtown' });
+ expect(pos.get('b')).toMatchObject({ x: 6, z: -6, district: 'downtown' });
+ expect(pos.get('c')).toMatchObject({ x: -6, z: 6, district: 'downtown' });
+ expect(pos.get('d')).toMatchObject({ x: 6, z: 6, district: 'downtown' });
+ // Each entry also carries a numeric building height (consumed by the
+ // PlayerController proximity check); positions are no longer height-blind.
+ expect(typeof pos.get('a').height).toBe('number');
+ expect(pos.get('a').height).toBeGreaterThan(0);
});
it('places a single active app at the origin', () => {
const pos = computeCityLayout([online('solo')]);
- expect(pos.get('solo')).toEqual({ x: 0, z: 0, district: 'downtown' });
+ expect(pos.get('solo')).toMatchObject({ x: 0, z: 0, district: 'downtown' });
});
it('offsets archived apps into a warehouse grid along +Z', () => {
@@ -26,9 +30,9 @@ describe('computeCityLayout', () => {
{ id: 'y', overallStatus: 'online', archived: true },
]);
// 1 active → activeRows 1 → warehouseZ = 1*12/2 + 4 = 10; 2 archived → 2 cols, X offset 6
- expect(pos.get('a')).toEqual({ x: 0, z: 0, district: 'downtown' });
- expect(pos.get('x')).toEqual({ x: -6, z: 10, district: 'warehouse' });
- expect(pos.get('y')).toEqual({ x: 6, z: 10, district: 'warehouse' });
+ expect(pos.get('a')).toMatchObject({ x: 0, z: 0, district: 'downtown' });
+ expect(pos.get('x')).toMatchObject({ x: -6, z: 10, district: 'warehouse' });
+ expect(pos.get('y')).toMatchObject({ x: 6, z: 10, district: 'warehouse' });
});
it('sorts active apps online-first so status drives grid order', () => {
@@ -37,7 +41,7 @@ describe('computeCityLayout', () => {
{ id: 'live', overallStatus: 'online', archived: false },
]);
// online sorts to index 0 (col 0), stopped to index 1 (col 1); 2 cols, 1 row, X offset 6
- expect(pos.get('live')).toEqual({ x: -6, z: 0, district: 'downtown' });
- expect(pos.get('stopped')).toEqual({ x: 6, z: 0, district: 'downtown' });
+ expect(pos.get('live')).toMatchObject({ x: -6, z: 0, district: 'downtown' });
+ expect(pos.get('stopped')).toMatchObject({ x: 6, z: 0, district: 'downtown' });
});
});
diff --git a/client/src/components/city/cityTheme.test.js b/client/src/components/city/cityTheme.test.js
index 49b1d40084..95e2be97bd 100644
--- a/client/src/components/city/cityTheme.test.js
+++ b/client/src/components/city/cityTheme.test.js
@@ -1,5 +1,5 @@
-import { describe, it, expect, beforeEach } from 'vitest';
-import { deriveCityPalette, applyCityBrandColors, resolveCityTimeOfDay, cityLabelColors, tintTowardAccent, tintStructure, CITY_COLORS, getBuildingColor } from './cityConstants';
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { deriveCityPalette, applyCityBrandColors, resolveCityTimeOfDay, cityLabelColors, tintTowardAccent, tintStructure, CITY_COLORS, getBuildingColor, seededRand, smoothstepRange, cityDayMix } from './cityConstants';
const hexLum = (hex) => {
const n = parseInt(hex.slice(1), 16);
@@ -206,3 +206,64 @@ describe('applyCityBrandColors', () => {
expect(CITY_COLORS.ground).toBe('#3b82f6');
});
});
+
+describe('seededRand', () => {
+ it('is deterministic for a given seed', () => {
+ const a = seededRand(42);
+ const b = seededRand(42);
+ const seqA = [a(), a(), a(), a(), a()];
+ const seqB = [b(), b(), b(), b(), b()];
+ expect(seqA).toEqual(seqB);
+ });
+
+ it('produces different streams for different seeds', () => {
+ const a = seededRand(42);
+ const b = seededRand(137);
+ expect(a()).not.toBe(b());
+ });
+
+ it('yields values in [0, 1)', () => {
+ const r = seededRand(3187);
+ for (let i = 0; i < 100; i++) {
+ const v = r();
+ expect(v).toBeGreaterThanOrEqual(0);
+ expect(v).toBeLessThan(1);
+ }
+ });
+
+ it('matches the original inline LCG it replaced', () => {
+ // Reference: the exact expression copy-pasted across the city components.
+ let s = 77;
+ const ref = () => { s = (s * 16807) % 2147483647; return (s & 0x7fffffff) / 2147483647; };
+ const r = seededRand(77);
+ expect([r(), r(), r()]).toEqual([ref(), ref(), ref()]);
+ });
+});
+
+describe('smoothstepRange', () => {
+ it('clamps below edge0 to 0 and above edge1 to 1', () => {
+ expect(smoothstepRange(0.35, 1, 0.2)).toBe(0);
+ expect(smoothstepRange(0.35, 1, 1)).toBe(1);
+ expect(smoothstepRange(0.35, 1, 2)).toBe(1);
+ });
+
+ it('returns the Hermite midpoint at the center', () => {
+ expect(smoothstepRange(0, 1, 0.5)).toBeCloseTo(0.5, 10);
+ });
+
+ it('guards against a zero-width range', () => {
+ expect(smoothstepRange(0.5, 0.5, 0.4)).toBe(0);
+ expect(smoothstepRange(0.5, 0.5, 0.6)).toBe(1);
+ });
+});
+
+describe('cityDayMix', () => {
+ it('is 1 in full daylight and 0 at night', () => {
+ expect(cityDayMix({ timeOfDay: 'noon' })).toBe(1);
+ expect(cityDayMix({ timeOfDay: 'sunset' })).toBe(0);
+ });
+
+ it('defaults to the night preset when unset', () => {
+ expect(cityDayMix(undefined)).toBe(0);
+ });
+});