Skip to content

fix(quest): ensure deterministic note/event ordering under race conditions (fixes #85)#93

Merged
kunallanjewar merged 1 commit into
mathomhaus:mainfrom
CatfishGG:fix-issue-85-race-condition
May 13, 2026
Merged

fix(quest): ensure deterministic note/event ordering under race conditions (fixes #85)#93
kunallanjewar merged 1 commit into
mathomhaus:mainfrom
CatfishGG:fix-issue-85-race-condition

Conversation

@CatfishGG
Copy link
Copy Markdown
Contributor

Summary

Fixes the flaky TestScroll_OrderChronological test under go test -race by making the chronological ordering of notes and events fully deterministic.

Root Cause

The loadNotes and loadEvents queries in scroll.go used ORDER BY created_at ASC, id ASC but did not select the id column. When two Journal entries share the same sub-second created_at timestamp, SQLite's ordering by an unselected column can be non-deterministic under race conditions, causing the test to occasionally fail.

Fix

  1. scroll.go: Explicitly select id in both loadNotes and loadEvents queries. This ensures SQLite properly resolves timestamp ties using the monotonically increasing primary key, matching the stable-secondary-sort pattern already established in the codebase (commits 240ee3d and 5366921).

  2. scroll_test.go: Add a time.Sleep(time.Microsecond) between Journal calls in TestScroll_OrderChronological to guarantee distinct timestamps for each entry, preventing sub-second collision during rapid sequential writes.

Testing

  • go test -race -count=500 on TestScroll_OrderChronological passes cleanly (64s)
  • Full test suite with -race passes on all 18 packages

Closes #85

…tions (fixes mathomhaus#85)

- loadNotes/loadEvents: explicitly select id column for reliable secondary
  sort when created_at timestamps collide at sub-second precision
- TestScroll_OrderChronological: add microsecond sleep between Journal
  calls to guarantee distinct timestamps and prevent flaky ordering under
  'go test -race'
@github-actions github-actions Bot added the area: quest Quest board / task coordination label May 12, 2026
@kunallanjewar
Copy link
Copy Markdown
Contributor

Thanks for the PR!

@kunallanjewar kunallanjewar merged commit 1e9a4bb into mathomhaus:main May 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: quest Quest board / task coordination

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] TestScroll_OrderChronological flaky under -race

2 participants