-- stale duplicate 삭제 (processing 10분+ 방치 + 같은 doc/stage에 pending 존재)
DELETE FROM processing_queue a
USING processing_queue b
WHERE a.document_id = b.document_id
  AND a.stage = b.stage
  AND a.status = 'processing'
  AND a.started_at < NOW() - INTERVAL '10 minutes'
  AND b.status = 'pending'
