@resolveio/server-lib 22.3.0 → 22.3.2

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": "@resolveio/server-lib",
3
- "version": "22.3.0",
3
+ "version": "22.3.2",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
@@ -60,7 +60,7 @@
60
60
  "path": "0.12.7",
61
61
  "pdf-lib": "1.17.1",
62
62
  "pm2": "7.0.1",
63
- "puppeteer": "24.29.0",
63
+ "puppeteer": "24.43.0",
64
64
  "rus-diff": "1.1.0",
65
65
  "rxjs": "7.8.2",
66
66
  "scmp": "2.1.0",
@@ -125,7 +125,7 @@
125
125
  "path": "0.12.7",
126
126
  "pdf-lib": "1.17.1",
127
127
  "pm2": "7.0.1",
128
- "puppeteer": "24.29.0",
128
+ "puppeteer": "24.43.0",
129
129
  "rus-diff": "1.1.0",
130
130
  "scmp": "2.1.0",
131
131
  "simpl-schema": "1.12.0",
package/server-app.d.ts CHANGED
@@ -63,11 +63,13 @@ export declare class ResolveIOMainServer {
63
63
  private _standaloneNodeReaperHighMinAgeSeconds;
64
64
  private _standaloneNodeReaperHighConsecutiveScans;
65
65
  private _standaloneNodeReaperDryRun;
66
+ private _standaloneNodeReaperAlertWindowMs;
66
67
  private _standaloneNodeReaperTimer;
67
68
  private _standaloneNodeReaperRunning;
68
69
  private _standaloneNodeReaperKillCounts;
69
70
  private _standaloneNodeReaperSuppressedSignatures;
70
71
  private _standaloneNodeReaperResourceHits;
72
+ private _standaloneNodeReaperAlertTimes;
71
73
  private _serverStartTime;
72
74
  private _lastErrorMsg;
73
75
  private _debugMsgRecv;
@@ -91,6 +93,8 @@ export declare class ResolveIOMainServer {
91
93
  private startAiAssistantCodexManagerIfEnabled;
92
94
  private startStandaloneNodeReaper;
93
95
  private reapStandaloneNodeProcesses;
96
+ private createStandaloneNodeReaperDetails;
97
+ private reportStandaloneNodeReaperAction;
94
98
  private listSystemProcesses;
95
99
  private parseProcessSnapshot;
96
100
  private execFileText;
@@ -174,10 +178,12 @@ export declare class ResolveIOMainServer {
174
178
  private resolveStandaloneNodeReaperHighMinAgeSeconds;
175
179
  private resolveStandaloneNodeReaperHighConsecutiveScans;
176
180
  private resolveStandaloneNodeReaperDryRun;
181
+ private resolveStandaloneNodeReaperAlertWindowMs;
177
182
  private isPm2ManagedRuntime;
178
183
  private isPrimaryPm2Instance;
179
184
  private isLocalRuntime;
180
185
  private normalizeWorkerSelectorValue;
186
+ private shouldStartCronManagerForWorker;
181
187
  private parseWorkerSelector;
182
188
  private workerMatchesSelector;
183
189
  private resolveWorkerRole;
package/server-app.js CHANGED
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -178,11 +189,13 @@ var ResolveIOMainServer = /** @class */ (function () {
178
189
  this._standaloneNodeReaperHighMinAgeSeconds = 60;
179
190
  this._standaloneNodeReaperHighConsecutiveScans = 2;
180
191
  this._standaloneNodeReaperDryRun = false;
192
+ this._standaloneNodeReaperAlertWindowMs = 60 * 60 * 1000;
181
193
  this._standaloneNodeReaperTimer = null;
182
194
  this._standaloneNodeReaperRunning = false;
183
195
  this._standaloneNodeReaperKillCounts = new Map();
184
196
  this._standaloneNodeReaperSuppressedSignatures = new Set();
185
197
  this._standaloneNodeReaperResourceHits = new Map();
198
+ this._standaloneNodeReaperAlertTimes = new Map();
186
199
  this._lastErrorMsg = null;
187
200
  this._debugMsgRecv = 0;
188
201
  this._debugMsgQueue = 0;
@@ -249,6 +262,7 @@ var ResolveIOMainServer = /** @class */ (function () {
249
262
  this._standaloneNodeReaperHighMinAgeSeconds = this.resolveStandaloneNodeReaperHighMinAgeSeconds();
250
263
  this._standaloneNodeReaperHighConsecutiveScans = this.resolveStandaloneNodeReaperHighConsecutiveScans();
251
264
  this._standaloneNodeReaperDryRun = this.resolveStandaloneNodeReaperDryRun();
265
+ this._standaloneNodeReaperAlertWindowMs = this.resolveStandaloneNodeReaperAlertWindowMs();
252
266
  this._dynamicAppGatewayEnabled = this.resolveDynamicAppGatewayEnabled();
253
267
  this._socketTier = this.resolveSocketTier();
254
268
  this._maxClientSockets = this.resolveMaxClientSockets(this._socketTier);
@@ -495,7 +509,7 @@ var ResolveIOMainServer = /** @class */ (function () {
495
509
  skipCronForProcessOnly = this.parseDebugFlag(process.env.SUPPORT_CODEX_MANAGER_PROCESS_ONLY)
496
510
  || this.parseDebugFlag(process.env.SUPPORT_AUTO_MANAGER_PROCESS_ONLY)
497
511
  || this.parseDebugFlag(process.env.AI_ASSISTANT_CODEX_MANAGER_PROCESS_ONLY);
498
- if (process.env.WORKER_INDEX === '0' && !skipCronForProcessOnly) {
512
+ if (this.shouldStartCronManagerForWorker() && !skipCronForProcessOnly) {
499
513
  this._cronManager = cron_manager_1.CronManager.create();
500
514
  }
501
515
  }
@@ -596,13 +610,15 @@ var ResolveIOMainServer = /** @class */ (function () {
596
610
  highRssMb: this._standaloneNodeReaperHighRssMb,
597
611
  highMinAgeSeconds: this._standaloneNodeReaperHighMinAgeSeconds,
598
612
  highConsecutiveScans: this._standaloneNodeReaperHighConsecutiveScans,
613
+ alertWindowMs: this._standaloneNodeReaperAlertWindowMs,
599
614
  dryRun: this._standaloneNodeReaperDryRun
600
615
  });
601
616
  };
602
617
  ResolveIOMainServer.prototype.reapStandaloneNodeProcesses = function () {
603
618
  return __awaiter(this, void 0, void 0, function () {
604
- var processes, protectedPids, _loop_1, this_1, processes_1, processes_1_1, proc;
619
+ var processes, protectedPids, _loop_1, this_1, processes_1, processes_1_1, proc, e_1_1;
605
620
  var e_1, _a;
621
+ var _this = this;
606
622
  var _b;
607
623
  return __generator(this, function (_c) {
608
624
  switch (_c.label) {
@@ -613,88 +629,165 @@ var ResolveIOMainServer = /** @class */ (function () {
613
629
  this._standaloneNodeReaperRunning = true;
614
630
  _c.label = 1;
615
631
  case 1:
616
- _c.trys.push([1, , 3, 4]);
632
+ _c.trys.push([1, , 11, 12]);
617
633
  return [4 /*yield*/, this.listSystemProcesses()];
618
634
  case 2:
619
635
  processes = _c.sent();
620
636
  protectedPids = this.resolvePm2ProtectedPids(processes);
621
637
  _loop_1 = function (proc) {
622
- if (!this_1.shouldReapStandaloneNodeProcess(proc, protectedPids)) {
623
- return "continue";
624
- }
625
- var signature = this_1.resolveStandaloneNodeProcessSignature(proc);
626
- if (!this_1.canReapStandaloneNodeSignature(signature)) {
627
- this_1.logStandaloneNodeReaperSuppressed(proc, signature);
628
- return "continue";
629
- }
630
- var reason = this_1.resolveStandaloneNodeReaperReason(proc);
631
- if (this_1._standaloneNodeReaperDryRun) {
632
- this_1.recordStandaloneNodeReaperKill(signature);
633
- console.warn(new Date(), '[Standalone Node Reaper] dry-run would terminate stale node process', {
634
- pid: proc.pid,
635
- ppid: proc.ppid,
636
- ageSeconds: proc.ageSeconds,
637
- cpuPct: proc.cpuPct,
638
- rssMb: (0, common_1.round)(proc.rssKb / 1024),
639
- reason: reason,
640
- command: proc.args
641
- });
642
- return "continue";
643
- }
644
- try {
645
- process.kill(proc.pid, 'SIGTERM');
646
- this_1.recordStandaloneNodeReaperKill(signature);
647
- console.warn(new Date(), '[Standalone Node Reaper] terminated stale node process', {
648
- pid: proc.pid,
649
- ppid: proc.ppid,
650
- ageSeconds: proc.ageSeconds,
651
- cpuPct: proc.cpuPct,
652
- rssMb: (0, common_1.round)(proc.rssKb / 1024),
653
- reason: reason,
654
- command: proc.args
655
- });
656
- var killTimer = setTimeout(function () {
657
- try {
658
- process.kill(proc.pid, 0);
659
- process.kill(proc.pid, 'SIGKILL');
660
- console.warn(new Date(), '[Standalone Node Reaper] force killed stale node process', {
661
- pid: proc.pid,
662
- reason: reason,
663
- command: proc.args
664
- });
665
- }
666
- catch (_a) { }
667
- }, 10000);
668
- (_b = killTimer.unref) === null || _b === void 0 ? void 0 : _b.call(killTimer);
669
- }
670
- catch (error) {
671
- if ((error === null || error === void 0 ? void 0 : error['code']) !== 'ESRCH') {
672
- console.error(new Date(), '[Standalone Node Reaper] kill failed', {
673
- pid: proc.pid,
674
- command: proc.args,
675
- error: (error === null || error === void 0 ? void 0 : error['message']) || error
676
- });
638
+ var signature, reason, details, details, killTimer, error_6;
639
+ return __generator(this, function (_d) {
640
+ switch (_d.label) {
641
+ case 0:
642
+ if (!this_1.shouldReapStandaloneNodeProcess(proc, protectedPids)) {
643
+ return [2 /*return*/, "continue"];
644
+ }
645
+ signature = this_1.resolveStandaloneNodeProcessSignature(proc);
646
+ if (!this_1.canReapStandaloneNodeSignature(signature)) {
647
+ this_1.logStandaloneNodeReaperSuppressed(proc, signature);
648
+ return [2 /*return*/, "continue"];
649
+ }
650
+ reason = this_1.resolveStandaloneNodeReaperReason(proc);
651
+ if (!this_1._standaloneNodeReaperDryRun) return [3 /*break*/, 2];
652
+ this_1.recordStandaloneNodeReaperKill(signature);
653
+ details = this_1.createStandaloneNodeReaperDetails(proc, reason, 'dry-run');
654
+ console.warn(new Date(), '[Standalone Node Reaper] dry-run would terminate stale node process', details);
655
+ return [4 /*yield*/, this_1.reportStandaloneNodeReaperAction(proc, reason, 'dry-run')];
656
+ case 1:
657
+ _d.sent();
658
+ return [2 /*return*/, "continue"];
659
+ case 2:
660
+ _d.trys.push([2, 4, , 5]);
661
+ process.kill(proc.pid, 'SIGTERM');
662
+ this_1.recordStandaloneNodeReaperKill(signature);
663
+ details = this_1.createStandaloneNodeReaperDetails(proc, reason, 'terminated');
664
+ console.warn(new Date(), '[Standalone Node Reaper] terminated stale node process', details);
665
+ return [4 /*yield*/, this_1.reportStandaloneNodeReaperAction(proc, reason, 'terminated')];
666
+ case 3:
667
+ _d.sent();
668
+ killTimer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
669
+ var _a;
670
+ return __generator(this, function (_b) {
671
+ switch (_b.label) {
672
+ case 0:
673
+ _b.trys.push([0, 2, , 3]);
674
+ process.kill(proc.pid, 0);
675
+ process.kill(proc.pid, 'SIGKILL');
676
+ console.warn(new Date(), '[Standalone Node Reaper] force killed stale node process', {
677
+ pid: proc.pid,
678
+ reason: reason,
679
+ command: proc.args
680
+ });
681
+ return [4 /*yield*/, this.reportStandaloneNodeReaperAction(proc, reason, 'force-killed')];
682
+ case 1:
683
+ _b.sent();
684
+ return [3 /*break*/, 3];
685
+ case 2:
686
+ _a = _b.sent();
687
+ return [3 /*break*/, 3];
688
+ case 3: return [2 /*return*/];
689
+ }
690
+ });
691
+ }); }, 10000);
692
+ (_b = killTimer.unref) === null || _b === void 0 ? void 0 : _b.call(killTimer);
693
+ return [3 /*break*/, 5];
694
+ case 4:
695
+ error_6 = _d.sent();
696
+ if ((error_6 === null || error_6 === void 0 ? void 0 : error_6['code']) !== 'ESRCH') {
697
+ console.error(new Date(), '[Standalone Node Reaper] kill failed', {
698
+ pid: proc.pid,
699
+ command: proc.args,
700
+ error: (error_6 === null || error_6 === void 0 ? void 0 : error_6['message']) || error_6
701
+ });
702
+ }
703
+ return [3 /*break*/, 5];
704
+ case 5: return [2 /*return*/];
677
705
  }
678
- }
706
+ });
679
707
  };
680
708
  this_1 = this;
709
+ _c.label = 3;
710
+ case 3:
711
+ _c.trys.push([3, 8, 9, 10]);
712
+ processes_1 = __values(processes), processes_1_1 = processes_1.next();
713
+ _c.label = 4;
714
+ case 4:
715
+ if (!!processes_1_1.done) return [3 /*break*/, 7];
716
+ proc = processes_1_1.value;
717
+ return [5 /*yield**/, _loop_1(proc)];
718
+ case 5:
719
+ _c.sent();
720
+ _c.label = 6;
721
+ case 6:
722
+ processes_1_1 = processes_1.next();
723
+ return [3 /*break*/, 4];
724
+ case 7: return [3 /*break*/, 10];
725
+ case 8:
726
+ e_1_1 = _c.sent();
727
+ e_1 = { error: e_1_1 };
728
+ return [3 /*break*/, 10];
729
+ case 9:
681
730
  try {
682
- for (processes_1 = __values(processes), processes_1_1 = processes_1.next(); !processes_1_1.done; processes_1_1 = processes_1.next()) {
683
- proc = processes_1_1.value;
684
- _loop_1(proc);
685
- }
731
+ if (processes_1_1 && !processes_1_1.done && (_a = processes_1.return)) _a.call(processes_1);
686
732
  }
687
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
688
- finally {
689
- try {
690
- if (processes_1_1 && !processes_1_1.done && (_a = processes_1.return)) _a.call(processes_1);
691
- }
692
- finally { if (e_1) throw e_1.error; }
733
+ finally { if (e_1) throw e_1.error; }
734
+ return [7 /*endfinally*/];
735
+ case 10: return [3 /*break*/, 12];
736
+ case 11:
737
+ this._standaloneNodeReaperRunning = false;
738
+ return [7 /*endfinally*/];
739
+ case 12: return [2 /*return*/];
740
+ }
741
+ });
742
+ });
743
+ };
744
+ ResolveIOMainServer.prototype.createStandaloneNodeReaperDetails = function (proc, reason, action) {
745
+ return {
746
+ action: action,
747
+ pid: proc.pid,
748
+ ppid: proc.ppid,
749
+ ageSeconds: proc.ageSeconds,
750
+ cpuPct: proc.cpuPct,
751
+ rssMb: (0, common_1.round)(proc.rssKb / 1024),
752
+ reason: reason,
753
+ command: proc.args
754
+ };
755
+ };
756
+ ResolveIOMainServer.prototype.reportStandaloneNodeReaperAction = function (proc, reason, action) {
757
+ return __awaiter(this, void 0, void 0, function () {
758
+ var signature, alertKey, now, lastReportedAt, error_7;
759
+ var _a;
760
+ return __generator(this, function (_b) {
761
+ switch (_b.label) {
762
+ case 0:
763
+ signature = this.resolveStandaloneNodeProcessSignature(proc);
764
+ alertKey = "".concat(action, "|").concat(signature);
765
+ now = Date.now();
766
+ lastReportedAt = this._standaloneNodeReaperAlertTimes.get(alertKey);
767
+ if (lastReportedAt && (now - lastReportedAt) < this._standaloneNodeReaperAlertWindowMs) {
768
+ return [2 /*return*/];
693
769
  }
770
+ _b.label = 1;
771
+ case 1:
772
+ _b.trys.push([1, 3, , 4]);
773
+ return [4 /*yield*/, this.reportServerError("SERVER - Standalone Node Reaper ".concat(action, " process - ").concat(((_a = resolveio_server_app_1.ResolveIOServer.getServerConfig()) === null || _a === void 0 ? void 0 : _a['CLIENT_NAME']) || resolveio_server_app_1.ResolveIOServer.getClientName()), crypto.randomUUID(), __assign(__assign({}, this.createStandaloneNodeReaperDetails(proc, reason, action)), { host: os.hostname(), workerIndex: process.env.WORKER_INDEX || null, workerInstance: process.env.NODE_APP_INSTANCE || null, dryRun: this._standaloneNodeReaperDryRun, alertWindowMs: this._standaloneNodeReaperAlertWindowMs }), {
774
+ context: 'standaloneNodeReaper',
775
+ action: action,
776
+ reason: reason,
777
+ signature: signature
778
+ }, 'warning')];
779
+ case 2:
780
+ _b.sent();
781
+ this._standaloneNodeReaperAlertTimes.set(alertKey, now);
694
782
  return [3 /*break*/, 4];
695
783
  case 3:
696
- this._standaloneNodeReaperRunning = false;
697
- return [7 /*endfinally*/];
784
+ error_7 = _b.sent();
785
+ console.error(new Date(), '[Standalone Node Reaper] alert failed', {
786
+ action: action,
787
+ pid: proc.pid,
788
+ error: (error_7 === null || error_7 === void 0 ? void 0 : error_7['message']) || error_7
789
+ });
790
+ return [3 /*break*/, 4];
698
791
  case 4: return [2 /*return*/];
699
792
  }
700
793
  });
@@ -1164,7 +1257,7 @@ var ResolveIOMainServer = /** @class */ (function () {
1164
1257
  return;
1165
1258
  }
1166
1259
  this._app.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
1167
- var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken, error_6;
1260
+ var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken, error_8;
1168
1261
  var _a, _b, _c;
1169
1262
  return __generator(this, function (_d) {
1170
1263
  switch (_d.label) {
@@ -1247,11 +1340,11 @@ var ResolveIOMainServer = /** @class */ (function () {
1247
1340
  next();
1248
1341
  return [3 /*break*/, 4];
1249
1342
  case 3:
1250
- error_6 = _d.sent();
1251
- console.error(new Date(), '[DynamicAppGateway] middleware failure', error_6);
1343
+ error_8 = _d.sent();
1344
+ console.error(new Date(), '[DynamicAppGateway] middleware failure', error_8);
1252
1345
  res.status(500).send(JSON.stringify({
1253
1346
  error: true,
1254
- result: (error_6 === null || error_6 === void 0 ? void 0 : error_6.message) || 'Dynamic app gateway error.'
1347
+ result: (error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || 'Dynamic app gateway error.'
1255
1348
  }));
1256
1349
  return [3 /*break*/, 4];
1257
1350
  case 4: return [2 /*return*/];
@@ -2077,7 +2170,7 @@ var ResolveIOMainServer = /** @class */ (function () {
2077
2170
  // Do not block message handler registration on DB write; this avoids losing
2078
2171
  // very-early subscription messages sent immediately after websocket open.
2079
2172
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
2080
- var error_7;
2173
+ var error_9;
2081
2174
  return __generator(this, function (_a) {
2082
2175
  switch (_a.label) {
2083
2176
  case 0:
@@ -2087,13 +2180,13 @@ var ResolveIOMainServer = /** @class */ (function () {
2087
2180
  _a.sent();
2088
2181
  return [3 /*break*/, 3];
2089
2182
  case 2:
2090
- error_7 = _a.sent();
2091
- console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_7);
2183
+ error_9 = _a.sent();
2184
+ console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_9);
2092
2185
  this.logConnectDebug('Create logged-in user failed', {
2093
2186
  id_socket: ws['id_socket'],
2094
2187
  id_user: ws['id_user'],
2095
2188
  user: ws['user'],
2096
- error: (error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || error_7
2189
+ error: (error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || error_9
2097
2190
  });
2098
2191
  return [3 /*break*/, 3];
2099
2192
  case 3: return [2 /*return*/];
@@ -2420,6 +2513,12 @@ var ResolveIOMainServer = /** @class */ (function () {
2420
2513
  var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_DRY_RUN) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_DRY_RUN'];
2421
2514
  return this.parseDebugFlag(raw);
2422
2515
  };
2516
+ ResolveIOMainServer.prototype.resolveStandaloneNodeReaperAlertWindowMs = function () {
2517
+ var _a, _b, _c;
2518
+ var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
2519
+ var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_ALERT_WINDOW_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_ALERT_WINDOW_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_ALERT_WINDOW_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_ALERT_WINDOW_MS'];
2520
+ return this.parsePositiveInt(raw, this._standaloneNodeReaperAlertWindowMs);
2521
+ };
2423
2522
  ResolveIOMainServer.prototype.isPm2ManagedRuntime = function () {
2424
2523
  return Boolean(process.env.pm_id
2425
2524
  || process.env.PM2_HOME
@@ -2443,6 +2542,19 @@ var ResolveIOMainServer = /** @class */ (function () {
2443
2542
  var normalized = String(value).trim();
2444
2543
  return normalized.length ? normalized : null;
2445
2544
  };
2545
+ ResolveIOMainServer.prototype.shouldStartCronManagerForWorker = function () {
2546
+ var workerIndex = this.normalizeWorkerSelectorValue(process.env.WORKER_INDEX);
2547
+ var workerInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE) || '0';
2548
+ var hasExplicitServerManagerOwner = process.env.SERVER_MANAGER_WORKER_INDEX !== undefined
2549
+ || process.env.SERVER_MANAGER_WORKER_INSTANCE !== undefined
2550
+ || process.env.SERVER_MANAGER_NODE_APP_INSTANCE !== undefined;
2551
+ if (!hasExplicitServerManagerOwner) {
2552
+ return workerIndex === '0';
2553
+ }
2554
+ var serverManagerWorkerIndex = this.normalizeWorkerSelectorValue(process.env.SERVER_MANAGER_WORKER_INDEX) || '0';
2555
+ var serverManagerWorkerInstance = this.normalizeWorkerSelectorValue(process.env.SERVER_MANAGER_WORKER_INSTANCE || process.env.SERVER_MANAGER_NODE_APP_INSTANCE) || '0';
2556
+ return workerIndex === serverManagerWorkerIndex && workerInstance === serverManagerWorkerInstance;
2557
+ };
2446
2558
  ResolveIOMainServer.prototype.parseWorkerSelector = function (value) {
2447
2559
  if (value === null || value === undefined) {
2448
2560
  return null;
@@ -3303,7 +3415,7 @@ var ResolveIOMainServer = /** @class */ (function () {
3303
3415
  });
3304
3416
  }
3305
3417
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
3306
- var error_8;
3418
+ var error_10;
3307
3419
  return __generator(this, function (_a) {
3308
3420
  switch (_a.label) {
3309
3421
  case 0:
@@ -3313,8 +3425,8 @@ var ResolveIOMainServer = /** @class */ (function () {
3313
3425
  _a.sent();
3314
3426
  return [3 /*break*/, 3];
3315
3427
  case 2:
3316
- error_8 = _a.sent();
3317
- console.error(new Date(), 'AI execution run failed:', error_8);
3428
+ error_10 = _a.sent();
3429
+ console.error(new Date(), 'AI execution run failed:', error_10);
3318
3430
  return [3 /*break*/, 3];
3319
3431
  case 3: return [2 /*return*/];
3320
3432
  }