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

refactor: freeze the shared identity transform constants (#5681)

[._.]/ Adam Eivy70ae3ef67fe3
diff --git a/server/lib/threejsTransform.js b/server/lib/threejsTransform.js
index 68be0019fc..4c13e97d3c 100644
--- a/server/lib/threejsTransform.js
+++ b/server/lib/threejsTransform.js
@@ -19,10 +19,16 @@
/** Degrees to radians. Not input-guarded: callers pass schema-validated angles. */
export const degreesToRadians = (degrees) => (degrees * Math.PI) / 180;
-export const IDENTITY_LINEAR = [1, 0, 0, 0, 1, 0, 0, 0, 1];
+// Frozen: these are shared across every gate in the process, and each one used
+// to be a module-private literal. A stray write would silently move the frame
+// every subsequent walk starts from.
+export const IDENTITY_LINEAR = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
/** Row-major 3x3 linear part plus a translation — an affine transform. */
-export const IDENTITY_TRANSFORM = { linear: [...IDENTITY_LINEAR], translation: [0, 0, 0] };
+export const IDENTITY_TRANSFORM = Object.freeze({
+ linear: IDENTITY_LINEAR,
+ translation: Object.freeze([0, 0, 0]),
+});
// A non-finite angle reads as 0 degrees — see `rotationMatrix`.
const angleCosSin = (degrees) => {
diff --git a/server/lib/threejsTransform.test.js b/server/lib/threejsTransform.test.js
index 4d331221cb..025343bbf6 100644
--- a/server/lib/threejsTransform.test.js
+++ b/server/lib/threejsTransform.test.js
@@ -105,6 +105,10 @@ describe('composeTransform', () => {
it('leaves IDENTITY_TRANSFORM unmutated so every walk starts from the same frame', () => {
composeTransform(IDENTITY_TRANSFORM, { position: [5, 5, 5], scale: [9, 9, 9] });
expect(IDENTITY_TRANSFORM).toEqual({ linear: IDENTITY_LINEAR, translation: [0, 0, 0] });
+ // Frozen rather than merely unwritten: these are process-wide now.
+ expect(Object.isFrozen(IDENTITY_TRANSFORM)).toBe(true);
+ expect(Object.isFrozen(IDENTITY_TRANSFORM.linear)).toBe(true);
+ expect(Object.isFrozen(IDENTITY_TRANSFORM.translation)).toBe(true);
});
});