Skip to content

Commit 3a75b1f

Browse files
committed
fix(agents): evict expired entries from steer rate-limit map
The module-level steerRateLimit map accumulates one entry per unique caller→subagent session pair and never removes them. Over a long-lived process with many subagent interactions, this grows without bound. Prune expired entries (older than 2 s) when the map exceeds 256 keys.
1 parent aedf3ee commit 3a75b1f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/agents/tools/subagents-tool.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const MAX_RECENT_MINUTES = 24 * 60;
5050
const MAX_STEER_MESSAGE_CHARS = 4_000;
5151
const STEER_RATE_LIMIT_MS = 2_000;
5252
const STEER_ABORT_SETTLE_TIMEOUT_MS = 5_000;
53+
const STEER_RATE_LIMIT_MAX_ENTRIES = 256;
5354

5455
const steerRateLimit = new Map<string, number>();
5556

@@ -607,6 +608,15 @@ export function createSubagentsTool(opts?: { agentSessionKey?: string }): AnyAge
607608
}
608609
steerRateLimit.set(rateKey, now);
609610

611+
// Evict expired entries to prevent unbounded growth
612+
if (steerRateLimit.size > STEER_RATE_LIMIT_MAX_ENTRIES) {
613+
for (const [k, ts] of steerRateLimit) {
614+
if (now - ts >= STEER_RATE_LIMIT_MS) {
615+
steerRateLimit.delete(k);
616+
}
617+
}
618+
}
619+
610620
// Suppress announce for the interrupted run before aborting so we don't
611621
// emit stale pre-steer findings if the run exits immediately.
612622
markSubagentRunForSteerRestart(resolved.entry.runId);

0 commit comments

Comments
 (0)