{"record":{"id":"7cf2be981b96468d","repo":"eyaltoledano/claude-task-master","slug":"invalid-run-id-id2","errorCode":null,"errorMessage":"Invalid run ID: ${id2}","messagePattern":"Invalid run ID: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/common/utils/run-id-generator.ts","lineNumber":121,"sourceCode":" * Can be used as a comparator function for Array.sort().\n *\n * @param {string} id1 - First run ID to compare\n * @param {string} id2 - Second run ID to compare\n * @returns {number} Negative if id1 < id2, positive if id1 > id2, zero if equal\n * @throws {Error} If either run ID is invalid\n *\n * @example\n * compareRunIds('2024-01-15T10:00:00.000Z', '2024-01-15T11:00:00.000Z') // returns negative number\n * ['2024-01-15T14:00:00.000Z', '2024-01-15T10:00:00.000Z'].sort(compareRunIds)\n * // returns ['2024-01-15T10:00:00.000Z', '2024-01-15T14:00:00.000Z']\n */\nexport function compareRunIds(id1: string, id2: string): number {\n\tif (!isValidRunId(id1)) {\n\t\tthrow new Error(`Invalid run ID: ${id1}`);\n\t}\n\n\tif (!isValidRunId(id2)) {\n\t\tthrow new Error(`Invalid run ID: ${id2}`);\n\t}\n\n\t// String comparison works for ISO 8601 timestamps\n\t// because they are lexicographically sortable\n\tif (id1 < id2) return -1;\n\tif (id1 > id2) return 1;\n\treturn 0;\n}\n","sourceCodeStart":103,"sourceCodeEnd":130,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/common/utils/run-id-generator.ts#L103-L130","documentation":"compareRunIds() validates both arguments; this throw fires when the SECOND run ID (id2) fails isValidRunId() — i.e. it is not a valid ISO 8601 UTC timestamp string. id1 was already validated successfully at this point.","triggerScenarios":"compareRunIds(goodId, 'invalid'); sorting arrays where the second element or later entries are corrupt; passing a Date object or number timestamp instead of a string as id2.","commonSituations":"Datasets with one malformed record; passing new Date() (a Date, not a string) as id2; IDs truncated by a fixed-width column or log parsing.","solutions":["Validate id2 with isValidRunId(id2) before calling and regenerate or discard it","Convert Date objects to ISO strings: id2.toISOString()","Filter collections with ids.filter(isValidRunId) before sorting"],"exampleFix":"// before\ncompareRunIds(id1, new Date()); // Date is not a string\n// after\ncompareRunIds(id1, new Date().toISOString());","handlingStrategy":"validation","validationCode":"if (!isValidRunId(id2)) throw new Error(`Cannot compare invalid second run ID: ${id2}`);\nif (id2 instanceof Date) id2 = id2.toISOString();","typeGuard":"function isStringRunId(v: unknown): v is string {\n  return typeof v === 'string' && isValidRunId(v);\n}","tryCatchPattern":"try {\n  return compareRunIds(id1, id2);\n} catch (err) {\n  if (err.message.includes(id2)) {\n    id2 = new Date().toISOString();\n    return compareRunIds(id1, id2);\n  }\n  throw err;\n}","preventionTips":["Convert Date objects with toISOString() before comparing","Sanitize data read from external sources (logs, DB) with isValidRunId","Keep a single ID-format constant shared by generator and validators"],"tags":["validation","run-id","sorting"],"backgroundTag":"invalid-identifier-format","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}