@yeaft/webchat-agent 0.1.559 → 0.1.561

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.559",
3
+ "version": "0.1.561",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -210,16 +210,31 @@ export function buildVpSnapshot(registry = defaultRegistry) {
210
210
  */
211
211
  export function handleVpSubscribe(sendUnifyEvent, registry = defaultRegistry) {
212
212
  const { loader, fresh } = ensureLoader(registry);
213
- // task-338-F2: replay semantics. The loader's own start() already scans
214
- // on first creation, so on a `fresh` loader we skip the extra rescan (it
215
- // would be redundant work and, more importantly, tests that seed the
216
- // registry BEFORE subscribing would see their seeded entries wiped by
217
- // a rescan against an unrelated DEFAULT_VP_LIB_DIR). On subsequent
218
- // subscribes (page reload, reconnect, second web client), rescanNow()
219
- // refreshes the registry so every client gets a snapshot that reflects
220
- // current disk catching the case where the FS watcher missed an
221
- // event or VPs were added between the initial scan and this subscribe.
222
- if (!fresh && loader && typeof loader.rescanNow === 'function') {
213
+ // task-338-F2 + task-339-followup: replay semantics.
214
+ //
215
+ // The loader's own start() already scans on first creation, so on a
216
+ // `fresh` loader an additional `rescanNow()` is normally redundant.
217
+ // HOWEVER in production (registry === defaultRegistry) the first
218
+ // subscribe can arrive far enough after module import that the on-disk
219
+ // library has diverged from what the initial scan captured (e.g. a
220
+ // platform where `fs.watch` is unreliable, or a containerized
221
+ // bind-mount, or seedDefaultVps writing role.md files after the scan
222
+ // but before the first subscribe). We rescan defensively on the
223
+ // production path so the first snapshot always reflects current disk.
224
+ //
225
+ // For NON-default registries (unit tests that seed VPs manually), we
226
+ // MUST skip the rescan: rescan against DEFAULT_VP_LIB_DIR would call
227
+ // registry.removeVp() for seeded ids that don't exist on disk, wiping
228
+ // the test fixture. See vp-bridge-live-diff.test.js and
229
+ // vp-bridge-first-subscribe-replay.test.js (test-seed preservation).
230
+ //
231
+ // On subsequent subscribes (page reload, reconnect, second web client)
232
+ // rescanNow() refreshes the registry so every client gets a snapshot
233
+ // that reflects current disk — catching the case where the FS watcher
234
+ // missed an event or VPs were added between the initial scan and this
235
+ // subscribe.
236
+ const shouldRescan = (fresh && registry === defaultRegistry) || !fresh;
237
+ if (shouldRescan && loader && typeof loader.rescanNow === 'function') {
223
238
  try { loader.rescanNow(); } catch { /* never crash subscribe on rescan */ }
224
239
  }
225
240
  _subscribers.add(sendUnifyEvent);