← Commit history

Stop cross-thread tab contamination (John: 'different ai threads opening pup window tabs into each others windows ... make sure their windows only open in tabs by default in the pup window they own'). Root cause: browser_open_tab with no sessionId fell back to activeSessionId — a SINGLE GLOBAL overwritten on every open by ANY thread — so a thread's tab landed in whatever window was last touched, often another agent's. Fix: the fallback is now callerOwnWindow(callerThread), the caller thread's own most-recently-created live session (matched via _ownerThread, which the bridge already stamps from the X-Adom-Caller-Thread header); the global activeSessionId is no longer a tab target. If the caller owns no window, open_tab now REFUSES with no_target_window + the caller's list of its own windows and a 'open one first' instruction, instead of silently contaminating. Plus a guard: adding a tab to a window owned by a DIFFERENT thread is refused (session_owned_by_another_thread) unless takeover:true, so even an explicit stray sessionId can't cross threads by accident. NOTE: does not touch the separate 'Not Responding' page-hang class John also saw (a spinning page in the herodeck-web/Orbital Lab window) — that is the per-session serialization / runaway-JS work still queued.

John Lauer ·7bde4bdca1 ·3mo ago ·parent df538a1
4 files changed +38−9
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.145",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.145/adom-bridge-puppeteer-v1.9.145.zip",-  "sha256": "2822144763a33c048747e67811e310968651cca7865dad422303ad9a8193f4e2",-  "size": 397735,+  "version": "1.9.146",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.146/adom-bridge-puppeteer-v1.9.146.zip",+  "sha256": "1585f261504d815264f5010a07b03c30b671beda0d1018930deddc46ef68a6db",+  "size": 398533,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.145+1.9.146
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.145",+  "version": "1.9.146",   "description": "Drives a browser ALREADY on the machine \u2014 installed Chrome, else Microsoft Edge (every Windows PC ships with Edge) \u2014 launched with a FRESH isolated profile, so the common case has NO ~150 MB Chrome-for-Testing download and it never touches the user's real tabs/logins. Binds its local server to LOOPBACK (127.0.0.1) only, so no Windows Firewall 'allow Node through the firewall' prompt ever pops. Chrome for Testing is fetched only as a LAST RESORT if the machine has no Chromium browser at all. SPAWN-VERIFIED fallback: pup tries each detected browser (Chrome \u2192 Edge \u2192 CfT) and actually launches it, falling through to the next if one won't start (and handling browsers like Edge that relaunch onto another PID), so a corrupt/partial install never hard-fails an open. The browser that launches is cached as the default (persisted across restarts) so it isn't re-probed each time. On spawn the bridge SELF-WARMS: detects browsers + disk, and only if the box has no Chrome/Edge and no cached CfT does it background-fetch CfT so the first open is instant. browser_use pins a specific browser (chrome | edge | cft | auto); {browser:'chrome',install:true} downloads & installs REAL Google Chrome (user-scoped, no admin) on an Edge-only box. browser_readiness (READ-ONLY) reports which browser will be used + the full candidate list + the default + free disk. Every failure returns a specific errorCode + _hint (chrome_install_no_disk, chrome_download_network, chrome_install_permission, chrome_stable_not_detected, \u2026). Launches with FULL browser permissions by default for full debug (strictPermissions:true opts out). Headful automation: open/close windows+tabs, navigate, screenshot, eval JS, record. pup is a GENERIC, non-profile browser only \u2014 every session is a fresh isolated Chrome/Edge process, never the user's real signed-in browser; profile defaults to sessionId. To drive the user's REAL Chrome/Edge (their profile, cookies, SSO), use the Adom browser EXTENSION's nbrowser_* verbs \u2014 a separate bridge, not pup's job. macOS (v1.9.74+): full parity with mac-native mechanics \u2014 background-by-default is the app-level hide (windows stay drivable/screenshottable while hidden), raise/lower map to unhide+activate/hide, browser_alert_window posts a native toast whose click focuses the window, browser_use {browser:'chrome',install:true} installs Chrome from the official dmg, and taskbar identity/badging remains Windows-only.",   "homepage": "https://wiki.adom.inc/adom/adom-desktop",   "author": "Adom Inc.",
src/server.js+32−3
@@ -242,6 +242,21 @@ try { let browsers = new Map(); let sessions = new Map(); let activeSessionId = null;+// v1.9.146 (John: 'different ai threads opening pup window tabs into each other's windows ... make+// sure their windows only open in tabs by default in the pup window they own'). activeSessionId is+// a SINGLE GLOBAL overwritten on every open by ANY thread, so browser_open_tab with no sessionId+// dumped the tab into whatever window was last touched — cross-thread contamination. This resolves+// the CALLER THREAD'S OWN window instead: the most recently created live session this thread owns.+function callerOwnWindow(callerThread) {+  if (!callerThread) return null;+  let best = null;+  for (const [sid, s] of sessions) {+    if (s && s._ownerThread === callerThread && isSessionAlive(s)) {+      if (!best || (s.createdAt || 0) >= (sessions.get(best).createdAt || 0)) best = sid;+    }+  }+  return best;+} let pupshotUrl = null; // v1.9.4: profileName -> in-flight launch Promise. A fresh profile isn't in `browsers` until its // Chrome launch FINISHES (~10-15s), so two near-simultaneous opens for the same profile used to@@ -7533,12 +7548,26 @@ const server = http.createServer(async (req, res) => {          // --- Tab-level commands ---         case 'browser_open_tab': {-          const sessionId = args.sessionId || activeSessionId;+          // v1.9.146: explicit sessionId wins; otherwise the CALLER THREAD's own most-recent window —+          // NEVER the global activeSessionId (that is another thread's window as often as not).+          const sessionId = args.sessionId || callerOwnWindow(_callerThread);           if (!sessionId || !sessions.has(sessionId)) {-            const available = [...sessions.keys()].join(', ');-            sendJSON(res, { success: false, error: `Session "${sessionId}" not found. Use browser_open_window first. Available: [${available}]` });+            const mine = _callerThread ? [...sessions].filter(([,s]) => s._ownerThread === _callerThread).map(([id]) => id) : [];+            sendJSON(res, { success: false, errorCode: 'no_target_window',+              error: `No window to add a tab to. ${args.sessionId ? `Session "${args.sessionId}" not found.` : (_callerThread ? `Your thread ("${_callerThread}") owns no open pup window yet.` : `No sessionId given and your thread sent no caller identity.`)} Open one with browser_open_window first (pass a sessionId you'll reuse), then browser_open_tab into it.`,+              yourWindows: mine });             return;           }+          // Guard: refuse to add a tab to a window owned by a DIFFERENT thread unless it was named+          // explicitly (a deliberate cross-thread action), so a stray call can't contaminate.+          {+            const _tgt = sessions.get(sessionId);+            if (_tgt && _tgt._ownerThread && _callerThread && _tgt._ownerThread !== _callerThread && !args.takeover) {+              sendJSON(res, { success: false, errorCode: 'session_owned_by_another_thread',+                error: `Window "${sessionId}" is owned by thread "${_tgt._ownerThread}", not "${_callerThread}". Opening a tab here would land in another agent's window. Open your OWN window (browser_open_window) or pass takeover:true if you truly mean to use theirs.` });+              return;+            }+          }           try {             const tabId = await addTabToSession(sessionId, args.url);             const session = sessions.get(sessionId);