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

fix(cos): stop the 3D avatar zooming in on degenerate canvas measurements

Adam Eivyd7353964b486
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index e846d129f3..a04e44ec54 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -95,6 +95,8 @@
## Fixed
+- **The Chief of Staff 3D avatar no longer slowly zooms itself in until you reload.** The full-bleed background avatar keeps a constant apparent size by moving the camera back as the panel grows (`CoSBackgroundCamera` derives `camera.position.z` from the live-measured canvas height). But a transient *zero / pre-layout / hidden* size reading — which fires when the agent panel collapses and re-expands, when the EventLog mounts on the "working on task" transition, or from tab-occlusion ResizeObserver frames — collapsed the scale factor to its floor and slammed the camera to its closest (most zoomed-in) position, which `OrbitControls` then latched with no guaranteed correction. Over a busy night of state transitions the avatar ended up "zoomed way in," fixable only by a page reload. The camera-distance math is now a pure, unit-tested helper that returns `null` for any degenerate (non-finite or sub-pixel) measurement, so those frames leave the camera at its last good framing instead of yanking it in. (`client/src/components/cos/CoSBackgroundCamera.jsx`)
+
- **[issue-1361] A behind/legacy sync peer can no longer erase a series' style guide, reader map, ticking clock, style notes, or seasons.** `mergeSeriesFromSync` applied an incoming series payload wholesale via last-writer-wins on `updatedAt`, and `sanitizeSeries` flattens an *absent* key to the same `null`/`[]`/`""` as an explicit clear. So when a peer that never authored a field (an older install, or one that predates the field) pushed a series with a newer `updatedAt` but no `styleGuide`/`arc`/`styleNotes`/`seasons` key — or sent `arc` without its newer `readerMap`/`tickingClock` sub-keys — the receiver overwrote and wiped the locally-authored value. The merge now consults the **raw** remote payload to tell "key absent" from "key present-but-empty": an absent key preserves the local value (mirroring the existing `universeId` hierarchy guard, and applied uniformly across the additive fields plus the additive sub-fields nested in `arc`), while an explicit `null`/empty from an up-to-date peer is still honored as an intentional clear. Tombstones are skipped (a deleted record carries no content to protect). (`server/services/pipeline/series.js`, #1361)
- **[issue-1359] A catalog image you generate now attaches even if you navigate away before it finishes.** When you used the catalog item editor's **Generate** button with a local or Codex image backend, the render is a queued job — and if you refreshed, switched to another item, or left the page before it completed, the finished image still landed in your media library but was never attached to the item, so it silently vanished from that item's Media panel. The attachment is now made server-side the moment the render completes, independent of whether that page is still open: the first image becomes the item's portrait, later ones attach as references — exactly as it would if you'd stayed on the page. (#1359)
diff --git a/client/src/components/cos/CoSBackgroundCamera.jsx b/client/src/components/cos/CoSBackgroundCamera.jsx
index 6ca534e50c..31278c93e3 100644
--- a/client/src/components/cos/CoSBackgroundCamera.jsx
+++ b/client/src/components/cos/CoSBackgroundCamera.jsx
@@ -1,8 +1,31 @@
import { useEffect } from 'react';
import { useThree } from '@react-three/fiber';
-const COMPACT_FRAME_HEIGHT = 128 * 6 / 5;
-const DESKTOP_FRAME_HEIGHT = 192 * 6 / 5;
+export const COMPACT_FRAME_HEIGHT = 128 * 6 / 5;
+export const DESKTOP_FRAME_HEIGHT = 192 * 6 / 5;
+
+// Compute the camera z-distance that keeps the avatar a constant apparent size
+// as the full-bleed background frame grows past the original framed-tile size.
+//
+// Returns `null` when the measured canvas size is degenerate (zero / sub-pixel /
+// pre-layout / hidden). In that case the caller MUST leave the camera where it
+// is. A zero/tiny measurement otherwise collapses distanceScale to its floor of
+// 1 and slams the camera to its closest (base z) position — i.e. zoomed all the
+// way in — which OrbitControls then latches with no guaranteed correction. That
+// was the "CoS avatar zooms way in overnight, reload fixes it" bug: transient
+// 0-height reports (panel collapse/expand, EventLog mounting on the
+// working-on-task transition, tab-occlusion ResizeObserver frames) each yanked
+// the camera in.
+export function computeCameraDistance(size, z) {
+ const width = size?.width;
+ const height = size?.height;
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width < 1 || height < 1) {
+ return null;
+ }
+ const oldFrameHeight = width >= 1024 ? DESKTOP_FRAME_HEIGHT : COMPACT_FRAME_HEIGHT;
+ const distanceScale = Math.max(1, height / oldFrameHeight);
+ return z * distanceScale;
+}
export default function CoSBackgroundCamera({ enabled = false, x = 0, y = 0, z = 3.5 }) {
const { camera, size } = useThree();
@@ -10,12 +33,11 @@ export default function CoSBackgroundCamera({ enabled = false, x = 0, y = 0, z =
useEffect(() => {
if (!enabled) return;
- const oldFrameHeight = size.width >= 1024
- ? DESKTOP_FRAME_HEIGHT
- : COMPACT_FRAME_HEIGHT;
- const distanceScale = Math.max(1, size.height / oldFrameHeight);
+ const distance = computeCameraDistance(size, z);
+ // Degenerate measurement — keep the last good framing instead of zooming in.
+ if (distance == null) return;
- camera.position.set(x, y, z * distanceScale);
+ camera.position.set(x, y, distance);
camera.updateProjectionMatrix();
}, [camera, enabled, size.height, size.width, x, y, z]);
diff --git a/client/src/components/cos/CoSBackgroundCamera.test.js b/client/src/components/cos/CoSBackgroundCamera.test.js
new file mode 100644
index 0000000000..43aa3beaa3
--- /dev/null
+++ b/client/src/components/cos/CoSBackgroundCamera.test.js
@@ -0,0 +1,49 @@
+import { describe, it, expect } from 'vitest';
+import {
+ computeCameraDistance,
+ COMPACT_FRAME_HEIGHT,
+ DESKTOP_FRAME_HEIGHT,
+} from './CoSBackgroundCamera.jsx';
+
+describe('computeCameraDistance', () => {
+ const z = 3.7;
+
+ it('pulls the camera back proportionally on a tall desktop frame', () => {
+ // A 460px-tall background panel on a wide viewport keeps the avatar the
+ // same apparent size as the original ~230px framed tile by moving the
+ // camera ~2x further away.
+ const expected = z * (460 / DESKTOP_FRAME_HEIGHT);
+ expect(computeCameraDistance({ width: 1280, height: 460 }, z)).toBeCloseTo(expected, 5);
+ });
+
+ it('uses the compact reference height below the 1024px breakpoint', () => {
+ const expected = z * (320 / COMPACT_FRAME_HEIGHT);
+ expect(computeCameraDistance({ width: 800, height: 320 }, z)).toBeCloseTo(expected, 5);
+ });
+
+ it('floors the distance at the base z (never zooms in past the framed tile)', () => {
+ // A frame shorter than the reference must NOT pull the camera closer than
+ // the base z, otherwise the avatar would appear zoomed in.
+ expect(computeCameraDistance({ width: 1280, height: 100 }, z)).toBe(z);
+ });
+
+ // Regression: the "avatar zooms way in overnight" bug. A transient zero /
+ // pre-layout / hidden measurement (panel collapse-expand, EventLog mounting
+ // on the working-on-task transition, tab occlusion ResizeObserver reports)
+ // must NOT move the camera. Previously it collapsed distanceScale to the
+ // floor and slammed the camera to its closest (zoomed-in) position, which
+ // OrbitControls then latched with no reliable correction.
+ it('returns null for a zero-height (degenerate) measurement so the camera is left alone', () => {
+ expect(computeCameraDistance({ width: 1280, height: 0 }, z)).toBeNull();
+ });
+
+ it('returns null for a sub-pixel / zero-width measurement', () => {
+ expect(computeCameraDistance({ width: 0, height: 460 }, z)).toBeNull();
+ expect(computeCameraDistance({ width: 1280, height: 0.4 }, z)).toBeNull();
+ });
+
+ it('returns null for non-finite measurements', () => {
+ expect(computeCameraDistance({ width: NaN, height: 460 }, z)).toBeNull();
+ expect(computeCameraDistance({ width: 1280, height: undefined }, z)).toBeNull();
+ });
+});