{"record":{"id":"16b1cc55eab9b587","repo":"santifer/career-ops","slug":"no-safe-report-number-range-remains","errorCode":null,"errorMessage":"No safe report-number range remains","messagePattern":"No safe report-number range remains","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"critical","filePath":"reserve-report-num.mjs","lineNumber":181,"sourceCode":"  mkdirSync(reportsDir, { recursive: true });\n\n  const lock = await acquireTrackerLock(trackerLockDirFor(trackerPath), {\n    timeoutMs: Number(process.env.CAREER_OPS_TRACKER_LOCK_TIMEOUT_MS) || 60_000,\n    retryMs: Number(process.env.CAREER_OPS_TRACKER_LOCK_RETRY_MS) || 75,\n    staleMs: Number(process.env.CAREER_OPS_TRACKER_LOCK_STALE_MS) || 10 * 60_000,\n    tracker: trackerPath,\n    ...options.lockOptions,\n  });\n\n  try {\n    let occupied = collectOccupied(reportsDir, trackerPath);\n    let base = highestNumber(occupied) + 1;\n    const token = randomUUID();\n\n    for (let tries = 0; tries < MAX_RETRIES; tries++) {\n      const end = base + (count - 1);\n      if (!Number.isSafeInteger(base) || !Number.isSafeInteger(end)) {\n        throw new RangeError('No safe report-number range remains');\n      }\n      const claimed = [];\n      let failedAt = null;\n      for (let num = base; num <= end; num++) {\n        if (claimSlot(reportsDir, num, occupied, token)) {\n          claimed.push(num);\n        } else {\n          failedAt = num;\n          break;\n        }\n      }\n      if (failedAt == null) {\n        Object.defineProperty(claimed, RESERVATION_TOKEN, { value: token });\n        return claimed;\n      }\n\n      for (const num of claimed) releaseSlot(reportsDir, num, { token });\n      occupied = collectOccupied(reportsDir, trackerPath);","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/reserve-report-num.mjs#L163-L199","documentation":"Inside the reservation retry loop, the code checks that both `base` (the starting ID) and `end` (base + count - 1) are safe integers before attempting to claim slots. If either exceeds Number.MAX_SAFE_INTEGER (~9 quadrillion), it throws a RangeError. This is an overflow guard — in practice it is effectively unreachable because the reports directory would be impossibly large.","triggerScenarios":"highestNumber(occupied) returning a value near Number.MAX_SAFE_INTEGER, then base = that + 1 overflowing; or count being large enough that base + count - 1 overflows. This requires billions of report files to exist.","commonSituations":"This error is not realistically hit in normal operation. It could theoretically surface if `occupied` collection logic were corrupted to return artificially huge numbers (e.g., parsing a sentinel filename with a huge embedded number), or in a long-running test that mocks highestNumber().","solutions":["Inspect the reports/ directory for corrupted sentinel files with unexpectedly large numbers in their names and remove them.","If this appears in tests, check that mocks for highestNumber/collectOccupied return realistic values.","As a guard, cap base before the loop: if (base > 1_000_000) throw new Error('report numbering corrupted — inspect reports/ dir').","Audit collectOccupied/highestNumber for any parsing that could inflate numbers."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const occupied = collectOccupied(reportsDir, trackerPath);\nconst base = highestNumber(occupied) + 1;\nif (!Number.isSafeInteger(base) || !Number.isSafeInteger(base + count - 1)) {\n  throw new Error('Report numbering overflow — inspect reports/ for corrupted sentinels');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Periodically audit reports/ for sentinel files with abnormally large numbers in their names.","Treat this error as a data-corruption signal — it should never occur in normal operation."],"tags":["overflow","rangeerror","report-number","defensive-guard"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}