Repository navigation
fix(bulk): reject one lone-surrogate doc per-item, not the whole batch - #1311
Merged
Merged
Conversation
One document carrying an unpaired UTF-16 surrogate in a `\uXXXX` string escape (e.g. an emoji cut in half by a fixed-width chunker, serialised as `"a\ud83db"`) made the bulk endpoint reject its entire batch of auto-id documents instead of that one document. A ~58,000-chunk load failed far from the cause with a single `lone leading surrogate in hex escape` and nothing indexed, violating the ES bulk contract of per-document error reporting. Root cause: the `index` turbo path validates each source line with `serde_json::IgnoredAny` (bulk.rs), which walks the JSON *without decoding* string contents, so an escape encoding an unpaired surrogate is ACCEPTED and the raw bytes retained. The auto-id docs are then grouped and handed as one batch to `Index::index_batch_turbo_raw`, which parses every doc into a `serde_json::Value` (`parse_validated_raw_batch` -> `IndexStore::parse_raw_batch` -> `serde_json::from_slice::<Value>`). That parse DOES decode escapes and rejects the unpaired surrogate, but it fails the whole batch with a single `Err`, so `process_bulk` marks every item in the batch failed. Unpaired surrogates are the sole semantic string check `Value` makes that `IgnoredAny` skips (nesting depth is already capped identically upstream in `validate_raw_json_nesting`). Fix: close that one gap at the per-item bulk layer, which already reports per-item errors. After `IgnoredAny` accepts an `index` source line, `lone_surrogate_escape_reason` scans it for an unpaired surrogate in a `\uXXXX` escape and, if found, returns a per-item 400 `document_parsing` error naming the bad document. The bad document therefore never enters a turbo batch, so the batch `Value` parse succeeds and its neighbours index. The scan runs only after `IgnoredAny` has guaranteed well-formed structure (every `\u` has four hex digits, every string is terminated), so it only checks surrogate pairing; a leading memchr fast-path skips the common backslash-free document entirely, preserving the turbo ingest win. A unit test pins the scan's accept/reject decision to serde_json's own `Value` decision across valid pairs, lone high/low surrogates (in body and key), escaped backslashes and ordinary escapes. Before: a 128-doc auto-id batch with one unpaired-surrogate doc -> all 128 items 400, 0 indexed. After: 1 item 400 (names the surrogate), 127 indexed. Files: - engine/crates/xerj-engine/src/bulk.rs: `lone_surrogate_escape_reason`, `lone_surrogate_document_reason`, the per-item `index` check, and tests. The fix is ES-compat-positive (per-item reporting mirrors ES) and touches no valid-JSON path, so the ES-YAML conformance gate is unaffected; the full gate runs in CI. Closes #1304
neoneye
pushed a commit
to agent-memory-atlas-archive/xerj-org--xerj
that referenced
this pull request
Oct 13, 2026
Window since v1.0.0-rc.93 (29 merged PRs): a wave of external-contributor fixes (Vinz2168, thomas-villani, yogthos, pierreaubert) plus a backlog-fix sweep closing six defects — hybrid query+knn page-local ranking (xerj-org#1303/xerj-org#1312), bulk lone-surrogate whole-batch rejection (xerj-org#1304/xerj-org#1311), autoindex --watch double-owner (xerj-org#1232/xerj-org#1307), sibling-fork reconcile abort (xerj-org#1230/xerj-org#1309), map-only --dataset accept-and-ignore (xerj-org#1231/xerj-org#1308), non-note Second Brain vocabulary (xerj-org#1100/xerj-org#1310). Three closed as already-fixed (xerj-org#1212, xerj-org#1244, xerj-org#1173). Stamp: workspace version 1.0.0-rc.93 -> 1.0.0-rc.94 (Cargo.toml + Cargo.lock), landing data-latest-tag, CHANGELOG [1.0.0-rc.94] section, ROADMA 77F6 P review line (now v1.0.0-rc.94) and rc.94 roll (nine open defects carried). Release-cut machine checks (docs_capability_lists, docs_do_not_promise_the_next_release) pass locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A bulk load of auto-id documents rejected its whole batch when a single
document carried an unpaired UTF-16 surrogate in a
\uXXXXstring escape —the shape a fixed-width-character chunker produces when it cuts an emoji in
half (
"a" + String.fromCharCode(0xd83d) + "b"→"a\ud83db"). ES's bulkcontract is per-document: the one bad document errors and its neighbours
index. This restores that.
Root cause
indexturbo path validates each source line withserde_json::IgnoredAny(bulk.rs), which walks the JSON withoutdecoding string contents, so an escape encoding an unpaired surrogate is
accepted and the raw bytes retained.
Index::index_batch_turbo_raw, which parses every doc into aserde_json::Value(parse_validated_raw_batch→IndexStore::parse_raw_batch→serde_json::from_slice::<Value>). Thatparse does decode escapes and rejects the unpaired surrogate — but it
fails the whole batch with a single
Err, soprocess_bulkmarks everyitem in the batch failed.
Unpaired surrogates are the only semantic string check
Valuemakes thatIgnoredAnyskips; nesting depth is already capped identically upstream invalidate_raw_json_nesting.Fix
Close that one gap at the per-item bulk layer, which already does per-item
error reporting. After
IgnoredAnyaccepts anindexsource line,lone_surrogate_escape_reasonscans it for an unpaired surrogate and, iffound, returns a per-item 400 naming the bad document. The bad document never
enters a turbo batch, so the batch
Valueparse succeeds and the neighboursindex.
The scan runs only after
IgnoredAnyhas guaranteed well-formed structure(every
\uhas four hex digits, every string is terminated), so it onlychecks surrogate pairing. A leading
memchrfast-path skips the commonbackslash-free document entirely, preserving the turbo ingest win.
Before / after
A 128-doc auto-id batch with one unpaired-surrogate document:
Tests (
cargo test -p xerj-engine --lib lone_surrogate)surrogate_scan_matches_serde_value_decision— pins the scan'saccept/reject decision to serde_json's own
Valuedecision across validpairs, lone high/low surrogates (in body and key), escaped backslashes and
ordinary escapes.
one_lone_surrogate_does_not_sink_its_bulk_batch— the issue repro: 127indexed, 1 per-item 400. Fails before the fix (all 128 fail), passes after.
multiple_bad_surrogates_each_fail_individually— two bad docs each failon their own; the rest index.
cargo fmt -p xerj-engine --checkandcargo clippy -p xerj-engine --libare clean. The change is ES-compat-positive and touches no valid-JSON path,
so the ES-YAML conformance gate is unaffected; the full gate runs in CI.
Closes #1304
🤖 Generated with Claude Code