Files
bterkuileandClaude Sonnet 5 37288db487 Deterministic tree ordering — the actual fix for the 'flaky ancestry' failures
Reproduced the reported ~50% intermittent ancestry failure (3-4 of 8 runs) and
captured it: NamespacedDirectory.roots returned [dir4, dir1] vs [dir1, dir4].
The session report blamed 'several dependent saves that occasionally race' —
wrong. Both records share position 0 and run_tree ordered by position alone,
so the tie order was whatever the index scan produced that run. No race, no
CAS involvement: an ORDER BY tie.

- run_tree now tie-breaks by created_at then META(c).id, exactly like
  run_docs already did for finder queries.
- The two client-side tree sorts (descendants, build_tree) get the same
  tie-break: Ruby's sort_by is not stable, so [depth, position] alone could
  reorder same-position siblings between runs.

ancestry_spec re-run repeatedly post-fix: no failures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-06 18:51:47 -05:00
..