bluera-knowledge 0.12.7 → 0.12.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.
@@ -1,10 +1,34 @@
1
1
  #!/usr/bin/env node
2
+ import { platform } from 'os';
2
3
  import { BackgroundWorker } from './background-worker.js';
3
4
  import { writePidFile, deletePidFile, buildPidFilePath } from './pid-file.js';
4
5
  import { createLogger, shutdownLogger } from '../logging/index.js';
5
- import { createServices } from '../services/index.js';
6
+ import { createServices, destroyServices } from '../services/index.js';
6
7
  import { JobService } from '../services/job.service.js';
7
8
 
9
+ /**
10
+ * Force exit the process to avoid ONNX runtime mutex crash on macOS.
11
+ *
12
+ * On macOS, the ONNX runtime (used by transformers.js for embeddings) has a known
13
+ * bug where static mutex cleanup fails during process exit, causing a crash with:
14
+ * "mutex lock failed: Invalid argument"
15
+ *
16
+ * This doesn't affect job completion - all work is done and persisted before exit.
17
+ * Using SIGKILL bypasses the problematic cleanup code.
18
+ *
19
+ * See: https://github.com/microsoft/onnxruntime/issues/24579
20
+ */
21
+ function forceExitOnMacOS(exitCode: number): void {
22
+ if (platform() === 'darwin') {
23
+ // Give time for any pending I/O to flush
24
+ setTimeout(() => {
25
+ process.kill(process.pid, 'SIGKILL');
26
+ }, 100);
27
+ } else {
28
+ process.exit(exitCode);
29
+ }
30
+ }
31
+
8
32
  const logger = createLogger('background-worker-cli');
9
33
 
10
34
  /**
@@ -90,8 +114,9 @@ async function main(): Promise<void> {
90
114
  }
91
115
 
92
116
  logger.info({ jobId }, 'Job completed successfully');
117
+ await destroyServices(services);
93
118
  await shutdownLogger();
94
- process.exit(0);
119
+ forceExitOnMacOS(0);
95
120
  } catch (error) {
96
121
  // Job service already updated with failure status in BackgroundWorker
97
122
  logger.error(
@@ -108,8 +133,9 @@ async function main(): Promise<void> {
108
133
  );
109
134
  }
110
135
 
136
+ await destroyServices(services);
111
137
  await shutdownLogger();
112
- process.exit(1);
138
+ forceExitOnMacOS(1);
113
139
  }
114
140
  }
115
141
 
@@ -119,5 +145,5 @@ main().catch(async (error: unknown) => {
119
145
  'Fatal error in background worker'
120
146
  );
121
147
  await shutdownLogger();
122
- process.exit(1);
148
+ forceExitOnMacOS(1);
123
149
  });
@@ -59,7 +59,10 @@ describe('BackgroundWorker', () => {
59
59
  details: { storeId: 'test' },
60
60
  });
61
61
 
62
- await expect(worker.executeJob(job.id)).rejects.toThrow('Unknown job type: unknown');
62
+ // Zod validation catches invalid job type when reading the job file
63
+ await expect(worker.executeJob(job.id)).rejects.toThrow(
64
+ /Invalid option.*clone.*index.*crawl/
65
+ );
63
66
  });
64
67
 
65
68
  it('should set job to running status before execution', async () => {