Gateway: bound agent run sequence tracking

This commit is contained in:
Vignesh Natarajan
2026-02-14 17:50:49 -08:00
parent 451deb066f
commit fc8f59261a
5 changed files with 68 additions and 1 deletions

View File

@@ -73,6 +73,7 @@ export function startGatewayMaintenanceTimers(params: {
// dedupe cache cleanup
const dedupeCleanup = setInterval(() => {
const AGENT_RUN_SEQ_MAX = 10_000;
const now = Date.now();
for (const [k, v] of params.dedupe) {
if (now - v.ts > DEDUPE_TTL_MS) {
@@ -86,6 +87,18 @@ export function startGatewayMaintenanceTimers(params: {
}
}
if (params.agentRunSeq.size > AGENT_RUN_SEQ_MAX) {
const excess = params.agentRunSeq.size - AGENT_RUN_SEQ_MAX;
let removed = 0;
for (const runId of params.agentRunSeq.keys()) {
params.agentRunSeq.delete(runId);
removed += 1;
if (removed >= excess) {
break;
}
}
}
for (const [runId, entry] of params.chatAbortControllers) {
if (now <= entry.expiresAtMs) {
continue;