mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 07:24:59 +00:00
fix(agents): bound media duplicate guard age
This commit is contained in:
@@ -378,6 +378,34 @@ describe("image generation task status", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not keep stale recent starts forever for non-finite maxAgeMs", () => {
|
||||
const now = Date.now();
|
||||
recordRecentMediaGenerationTaskStartForSession({
|
||||
sessionKey: "agent:main",
|
||||
taskKind: IMAGE_GENERATION_TASK_KIND,
|
||||
sourcePrefix: "image_generate",
|
||||
taskId: "task-stale",
|
||||
runId: "run-stale",
|
||||
taskLabel: "stale prompt",
|
||||
requestKey: "image-request:stale",
|
||||
providerId: "xai",
|
||||
progressSummary: "Generating stale image",
|
||||
nowMs: now - 1,
|
||||
});
|
||||
|
||||
expect(
|
||||
findRecentStartedMediaGenerationTaskForSession({
|
||||
sessionKey: "agent:main",
|
||||
taskKind: IMAGE_GENERATION_TASK_KIND,
|
||||
sourcePrefix: "image_generate",
|
||||
taskLabel: "stale prompt",
|
||||
requestKey: "image-request:stale",
|
||||
maxAgeMs: Number.POSITIVE_INFINITY,
|
||||
nowMs: now,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not block a distinct prompt from a cached active recent start", () => {
|
||||
recordRecentMediaGenerationTaskStartForSession({
|
||||
sessionKey: "agent:main",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolveNonNegativeIntegerOption } from "../shared/number-coercion.js";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
@@ -220,7 +221,7 @@ export function findRecentStartedMediaGenerationTaskForSession(params: {
|
||||
return undefined;
|
||||
}
|
||||
const nowMs = params.nowMs ?? Date.now();
|
||||
const maxAgeMs = Math.max(0, Math.floor(params.maxAgeMs));
|
||||
const maxAgeMs = resolveNonNegativeIntegerOption(params.maxAgeMs, 0);
|
||||
const taskLabel = normalizeOptionalString(params.taskLabel);
|
||||
pruneRecentMediaGenerationTaskStarts({ maxAgeMs, nowMs, preserveKey: key });
|
||||
const entries = recentMediaGenerationTaskStarts.get(key);
|
||||
|
||||
Reference in New Issue
Block a user