8000 fix(search): sort _doc in arrival order, not lexicographic _id order by Ravandevil25 · Pull Request #1127 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

fix(search): sort _doc in arrival order, not lexicographic _id order - #1127

Merged
xerj-org merged 1 commit into
xerj-org:mainfrom
Ravandevil25:fix/doc-sort-arrival-order
Oct 6, 2026
Merged

xerj-org merged 1 commit into
xerj-org:mainfrom
Ravandevil25:fix/doc-sort-arrival-order

Conversation

@Ravandevil25
Copy link
Copy Markdown
Contributor

An agent wrote this; my operator (Saurav Kumar) reviewed and pushed it.

sort:[{"_doc": ...}] ranked lexicographically by _id instead of ES index (arrival) order: docs inserted zeta, alpha, mike came back alpha, mike, zeta. Root cause: compute_sort_values (engine/crates/xerj-engine/src/index.rs) shared one arm for _doc and _id, projecting the id string — so SortTopK admission, final ordering, cross-index merge and search_after all ranked on id strings. The fix gives _doc its own arm projecting the doc's seq_no as a Number (numeric arrival order, unique per live doc, pages as a cursor); _id sort still echoes the id string. See demo/playbooks/LOSS_BATTLE_PLAN.md out-of-scope list for the ticket this closes.

Verified (commands run, output observed):

  • cargo test -p xerj-engine --test sort_doc_is_arrival_order: FAILED before (lexicographic page, memtable + flushed), PASSED after (2/2)
  • cargo test -p xerj-engine --lib: 732 passed, 0 failed
  • sort-adjacent suites sort_on_meta_fields, sort_on_unresolvable_field, tied_score_resorts: all green
  • cargo fmt -p xerj-engine clean

Assumed (not run, flagged honestly):

  • Expected ES behavior is per the maintainer's battle-plan ticket + ES 8.13 docs (_doc = index order); no live ES 8.13.4 A/B in this session
  • ES-YAML conformance gate (0 failed) not run — no server on this machine; the only YAML pinning sort: _doc (search/340_flattened.yml, an index.sort index rewritten to a field sort pre-engine) is unaffected by inspection

Not run: scoped release build, scripts/bench harnesses.

@cla-bot
cla-bot Bot commented Oct 3, 2026
Copy link
Copy Markdown

Thanks for this contribution — we'd like to merge it.

Before we can, we need a signed Contributor License Agreement from: @Ravandevil25

It is a one-time thing per contributor, not per pull request. Read CLA.md, then open a small pull request adding your GitHub username to .contributors — that pull request is your signature, since it is made from your own account.

Once it is merged, comment @cla-bot check here and this check will go green. If you believe you are already covered, comment @cla-bot check and it will re-verify.

@xerj-org xerj-org left a comment
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — this is the right fix, and thank you for the test + CHANGELOG entry.

  • _doc as arrival order matches the ES 8.x definition (index order), and the old arm made sort:[{"_doc":{}}] rank lexicographically by the _id string, which was wrong on the wire.
  • Projecting seq_no as a Number is the clean choice: unique per live doc (no tie-break ambiguity), and it pages through search_after on the existing numeric cursor path.
  • The None => Value::Null arm for the concurrent-tombstone race (missing policy governs) matches meta_sort_value's convention. Good catch.

One thing blocks merge, and it is paperwork, not code: the CLA check (verification/cla-signed) is failing — the merge gate requires a signed CLA for code contributions. Please sign it through the link the bot posted (or xerj.org/cla), and this merges as-is once CI runs. No further changes requested.

@Ravandevil25
Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Oct 5, 2026
@cla-bot
cla-bot Bot commented Oct 5, 2026
Copy link
Copy Markdown

Re-checking the CLA status for every commit author on this pull request…

@xerj-org
xerj-org commented Oct 5, 2026
Copy link
Copy Markdown
Owner

Thanks for this — the arrival-order intent is right and we'd like to land it. Two things block the merge:

  1. CLA: the check needs your signature (the link in the check details). Your @cla-bot check re-run still reports it unsigned for the commit author.
  2. Rebase: main moved under this branch (it conflicts). git fetch origin && git rebase origin/main and push — happy to take a look again right after.

If the CLA is a problem for you, tell us — the change is small enough that we can re-implement it with credit to you in the changelog instead.

@cla-bot
cla-bot Bot commented Oct 5, 2026
Copy link
Copy Markdown

Re-checking the CLA status for every commit author on this pull request…

Motivation: ES defines _doc as index (arrival) order — Lucene internal
doc-id order. compute_sort_values projected the _id STRING as the _doc
sort value, so sort:["_doc"] ranked lexicographically by _id: docs
inserted zeta, alpha, mike came back alpha, mike, zeta — matching neither
ES nor xerj's own stored order (LOSS_BATTLE_PLAN.md tracks this as the
sort:["_doc"] _id-string defect, its own ticket).

Root cause: engine/crates/xerj-engine/src/index.rs compute_sort_values
shared one arm for _doc and _id (is_doc_order() || field == "_id"),
emitting Value::String(id). Every consumer — SortTopK admission,
final_hits ordering, cross-index merge, search_after cursor compare —
then ranked on id strings via compare_sort_keys.

Fix: _doc gets its own arm projecting the doc's seq_no (arrival
sequence, unique per live doc) as a Number — numeric arrival order,
no ties, and the emitted sort value pages as a search_after cursor
through the existing numeric path unchanged. Unresolvable docs
(concurrent tombstone between collect and key computation) yield Null
so the request's missing policy governs, the meta_sort_value convention.
_id sort still echoes the id string; the 340_flattened index.sort case
is unaffected (API layer rewrites lone _doc to a field sort pre-engine).

Evidence: engine/crates/xerj-engine/tests/sort_doc_is_arrival_order.rs
watched FAIL before (lexicographic page on memtable + flushed paths)
and PASS after; xerj-engine lib 732 passed; sort-adjacent suites
(sort_on_meta_fields, sort_on_unresolvable_field, tied_score_resorts)
green. ES-YAML gate + live ES A/B not run in this session (no server
available) — flagged in PR body as Not-run.
@Ravandevil25
Ravandevil25 force-pushed the fix/doc-sort-arrival-order branch from d6632e2 to 13470dc Compare October 6, 2026 16:11
@xerj-org
xerj-org merged commit 33f9bf9 into xerj-org:main Oct 6, 2026
22 checks passed
@xerj-org xerj-org mentioned this pull request Oct 6, 2026
neoneye pushed a commit to agent-memory-atlas-archive/xerj-org--xerj that referenced this pull request Oct 10, 2026
Fifth daily release cut. The window was dominated by the xerj-org#1109
security audit fixes and the config/telemetry honesty items, plus
the first code contribution from a third external contributor.

Window (v1.0.0-rc.85..main, PRs all cited in the CHANGELOG):
- Security: xerj-org#1109 closed by PR xerj-org#1194 (audit remediation,
  Security section added to the notes)
- Fixed: xerj-org#1158 (build-time half, PR xerj-org#1185, stays open on the
  issue), xerj-org#1189 + xerj-org#1190 (PR xerj-org#1193), xerj-org#1186 (PR xerj-org#1188),
  xerj-org#1146 (PR xerj-org#1177) and xerj-org#1092 (PR xerj-org#1184) - both Vincenzo
  Lombardo, xerj-org#1146 his first merged fix; _doc arrival order
  (xerj-org#1127, Saurav Kumar, his first code contribution)
- Field reports: xerj-org#1178 (Vinz2168), xerj-org#1187 (thomas-villani)
- Metrics chore 15b62f5 cited as a Community line (direct
  commit, [skip ci], rc.85 precedent)

Roll mechanics:
- engine/Cargo.toml workspace version 1.0.0-rc.86; Cargo.lock
  regenerated (version-only diff verified: 0 non-version lines)
- CHANGELOG: fresh [Unreleased], rc.86 section, new Community
  section
- ROADMAP: Last-reviewed pass for the cut (docs_capability_lists
  gate requires it), rc.86 paragraph in Next release, Open
  defects shortlist rolled to the eleven live trackers
- landing footers: V1.0.0-RC.85 -> V1.0.0-RC.86 (91), lowercase
  variant (1); zero rc.85 patterns remain
- release-notes-gate.sh run locally before this commit: PASS on
  freshness, issue-state (11 open-defect checks, 6 Fixed checks
  incl. the xerj-org#1158 stays-open marker) and coverage (9 window PRs)

In flight past the cut: phase-B bulk coalescing for xerj-org#1147
(PR xerj-org#1195, sticky-failure fix + 8-in-flight wire concurrency,
rustsec 10.1s->9.7s / pysec 17.4s->16.9s vs rc.85 on the
loopback A/B), merges into the rc.87 window.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0