fluxy-bot 0.5.42 → 0.5.44

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": "fluxy-bot",
3
- "version": "0.5.42",
3
+ "version": "0.5.44",
4
4
  "description": "Self-hosted, self-evolving AI agent with its own dashboard.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,10 +11,27 @@ export function getWorkerPort(basePort: number): number {
11
11
  return basePort + 1;
12
12
  }
13
13
 
14
+ let lastSpawnTime = 0;
15
+ let intentionallyStopped = false;
16
+ const STABLE_THRESHOLD = 30_000;
17
+
14
18
  export function spawnWorker(port: number): ChildProcess {
15
19
  const workerPath = path.join(PKG_DIR, 'worker', 'index.ts');
20
+ lastSpawnTime = Date.now();
21
+ intentionallyStopped = false;
22
+
23
+ // Wrap the worker in an inline loader that:
24
+ // 1. Dynamically imports the worker (tsx handles .ts compilation)
25
+ // 2. Adds a keepalive timer so the event loop never drains (fixes exit code 0 under systemd)
26
+ // 3. Catches and logs import errors instead of silently exiting
27
+ const workerUrl = 'file://' + workerPath.replace(/\\/g, '/');
28
+ const wrapper = [
29
+ `import('${workerUrl}')`,
30
+ ` .catch(e => { console.error('[worker] Fatal:', e); process.exit(1); });`,
31
+ `setInterval(() => {}, 60000);`,
32
+ ].join('\n');
16
33
 
17
- child = spawn(process.execPath, ['--import', 'tsx/esm', workerPath], {
34
+ child = spawn(process.execPath, ['--import', 'tsx/esm', '--input-type=module', '-e', wrapper], {
18
35
  cwd: PKG_DIR,
19
36
  stdio: ['ignore', 'pipe', 'pipe'],
20
37
  env: { ...process.env, WORKER_PORT: String(port) },
@@ -29,15 +46,18 @@ export function spawnWorker(port: number): ChildProcess {
29
46
  });
30
47
 
31
48
  child.on('exit', (code) => {
32
- if (code !== 0 && code !== null) {
33
- log.warn(`Worker crashed (code ${code})`);
34
- if (restarts < MAX_RESTARTS) {
35
- restarts++;
36
- log.info(`Restarting worker (${restarts}/${MAX_RESTARTS})...`);
37
- setTimeout(() => spawnWorker(port), 1000);
38
- } else {
39
- log.error('Worker failed too many times. Use Fluxy chat to debug.');
40
- }
49
+ if (intentionallyStopped) return;
50
+
51
+ log.warn(`Worker exited unexpectedly (code ${code})`);
52
+ if (Date.now() - lastSpawnTime > STABLE_THRESHOLD) {
53
+ restarts = 0;
54
+ }
55
+ if (restarts < MAX_RESTARTS) {
56
+ restarts++;
57
+ log.info(`Restarting worker (${restarts}/${MAX_RESTARTS})...`);
58
+ setTimeout(() => spawnWorker(port), 1000 * restarts);
59
+ } else {
60
+ log.error('Worker failed too many times. Use Fluxy chat to debug.');
41
61
  }
42
62
  });
43
63
 
@@ -46,6 +66,7 @@ export function spawnWorker(port: number): ChildProcess {
46
66
  }
47
67
 
48
68
  export function stopWorker(): void {
69
+ intentionallyStopped = true;
49
70
  child?.kill();
50
71
  child = null;
51
72
  }