grepmax 0.26.58 → 0.26.60

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.
@@ -60,6 +60,7 @@ const index_config_1 = require("../index/index-config");
60
60
  const autostart_1 = require("../utils/autostart");
61
61
  const kernel_zone_1 = require("../utils/kernel-zone");
62
62
  const logger_1 = require("../utils/logger");
63
+ const resource_budget_1 = require("../utils/resource-budget");
63
64
  const safety_latch_1 = require("../utils/safety-latch");
64
65
  const TASK_TIMEOUT_MS = (() => {
65
66
  var _a;
@@ -135,11 +136,37 @@ class ProcessWorker {
135
136
  // fire for the same crash.
136
137
  this.cleanedUp = false;
137
138
  const memArgs = maxMemoryMb ? [`--max-old-space-size=${maxMemoryMb}`] : [];
138
- this.child = childProcess.fork(modulePath, {
139
- execArgv: [...memArgs, ...execArgv],
140
- env: Object.assign(Object.assign({}, process.env), embeddingEnvironment),
141
- serialization: "advanced",
139
+ this.resourceReservation = resource_budget_1.resourceBudget.reserve(resource_budget_1.WORKER_RESOURCE_RESERVE_MB, "worker");
140
+ try {
141
+ const denied = (0, autostart_1.daemonStartDeniedReason)();
142
+ if (denied)
143
+ throw new Error(denied);
144
+ this.child = childProcess.fork(modulePath, {
145
+ execArgv: [...memArgs, ...execArgv],
146
+ env: Object.assign(Object.assign({}, process.env), embeddingEnvironment),
147
+ serialization: "advanced",
148
+ });
149
+ }
150
+ catch (error) {
151
+ this.resourceReservation.release();
152
+ throw error;
153
+ }
154
+ // Keep the reservation until close, including SIGKILL/timeout paths.
155
+ this.child.once("close", () => {
156
+ try {
157
+ this.resourceReservation.release();
158
+ }
159
+ catch (_a) { }
142
160
  });
161
+ try {
162
+ if (!this.child.pid)
163
+ throw new Error("worker PID unavailable");
164
+ this.resourceReservation.attach(this.child.pid);
165
+ }
166
+ catch (error) {
167
+ this.child.kill("SIGKILL");
168
+ throw error;
169
+ }
143
170
  }
144
171
  }
145
172
  function resolveProcessWorker() {
@@ -365,7 +392,7 @@ class WorkerPool {
365
392
  var _a;
366
393
  return Object.assign(new Error((_a = this.spawnDeniedReason) !== null && _a !== void 0 ? _a : "Worker spawn denied"), { code: "HOST_SAFETY" });
367
394
  }
368
- denySpawn(reason, persist = true) {
395
+ denySpawn(reason, persist = false) {
369
396
  // A pool cannot automatically recover after a failed admission. In
370
397
  // particular, timer/exit callbacks must not retry forks or strand queues.
371
398
  this.spawnDeniedReason = `Worker spawn denied: ${reason}`;
@@ -399,11 +426,11 @@ class WorkerPool {
399
426
  if (process.platform === "darwin") {
400
427
  const memory = (0, kernel_zone_1.probeMemoryPressure)();
401
428
  if (memory.status !== "known" || memory.pressure !== "normal") {
402
- return this.denySpawn(`OS memory pressure ${memory.status === "known" ? memory.pressure : memory.status}; ${(0, kernel_zone_1.formatPressureProbe)(memory)}`);
429
+ return this.denySpawn(`OS memory pressure ${memory.status === "known" ? memory.pressure : memory.status}; ${(0, kernel_zone_1.formatPressureProbe)(memory)}`, memory.status === "known" && memory.pressure === "critical");
403
430
  }
404
431
  const kernel = (0, kernel_zone_1.probeKernelZoneUsage)();
405
432
  if (kernel.status !== "known" || kernel.usage.pressure !== "ok") {
406
- return this.denySpawn(`kernel pressure ${kernel.status === "known" ? kernel.usage.pressure : kernel.status}; ${(0, kernel_zone_1.formatPressureProbe)(kernel)}`);
433
+ return this.denySpawn(`kernel pressure ${kernel.status === "known" ? kernel.usage.pressure : kernel.status}; ${(0, kernel_zone_1.formatPressureProbe)(kernel)}`, kernel.status === "known" && kernel.usage.pressure === "critical");
407
434
  }
408
435
  }
409
436
  if (process.platform === "darwin") {
@@ -411,7 +438,8 @@ class WorkerPool {
411
438
  const freshMemory = (0, kernel_zone_1.probeMemoryPressure)();
412
439
  if (freshMemory.status !== "known" ||
413
440
  freshMemory.pressure !== "normal") {
414
- return this.denySpawn(`OS memory pressure ${freshMemory.status === "known" ? freshMemory.pressure : freshMemory.status}; ${(0, kernel_zone_1.formatPressureProbe)(freshMemory)}`);
441
+ return this.denySpawn(`OS memory pressure ${freshMemory.status === "known" ? freshMemory.pressure : freshMemory.status}; ${(0, kernel_zone_1.formatPressureProbe)(freshMemory)}`, freshMemory.status === "known" &&
442
+ freshMemory.pressure === "critical");
415
443
  }
416
444
  }
417
445
  // Probes are synchronous but another process can quarantine the host
@@ -421,8 +449,10 @@ class WorkerPool {
421
449
  return this.denySpawn(finalQuarantine, false);
422
450
  worker = new ProcessWorker(this.modulePath, this.execArgv, this.embeddingEnvironment, config_1.MAX_WORKER_MEMORY_MB);
423
451
  }
424
- catch (_a) {
425
- return this.denySpawn("host admission or fork failed");
452
+ catch (error) {
453
+ return this.denySpawn(error instanceof Error
454
+ ? error.message
455
+ : "host admission or fork failed");
426
456
  }
427
457
  (0, logger_1.log)("pool", `spawn PID:${worker.child.pid} (${this.workers.length + 1}/${Math.max(1, config_1.CONFIG.WORKER_THREADS)})`);
428
458
  const onMessage = (msg) => {
@@ -625,6 +655,15 @@ class WorkerPool {
625
655
  this.dispatch();
626
656
  return;
627
657
  }
658
+ try {
659
+ resource_budget_1.resourceBudget.check();
660
+ }
661
+ catch (error) {
662
+ this.denySpawn(error instanceof Error
663
+ ? error.message
664
+ : "aggregate resource admission unavailable");
665
+ return;
666
+ }
628
667
  idle.busy = true;
629
668
  idle.pendingTaskId = task.id;
630
669
  idle.busySince = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.26.58",
3
+ "version": "0.26.60",
4
4
  "author": "Robert Owens <78518764+reowens@users.noreply.github.com>",
5
5
  "homepage": "https://github.com/reowens/grepmax",
6
6
  "bugs": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.26.58",
3
+ "version": "0.26.60",
4
4
  "description": "Semantic code search for Claude Code. Automatically indexes your project and provides intelligent search capabilities.",
5
5
  "author": {
6
6
  "name": "Robert Owens",