shadok-ai 0.16.8 → 0.16.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -531,16 +531,19 @@ every 25s (tunable with `SHADOK_WS_PING_MS`) to keep the connection warm, so no
531
531
  proxy change is normally needed; if your proxy still cuts it, raise
532
532
  `proxy_read_timeout` above the ping interval.
533
533
 
534
- **Sleep / wake.** When a laptop sleeps, the socket's TCP connection usually dies
535
- without the browser ever seeing a `close`, so it keeps reporting the link as
536
- "open" while nothing flows. On wake the cockpit no longer trusts that stale
537
- state: a real wake — the page becoming visible after more than ~10s away, a
538
- network change (`online`), or a page restored from the back/forward cache —
539
- tears the suspect socket down and opens a fresh one at once, reattaching to the
540
- same session. A quick tab switch is left alone (the link is almost certainly
541
- fine), so you don't pay a reconnect every time you glance away. Previously a
542
- woken tab waited out the browser's own TCP timeout, tens of seconds to minutes,
543
- stuck on "reconnecting…".
534
+ **Sleep / wake / network blips.** When the machine comes back (an `online`
535
+ event, the tab becoming visible, a back/forward-cache restore), the cockpit
536
+ revives the links that actually **dropped** — resetting their backoff so a
537
+ genuinely-closed socket reconnects promptly instead of waiting out a delay that
538
+ climbed while you were away. A socket that still reports "open" is left alone:
539
+ `online` fires on every network blip (wifi roam, VPN, interface change), and
540
+ force-reconnecting healthy links on each one reconnected all your agents at
541
+ once — tripping the upstream single-use-token OAuth refresh race so a batch
542
+ stuck on "connecting…". A slept socket that looks "open" but is dead is
543
+ terminated by the server heartbeat (~50s) and reconnects on the resulting
544
+ `close` without that churn. Only a back/forward-cache restore force-replaces an
545
+ "open" socket, because there the restored page's old sockets are dead yet fire
546
+ no `close`.
544
547
 
545
548
  ### Cross-instance peers
546
549
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.16.8",
3
+ "version": "0.16.9",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",
package/public/index.html CHANGED
@@ -7095,51 +7095,45 @@
7095
7095
  // off. Bounded so an update that never lands doesn't leave us hammering.
7096
7096
  let reloadExpectedUntil = 0;
7097
7097
 
7098
- /** Reconnect every dropped tab immediately (no backoff wait) — fired when the
7099
- * machine/tab comes back (online / visible), the common laptop-wake case.
7100
- * `force` replaces even a socket that still reports OPEN: after a laptop
7101
- * sleep the TCP connection is usually dead while the browser has seen no
7102
- * `close`, so `readyState` lies "OPEN" and the gentle path would skip the
7103
- * tab — leaving it stranded until the browser's own TCP timeout fires
7104
- * (tens of seconds to minutes), which is exactly the "stuck reconnecting,
7105
- * very slow" symptom. A CONNECTING socket is always left alone: a link is
7106
- * already in flight, and tearing it down would only restart the clock. */
7098
+ /** Revive the tabs whose link actually DROPPED — fired when the machine/tab
7099
+ * comes back (online / visible). It resets the backoff and reconnects at
7100
+ * once, so a genuinely-closed socket comes back promptly instead of waiting
7101
+ * out an exponential delay that climbed while we were away.
7102
+ *
7103
+ * It deliberately does NOT touch a socket that still reports OPEN. An earlier
7104
+ * version force-replaced OPEN sockets too (to catch a laptop-sleep "zombie" —
7105
+ * OPEN on the client, dead on the wire). But `online` fires on EVERY network
7106
+ * blip (wifi roam, VPN, interface change), and force-closing every healthy
7107
+ * link on each blip reconnected all N agents at once — tripping the upstream
7108
+ * OAuth refresh-token race (single-use tokens, concurrent `claude --resume`,
7109
+ * biting at ~10–30 agents) so a whole batch stuck on "connecting…". That mass
7110
+ * churn was worse than the zombie it chased: a slept socket is terminated by
7111
+ * the server heartbeat (~50s) and the resulting `close` reconnects it anyway,
7112
+ * no force needed. `force` is kept ONLY for a bfcache `pageshow`, where the
7113
+ * restored page's old sockets are genuinely dead and fire no `close`. */
7107
7114
  function reconnectAllNow(force) {
7108
7115
  for (const t of tabs) {
7109
7116
  if (t.closing || !t.sessionId) continue;
7110
7117
  const st = t.ws && t.ws.readyState;
7111
7118
  if (st === WebSocket.CONNECTING) continue; // a link is already on its way
7112
- if (st === WebSocket.OPEN && !force) continue; // healthy and no reason to doubt it
7119
+ if (st === WebSocket.OPEN && !force) continue; // healthy — leave it, a blip is not a death
7113
7120
  if (t.reconnectTimer) clearTimeout(t.reconnectTimer);
7114
- t.reconnectAttempts = 0;
7121
+ t.reconnectAttempts = 0; // reset the backoff: reconnect promptly, not after a climbed delay
7115
7122
  const old = t.ws;
7116
7123
  openLink(t); // replaces t.ws with the fresh socket
7117
- // Close the suspected-zombie only after openLink swapped t.ws, so its
7124
+ // Close a forced (bfcache) zombie only after openLink swapped t.ws, so its
7118
7125
  // `close` handler sees `t.ws !== ws` and does not schedule a competing
7119
7126
  // reconnect. A no-op when `old` was already closed.
7120
7127
  if (old && old !== t.ws) { try { old.close(); } catch {} }
7121
7128
  }
7122
7129
  }
7123
7130
 
7124
- // A real wake (laptop sleep, bfcache restore, a network change) must force a
7125
- // fresh link; a quick tab switch must not — forcing there would flash
7126
- // "reconnecting" and pay a resume round-trip every time you glance away.
7127
- // The tell is how long we were hidden: seconds for an alt-tab, minutes for a
7128
- // sleep. `online` and a bfcache `pageshow` are forced outright — the network
7129
- // or the page itself just changed under us.
7130
- const STALE_WAKE_MS = 10_000;
7131
- let hiddenAt = 0;
7132
- function wokeAfterLongAway() {
7133
- const away = hiddenAt ? Date.now() - hiddenAt : 0;
7134
- hiddenAt = 0;
7135
- return away > STALE_WAKE_MS;
7136
- }
7137
- window.addEventListener("online", () => reconnectAllNow(true));
7138
- window.addEventListener("pageshow", (e) => reconnectAllNow(!!e.persisted || wokeAfterLongAway()));
7139
- document.addEventListener("visibilitychange", () => {
7140
- if (document.hidden) { hiddenAt = Date.now(); return; }
7141
- reconnectAllNow(wokeAfterLongAway());
7142
- });
7131
+ // Reconnect the links that dropped while we were away — but never disturb a
7132
+ // healthy one (see reconnectAllNow). Only a bfcache restore forces, because
7133
+ // there the old sockets are dead yet fire no `close`.
7134
+ window.addEventListener("online", () => reconnectAllNow(false));
7135
+ window.addEventListener("pageshow", (e) => reconnectAllNow(!!e.persisted));
7136
+ document.addEventListener("visibilitychange", () => { if (!document.hidden) reconnectAllNow(false); });
7143
7137
 
7144
7138
  /**
7145
7139
  * Lists the agents alive in the server right now — including ones spawned