fix: reverse snapshot order to preserve capture sequence during stable sort

This commit is contained in:
CJACK
2026-04-06 02:51:06 +08:00
parent 1664349a29
commit 2857a171cc
2 changed files with 39 additions and 4 deletions

View File

@@ -324,11 +324,13 @@ func buildCaptureChains(snapshot []devcapture.Entry) []captureChain {
return nil
}
ordered := make([]devcapture.Entry, len(snapshot))
copy(ordered, snapshot)
// devcapture snapshots are newest-first because the store prepends entries.
// Reverse once so equal-second timestamps can preserve the actual capture
// order (completion before continue) under the stable CreatedAt sort below.
for i := range snapshot {
ordered[len(snapshot)-1-i] = snapshot[i]
}
sort.SliceStable(ordered, func(i, j int) bool {
if ordered[i].CreatedAt == ordered[j].CreatedAt {
return ordered[i].ID < ordered[j].ID
}
return ordered[i].CreatedAt < ordered[j].CreatedAt
})