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
fix([codex5-client-error-reporter]): address codex review iter 1
[._.]/ Adam Eivyd96e2a44290d
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 6ca247fa64..686d2c41f0 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Added-- **[codex5-client-error-reporter] Browser-side errors and unhandled promise rejections surface in Review Hub.** Crashes that used to vanish into the browser console now land as Review Hub alerts so they can be triaged alongside server errors and CoS work. Repeats of the same error inside an hour aggregate into a single entry, and bursty render storms are throttled so the hub stays readable.+- **[codex5-client-error-reporter] Browser-side errors and unhandled promise rejections surface in Review Hub.** Crashes that used to vanish into the browser console now land as Review Hub alerts so they can be triaged alongside server errors and CoS work. Repeats of the same error within a day aggregate into a single entry, and bursty render storms are throttled so the hub stays readable.- **[versioning-diff-view-per-stage-persist-last-n] Pipeline text stages now keep a version history.** Each regenerate snapshots the prior draft (up to five back) and a new "History" button on the Idea / Prose / Comic Script / Teleplay editors opens a side-by-side word diff against the current version with one-click restore.## Changeddiff --git a/client/src/lib/clientErrorReporter.js b/client/src/lib/clientErrorReporter.jsindex d26f569be7..ac29038263 100644--- a/client/src/lib/clientErrorReporter.js+++ b/client/src/lib/clientErrorReporter.js@@ -43,14 +43,30 @@ function pruneRecent(now) {}}+// Guarded stringify so a circular rejection reason or a value that throws+// from its toString() can't itself throw out of the global error handler —+// `reportClientError`'s "never throws" contract is critical because we wire+// it from `unhandledrejection`.+function safeStringify(value) {+ try {+ return JSON.stringify(value);+ } catch {+ try { return Object.prototype.toString.call(value); } catch { return '[unstringifiable]'; }+ }+}++function safeToString(value) {+ try { return String(value); } catch { return '[unstringifiable]'; }+}+function extractFromReason(reason) {if (reason instanceof Error) {- return { message: reason.message || String(reason), stack: reason.stack };+ return { message: reason.message || safeToString(reason), stack: reason.stack };}if (reason && typeof reason === 'object') {- return { message: String(reason.message ?? JSON.stringify(reason)), stack: reason.stack };+ return { message: safeToString(reason.message ?? safeStringify(reason)), stack: reason.stack };}- return { message: String(reason ?? 'Unknown'), stack: undefined };+ return { message: safeToString(reason ?? 'Unknown'), stack: undefined };}/**diff --git a/client/src/lib/clientErrorReporter.test.js b/client/src/lib/clientErrorReporter.test.jsindex 3b2d5e4ce3..98fbace280 100644--- a/client/src/lib/clientErrorReporter.test.js+++ b/client/src/lib/clientErrorReporter.test.js@@ -23,6 +23,17 @@ describe('buildPayload', () => {expect(out.stack).toBeUndefined();});+ it('does not throw when the rejection reason is a circular object', () => {+ const circular = { name: 'oops' };+ circular.self = circular;+ expect(() => buildPayload({ type: 'unhandledrejection', reason: circular })).not.toThrow();+ });++ it('does not throw when the rejection reason has a hostile toString', () => {+ const hostile = { toString() { throw new Error('nope'); } };+ expect(() => buildPayload({ type: 'unhandledrejection', reason: hostile })).not.toThrow();+ });+it('extracts message + stack + filename/lineno/colno from an error event', () => {const err = new Error('boom');err.stack = 'Error: boom\n at foo (foo.js:1:1)';diff --git a/server/services/clientErrors.js b/server/services/clientErrors.jsindex 6f851acfa6..1baa23c4e3 100644--- a/server/services/clientErrors.js+++ b/server/services/clientErrors.js@@ -19,9 +19,10 @@ const MAX_STACK_CHARS = 4000;const MAX_URL_CHARS = 500;const MAX_USER_AGENT_CHARS = 300;-// Throttle: backstop against a buggy client that bypasses its own throttle.-// At steady state the client is the primary limiter; this guarantees the-// server can't be DoS'd into writing the Review Hub at line rate.+// Throttle: backstop against a buggy or error-looping client that bypasses+// its own throttle. At steady state the client is the primary limiter; this+// guarantees a misbehaving build can't drive the Review Hub at line rate.+// Not a DoS shield — this is a single-user app behind Tailscale.const MIN_ACCEPT_INTERVAL_MS = 1000;// Dedup window matches `reviewService.createItem`'s own alert-dedup window// (24h, keyed off `metadata.referenceId`) so an entry that evicts here@@ -65,7 +66,9 @@ function sanitize(payload) {const stack = redactSecrets(truncate(payload.stack, MAX_STACK_CHARS));const url = truncate(stripQueryString(payload.url), MAX_URL_CHARS);const userAgent = truncate(payload.userAgent, MAX_USER_AGENT_CHARS);- const source = truncate(payload.source, MAX_URL_CHARS);+ // `source` is a script URL (e.g. /assets/index-abc.js?v=…) — strip queries+ // so cache-busted requests dedup together and tokens don't leak.+ const source = truncate(stripQueryString(payload.source), MAX_URL_CHARS);return {type: payload.type,message,@@ -139,6 +142,11 @@ export async function recordClientError(rawPayload) {return { accepted: false, reason: 'duplicate' };}+ // Advance the throttle clock BEFORE the write so a sustained createItem+ // failure (disk full, file lock, etc.) is rate-limited too — otherwise a+ // looping client could attempt one write per call regardless of throughput.+ lastAcceptedAt = now;+const item = await reviewService.createItem({type: 'alert',title: buildTitle(payload),@@ -160,7 +168,6 @@ export async function recordClientError(rawPayload) {if (!item) return { accepted: false, reason: 'review-hub-write-failed' };recentHashes.set(hash, now);- lastAcceptedAt = now;pruneRecent(now);return { accepted: true, itemId: item.id };}diff --git a/server/services/clientErrors.test.js b/server/services/clientErrors.test.jsindex b99ca30939..7f0dc72e63 100644--- a/server/services/clientErrors.test.js+++ b/server/services/clientErrors.test.js@@ -120,4 +120,35 @@ describe('recordClientError', () => {expect(result.accepted).toBe(false);expect(result.reason).toBe('review-hub-write-failed');});++ it('throttles subsequent calls even when the previous Review Hub write failed', async () => {+ review.createItem.mockRejectedValueOnce(new Error('disk full'));+ const first = await recordClientError({+ type: 'error',+ message: 'first failing error',+ stack: 'Error: first\n at foo (a.js:1:1)',+ });+ expect(first.reason).toBe('review-hub-write-failed');++ const second = await recordClientError({+ type: 'error',+ message: 'second distinct error',+ stack: 'Error: second\n at bar (b.js:1:1)',+ });+ expect(second.accepted).toBe(false);+ expect(second.reason).toBe('rate-limited');+ expect(review.createItem).toHaveBeenCalledTimes(1);+ });++ it('strips the query string from the source script URL', async () => {+ await recordClientError({+ type: 'error',+ message: 'boom',+ source: '/assets/index-abc.js?token=keepout',+ });+ const arg = review.createItem.mock.calls[0][0];+ expect(arg.description).toContain('Source: /assets/index-abc.js');+ expect(arg.description).not.toContain('token=keepout');+ expect(arg.metadata.source).toBe('/assets/index-abc.js');+ });});