Skip to content

Commit 8eb5ff0

Browse files
committed
fix(agents): bound media duplicate guard age
1 parent 309fdd9 commit 8eb5ff0

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/agents/image-generation-task-status.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,34 @@ describe("image generation task status", () => {
378378
).toBeUndefined();
379379
});
380380

381+
it("does not keep stale recent starts forever for non-finite maxAgeMs", () => {
382+
const now = Date.now();
383+
recordRecentMediaGenerationTaskStartForSession({
384+
sessionKey: "agent:main",
385+
taskKind: IMAGE_GENERATION_TASK_KIND,
386+
sourcePrefix: "image_generate",
387+
taskId: "task-stale",
388+
runId: "run-stale",
389+
taskLabel: "stale prompt",
390+
requestKey: "image-request:stale",
391+
providerId: "xai",
392+
progressSummary: "Generating stale image",
393+
nowMs: now - 1,
394+
});
395+
396+
expect(
397+
findRecentStartedMediaGenerationTaskForSession({
398+
sessionKey: "agent:main",
399+
taskKind: IMAGE_GENERATION_TASK_KIND,
400+
sourcePrefix: "image_generate",
401+
taskLabel: "stale prompt",
402+
requestKey: "image-request:stale",
403+
maxAgeMs: Number.POSITIVE_INFINITY,
404+
nowMs: now,
405+
}),
406+
).toBeUndefined();
407+
});
408+
381409
it("does not block a distinct prompt from a cached active recent start", () => {
382410
recordRecentMediaGenerationTaskStartForSession({
383411
sessionKey: "agent:main",

src/agents/media-generation-task-status-shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resolveNonNegativeIntegerOption } from "../shared/number-coercion.js";
12
import {
23
normalizeLowercaseStringOrEmpty,
34
normalizeOptionalString,
@@ -220,7 +221,7 @@ export function findRecentStartedMediaGenerationTaskForSession(params: {
220221
return undefined;
221222
}
222223
const nowMs = params.nowMs ?? Date.now();
223-
const maxAgeMs = Math.max(0, Math.floor(params.maxAgeMs));
224+
const maxAgeMs = resolveNonNegativeIntegerOption(params.maxAgeMs, 0);
224225
const taskLabel = normalizeOptionalString(params.taskLabel);
225226
pruneRecentMediaGenerationTaskStarts({ maxAgeMs, nowMs, preserveKey: key });
226227
const entries = recentMediaGenerationTaskStarts.get(key);

0 commit comments

Comments
 (0)