Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(shared): settle synchronously rejected queued bulkhead tasks

Rudy Celekli95020cb8e1b6
diff --git a/v3/@claude-flow/shared/src/resilience/bulkhead-sync-throw.test.ts b/v3/@claude-flow/shared/src/resilience/bulkhead-sync-throw.test.ts
new file mode 100644
index 0000000000..8f44644510
--- /dev/null
+++ b/v3/@claude-flow/shared/src/resilience/bulkhead-sync-throw.test.ts
@@ -0,0 +1,36 @@
+import { describe, it, expect } from 'vitest';
+import { Bulkhead } from './bulkhead.js';
+
+describe('queued bulkhead failures', () => {
+ it('rejects the throwing task and preserves the previous result and remaining capacity', async () => {
+ const bulkhead = new Bulkhead({
+ name: 'test',
+ maxConcurrent: 1,
+ maxQueue: 2,
+ queueTimeout: 100,
+ });
+ let release!: (value: string) => void;
+ const first = bulkhead.execute(
+ () =>
+ new Promise<string>((resolve) => {
+ release = resolve;
+ }),
+ );
+ const failure = new Error('synchronous callback failure');
+ const second = bulkhead.execute(() => {
+ throw failure;
+ });
+ const secondResult = second.catch((error) => error);
+ const third = bulkhead.execute(async () => 'third');
+ release('first');
+ await expect(first).resolves.toBe('first');
+ expect(await secondResult).toBe(failure);
+ await expect(third).resolves.toBe('third');
+ await Promise.resolve();
+ expect(bulkhead.getStats()).toMatchObject({
+ active: 0,
+ queued: 0,
+ completed: 2,
+ });
+ });
+});
diff --git a/v3/@claude-flow/shared/src/resilience/bulkhead.ts b/v3/@claude-flow/shared/src/resilience/bulkhead.ts
index 08cbb731a4..d129a5a94a 100644
--- a/v3/@claude-flow/shared/src/resilience/bulkhead.ts
+++ b/v3/@claude-flow/shared/src/resilience/bulkhead.ts
@@ -222,7 +222,8 @@ export class Bulkhead extends EventEmitter {
this.active++;
this.emit('acquire');
- item.fn()
+ Promise.resolve()
+ .then(() => item.fn())
.then((result) => {
this.completed++;
item.resolve(result);