Skip to content

fix(ui): Hebrew and Arabic chat messages render left-to-right when the text starts with a bidi mark - #137474

Merged
vyctorbrzezowski merged 3 commits into
openclaw:mainfrom
arieleli01212:fix/text-direction-bidi-controls
Sep 4, 2026
Merged

vyctorbrzezowski merged 3 commits into
openclaw:mainfrom
arieleli01212:fix/text-direction-bidi-controls

Conversation

@arieleli01212

@arieleli01212 arieleli01212 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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.ts does wrap RTL runs in U+2067 … U+2069, but that wrapping is reachable only through sanitizeRenderableText / sanitizeRenderableLine, and every caller of those lives under src/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

detectTextDirection looked for the first strong character but skipped only /[\s\p{P}\p{S}]/u. Unicode format characters (general category Cf) are not in that set, so a leading RLM or RLI reached the script test at ui/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.ts gains two rules and loses one seam:

  • Explicit directional controls decide outright. RLM, RLE, RLO, RLI, and ALM resolve to rtl; LRM, LRE, LRO, and LRI resolve to ltr. 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.
  • Remaining Cf characters 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.
  • The skipPattern parameter 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 to ltr; 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-text markup, dir computed by the current detectTextDirection and 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.ts emits" — 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 in U+2067 … U+2069 arriving 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.

Before — main After
contributor capture, before contributor capture, after

Before / after / alternative, maintainer capture. Nine samples through the real .chat-text rules from ui/src/styles/chat/text.css and the real light-theme tokens from ui/src/styles/base.css, in an isolated browser at 1280px and 390px. Each cell reports the dir attribute and the direction the browser actually computed, so the third column shows what dir="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:

desktop

Mobile, 390px:

mobile

Regression coverage. ui/src/lib/text-direction.test.ts is 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-fix main, for the intended reason — the leading control or neutral format character reaches the script test and forces ltr.

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 oxfmt over both touched files from an installed checkout.

Risk and coverage

What else could break. detectTextDirection is a shared owner with seven production call sites, and every one of them writes the result straight into a dir attribute: 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 dir attribute — 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 both Cf and Script=Arabic (U+0600–U+0605, U+06DD) and are now stepped over instead of resolving rtl on sight; in real text they are immediately followed by Arabic-Indic digits, which resolve rtl anyway, 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 a dir attribute — so replacing the module with dir="auto" is a plausible net-negative-LOC refactor. It is already house precedent at ui/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:29 decides 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 skipPattern parameter 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 4, 2026, 3:01 PM ET / 19:01 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 8740569c80f3ebd4f37883d17d51d4fb424f3c18

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and regression coverage are coherent, but merge readiness is capped by the missing served-Control-UI proof.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The changed production owner is the Control UI direction detector, whose result is assigned to rendered chat dir attributes. The prepared screenshots show the corrected outcome only for isolated .chat-text markup, not the served Control UI bundle at this head, so they do not yet establish real after-fix behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The changed production owner is the Control UI direction detector, whose result is assigned to rendered chat dir attributes. The prepared screenshots show the corrected outcome only for isolated .chat-text markup, not the served Control UI bundle at this head, so they do not yet establish real after-fix behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items Current main remains affected: Fetched main still skips only whitespace, punctuation, and symbols; a leading Unicode format character reaches the script test and returns ltr before the following RTL character is examined.
Latest stable release remains affected: Release v2026.9.1 contains the same detector implementation and therefore does not already solve this PR's reported Control UI behavior.
Introduced repair is at the shared owner: The PR checks explicit controls before skipping Unicode format characters, then applies the existing script-based first-strong fallback.
Findings None None.
Security None None.

How this fits together

Control UI chat surfaces derive a dir attribute from raw text for message bodies, composer input, notices, and session content. That value drives browser text flow and RTL alignment in the rendered chat UI.

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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The changed production owner is the Control UI direction detector, whose result is assigned to rendered chat dir attributes. The prepared screenshots show the corrected outcome only for isolated .chat-text markup, not the served Control UI bundle at this head, so they do not yet establish real after-fix behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The available before/after screenshots do not prove that the served Control UI bundle at this head assigns the corrected direction during an actual chat flow.
  • Complete next step (P2) - Add real after-fix proof from the served Control UI at this exact head before merge.
Agent review details

Security

None.

PR surface

Source +17, Tests +53. Total +70 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 9 +17
Tests 1 69 16 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 95 25 +70

Review metrics

Metric Value Why it matters
Production versus test LOC production +26/-9 (net +17); tests +69/-16 (net +53) The production growth defines the two bidi-control classes and the neutral-format skip class; the larger test expansion protects their shared UI behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #137472
Summary: This PR directly targets the same leading-bidi-control Control UI behavior reported by the linked open issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Mantis proof suggestion

A 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:

@openclaw-mantis verify the served web UI chat renders an RLM- or RLI-prefixed Hebrew or Arabic message right-to-left and return redacted proof.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs a deterministic but bounded Control UI layout defect affecting RTL text with leading bidi controls.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The changed production owner is the Control UI direction detector, whose result is assigned to rendered chat dir attributes. The prepared screenshots show the corrected outcome only for isolated .chat-text markup, not the served Control UI bundle at this head, so they do not yet establish real after-fix behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The changed production owner is the Control UI direction detector, whose result is assigned to rendered chat dir attributes. The prepared screenshots show the corrected outcome only for isolated .chat-text markup, not the served Control UI bundle at this head, so they do not yet establish real after-fix behavior.

Evidence

What I checked:

  • Current main remains affected: Fetched main still skips only whitespace, punctuation, and symbols; a leading Unicode format character reaches the script test and returns ltr before the following RTL character is examined. (ui/src/lib/text-direction.ts:24, 01d4b6445417)
  • Latest stable release remains affected: Release v2026.9.1 contains the same detector implementation and therefore does not already solve this PR's reported Control UI behavior. (ui/src/lib/text-direction.ts:24, ad6fe23aecb9)
  • Introduced repair is at the shared owner: The PR checks explicit controls before skipping Unicode format characters, then applies the existing script-based first-strong fallback. (ui/src/lib/text-direction.ts:35, 8740569c80f3)
  • Consumer boundary: Rendered chat message text writes the detector result directly to its dir attribute, which reaches the RTL stylesheet rule. (ui/src/pages/chat/components/chat-message-text.ts:228, 8740569c80f3)
  • Regression coverage: The updated table covers controls, neutral format characters, and a complete Cf-family sweep at the detector boundary. (ui/src/lib/text-direction.test.ts:51, 8740569c80f3)
  • Prepared visual proof: The two inspected captures visibly show the intended before/after direction change, but their captions identify isolated .chat-text markup rather than a served Control UI bundle at this head.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a sanitized screenshot or recording from the served Control UI at this head showing RLM- or RLI-prefixed RTL text and the corrected rendered direction; redact private endpoints and identifiers.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-03T18:30:51.119Z sha 2c0de58d6f3bd742d1f4ac32e5f208f0261fed15 :: blocked before merge. :: none
  • reviewed 2026-09-03T21:54:47.585Z sha 2badd072fb5ca7e1342c270901cce2412a7d7aae :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T02:43:27.043Z sha 111a2a57d351ef8d5ce8acb04e8f86236d29ccd6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T14:00:39.594Z sha 111a2a57d351ef8d5ce8acb04e8f86236d29ccd6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T17:38:55.633Z sha 0b3c3af927fb14fb4ea7f6ead08970bbc6a9991a :: needs real behavior proof before merge. :: none

@vyctorbrzezowski vyctorbrzezowski self-assigned this Sep 3, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@vyctorbrzezowski

Copy link
Copy Markdown
Member

Follow-up on the leading-format-character behavior, with the sweep that settles it.

The eight code points do not regress

A review of this change flagged eight Unicode Cf code points as still resolving left-to-right: U+0600–U+0604 (Arabic number signs), U+070F (Syriac abbreviation mark), and U+0890/U+0891 (Arabic pound and piastre marks above). Sweeping all 170 Cf code points against the detector on this branch does not reproduce that. Each of the eight resolves rtl in front of a strong RTL letter, on this branch and on main alike.

The reason is the shape of the skip class. It is the \p{Cf} property, not an enumerated list, so it already covers every format character including those eight; the detector steps over the mark and the strong letter behind it decides. An enumerated list is exactly where that report would have been correct, which is why the property class is the one worth keeping.

Full sweep, all 170 Cf code points in leading position followed by a strong RTL letter, both scripts, 340 cases:

Measure Result
Correct on this branch 340 / 340
Regressions against main 0
Cases this branch fixes that main gets wrong 312

What the report did get right

The description's enumeration of the affected set was wrong, and this is the correction.

The characters that are both Cf and an RTL script — the ones main resolved on sight rather than stepping over — are U+0600–U+0604, U+070F, U+0890, and U+0891. The description named U+0605 and U+06DD instead. Those two are the opposite case: they are Cf but carry no RTL script, so main reached the script test, matched nothing, and answered ltr in front of Arabic text. This branch fixes them. U+08E2 behaves the same way and was also unnamed.

Where behavior does differ from main

One place, and it is narrow: an Arabic number sign followed by an ASCII digit, for example U+0600 then 3. main answered rtl, because the sign itself is an Arabic-script character and was tested directly. This branch answers ltr.

ltr is the correct reading. An Arabic number sign is a weak type and an ASCII digit is a weak type, so the string contains no strong character at all and the default stands. Followed by an Arabic-Indic digit — which is what these prefix marks introduce in practice — the answer is rtl on both. The divergence is now pinned by a test with that reasoning at the code site, so any future change to the skip class has to be deliberate about it rather than flipping it by accident.

Coverage added

The report did not hold, but the coverage gap behind it was real: nothing pinned those code points, so nothing would have caught it if a later change narrowed the skip class. Added in this branch:

  • One case per code point for all eight, plus the Arabic-Indic digit follow.
  • The ASCII-digit case above, pinning the one intentional difference.
  • A property sweep over every Cf code point, asserting each one is stepped over to reach the strong letter behind it, with the four explicit left-to-right overrides still winning. Enumerated cases only pin the characters someone thought of; the sweep pins the family. It costs 18ms and fails against pre-fix code for the intended reason, listing every offender.

No production change was needed for any of this — the skip class already had the coverage.

Risk and coverage

What else could break. The detector is a shared owner with seven call sites, every one of them writing the result into a dir attribute: chat message bodies, chat notices, the composer textarea, the composer dictation preview, the session rail question and answer, and sidebar content. .chat-text[dir="rtl"] drives a real text-align rule, so a wrong value is a visible layout change for a whole language family, not a subtle one.

Proof it does not break. The 340-case sweep covers the entire Cf family in leading position against both an Arabic and a Hebrew strong letter, with zero regressions against main. The wider table covers bare Hebrew, Arabic and Latin, Markdown prefixes, every direction-bearing control in both directions, isolate wrappers, and format-only input. No call site branches on the value or stores it, so a per-consumer review reduces to the one function, and these tests are that review. The change is additive at the front of the scan, so text whose first significant character is not a format character takes exactly the path it took before.

What stays uncovered. Direction is still decided from raw Markdown rather than rendered text, so a message opening with an HTML block still resolves ltr. Digits and other weak types are still not strong characters, by design, which is what the ASCII-digit case above records. And the sweep asserts leading position only — a format character in the middle of a run is not covered, because the detector stops at the first strong character before reaching it.

@vyctorbrzezowski
vyctorbrzezowski force-pushed the fix/text-direction-bidi-controls branch from 111a2a5 to 0b3c3af Compare September 4, 2026 17:06
arieleli01212 and others added 3 commits September 4, 2026 18:52
…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.
@vyctorbrzezowski
vyctorbrzezowski force-pushed the fix/text-direction-bidi-controls branch from 0b3c3af to 8740569 Compare September 4, 2026 18:53
@vyctorbrzezowski

Copy link
Copy Markdown
Member

Served Control UI proof from exact head 8740569c80f3ebd4f37883d17d51d4fb424f3c18 (built production bundle + mock Gateway, dark mode): 1440 Before/After · 390 Before/After

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.

@vyctorbrzezowski
vyctorbrzezowski merged commit 7911a0c into openclaw:main Sep 4, 2026
299 of 301 checks passed
@vyctorbrzezowski

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI chat renders RTL messages left-to-right when the text starts with a bidi control (RLM/RLI)

2 participants