{"record":{"id":"24db861e84833be0","repo":"santifer/career-ops","slug":"tracker-addition-num-already-used-assigni","errorCode":null,"errorMessage":"⚠️  Tracker #${addition.num} already used; assigning #${entryNum} to ${addition.company} — ${addition.role}. Report link remains ${addition.report}.","messagePattern":"⚠️  Tracker #(.+?) already used; assigning #(.+?) to (.+?) — (.+?)\\. Report link remains (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"merge-tracker.mjs","lineNumber":1708,"sourceCode":"      console.error(\n        `❌ ${file}: could not locate tracker row #${duplicate.num} ` +\n        `(${duplicate.company} — ${duplicate.role}) to update; this evaluation was NOT merged.`,\n      );\n      failedAdditions.push(file);\n    }\n  } else {\n    // New entry - preserve the TSV's reserved ID whenever it is actually\n    // free. Parallel workers can finish out of order, so a valid reservation\n    // may be lower than the current tracker maximum (#1733). Renumber only on\n    // a real collision, using the next free ID above the current maximum and\n    // warning loudly so report/tracker drift is visible (#1704).\n    let entryNum;\n    if (!usedNumbers.has(addition.num)) {\n      entryNum = addition.num;\n    } else {\n      entryNum = maxNum + 1;\n      while (usedNumbers.has(entryNum)) entryNum++;\n      console.warn(\n        `⚠️  Tracker #${addition.num} already used; assigning #${entryNum} to ` +\n        `${addition.company} — ${addition.role}. Report link remains ${addition.report}.`,\n      );\n    }\n    usedNumbers.add(entryNum);\n    if (entryNum > maxNum) maxNum = entryNum;\n\n    const pdf = reportNum && pdfIndex.has(String(reportNum)) ? '✅' : addition.pdf;\n    const newLine = buildRow({\n      num: entryNum, date: addition.date, company: addition.company, role: addition.role,\n      via: addition.via || '—',\n      location: addition.location || '—',\n      score: addition.score, status: addition.status, pdf,\n      report: addition.report, notes: addition.notes,\n      // Write the key on the way in. Backfill is the one-time EXPAND phase for\n      // rows that predate the column; a row added today must carry its own URL\n      // or Pass 0 can never match it and dedup stays fuzzy-only for new work.\n      url: addition.url || '',","sourceCodeStart":1690,"sourceCodeEnd":1726,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/merge-tracker.mjs#L1690-L1726","documentation":"When a tracker addition's requested number (addition.num) is already occupied by an existing row, merge-tracker.mjs does not overwrite it: it assigns the next free number (maxNum+1, skipping used ones) and warns. The report link stays pointing at the original report file — only the tracker row number differs.","triggerScenarios":"Two workers or two merge runs both computed/claimed the same tracker # (e.g. both used max+1 without coordination), or the TSV's num collides with a row added since the TSV was generated.","commonSituations":"Parallel batch fan-outs that skipped reserve-report-num.mjs and each computed max+1 (#749 race); re-running a merge after another addition claimed the number; a hand-written TSV reusing an existing row number.","solutions":["Confirm the newly numbered row's report link still points at the intended report in reports/ — content is intact, only the # changed.","For parallel workers, reserve ranges first with node reserve-report-num.mjs --count N and hand each worker its own number.","Re-run node merge-tracker.mjs — merges are idempotent and renumbering warnings resolve once numbers are unique.","Fix the generator to derive num from a reserved range instead of max+1."],"exampleFix":"// before (race)\nconst num = maxExisting + 1;\n// after\n$ node reserve-report-num.mjs --count 4\n// prints e.g. 042-045; hand one number to each worker","handlingStrategy":"validation","validationCode":"const used = new Set(existingRows.map(r => r.num));\nif (used.has(num)) console.warn(`#${num} already used — reserve a number with node reserve-report-num.mjs`);","typeGuard":"const isFreeNumber = (num, used) => !used.has(num);","tryCatchPattern":null,"preventionTips":["Reserve report/tracker number ranges with node reserve-report-num.mjs before parallel fan-outs.","Never let workers compute max+1 themselves (#749 race).","Run merge-tracker.mjs from a single serialized step in the pipeline.","After a renumbering warning, verify the row's report link points at the right report."],"tags":["numbering","race-condition","idempotency"],"backgroundTag":"file-already-exists","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}