Skip to content

Keep the audit log in the order events happened when the clock steps back - #290

Merged
gccody merged 1 commit into
mainfrom
fix/audit-order-clock-steps
Nov 12, 2026
Merged

gccody merged 1 commit into
mainfrom
fix/audit-order-clock-steps

Conversation

@gccody

@gccody gccody commented Nov 12, 2026

Copy link
Copy Markdown
Owner

The audit log lists events newest first by created_at, then by ID. created_at came from one read of the wall clock, and the UUIDv7 ID from a second read. When the clock steps back, as WSL's does by whole seconds under load (and as NTP can on a real server), later events got earlier times and the log came back out of order.

That was the cause of two flaky server tests:

  • reports::reports_need_their_permissions_and_are_audited
  • alerts::channels_email_users_and_roles_and_test_webhooks

In one failing run, three events were stamped 14 s before the event that came ahead of them, though their IDs were still in order.

The fix: audit::record now uses the time inside the event's ID as its created_at. The uuid crate keeps a process's v7 IDs increasing even when the clock goes back, so time and ID now agree and the order holds.

Testing

  • Stress run, 6 at a time on SQLite and Postgres:
    • before: the reports test failed 8 of 54 runs, the alerts test 2 of 24
    • after: 0 of 48 for each
  • Full server suite on SQLite and PostgreSQL 16: 719 passed. The applications file timed out opening SQLite once while the machine was stalled on disk, and passed on rerun.
  • clippy -D warnings and fmt are clean.

@gccody
gccody enabled auto-merge (squash) November 12, 2026 00:56
@gccody
gccody merged commit b80f84b into main Nov 12, 2026
9 checks passed
@gccody
gccody deleted the fix/audit-order-clock-steps branch November 12, 2026 01:12
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