Confirmed.  See test attached.

I'll take ownership of this bug.
Handled.

Looks like sorting by scheduled will always overrule deadline sorting.  As in
items with only a deadline won't be sorted at all if scheduled is in the
sorting strategy.  Sorting by '(deadline-up scheduled-up) in completely
equivalent to sorting by '(scheduled-up).

It's actually much worse then that.  Combining any of the following properties
will give a similar overwritten effect: scheduled, deadline, ts, tsia,
timestamp.

This issue comes from headings being sorted by `org-cmp-ts' which uses the
return value of `org-agenda-entry-get-agenda-timestamp' after a couple layers
of indirection.  The problem is pretty obvious when reading
`org-agenda-entry-get-agenda-timestamp'.

I'll have to look into it a little more but the idea of sorting things from
multiple pieces of metadata is similar to what I worked on before with
`org-tags-sort' so I think I can handle this.

>From e5f69311e440335bce5db264aa087734440e4955 Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email protected]>
Date: Fri, 7 Nov 2025 15:33:05 -0500
Subject: [PATCH] testing/lisp/test-org-agenda.el (test-org-agenda/sorting):
 New test

* testing/lisp/test-org-agenda.el (test-org-agenda/sorting): New test.
---
 testing/lisp/test-org-agenda.el | 69 +++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 51e75102c..a2f9fc572 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -666,6 +666,75 @@ test-org-agenda/skip-scheduled-repeats-after-deadline
               (buffer-string))))))
       (org-test-agenda--kill-all-agendas))))
 
+(ert-deftest test-org-agenda/sorting ()
+  "Test if `org-agenda' sorts according to `org-agenda-sorting-strategy'."
+  :expected-result :failed
+  (let ((set-agenda-with-priority
+         (lambda (priority)
+           (setq org-agenda-custom-commands
+                 `(("f" "no fluff" todo ""
+                    ((org-agenda-todo-keyword-format "")
+                     (org-agenda-overriding-header "")
+                     (org-agenda-prefix-format "")
+                     (org-agenda-remove-tags t)
+                     (org-agenda-sorting-strategy ',priority)))))))
+        org-agenda-custom-commands)
+    (org-test-at-time "2025-11-07"
+      (org-test-agenda-with-agenda
+       "* TODO scheduled yesterday
+SCHEDULED: <2025-11-06>
+* TODO scheduled today
+SCHEDULED: <2025-11-07>
+* TODO scheduled tomorrow
+SCHEDULED: <2025-11-08>
+* TODO deadline yesterday
+DEADLINE: <2025-11-06>
+* TODO deadline today
+DEADLINE: <2025-11-07>
+* TODO deadline tomorrow
+DEADLINE: <2025-11-08>
+* TODO both yesterday
+SCHEDULED: <2025-11-06>
+DEADLINE: <2025-11-06>
+* TODO both today
+SCHEDULED: <2025-11-07>
+DEADLINE: <2025-11-07>
+* TODO both tomorrow
+SCHEDULED: <2025-11-08>
+DEADLINE: <2025-11-08>"
+       (should
+        (string-equal
+         (string-trim
+          (progn
+            (funcall set-agenda-with-priority '(deadline-up scheduled-up))
+            (org-agenda nil "f")
+            (substring-no-properties (buffer-string))))
+         "deadline yesterday
+deadline today
+deadline tomorrow
+scheduled yesterday
+both yesterday
+scheduled today
+both today
+scheduled tomorrow
+both tomorrow"))
+       (should
+        (string-equal
+         (string-trim
+          (progn
+            (funcall set-agenda-with-priority '(scheduled-down deadline-down))
+            (org-agenda nil "f")
+            (substring-no-properties (buffer-string))))
+         "scheduled tomorrow
+both tomorrow
+scheduled today
+both today
+scheduled yesterday
+both yesterday
+deadline tomorrow
+deadline today
+deadline yesterday"))))))
+
 (ert-deftest test-org-agenda/tags-sorting ()
   "Test if `org-agenda' sorts tags according to `org-tags-sort-function'."
   (let ((string-length< (lambda (s1 s2)

base-commit: af1478121ff3292ae3b7d60878e91b539c51e60f
-- 
2.51.2

Reply via email to