@probelabs/probe 0.6.0-rc221 → 0.6.0-rc222

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": "@probelabs/probe",
3
- "version": "0.6.0-rc221",
3
+ "version": "0.6.0-rc222",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
package/src/delegate.js CHANGED
@@ -194,9 +194,14 @@ class DelegationManager {
194
194
 
195
195
  /**
196
196
  * Process the wait queue - grant slot to next waiting delegation
197
+ * Uses setImmediate to avoid blocking the event loop when resolving promises.
197
198
  * @private
198
199
  */
199
200
  _processQueue(debug = false) {
201
+ // Collect callbacks to invoke after the loop to avoid blocking the event loop
202
+ const toResolve = [];
203
+ const toReject = [];
204
+
200
205
  // Process queue items one at a time when slots are available
201
206
  // Items are only removed when they can be granted or must be rejected
202
207
  while (this.waitQueue.length > 0 && this.globalActive < this.maxConcurrent) {
@@ -216,7 +221,7 @@ class DelegationManager {
216
221
  if (debug) {
217
222
  console.error(`[DelegationManager] Session limit (${this.maxPerSession}) reached for queued item, rejecting`);
218
223
  }
219
- reject(new Error(`Maximum delegations per session (${this.maxPerSession}) reached for session ${parentSessionId}`));
224
+ toReject.push({ reject, error: new Error(`Maximum delegations per session (${this.maxPerSession}) reached for session ${parentSessionId}`) });
220
225
  // Continue to process next item in queue
221
226
  continue;
222
227
  }
@@ -230,7 +235,21 @@ class DelegationManager {
230
235
  console.error(`[DelegationManager] Granted slot from queue (waited ${waitTime}ms). Active: ${this.globalActive}/${this.maxConcurrent}`);
231
236
  }
232
237
 
233
- resolve(true);
238
+ toResolve.push(resolve);
239
+ }
240
+
241
+ // Defer promise resolutions/rejections to next tick to avoid blocking the event loop.
242
+ // This is critical: synchronous resolve()/reject() calls in a tight loop can saturate
243
+ // the microtask queue and prevent other async operations from proceeding.
244
+ if (toResolve.length > 0 || toReject.length > 0) {
245
+ setImmediate(() => {
246
+ for (const resolve of toResolve) {
247
+ resolve(true);
248
+ }
249
+ for (const { reject, error } of toReject) {
250
+ reject(error);
251
+ }
252
+ });
234
253
  }
235
254
  }
236
255
 
@@ -293,6 +312,9 @@ const defaultDelegationManager = new DelegationManager();
293
312
  // Export the class for per-instance usage
294
313
  export { DelegationManager };
295
314
 
315
+ // Default delegation timeout from environment variable or 300 seconds (5 minutes)
316
+ const DEFAULT_DELEGATE_TIMEOUT = parseInt(process.env.DELEGATE_TIMEOUT, 10) || 300;
317
+
296
318
  /**
297
319
  * Delegate a big distinct task to a probe subagent (used automatically by AI agents)
298
320
  *
@@ -309,7 +331,7 @@ export { DelegationManager };
309
331
  *
310
332
  * @param {Object} options - Delegate options
311
333
  * @param {string} options.task - A complete, self-contained task for the subagent. Should be specific and focused on one area of expertise.
312
- * @param {number} [options.timeout=300] - Timeout in seconds (default: 5 minutes)
334
+ * @param {number} [options.timeout] - Timeout in seconds (default: DELEGATE_TIMEOUT env var or 300)
313
335
  * @param {boolean} [options.debug=false] - Enable debug logging
314
336
  * @param {number} [options.currentIteration=0] - Current tool iteration count from parent agent
315
337
  * @param {number} [options.maxIterations=30] - Maximum tool iterations allowed
@@ -335,7 +357,7 @@ export { DelegationManager };
335
357
  */
336
358
  export async function delegate({
337
359
  task,
338
- timeout = 300,
360
+ timeout = DEFAULT_DELEGATE_TIMEOUT,
339
361
  debug = false,
340
362
  currentIteration = 0,
341
363
  maxIterations = 30,