Cloud agents view: Completed group not sorted by completion time (uses createdAt, not firstTerminalAt)
What happened
In the cloud / background agents view (FleetView), the Completed group is not ordered by completion time. The most-recently-completed agent should be at the top, but it isn't.
Reading the relative-time ("time ago") column top-to-bottom in the Completed group, the sequence is neither ascending nor descending:
10h, 4m, 1h, 13m, 4m, 6m, 21m, 1h, 1h, 1d, 27m, 47m, 8m, 23m, 43s, 18m, 18m, 18m, ...
A 43s-ago completion sits below several older 1h/1d items, and a 10h item is pinned at the very top. The long trailing run of identical 18m values points at the actual sort key (see below).
What I expected
The Completed group sorted by completion time, newest first (most-recently-finished agent on top).
Root cause (from inspecting the bundled build)
The Completed group is the done bucket. The default list ordering uses a comparator keyed on creation time, ascending — not completion time:
- Creation-time key:
sortOrder ?? Date.parse(createdAt) - Completion-time key:
Date.parse(firstTerminalAt ?? updatedAt)— this exists (firstTerminalAtis stamped once when an agent first reaches a terminal state) but is only applied in the alternate "state" sort mode.
So in the default view the done bucket sorts by createdAt ascending, which is why newest-completed is not on top and why agents sharing a launch batch cluster together (the 18m run). The completion timestamp (firstTerminalAt) is already tracked per agent — the fix is to key the done group's default sort on firstTerminalAt and sort descending.
Environment
- Claude Code:
2.1.202(also present in2.1.203/2.1.204) - Platform: macOS (darwin 25.5.0), arm64
Repro
- Launch several cloud/background agents at different times so they complete at different times (not in creation order).
- Open the cloud agents view.
- Observe the Completed group is ordered by launch/creation time, not by when each agent finished.