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): release settled retry timeout timers

Rudy Celekli450fe0a8c0e3
diff --git a/v3/@claude-flow/shared/src/resilience/retry-timeout-cleanup.test.ts b/v3/@claude-flow/shared/src/resilience/retry-timeout-cleanup.test.ts
new file mode 100644
index 0000000000..a3808ace77
--- /dev/null
+++ b/v3/@claude-flow/shared/src/resilience/retry-timeout-cleanup.test.ts
@@ -0,0 +1,40 @@
+import { afterEach, describe, it, expect, vi } from 'vitest';
+import { retry } from './retry.js';
+afterEach(() => vi.useRealTimers());
+describe('retry timeout lifetime', () => {
+ it('does not keep a success timer alive after an attempt settles', async () => {
+ vi.useFakeTimers();
+ const result = await retry(async () => 42, {
+ maxAttempts: 1,
+ timeout: 30000,
+ });
+ expect(result.success).toBe(true);
+ expect(result.result).toBe(42);
+ expect(vi.getTimerCount()).toBe(0);
+ });
+ it('releases timers for rejected attempts without suppressing their errors', async () => {
+ vi.useFakeTimers();
+ const err = new Error('no');
+ const result = await retry(
+ async () => {
+ throw err;
+ },
+ { maxAttempts: 1 },
+ );
+ expect(result.success).toBe(false);
+ expect(result.errors).toEqual([err]);
+ expect(vi.getTimerCount()).toBe(0);
+ });
+ it('still bounds a pending operation and reports the timeout', async () => {
+ vi.useFakeTimers();
+ const promise = retry(() => new Promise(() => {}), {
+ maxAttempts: 1,
+ timeout: 10,
+ });
+ await vi.advanceTimersByTimeAsync(10);
+ const result = await promise;
+ expect(result.success).toBe(false);
+ expect(result.errors[0].message).toContain('timed out');
+ expect(vi.getTimerCount()).toBe(0);
+ });
+});
diff --git a/v3/@claude-flow/shared/src/resilience/retry.ts b/v3/@claude-flow/shared/src/resilience/retry.ts
index 8d43790bbd..e3cce1bd9a 100644
--- a/v3/@claude-flow/shared/src/resilience/retry.ts
+++ b/v3/@claude-flow/shared/src/resilience/retry.ts
@@ -174,13 +174,18 @@ export function withRetry<T extends (...args: unknown[]) => Promise<unknown>>(
* Execute with timeout
*/
async function withTimeout<T>(promise: Promise<T>, timeout: number, attempt: number): Promise<T> {
+ let timer: ReturnType<typeof setTimeout> | undefined;
const timeoutPromise = new Promise<never>((_, reject) => {
- setTimeout(() => {
+ timer = setTimeout(() => {
reject(new Error(`Attempt ${attempt} timed out after ${timeout}ms`));
}, timeout);
});
- return Promise.race([promise, timeoutPromise]);
+ try {
+ return await Promise.race([promise, timeoutPromise]);
+ } finally {
+ if (timer !== undefined) clearTimeout(timer);
+ }
}
/**