@camstack/server 1.2.185 → 1.2.187

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.
Files changed (2) hide show
  1. package/dist/main.js +61 -1
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -239,6 +239,15 @@ async function bootstrap() {
239
239
  // 256KB pages it committed at a sawtooth peak, and an ordinary major GC does not
240
240
  // return them. `createV8Reclaimer()` returns undefined if V8 declines, and the
241
241
  // heartbeat then behaves exactly as it did before.
242
+ //
243
+ // What it recovers, and what it does NOT: the reclaimer is
244
+ // `gc({ execution: 'sync', flavor: 'last-resort' })` — V8 and only V8. It hands back the
245
+ // 256KB pages V8 committed at a sawtooth peak, which on 2026-08-27 was ~1.3GB of a 4.87GiB
246
+ // process. The other ~2.8GB, spread across 13 anonymous mappings >=64MB, is glibc memory
247
+ // already freed by the allocator and never returned to the kernel; nothing in this repository
248
+ // calls `malloc_trim`, and no V8 flavor reaches it. So the pass is a real bound on the V8
249
+ // share and touches none of the share that grew. It is telemetry plus a partial bound, not a
250
+ // fix — do not read a reclaim line as "the leak was handled".
242
251
  const heapReclaimer = (0, system_1.createV8Reclaimer)();
243
252
  const heapReclaim = heapReclaimer === undefined ? undefined : { reclaim: heapReclaimer };
244
253
  // ...and the budget the heartbeat alarms on. hub-main has no manifest to declare one in, and
@@ -246,7 +255,39 @@ async function bootstrap() {
246
255
  // the image never carries this repo's backend. So the number lives in `@camstack/server`,
247
256
  // which is what `applyServerUpdate` replaces, for exactly the reason the heartbeat itself is
248
257
  // started from this file. See `hubMainRssBudget` for why 4096, and why it is expected to fire.
249
- (0, system_1.startHeapWatch)('hub-main', undefined, undefined, heapReclaim, undefined, undefined, true, (0, system_1.hubMainRssBudget)());
258
+ //
259
+ // The sink is DEFERRED. Started here, before any logger exists, the heartbeat could only ever
260
+ // reach `console.log` — which is not a log destination, so for 42 hours Loki carried a `[mem]`
261
+ // line for every runner in the cluster and none for the largest process in it. The sink is
262
+ // repointed at `LoggingService` the moment it exists (below), and boot lines keep going to
263
+ // stdout exactly as before. See `createDeferredHeapWatchSink`.
264
+ const heapWatchSink = (0, system_1.createDeferredHeapWatchSink)(system_1.HUB_MAIN_HEAP_WATCH_LABEL);
265
+ // ...and the event planes, which is the OTHER half of what this process is.
266
+ // hub-main's `arrayBuffers` is a rate, not a set: every forced compaction
267
+ // drops it to 12-29MB (ten passes out of ten, 2026-08-29), so the number to
268
+ // watch is the slope — 181-330MB/min steady, one burst of >=1.3GB in <=11s —
269
+ // and the traffic behind it is ~22 000 socket reads/s and ~22 500 writes/s at
270
+ // a 0.33KB mean. `LocalChildRegistry` has counted that per child since the
271
+ // fan-out gate was built and NOTHING has ever read it; `getMoleculerEventStats`
272
+ // likewise, while the hub runs `CAMSTACK_MOLECULER_EVENT_FANOUT=shadow` — a
273
+ // burn-in with no end condition, because the evidence that would authorise the
274
+ // flip to `filter` was never surfaced. This surfaces it and changes no default.
275
+ //
276
+ // Every source is read LAZILY: this runs as the first statement of bootstrap()
277
+ // and `MoleculerService` does not exist for hundreds of lines. Until it does,
278
+ // the reader reports `undefined` and the line carries no fan-out fields at all
279
+ // — a plane that does not exist yet must not be reported as a silent one.
280
+ let moleculerForEventPlane = null;
281
+ (0, system_1.startHeapWatch)(system_1.HUB_MAIN_HEAP_WATCH_LABEL, heapWatchSink.sink, undefined, heapReclaim, undefined, undefined, true, (0, system_1.hubMainRssBudget)(), {
282
+ eventPlane: (0, system_1.createEventPlaneReader)({
283
+ registry: () => moleculerForEventPlane?.childRegistry ?? null,
284
+ crossNodeStats: () => {
285
+ const broker = moleculerForEventPlane?.broker;
286
+ return broker === undefined ? null : (0, system_1.getMoleculerEventStats)(broker);
287
+ },
288
+ crossNodeMode: () => (0, system_1.readMoleculerFanoutMode)(),
289
+ }),
290
+ });
250
291
  // Clean up orphaned processes from previous crashes before starting
251
292
  cleanupOrphanProcesses();
252
293
  // SPA fallback — set later when admin UI is resolved, used by addon route catch-all
@@ -334,6 +375,21 @@ async function bootstrap() {
334
375
  // If registration fails, start in degraded mode: serve a health warning endpoint.
335
376
  // Instantiate new core services
336
377
  const loggingService = app.get(logging_service_1.LoggingService);
378
+ // The heap heartbeat's handover: from here on hub-main's `[mem]` lines go through the log
379
+ // manager like every runner's do — buffer, console destination, rotated file and Loki — so
380
+ // the one process that mediates every cross-runner call is finally trendable next to the
381
+ // runners it forked, in the same vocabulary. Destinations that register later (Loki is an
382
+ // addon, so it does) are replayed the ring buffer, so the lines between here and then ship
383
+ // too. Deliberately the FIRST thing done with `loggingService`.
384
+ const heapWatchLogger = loggingService.createLogger('heap-watch');
385
+ heapWatchSink.attach({
386
+ info: (line) => {
387
+ heapWatchLogger.info(line);
388
+ },
389
+ warn: (line) => {
390
+ heapWatchLogger.warn(line);
391
+ },
392
+ });
337
393
  const addonRouteRegistry = new system_1.AddonRouteRegistry();
338
394
  const dataPlaneRegistry = new system_1.DataPlaneRegistry();
339
395
  // Use Fastify-managed notification/toast wrappers (globally provided by NotificationModule)
@@ -448,6 +504,10 @@ async function bootstrap() {
448
504
  // Register log-receiver service for agent log forwarding (after app.init
449
505
  // so Moleculer re-advertises the service list to the network)
450
506
  const moleculer = app.get(moleculer_service_1.MoleculerService);
507
+ // Hand the heartbeat its event-plane sources. The reader holds this by
508
+ // closure and re-reads `childRegistry` / `broker` on every line, so a registry
509
+ // that is rebuilt later is picked up without re-wiring anything.
510
+ moleculerForEventPlane = moleculer;
451
511
  moleculer.registerLogReceiver();
452
512
  // Hub-internal `model-distributor` provider — pushes a model format that is
453
513
  // resident on the hub `/data/models` to an agent's `/data/models` (Model
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.185",
3
+ "version": "1.2.187",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",