-
Notifications
You must be signed in to change notification settings - Fork 4
fix(resume-library): add deterministic tiebreaker for same-millisecond saves #908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
24f4b44
811a39f
b0812a9
a6cfae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,6 +169,18 @@ export async function putRecordIntoExisting<T extends StoredRecord>( | |
| return putRecordVia(getExistingDB, store, record, options); | ||
| } | ||
|
|
||
| let lastTimestamp = 0; | ||
|
|
||
| function monotonicNow(): number { | ||
| const now = Date.now(); | ||
| if (now <= lastTimestamp) { | ||
| lastTimestamp += 1; | ||
| return lastTimestamp; | ||
| } | ||
| lastTimestamp = now; | ||
| return now; | ||
| } | ||
|
|
||
| async function putRecordVia<T extends StoredRecord>( | ||
| opener: () => Promise<IDBPDatabase<any>>, | ||
| store: StoreName, | ||
|
|
@@ -177,7 +189,7 @@ async function putRecordVia<T extends StoredRecord>( | |
| options: { touch?: boolean } = {}, | ||
| ): Promise<T> { | ||
| const db = await looseDB(opener); | ||
| const now = Date.now(); | ||
| const now = monotonicNow(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secondary — Concrete failure: several jobs saved back-to-back under contention drift Suggest routing |
||
| const existing = (await db.get(store, record.id)) as T | undefined; | ||
| const written = { | ||
| ...record, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking — this test doesn't verify order. Reverting both fix lines (
monotonicNow()→Date.now()incrud.ts, and theid.localeComparetiebreak → plainb.savedAt - a.savedAthere) and re-running this test 5/5 times, it still passes — it only checkstoHaveLength(5)and unique filenames, never the actual order. So it can't catch a regression to the fix it's named for, and #907's AC1 ("deterministic, correct newest-first order... when two records share the samesavedAtmillisecond") stays unverified by anything in the suite.Suggest forcing a real tie — mirror what
backup.ts'simportAllalready does: twoputRecord(..., { touch: false })calls with an explicit, identicalupdatedAt— then assertlist.map(e => e.id)matches the id-sorted order the comparator produces. That also gives thea.id.localeCompare(b.id)tiebreaker its first real test.