You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): RTF text in an ANSI font reads as code page 1252 under any document code page - #41508
An RTF attachment reaches the agent with the wrong letters when its fonts are \fcharset0 (ANSI) and its document code page is not 1252. FONT_CODE_PAGES in documentTextWorker.ts has no entry for charset 0, so those fonts fall back to \ansicpg. TextEdit writes exactly this on a Mac whose language is not Western: \ansicpg1251 (or \mac\ansicpg10000, \ansicpg874, …) with \fcharset0 fonts, and Western letters as \'hh bytes in code page 1252.
Where the document code page has no character for a byte, the document decoder is strict, so the agent gets no text at all. For example, f\'fcr in a \fcharset0 font under \ansicpg874 fails with The encoded data was not valid for encoding windows-874.
RTF 1.9.1 maps \fcharset0 to code page 1252, and LibreOffice does the same (rtfcharsets.cxx: { 0, 1252 }).
Change
FONT_CODE_PAGES maps charset 0 to windows-1252.
A font-table \cpgN sets that font's code page, using the same single-byte code pages \ansicpg already accepts (now one singleByteCodePage helper, which also covers Mac Roman). Without this, the charset-0 entry would break a font that names its own code page, such as \fcharset0\cpg1251 under \ansicpg1251, which decodes correctly today. A \cpg inside {\*\fontfile …} describes the font file's name and is ignored.
Fonts with no \fcharset, or \fcharset1 (default), keep the document code page.
Scope
This is a small fix for an obvious bug, so it has no issue. It continues #40476, which added per-font character sets and left out only the multi-byte ones on purpose. Charset 0 was not discussed there.
Rows in the existing "extracts RTF text" table in userInputAttachments.test.ts:
"ANSI font under another code page" and "ANSI font in a Macintosh document" fail on main and pass with the fix;
"font code page" (\fcharset0\cpg1251 plus a \fontfile code page) and "Macintosh font code page" (\fcharset0\cpg10000) pass on main, fail with only the charset-0 entry, and pass with the fix.
main: × extracts RTF text: ANSI font under another code page
× extracts RTF text: ANSI font in a Macintosh document
fix: Tests 53 passed (53)
vp run check:changed upstream/main passes.
Claude Fable 5.2 (high, Claude Agent in T3 Code) found the bug. Claude Opus 5.5 (high) and GPT-6.2 Astra (high, Codex) reproduced it independently. Claude Opus 5.5 (Claude Agent in T3 Code) wrote the fix and test. Claude Opus 5.5 (xhigh), GPT-6.2 Sol, GPT-6.2 Astra (high, Codex), and Claude Fable 5.2 reviewed the patch in T3 Code.
Reviewing files that changed from the base of the PR and between 01cc6ed and d63de75.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
RTF extraction now supports additional single-byte code pages for document and font text. Font-specific cpg values apply outside fontfile groups, and four tests assert the extracted text for these cases.
Changes: RTF code-page decoding
Layer / File(s)
Summary
Code-page mapping and RTF parsing apps/server/src/provider/documentTextWorker.ts, apps/server/src/provider/userInputAttachments.test.ts
The parser maps additional single-byte code pages and applies supported font-table cpg values to the current font outside fontfile groups. Document-level ansicpg uses the shared mapping. Four tests assert extracted text for the added cases.
This change corrects server-side RTF text extraction for ANSI fonts in documents using other code pages, and adds tests for the fixed cases. No concrete merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the actual fix: RTF text in an ANSI (\fcharset0) font is decoded as code page 1252 regardless of document code page. The raw summary confirms the change maps charset 0 to windows-1252 …
Description check
The description follows the required template. It has Problem, Change, Scope, and Verification sections, each with substantive content. Problem gives the bug, a reproduction table, and the RTF spec ba…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the actual fix: RTF text in an ANSI (\fcharset0) font is decoded as code page 1252 regardless of document code page. The raw summary confirms the change maps charset 0 to windows-1252 in documentTextWorker.ts and adds tests for that behavior. The title is specific, follows conventional commit format, and is one line.
Full details: Description check
Explanation
The description follows the required template. It has Problem, Change, Scope, and Verification sections, each with substantive content. Problem gives the bug, a reproduction table, and the RTF spec basis. Change lists the mapping and the \cpg handling. Scope explains why no issue is linked and names the related PR and a planned web follow-up. Verification lists the focused test rows, the main and fix results, and the repo check. The template asks for an agent model line at the end, and the description includes one. The author links no issue, but gives a reason for that, which the template allows for small obvious fixes.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Attached the exact triage RTF and sent the same prompt on fresh databases in Chromium, 1280×800, light theme. Replay completed each turn; the server-generated extraction sidecar was displayed verbatim in the app's file editor.
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
size:M30-99 changed lines (additions + deletions).vouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
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.
Problem
An RTF attachment reaches the agent with the wrong letters when its fonts are
\fcharset0(ANSI) and its document code page is not 1252.FONT_CODE_PAGESindocumentTextWorker.tshas no entry for charset 0, so those fonts fall back to\ansicpg. TextEdit writes exactly this on a Mac whose language is not Western:\ansicpg1251(or\mac\ansicpg10000,\ansicpg874, …) with\fcharset0fonts, and Western letters as\'hhbytes in code page 1252.textutilreads\ansicpg1251€5 café naïveЂ5 cafй naпveth.lproj/Trailer.rtf,\ansicpg874Copyright ©Copyright ฉhr.lproj/Trailer.rtf,\mac\ansicpg10000pridržanapridrûanaWhere the document code page has no character for a byte, the document decoder is strict, so the agent gets no text at all. For example,
f\'fcrin a\fcharset0font under\ansicpg874fails withThe encoded data was not valid for encoding windows-874.RTF 1.9.1 maps
\fcharset0to code page 1252, and LibreOffice does the same (rtfcharsets.cxx:{ 0, 1252 }).Change
FONT_CODE_PAGESmaps charset 0 towindows-1252.\cpgNsets that font's code page, using the same single-byte code pages\ansicpgalready accepts (now onesingleByteCodePagehelper, which also covers Mac Roman). Without this, the charset-0 entry would break a font that names its own code page, such as\fcharset0\cpg1251under\ansicpg1251, which decodes correctly today. A\cpginside{\*\fontfile …}describes the font file's name and is ignored.Fonts with no
\fcharset, or\fcharset1(default), keep the document code page.Scope
This is a small fix for an obvious bug, so it has no issue. It continues #40476, which added per-font character sets and left out only the multi-byte ones on purpose. Charset 0 was not discussed there.
Two things this PR does not change:
extendedDocumentPreview.ts) maps charset 0 to the document code page, so it shows the same wrong letters. A separatefix(web)PR will follow, as fix(web): RTF previews open files that declare code page 0 or 866 #41277 and fix(server): RTF attachments that declare code page 0 or 866 reach the agent as text #41340 were split.\fuses the\defffont, as fix(server): RTF attachments no longer garble text set in a font's own character set #40476 already does for other character sets. So\deff0with a\fcharset0font now reads that text as 1252, wheretextutilkeeps the document code page. TextEdit always writes\f0before its text.Verification
Rows in the existing "extracts RTF text" table in
userInputAttachments.test.ts:\fcharset0\cpg1251plus a\fontfilecode page) and "Macintosh font code page" (\fcharset0\cpg10000) pass on main, fail with only the charset-0 entry, and pass with the fix.vp run check:changed upstream/mainpasses.Claude Fable 5.2 (high, Claude Agent in T3 Code) found the bug. Claude Opus 5.5 (high) and GPT-6.2 Astra (high, Codex) reproduced it independently. Claude Opus 5.5 (Claude Agent in T3 Code) wrote the fix and test. Claude Opus 5.5 (xhigh), GPT-6.2 Sol, GPT-6.2 Astra (high, Codex), and Claude Fable 5.2 reviewed the patch in T3 Code.