Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(backoff): no load data skips only the CPU checks, not the limits (#8913)

garrytan261da5b9900f
diff --git a/src/core/backoff.ts b/src/core/backoff.ts
index 0842249ddf..7bdc7fb494 100644
--- a/src/core/backoff.ts
+++ b/src/core/backoff.ts
@@ -5,8 +5,9 @@
* the system. Checks CPU load, memory, and concurrent process count.
*
* Note on os.loadavg(): returns [0,0,0] on Windows. When load data is
- * unavailable (all zeros on non-Linux/macOS), defaults to "proceed" since
- * we can't determine actual load.
+ * unavailable (all zeros on non-Linux/macOS), the CPU load checks are skipped
+ * since we can't determine actual load; the concurrency and memory limits
+ * still apply.
*/
import { loadavg, freemem, totalmem, cpus } from 'os';
@@ -109,11 +110,6 @@ export function shouldProceed(config?: Partial<ThrottleConfig>): ThrottleResult
const load = getLoad();
const memUsed = getMemoryUsage();
- // Windows/unsupported: loadavg returns [0,0,0] — can't determine load, proceed
- if (loadavg()[0] === 0 && loadavg()[1] === 0 && loadavg()[2] === 0) {
- return { proceed: true, delay: 0, reason: 'Load data unavailable (Windows?), proceeding', load: 0, memoryUsed: memUsed };
- }
-
// Concurrent process limit
if (_activeProcesses >= MAX_CONCURRENT) {
return { proceed: false, delay: 5000, reason: `${_activeProcesses} batch processes active (max ${MAX_CONCURRENT})`, load, memoryUsed: memUsed };
@@ -124,6 +120,11 @@ export function shouldProceed(config?: Partial<ThrottleConfig>): ThrottleResult
return { proceed: false, delay: 30000, reason: `Memory ${(memUsed * 100).toFixed(0)}% > ${(cfg.memoryStopPct * 100).toFixed(0)}% threshold`, load, memoryUsed: memUsed };
}
+ // Windows/unsupported: loadavg returns [0,0,0] — can't determine load, skip the CPU checks
+ if (loadavg().every(avg => avg === 0)) {
+ return { proceed: true, delay: 0, reason: 'Load data unavailable (Windows?), proceeding', load: 0, memoryUsed: memUsed };
+ }
+
// CPU load checks
const activeMultiplier = isActiveHours(cfg) ? cfg.activeHoursMultiplier : 1;
diff --git a/test/backoff.test.ts b/test/backoff.test.ts
index cfa5cdee23..c5ff5f8741 100644
--- a/test/backoff.test.ts
+++ b/test/backoff.test.ts
@@ -1,4 +1,5 @@
-import { describe, test, expect, beforeEach } from 'bun:test';
+import { describe, test, expect, beforeEach, spyOn } from 'bun:test';
+import * as os from 'os';
import { shouldProceed, preflight, complete, getThrottleState, _resetForTest } from '../src/core/backoff.ts';
describe('backoff', () => {
@@ -36,6 +37,24 @@ describe('backoff', () => {
expect(blocked.reason).toContain('batch processes active');
});
+ test('#8913: no load data (loadavg all zero, as on Windows) skips only the CPU checks', async () => {
+ const loadavg = spyOn(os, 'loadavg').mockReturnValue([0, 0, 0]);
+ try {
+ const cpuOnly = { loadStopPct: 0, loadSlowPct: 0, memoryStopPct: Infinity };
+ expect(shouldProceed(cpuOnly)).toMatchObject({ proceed: true, delay: 0 });
+ const memoryFull = shouldProceed({ memoryStopPct: 0 });
+ expect(memoryFull.proceed).toBe(false);
+ expect(memoryFull.reason).toContain('Memory');
+ expect(await preflight('a', cpuOnly)).toBe(true);
+ expect(await preflight('b', cpuOnly)).toBe(true);
+ expect(await preflight('c', cpuOnly)).toBe(false);
+ expect(shouldProceed(cpuOnly).reason).toContain('batch processes active');
+ } finally {
+ loadavg.mockRestore();
+ _resetForTest();
+ }
+ });
+
test('complete decrements active process count', async () => {
const cfg = { loadStopPct: Infinity, loadSlowPct: Infinity, memoryStopPct: Infinity };
expect(await preflight('test-1', cfg)).toBe(true);