Yes, in Carbon 3.x, diffInSeconds() now returns a signed value, unlike Carbon 2.x, which always returned positive.
Fix:
Use abs() to get a positive value:
$duration_in_secs = abs($time_after->diffInSeconds($time_before));
Or swap the arguments:
$duration_in_secs = $time_before->diffInSeconds($time_after);