-- Keep one in-flight "详情替换" batch per identical submission. A double click or a -- second browser tab can no longer queue (and bill) the same images twice, while a -- different card selection - for example re-running one finished card - still starts -- its own batch. CREATE UNIQUE INDEX IF NOT EXISTS "CanvasImageTask_detail_batch_submission_key" ON "CanvasImageTask" ("userId", (request ->> 'submissionKey')) WHERE request ->> 'taskKind' = 'agent-detail-replacement-batch' AND request ->> 'submissionKey' IS NOT NULL AND status IN ('pending', 'running');