Repository navigation
fix(runtime): locate history excerpts by original byte offsets under Unicode lowercasing (F24) - #82
Merged
Merged
Conversation
…Unicode lowercasing (F24) search_history found the needle in a lowercased copy of each text and used that byte offset in the original. Lowercasing changes byte length for some characters (İ 2→3 bytes, ẞ 3→2), so after enough of them the offset drifted: excerpts could miss their match or, with enough drift, snap to the wrong region entirely. find_case_insensitive lowercases the haystack one char at a time and keeps the original char boundaries, so the returned span always indexes the original text and covers the whole match. A needle that would end inside a multi-char lowering does not match half a character. ASCII haystacks keep the byte-for-byte fast path (to_ascii_lowercase + memchr-backed find). excerpt_around takes the haystack and needle only. Tests: İ/ẞ prefixes of several shapes, and a 600-char İ prefix whose drift exceeds the excerpt half-width; span assertions for growing and shrinking lowerings. context_assembly bench search timings unchanged within noise. Closes ENG-805.
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.
fix(runtime): locate history excerpts by original byte offsets under Unicode lowercasing (F24)
Linear: ENG-805 · audit F24 (P2 · S). No protocol/schema change.
Bug
search_historyfound the query intext.to_lowercase()and used that byte offset to slicetext.İlowers from 2 bytes to 3,ẞfrom 3 to 2, so with enough of them before a match the offset drifts — the excerpt drifts off its match, and past the excerpt half-width loses it entirely.Fix
find_case_insensitive(haystack, needle) -> Option<(start, end)>lowers the haystack char by char, tracking original char boundaries, so the span always indexes the original and covers the full match. A needle that would end mid-lowering ("i"against"İ"→"i̇") does not match half a char. ASCII haystacks — the common case, and what the F06 bench measures — keep the byte-for-byte path.excerpt_arounddrops itsloweredparameter; the one caller intranscript.rsno longer allocates a lowercased copy per text.Verification
matches_after_length_changing_lowercase_are_located_in_the_original(İ/ẞ prefixes; a 600-char drift beyond the half-width),case_insensitive_search_spans_original_bytes_and_respects_char_lowering.cargo test -p qq-core674 pass; fmt; clippy-D warnings.context_assemblybench: search 27 / 35 ms at 1k / 10k archived runs vs 26 / 30 ms before — within run-to-run noise (fixture is ASCII → fast path).