feat(sync): add deterministic maintenance-thread dedup key

This commit is contained in:
Gabriel Brown
2026-07-11 13:48:49 -04:00
parent 4684617fed
commit c3f73ac656
3 changed files with 69 additions and 1 deletions
@@ -0,0 +1,21 @@
/**
* Pure, deterministic dedup key for maintenance threads.
*
* Derives a stable key from the merge-base + head SHAs so that repeated
* scheduled sync runs against the same upstream state collapse onto a single
* maintenance thread instead of creating a new one each run. NEVER involves
* Date.now()/random — the key must be identical for identical inputs.
*
* Returns `null` when the head SHA is missing/empty (unresolvable head → the
* caller cannot dedup and should SKIP thread creation rather than mint a
* unique key).
*/
export const maintenanceDedupKey = (input: {
mergeBaseSha?: string;
headSha?: string;
}): string | null => {
const head = input.headSha?.trim();
if (!head) return null;
const base = input.mergeBaseSha?.trim() || 'nobase';
return `${base}:${head}`;
};