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 <noreply@anthropic.com>
This commit is contained in:
ajspig 2026-08-04 16:10:56 -04:00
parent 5f1752bd48
commit a0563f261e
1 changed files with 6 additions and 2 deletions

View File

@ -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