From a0563f261e6fa05790e97fa07490ea4eaa382e8a Mon Sep 17 00:00:00 2001 From: ajspig Date: Tue, 4 Aug 2026 16:10:56 -0400 Subject: [PATCH] fix: deterministic pagination order for derived conclusions created_at is the transaction timestamp, so conclusions derived in the same batch share it; add an id tie-breaker (mirroring the created_at direction) so /derived pagination can't skip or duplicate rows across page boundaries. Matches the existing precedent in query_documents_most_derived. Co-Authored-By: Claude Fable 5 --- src/crud/document.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/crud/document.py b/src/crud/document.py index 646fe2d9..a7afee2e 100644 --- a/src/crud/document.py +++ b/src/crud/document.py @@ -1394,9 +1394,13 @@ def get_child_observations( if observed: stmt = stmt.where(models.Document.observed == observed) + # created_at is the transaction timestamp, so documents created in the + # same batch share it -- id keeps pagination deterministic. if reverse: - stmt = stmt.order_by(models.Document.created_at.asc()) + stmt = stmt.order_by(models.Document.created_at.asc(), models.Document.id.asc()) else: - stmt = stmt.order_by(models.Document.created_at.desc()) + stmt = stmt.order_by( + models.Document.created_at.desc(), models.Document.id.desc() + ) return stmt