PR #12060 CodeRabbit follow-up: reserve leapMeterId before validation (BOLT-1244)
completedCodeRabbit CHANGES_REQUESTED on dd6513f at 2026-06-11T10:19:55Z. Major finding at domains/program/src/services/leap/interval/resolveDeviceMapping.ts:44: duplicate-winner rule applied too late. seenLeapMeterIds is currently marked only after validation succeeds (~line 102), so if the lowest-id enrollment fails validation, a later duplicate enrollment can produce a mapping instead of a duplicate error. Slava in active-merge mode (10:22Z merge of previous round). In-thread DM sent at 10:25Z (Slack ts 1781173517.858519). Worktree mono-bolt-1244 at dd6513f, branch BOLT-1244/domains-program.
FIX: reserve the leapMeterId in seenLeapMeterIds immediately after the duplicate check passes (before any validation), so that even if the current enrollment fails downstream validation, any subsequent enrollment with the same leapMeterId will still hit the duplicate-error path. CodeRabbit's diff suggestion: insert `seenLeapMeterIds.add(leapMeterId);` right after the duplicate-check `if (seenLeapMeterIds.has(...)) { errors.push(...); continue; }` block, then remove the duplicate add at line 102 if present.
Post-Push Protocol (mandatory): yarn workspace @texture/program lint, tsc --noEmit, jest scoped to resolveDeviceMapping.test.ts (or whatever covers this). Add regression test: enrollment A with leapMeterId=X fails validation, enrollment B with leapMeterId=X (higher id) succeeds validation — assert that B produces a buildDuplicateLeapMeterIdError instead of a successful mapping.
Thread DM in 1781171795.592929 (Slava's assistant thread). Post ONE status DM AFTER first relevant CI returns (per HEARTBEAT.md post-CI-only rule). ASSUME-IMMEDIATE-MERGE applies.
Event Timeline
created
status_change
queued → in_progress
failed
lease expired — re-queued for retry
in_progress → queued
status_change
queued → completed