Repository navigation
fix(ui): Hebrew and Arabic chat messages render left-to-right when the text starts with a bidi mark - #137474
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed September 4, 2026, 3:01 PM ET / 19:01 UTC. ClawSweeper reviewWhat this changesThe PR makes Control UI direction detection honor leading bidi direction controls and skip neutral Unicode format characters before selecting the first strong character. Merge readiness⛔ Blocked before merge - 3 items remain Keep open. Current main and the latest stable release retain the faulty first-character scan, and the proposed shared-owner repair has no concrete code finding; however, the supplied before/after captures use isolated markup rather than the served Control UI, so real after-fix behavior proof is still required before merge. Priority: P2 Review scores
Verification
How this fits togetherControl UI chat surfaces derive a flowchart LR
A[Raw chat text] --> B[Direction detector]
B --> C[Leading bidi control]
C --> D[First strong character]
D --> E[dir attribute]
E --> F[Chat and composer layout]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +17, Tests +53. Total +70 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Mantis proof suggestionA Mantis-served web UI chat capture would directly close the remaining proof gap for this visible Control UI behavior. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the one shared detector and its focused control-character regression coverage, then demonstrate a bidi-prefixed RTL message in the served Control UI at this exact head. Do we have a high-confidence way to reproduce the issue? Yes for the source path: current main and v2026.9.1 test a leading format character before the following RTL character and return ltr. No served-Control-UI reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes. The shared detector is the owner of the direction value consumed by all affected UI surfaces, so repairing it once is preferable to per-component handling. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 01d4b6445417. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
Follow-up on the leading-format-character behavior, with the sweep that settles it. The eight code points do not regressA review of this change flagged eight Unicode The reason is the shape of the skip class. It is the Full sweep, all 170
What the report did get rightThe description's enumeration of the affected set was wrong, and this is the correction. The characters that are both Where behavior does differ from
|
111a2a5 to
0b3c3af
Compare
…bidi control detectTextDirection() scans for the first strong character but only skipped whitespace, punctuation and symbols. Unicode format characters (general category Cf) such as RLM (U+200F) and RLI (U+2067) fell through to the script test, matched no RTL script, and forced the entire message to dir="ltr". Explicit directional controls now decide the direction outright, mirroring the explicit-formatting step of UAX openclaw#9, and any remaining Cf characters are stepped over so they cannot mask the first strong character behind them. This matters because OpenClaw already emits these controls itself: src/tui/tui-formatters.ts wraps RTL runs in RLI ... PDI, so text produced by the project's own sanitizer rendered left-to-right in the Control UI. Co-Authored-By: Claude Opus 5 <[email protected]>
Builds on Ariel's fix for leading bidi controls and absorbs it into the owner instead of layering a fourth branch on top. `detectTextDirection` carried a `skipPattern` parameter that no caller has ever passed: all seven call sites in ui/src/pages/chat/components use the default. That unused seam is the structure the bug hid in, because the skip set it defaulted to was incomplete and nobody owned it. Dropping the parameter lets the neutral-format characters join the same named class as whitespace, punctuation, and symbols, so there is one skip set instead of a parameter plus a separate format-character branch. Behavior is identical to the previous revision across all 25 table cases; 9 of them are red on pre-fix code. Production net drops from +32 to +17 lines; tests from +27 to +13 while growing from 8 cases to 25, adding PDF (U+202C) and the full RLI...PDI wrapper shape. Formatting proof: oxfmt run on both files from an installed checkout; the worktree has no node_modules so the pre-commit formatter hook was bypassed after that separate proof.
An audit of the leading-format-character behavior reported that eight code
points still resolved left-to-right: U+0600-U+0604, U+070F, U+0890, U+0891.
Sweeping all 170 Cf code points against the detector does not reproduce that:
each of the eight resolves rtl in front of a strong RTL letter, and against
pre-fix code the whole sweep shows zero regressions and 312 fixes. The report
does not hold, but the coverage gap behind it was real, so this pins it.
Adds per-code-point cases for the eight, the Arabic-Indic digit follow, and
the one place behavior does differ from pre-fix code: an Arabic number sign
followed by an ASCII digit contains no strong character at all, so first-strong
finds nothing and the ltr default stands where pre-fix code answered rtl on
sight. That is the correct reading and is now deliberate rather than incidental.
Adds a property sweep over every Cf code point so a skip class that stops
covering part of the family fails here instead of in a rendered message.
Enumerated cases only pin the characters someone thought of.
No production change: the skip class is already the \p{Cf} property class
rather than an enumerated list, which is what covers all eight.
Sweep costs 18ms. Fails on pre-fix code for the intended reason.
0b3c3af to
8740569
Compare
|
Served Control UI proof from exact head At both viewports, RLM-prefixed Hebrew and ZWJ-prefixed Arabic switch from LTR on main to RTL/right-aligned on this PR; LRM, ALM, U+0890, and U+0891 remain visually identical, with Arabic joining intact. |
|
Merged via squash.
|
…e text starts with a bidi mark (openclaw#137474) * fix(ui): keep RTL chat messages right-aligned when they start with a bidi control detectTextDirection() scans for the first strong character but only skipped whitespace, punctuation and symbols. Unicode format characters (general category Cf) such as RLM (U+200F) and RLI (U+2067) fell through to the script test, matched no RTL script, and forced the entire message to dir="ltr". Explicit directional controls now decide the direction outright, mirroring the explicit-formatting step of UAX openclaw#9, and any remaining Cf characters are stepped over so they cannot mask the first strong character behind them. This matters because OpenClaw already emits these controls itself: src/tui/tui-formatters.ts wraps RTL runs in RLI ... PDI, so text produced by the project's own sanitizer rendered left-to-right in the Control UI. Co-Authored-By: Claude Opus 5 <[email protected]> * refactor(ui): fold bidi controls into the direction detector's skip set Builds on Ariel's fix for leading bidi controls and absorbs it into the owner instead of layering a fourth branch on top. `detectTextDirection` carried a `skipPattern` parameter that no caller has ever passed: all seven call sites in ui/src/pages/chat/components use the default. That unused seam is the structure the bug hid in, because the skip set it defaulted to was incomplete and nobody owned it. Dropping the parameter lets the neutral-format characters join the same named class as whitespace, punctuation, and symbols, so there is one skip set instead of a parameter plus a separate format-character branch. Behavior is identical to the previous revision across all 25 table cases; 9 of them are red on pre-fix code. Production net drops from +32 to +17 lines; tests from +27 to +13 while growing from 8 cases to 25, adding PDF (U+202C) and the full RLI...PDI wrapper shape. Formatting proof: oxfmt run on both files from an installed checkout; the worktree has no node_modules so the pre-commit formatter hook was bypassed after that separate proof. * test(ui): sweep the whole Cf family in the direction detector An audit of the leading-format-character behavior reported that eight code points still resolved left-to-right: U+0600-U+0604, U+070F, U+0890, U+0891. Sweeping all 170 Cf code points against the detector does not reproduce that: each of the eight resolves rtl in front of a strong RTL letter, and against pre-fix code the whole sweep shows zero regressions and 312 fixes. The report does not hold, but the coverage gap behind it was real, so this pins it. Adds per-code-point cases for the eight, the Arabic-Indic digit follow, and the one place behavior does differ from pre-fix code: an Arabic number sign followed by an ASCII digit contains no strong character at all, so first-strong finds nothing and the ltr default stands where pre-fix code answered rtl on sight. That is the correct reading and is now deliberate rather than incidental. Adds a property sweep over every Cf code point so a skip class that stops covering part of the family fails here instead of in a rendered message. Enumerated cases only pin the characters someone thought of. No production change: the skip class is already the \p{Cf} property class rather than an enumerated list, which is what covers all eight. Sweep costs 18ms. Fails on pre-fix code for the intended reason. --------- Co-authored-by: Ariel <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]> Co-authored-by: vyctorbrzezowski <[email protected]>
Closes #137472
What Problem This Solves
Hebrew, Arabic, and every other right-to-left script in the Control UI chat rendered left-to-right — sentence-final
?/!/.on the wrong visual side, digits and embedded Latin words in the wrong place — whenever the message text began with an explicit bidi control such as RLM (U+200F) or RLI (U+2067). Removing the mark made the same sentence render correctly, so users who marked their RTL text up properly were the only ones who got the broken layout.Leading directional marks are ordinary in RTL-authored text: editors, keyboards, and messaging clients insert them, and they survive copy-and-paste. The detector runs on raw, unrendered text at seven Control UI surfaces, including the live composer (
ui/src/pages/chat/components/chat-composer.ts:335), so a user pasting RLM-prefixed Hebrew got a left-to-right composer as they typed.A note on scope, since an earlier draft of this description overstated it:
src/tui/tui-formatters.tsdoes wrap RTL runs inU+2067 … U+2069, but that wrapping is reachable only throughsanitizeRenderableText/sanitizeRenderableLine, and every caller of those lives undersrc/tui/**. It is a terminal-render-time transform and does not reach the Control UI. The bug is real on the surfaces listed above; the TUI is not its producer.Why This Change Was Made
detectTextDirectionlooked for the first strong character but skipped only/[\s\p{P}\p{S}]/u. Unicode format characters (general categoryCf) are not in that set, so a leading RLM or RLI reached the script test atui/src/lib/text-direction.ts:27, matched no RTL script, and returned"ltr"on the very first character.In this PR,
ui/src/lib/text-direction.tsgains two rules and loses one seam:rtl; LRM, LRE, LRO, and LRI resolve toltr. This mirrors the explicit-formatting step of UAX sendMessageWeb() only handles images, should support audio/video/documents #9, where an explicit control outranks the implicit first-strong-character scan rather than being ignored by it.Cfcharacters are stepped over. PDF, PDI, FSI, ZWJ/ZWNJ, and BOM carry no direction of their own, so they no longer mask the first strong character behind them.skipPatternparameter is gone. No caller ever passed it — all seven call sites use the default — and that unowned, incomplete skip set is the structure the bug hid in. Folding the neutral format characters into a single named skip class absorbs the repair into the owner instead of adding a fourth branch beside a dead parameter.Non-goals, to keep this focused: the outbound isolation discussed in #68105 is a different layer and is untouched here. A message whose raw source begins with HTML (for example
<details>) still resolves toltr; that gap is recorded in #137472 and in the follow-up note below.User Impact
RTL chat messages now render right-to-left whether or not the author marked them up with a bidi control, so punctuation, digits, parentheses, and embedded Latin words land where readers expect. Text with no bidi marks is unaffected, and LTR text explicitly marked with LRM/LRI is now honored as LTR instead of being decided by whatever character happened to come next.
Evidence
Before / after, contributor capture. Four messages rendered through the same
.chat-textmarkup,dircomputed by the currentdetectTextDirectionand by the corrected one. The last row carries no bidi mark and is the unchanged control.Two notes on reading these. The captions are baked into the images, and the second row's label — "exactly what
src/tui/tui-formatters.tsemits" — is superseded by the scope correction in the first section above: that wrapping is terminal-render-time only and does not reach the Control UI. Read that row as what it actually demonstrates, an RTL run wrapped inU+2067 … U+2069arriving as pasted or authored text, which is the input the detector has to handle regardless of who produced it. The images are also re-hosted here as permanent attachments; they were originally hotlinked to a fork commit that is not reachable from this branch's head and would have died with the fork.mainBefore / after / alternative, maintainer capture. Nine samples through the real
.chat-textrules fromui/src/styles/chat/text.cssand the real light-theme tokens fromui/src/styles/base.css, in an isolated browser at 1280px and 390px. Each cell reports thedirattribute and the direction the browser actually computed, so the third column shows whatdir="auto"would have resolved rather than the literal attribute. Rows 1–3 are the defect; rows 5–8 are unchanged controls; row 9 is the HTML-leading gap this PR does not close.Desktop, 1280px:
Mobile, 390px:
Regression coverage.
ui/src/lib/text-direction.test.tsis a 25-case table covering: bare Hebrew, Arabic, and Latin; Markdown prefixes; RLM, RLE, RLI, and ALM before RTL text; RLM and RLO overriding Latin; LRM, LRE, LRO, and LRI overriding Hebrew; RLI…PDI and FSI…PDI wrappers; PDF, ZWJ, and BOM before Hebrew; and format-only input. Nine of the 25 cases are red against pre-fixmain, for the intended reason — the leading control or neutral format character reaches the script test and forcesltr.Verification runs. Exact-head CI on this branch is the validation of record; the fix is a fork-authored change and its suites were not run on a maintainer workstation. Formatting was confirmed with
oxfmtover both touched files from an installed checkout.Risk and coverage
What else could break.
detectTextDirectionis a shared owner with seven production call sites, and every one of them writes the result straight into adirattribute: chat message bodies (chat-message-markdown.ts:346), chat notices (chat-divider.ts:81), the live composer textarea (chat-composer.ts:335), the composer dictation preview (chat-composer-view.ts:240→:409), the session rail question and answer (chat-session-rail.ts:421,:424), and sidebar content (chat-sidebar-content.ts:376). A wrong direction on any of them is a visible layout regression for an entire language family.Proof it does not break. The change is additive at the front of the scan: text whose first significant character is not a bidi control takes exactly the path it took before, which the four unchanged control rows in both captures show. Every call site consumes the return value only as a
dirattribute — none branches on it, stores it, or derives layout from it — so a per-consumer behavior review reduces to the one function, and the 25-case table is that review. The two candidate implementations for this repair, the one originally proposed and the one on the branch now, were run against the full table and agree on all 25 cases, so the compaction described above is surface reduction, not a behavior change.What stays uncovered. Three things. First, direction is still decided from raw Markdown rather than rendered text, so a message opening with an HTML block still resolves
ltr— row 9 of the maintainer capture, and the same gap #137472 records. Second, a handful of characters are bothCfandScript=Arabic(U+0600–U+0605,U+06DD) and are now stepped over instead of resolvingrtlon sight; in real text they are immediately followed by Arabic-Indic digits, which resolvertlanyway, and this is an accepted trade for one skip class instead of a carve-out. Third, both captures are mocks of the chat surface rather than a live gateway session; they use the product's own stylesheet rules and markup, but they are not a running Control UI.Follow-ups found on the way, recorded rather than silently passed by. Neither belongs in a bug fix that closes a filed issue.
dir="auto"resolved correctly on all nine samples, including the HTML-leading row this PR leaves open, and every call site uses the detector's value only as adirattribute — so replacing the module withdir="auto"is a plausible net-negative-LOC refactor. It is already house precedent atui/src/pages/about/view.ts:121. It is also a behavior change across seven surfaces on a default path and needs its own proof and a product call.src/tui/tui-formatters.ts:29decides RTL from hand-rolled BMP ranges, so Adlam (U+1E900), Phoenician (U+10900), and Lydian (U+10920) are never isolated in terminal output even though the Control UI detector covers all three; it also asks "contains any RTL character" where the Control UI asks "first strong character". Different owner, different surface, and it needs terminal proof of its own.On the production-LOC item. Production is +17 net, down from +32, by deleting the unused
skipPatternparameter and folding the neutral format characters into the same named skip class rather than adding a branch beside it; the remaining growth is two closed control classes and the comments that make invisible code points reviewable, and the single-owner design ClawSweeper asked to preserve is intact.Provenance
The fix and its first round of evidence are by @arieleli01212, whose commit is preserved at the base of this branch and who stated on opening it that they had read the diff and understood what it does. The follow-up commit is maintainer work: the compaction described above, the expanded test table, the maintainer captures, and the scope correction in the first section.
Allow edits from maintainers is enabled on this PR.