← Commit history

Negative-result backoff on window-handle resolution: a shared-profile window that cannot be disambiguated was re-probed with PowerShell EnumWindows passes on every overlay, park, and flash touch, forever; three straight misses now put that session on a 5-minute resolution cooldown (any real handle landing clears it). Ends the hot loop that burned laptop CPU and blocked the event loop so often that ab's 1500ms health marker probe timed out against a live bridge, judged it unhealthy, and reap-looped it, the other half of the 557 flap

John Lauer ·ba7e4534af ·2mo ago ·parent d7c05d1
4 files changed +33−9
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "2.0.16",-  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.16/adom-bridge-puppeteer-v2.0.16.zip",-  "sha256": "04e9d602d07b2b124c31baaff2d0564cffc22b0393931f669e8bc5fe934f3fc2",-  "size": 642918,+  "version": "2.0.17",+  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.17/adom-bridge-puppeteer-v2.0.17.zip",+  "sha256": "83af2a53eace1adc6bc8b198a7daf1bc37471408a2d5f60175af417ebcc2aa41",+  "size": 643632,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.16+2.0.17
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.16",+  "version": "2.0.17",   "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. pup_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. pup_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, pup_alert_window posts a native toast whose click focuses the window, pup_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-bridge",   "author": "Adom Inc.",
src/server.js+27−3
@@ -1251,6 +1251,9 @@ function deleteSessionFile(sessionId) { // full saveSessionFile with url/pid isn't required at every resolution). Called whenever the handle // is resolved, so a bridge respawn can restore it and skip the wiggle. function persistSessionHwnd(sessionId, hwnd) {+  // v2.0.17: a real handle landing (birth, park, title-tag, wiggle — every success funnels here)+  // clears the resolution backoff so a session that finally resolved is probed normally again.+  try { const s = sessions.get(sessionId); if (s && hwnd) { s._hwndFailStreak = 0; s._hwndBackoffUntil = 0; } } catch (e) {}   try {     const f = sessionFilePath(sessionId);     if (!fs.existsSync(f)) return;@@ -5475,12 +5478,20 @@ async function windowTarget(session, sessionId) { } async function resolveSessionHwndByBounds(session, sessionId) {   if (process.platform !== 'win32' || !session) return null;+  // v2.0.17 (#557 follow-through): NEGATIVE-RESULT BACKOFF. A shared-profile window that resolution+  // CANNOT disambiguate (N windows, many wiggle-matches) was re-probed on every overlay/park/flash+  // touch — a hot loop of PowerShell EnumWindows passes, forever, per unresolvable session. That+  // burned CPU (John's laptop-load report) AND blocked the event loop often enough that ab's 1500ms+  // /health marker probe timed out, so ab judged a LIVE bridge unhealthy, reaped it (0 tracked pids),+  // and spawn-looped — the #557 flap's other half. Three consecutive failures now put the session on+  // a 5-minute resolution cooldown; any success (or a fresh open with a birth-time handle) resets it.+  if (session._hwndBackoffUntil && Date.now() < session._hwndBackoffUntil) return null;   let _releaseWiggle = null;   // v1.9.291: hoisted so the outer catch can always release the lock   try {     // v1.9.278: NEVER trust a cached hwnd blind - validate it still belongs to pup before reuse     // (a dead/recycled handle now owned by Edge is exactly how the Edge overlay happened).     if (session._hwnd) {-      if (await hwndBelongsToPup(session._hwnd, session)) return Number(session._hwnd);+      if (await hwndBelongsToPup(session._hwnd, session)) { session._hwndFailStreak = 0; session._hwndBackoffUntil = 0; return Number(session._hwnd); }       console.log(`[hwnd] "${sessionId}" cached hwnd ${session._hwnd} is stale/foreign — discarding and re-resolving`);       session._hwnd = null;     }@@ -5629,9 +5640,22 @@ async function resolveSessionHwndByBounds(session, sessionId) {     // Multiple windows on the profile and no unique wiggle match → we cannot know which is ours, so     // leave it BARE rather than paint a guessed/shared handle (John's rule: bare > wrong). This is the     // case the birth-time resolution (todo #5) will finally fix for multi-window profiles.-    console.log(`[hwnd] "${sessionId}" NOT resolved — ${_profWins.size} windows on this profile, ${matches.size} wiggle-matches; leaving bare rather than guessing`);+    session._hwndFailStreak = (session._hwndFailStreak || 0) + 1;+    if (session._hwndFailStreak >= 3) {+      session._hwndBackoffUntil = Date.now() + 5 * 60000;+      console.log(`[hwnd] "${sessionId}" NOT resolved — ${_profWins.size} windows on this profile, ${matches.size} wiggle-matches; leaving bare + BACKING OFF resolution for 5 min (${session._hwndFailStreak} straight misses — stop hammering PowerShell for an answer that isn't changing)`);+    } else {+      console.log(`[hwnd] "${sessionId}" NOT resolved — ${_profWins.size} windows on this profile, ${matches.size} wiggle-matches; leaving bare rather than guessing`);+    }     return null;-  } catch (e) { if (_releaseWiggle) { try { _releaseWiggle(); } catch (x) {} } console.log(`[hwnd] "${sessionId}" bounds resolve failed: ${e.message}`); return null; }+  } catch (e) {+    if (_releaseWiggle) { try { _releaseWiggle(); } catch (x) {} }+    // v2.0.17: exceptions count toward the same backoff — the EBUSY spin was exactly this path looping.+    session._hwndFailStreak = (session._hwndFailStreak || 0) + 1;+    if (session._hwndFailStreak >= 3) session._hwndBackoffUntil = Date.now() + 5 * 60000;+    console.log(`[hwnd] "${sessionId}" bounds resolve failed: ${e.message}${session._hwndFailStreak >= 3 ? ' — backing off resolution for 5 min' : ''}`);+    return null;+  } }  async function pageWindowId(page) {