Skip to content

Order trimmed analyses and same-time notes by the order written - #22

Merged
tdwd merged 2 commits into
mainfrom
jobs-trim-order
Oct 9, 2026
Merged

tdwd merged 2 commits into
mainfrom
jobs-trim-order

Conversation

@tdwd

@tdwd tdwd commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Two fixes for the same cause: back-to-back time.Now calls can return the same time. On the machine this was found on, about 3% of consecutive calls returned a time no later than the one before.

  1. Trim a session's analyses by the order they started. trimJobs sorted by Started, so with equal times the job that survived depended on map iteration order. TestJobsAreBounded failed now and then because of it. Jobs now carry the number their ID is made from, and trimming sorts by that.
  2. Keep a log's order for notes that share a time. Notes sorted the merged logs with an unstable sort, so same-time notes from one log could come back reordered once a connected log was merged in. Now sort.SliceStable.

Each commit's new test fails against the old code: 5 of 5 runs for the jobs test, every run for the notes test.

tdwd added 2 commits October 9, 2026 16:05
trimJobs sorted a session's jobs by Started to drop the oldest. Two
time.Now calls back to back can return the same time, and when two jobs
did, the sort left which one survived to the map's iteration order.
TestJobsAreBounded then failed now and then, finding the oldest job
still there.

Each job now keeps the number its ID is made from, and trimJobs sorts by
that. The new test gives every job the same Started and checks that the
newest maxJobs survive.
Notes merges the session's log with its connected sessions' logs and
sorts by At. sort.Slice is not stable, so a log's notes that read the
same clock value could come back in a different order from the one they
were written in, once a connected log was merged in. sort.SliceStable
keeps each log's own order for those.
@tdwd
tdwd merged commit 63db251 into main Oct 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant