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: address review — guard WS JSON.parse, contain reconnect rejections, mirror realpath in test helper
Adam Eivy8b4e680b34b0
diff --git a/browser/server.js b/browser/server.jsindex dcf63e5aef..4f6f3fd273 100644--- a/browser/server.js+++ b/browser/server.js@@ -87,7 +87,13 @@ async function configureDownloadBehavior(downloadDir) {});ws.addEventListener('message', (event) => {- const msg = JSON.parse(event.data);+ // Chrome should only send JSON on this WS, but guard against truncated+ // frames / non-JSON noise so a single bad message can't crash the service.+ let msg;+ try { msg = JSON.parse(event.data); } catch (err) {+ console.error(`⚠️ Ignoring non-JSON WS frame: ${err.message}`);+ return;+ }if (msg.id === 1) {if (msg.error) {console.error(`❌ Browser.setDownloadBehavior failed: ${msg.error.message || JSON.stringify(msg.error)}`);@@ -114,9 +120,16 @@ function scheduleDownloadReconnect() {downloadWsReconnectTimer = setTimeout(async () => {downloadWsReconnectTimer = null;if (shuttingDown || !downloadDirCurrent) return;- if (await checkCdp()) {- await configureDownloadBehavior(downloadDirCurrent);- } else {+ // Contain any rejection from checkCdp/configureDownloadBehavior so an+ // async setTimeout callback can't escape as an unhandledRejection.+ try {+ if (await checkCdp()) {+ await configureDownloadBehavior(downloadDirCurrent);+ } else {+ scheduleDownloadReconnect();+ }+ } catch (err) {+ console.error(`⚠️ Download keep-alive reconnect failed: ${err.message}`);scheduleDownloadReconnect();}}, 2000);diff --git a/server/services/worktreeManager.test.js b/server/services/worktreeManager.test.jsindex 44ba3c0dbf..4efc1d3236 100644--- a/server/services/worktreeManager.test.js+++ b/server/services/worktreeManager.test.js@@ -234,9 +234,16 @@ describe('Auto-generated Lockfile Detection', () => {describe('Broken Worktree Detection', () => {// Mirrors the rev-parse validation logic in removeWorktree that prevents// git status from resolving to a parent repo (e.g., PortOS) when the- // worktree's .git file is missing- function isBrokenWorktree(detectedToplevel, expectedWorktreePath) {- return detectedToplevel && detectedToplevel !== expectedWorktreePath;+ // worktree's .git file is missing. Mirrors the realpath-normalization too+ // so symlink-equivalent paths (/var <-> /private/var) don't false-positive.+ function isBrokenWorktree(detectedToplevel, expectedWorktreePath, realpathFn = p => p) {+ if (!detectedToplevel) return false;+ if (detectedToplevel === expectedWorktreePath) return false;+ try {+ return realpathFn(detectedToplevel) !== realpathFn(expectedWorktreePath);+ } catch {+ return detectedToplevel !== expectedWorktreePath;+ }}it('should detect worktree resolving to parent repo as broken', () => {@@ -255,6 +262,14 @@ describe('Broken Worktree Detection', () => {const worktreePath = '/data/cos/worktrees/agent-abc';expect(isBrokenWorktree(null, worktreePath)).toBeFalsy();});++ it('should treat symlink-equivalent paths as the same worktree', () => {+ // e.g. /var/folders/... resolves to /private/var/folders/... on macOS+ const worktreePath = '/var/data/cos/worktrees/agent-abc';+ const detectedToplevel = '/private/var/data/cos/worktrees/agent-abc';+ const realpathFn = p => p.replace(/^\/var\//, '/private/var/');+ expect(isBrokenWorktree(detectedToplevel, worktreePath, realpathFn)).toBe(false);+ });});describe('Orphaned Worktree Detection', () => {