Skip to content

Studio: preserve Unicode across continued XLS strings - #16713

Merged
oobabooga merged 3 commits into
unslothai:mainfrom
DimitriChrysafis:studio-xls-continued-unicode
Nov 6, 2026
Merged

oobabooga merged 3 commits into
unslothai:mainfrom
DimitriChrysafis:studio-xls-continued-unicode

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

What was broken

Binary XLS cell text can lose supplementary Unicode characters during RAG parsing. Emoji and CJK names become replacement characters when a UTF-16 surrogate pair crosses a BIFF CONTINUE record. The damaged text is then stored and indexed, so searches for the original name can miss it.

Repro

  1. On main at 91be10960, use xlwt 1.3.0 to write 'A' * 4105 + '\U0001f600tail' into the first cell of an .xls workbook.
  2. Read it with office_formats.xls, or upload it for RAG indexing.
  3. The emoji becomes two replacement characters. Prefix lengths 4104 and 4106 round-trip correctly; 4105 splits its surrogate pair across records.

Fix

Keep single-fragment strings on the direct decode path. For continued strings, normalize compressed fragments to UTF-16LE bytes and decode the joined stream once. This preserves pairs across record boundaries while retaining width changes, metadata skipping, replacement of malformed Unicode, and the returned record position.

This fixes both shared strings and cached formula results. It does not change XLSX parsing.

Test

Ten regression cases fail before the fix; all 18 selected cases pass afterward. Coverage includes shared and formula strings, emoji and CJK characters, compressed/wide transitions, full 8KB record boundaries, formatting metadata, malformed surrogates, and separate-string boundaries. Upload-to-FTS tests verify that a split CJK surname remains searchable, with stub embeddings and real ingestion/SQLite.

From studio/backend:

$ python -m pytest -q --tb=short --timeout=330 tests/test_rag_office_formats.py
158 passed in 4.54s
$ python -m pytest -q --tb=short -n 4 --dist loadgroup --timeout=330 tests/test_rag_office_formats.py tests/test_rag_parsing.py tests/test_rag_ingestion.py tests/test_rag_retrieval.py
330 passed, 1 skipped in 6.79s

The skip is the opt-in real-embedder test. Separately verified xlwt-produced workbooks at all three prefix lengths. The broken case now round-trips exactly, and the controls are unchanged. Local ASCII/BMP single-fragment microbenchmarks show no regression.

All seven repository checks and the pinned pre-commit formatter pass. No schema or dependency changes.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T19:27:25.082958Z b277cfe Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: fdb9f5e3c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 3323b11f13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: b277cfe24d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oobabooga

Copy link
Copy Markdown
Member

When an emoji or rare CJK character in an .xls cell was split across two records, _xls_string turned it into two replacement characters, so the knowledge base couldn't find it. Joining the bytes before decoding fixes that.

None of the 874 real .xls files I tried from online sources hit the bug, and they all read the same as on main.

I pushed b277cfe so a corrupt file with a record ending mid-character gets one replacement character, as on main, instead of garbling the rest of the string.

Mirror CI is clear at d8fac12, before that commit; the one failure is the test_fp8_lora.py test fixed on main by #16855.

@oobabooga
oobabooga merged commit b597d1e into unslothai:main Nov 6, 2026
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.

3 participants