Skip to content

Fix non-deterministic activity log order for same-second events#2427

Open
AltinEtemaj wants to merge 1 commit intolunarphp:1.xfrom
AltinEtemaj:fix/activity-log-sort-order
Open

Fix non-deterministic activity log order for same-second events#2427
AltinEtemaj wants to merge 1 commit intolunarphp:1.xfrom
AltinEtemaj:fix/activity-log-sort-order

Conversation

@AltinEtemaj
Copy link
Copy Markdown

Bug Report

Description

The order timeline in the admin panel displays activity log entries in a non-deterministic order when multiple events occur within the same second. This causes entries like "order updated" to appear before "order created", which is confusing and incorrect.

Root Cause

In ActivityLogFeed.php, activities are sorted by created_at:

$activities = $this->subject->activities()
    ->orderBy('created_at', 'desc')
    ->with(['causer', 'subject'])
    ->paginate(10, ['*'], $this->pageName);

When an order is placed, multiple activity log entries are created within the same request cycle (order created, order updated, order line created, payment capture, etc.). These all share the exact same created_at timestamp, so the database returns them in an undefined order.

Steps to Reproduce

  1. Place an order through the storefront
  2. Open the order in the admin panel
  3. Observe the timeline — "order updated" may appear before "order created"

Fix

Replace orderBy('created_at', 'desc') with orderBy('id', 'desc'). The auto-incrementing id column preserves the true insertion order, even when multiple events share the same timestamp.

- ->orderBy('created_at', 'desc')
+ ->orderBy('id', 'desc')

Sort activity log entries by `id` instead of `created_at` to ensure
correct chronological order when multiple events occur within the
same second (e.g. order created, updated, and placed during checkout).
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Mar 30, 2026
@alecritson alecritson requested a review from glennjacobs March 31, 2026 07:05
@alecritson alecritson added the admin panel Improvements or additions to admin panel label Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

admin panel Improvements or additions to admin panel

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants