{"record":{"id":"9bfa4434f7801145","repo":"apify/crawlee","slug":"request-id-does-not-match-its-uniquekey","errorCode":null,"errorMessage":"Request ID does not match its uniqueKey.","messagePattern":"Request ID does not match its uniqueKey\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/memory-storage/resource-clients/request-queue.ts","lineNumber":495,"sourceCode":"        this.accessedAt = new Date();\n\n        if (hasBeenModified) {\n            this.modifiedAt = new Date();\n        }\n    }\n\n    private jsonToRequest<T>(requestJson?: string): T | undefined {\n        if (!requestJson) return undefined;\n        const request = JSON.parse(requestJson);\n        return purgeNullsFromObject(request);\n    }\n\n    private createInternalRequest(request: storage.RequestSchema, forefront?: boolean): InternalRequest {\n        const orderNo = this.calculateOrderNo(request, forefront);\n        const id = uniqueKeyToRequestId(request.uniqueKey);\n\n        if (request.id && request.id !== id) {\n            throw new Error('Request ID does not match its uniqueKey.');\n        }\n\n        const json = JSON.stringify({ ...request, id });\n        return {\n            id,\n            json,\n            method: request.method,\n            orderNo,\n            retryCount: request.retryCount ?? 0,\n            uniqueKey: request.uniqueKey,\n            url: request.url,\n        };\n    }\n\n    private calculateOrderNo(request: storage.RequestSchema, forefront?: boolean) {\n        if (request.handledAt) return null;\n\n        const timestamp = Date.now();","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/memory-storage/resource-clients/request-queue.ts#L477-L513","documentation":"The request queue stores requests keyed by a uniqueKey, and derives the internal request ID deterministically from that uniqueKey via uniqueKeyToRequestId. When a caller supplies a RequestSchema whose explicit `id` does not match the ID recomputed from its `uniqueKey`, the queue refuses the write because the stored record would be inconsistent (lookup by id and by uniqueKey would disagree).","triggerScenarios":"Calling queue.addRequest() (via requestModel -> createInternalRequest) with a request object that has both `id` and `uniqueKey` set, where `id !== uniqueKeyToRequestId(uniqueKey)` — e.g. reusing an ID from a different request, or hand-crafting a request with an id not derived from the uniqueKey.","commonSituations":"Manually constructing Request objects with copied/stale IDs; migrating requests between queues while keeping old ids; generating uniqueKey after assigning id; deserializing requests whose uniqueKey was changed but id was not recomputed.","solutions":["Remove the explicit `id` field and let createInternalRequest compute it from the uniqueKey.","Set `id` to the value returned by uniqueKeyToRequestId(request.uniqueKey).","If the uniqueKey changed, recompute the id (or drop it) before calling addRequest.","Verify you are not reusing request objects across queues with different uniqueKey normalization."],"exampleFix":"// before\nawait queue.addRequest({ id: 'abc-123', uniqueKey: 'https://example.com', url: 'https://example.com' });\n// after\nawait queue.addRequest({ uniqueKey: 'https://example.com', url: 'https://example.com' }); // id derived automatically","handlingStrategy":"validation","validationCode":"import { uniqueKeyToRequestId } from '@crawlee/core';\nif (request.id && request.id !== uniqueKeyToRequestId(request.uniqueKey)) {\n  throw new Error(`id ${request.id} does not match uniqueKey ${request.uniqueKey}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await queue.addRequest(request);\n} catch (err) {\n  if ((err as Error).message.includes('does not match its uniqueKey')) {\n    delete request.id;\n    await queue.addRequest(request);\n  } else throw err;\n}","preventionTips":["Never set `id` manually on requests added to a queue.","Recompute or drop `id` whenever `uniqueKey` changes.","Centralize request construction in one factory function.","Strip ids when migrating requests between queues."],"tags":["request-queue","data-integrity","storage"],"backgroundTag":"request-id-uniquekey-mismatch","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}