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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review round 3 (codex): normalize mirror timestamp to a PG-valid value
Adam Eivyd625452d8355
diff --git a/server/services/creativeDirector/projectsLogic.js b/server/services/creativeDirector/projectsLogic.jsindex 60bfe344ca..f11d5a2ce8 100644--- a/server/services/creativeDirector/projectsLogic.js+++ b/server/services/creativeDirector/projectsLogic.js@@ -65,9 +65,22 @@ export function mirrorStatus(status) {return (typeof status === 'string' && status ? status : 'draft').slice(0, STATUS_COLUMN_MAX);}-/** Safe ISO timestamp for a TIMESTAMPTZ mirror column, falling back to `now`. */+/**+ * Safe ISO timestamp for a TIMESTAMPTZ mirror column, falling back to `fallback`.+ *+ * Returns the NORMALIZED canonical ISO string (`Date#toISOString`), not the raw+ * input — because `Date.parse` accepts out-of-range calendar dates by rolling+ * them over (`2026-02-31` → Mar 3), and echoing that raw string would still+ * make Postgres reject the TIMESTAMPTZ bind and throw. Normalizing guarantees a+ * value PG always accepts. The raw original is still preserved verbatim in the+ * JSONB `data` (callers stringify the full record separately), so this only+ * affects the queryable mirror column.+ */export function mirrorTimestamp(value, fallback) {- if (typeof value === 'string' && !Number.isNaN(Date.parse(value))) return value;+ if (typeof value === 'string') {+ const ms = Date.parse(value);+ if (!Number.isNaN(ms)) return new Date(ms).toISOString();+ }return fallback;}diff --git a/server/services/creativeDirector/projectsLogic.test.js b/server/services/creativeDirector/projectsLogic.test.jsindex 10c24ac970..c16a4b1ddc 100644--- a/server/services/creativeDirector/projectsLogic.test.js+++ b/server/services/creativeDirector/projectsLogic.test.js@@ -122,8 +122,12 @@ describe('mirrorStatus / mirrorTimestamp (typed-column safety)', () => {expect(mirrorStatus(null)).toBe('draft');expect(mirrorStatus(undefined)).toBe('draft');});- it('mirrorTimestamp passes valid ISO through and falls back otherwise', () => {+ it('mirrorTimestamp returns a NORMALIZED ISO string and falls back otherwise', () => {expect(mirrorTimestamp('2026-01-01T00:00:00.000Z', 'fb')).toBe('2026-01-01T00:00:00.000Z');+ // Out-of-range calendar date: Date.parse rolls it over (Feb 31 → Mar 3).+ // The mirror column must get the NORMALIZED value PG accepts, not the raw+ // string PG would reject — otherwise the INSERT throws and blocks boot.+ expect(mirrorTimestamp('2026-02-31T00:00:00.000Z', 'fb')).toBe('2026-03-03T00:00:00.000Z');expect(mirrorTimestamp('not-a-date', 'fb')).toBe('fb');expect(mirrorTimestamp(12345, 'fb')).toBe('fb');expect(mirrorTimestamp(null, 'fb')).toBe('fb');