Skip to content

fix(browser): avoid splitting surrogate pairs in page text - #191899

Merged
obviyus merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/proof-round5-3
Nov 3, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/proof-round5-3

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes broken Unicode at the end of extracted browser page text when its limit falls inside an emoji's UTF-16 surrogate pair.

User Impact

Extraction keeps or omits the entire pair without exceeding the existing budget. For A😀B at a two-code-unit cap, the result is A with truncated=true, not A plus a dangling surrogate. ASCII text and complete-pair limits are unchanged; no configuration or migration is required.

Why This Change Was Made

Reuse the existing SDK UTF-16-safe truncation owner already used by browser response-body extraction instead of slicing through a pair. No new helper, dependency, export, public type, limit or grapheme-counting behavior.

Preserves @zhangguiping-xydt's fix and original commit. Consolidates the regression into the existing activity fixture, retains selector/fallback and hard-limit coverage, removes the proposed test allocation, and documents the budget.

Evidence

Four real-Chrome public extraction traces

Built Gateway and public CLI with real Chromium in secretless Node 24.22.1 Docker: main twice returns a lone surrogate; candidate twice returns well-formed text within the budget. Complete-emoji, untruncated and ASCII controls are unchanged.

15 focused tests pass across the activity and public text-route owners. The final activity file on main fails only the split-surrogate regression (10 controls pass). Typed lint and formatting pass. Production +2/-2; tests +16/-17 (net -1); docs +4.

Merge danger

Two-way door: reverting restores the old boundary slicing, without state writes or migration. Blast radius is Playwright-backed browser page-text extraction at a surrogate-pair boundary. This does not repair already malformed input or change the budget to code points or grapheme clusters.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves complete UTF-16 surrogate pairs when truncating extracted browser page text.

Example: Extract article text A😀B with maxChars=2.

  • Before: Returns A followed by a lone high surrogate, with truncated=true.
  • After: Returns A with truncated=true, staying within the existing budget.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal, useful repair with exact-head shipped-entry-point proof, reported red/green regression validation, no persistence changes, and no findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): At candidate c0c21b4, public CLI browser.request calls reached GET /text through a built Gateway and real Chromium in secretless Node 24.22.1 Docker; two candidate runs returned well-formed bounded text where two baseline runs split the pair, with complete-pair, exact-fit, and ASCII controls unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Extracted browser text can end with a broken Unicode character when its budget cuts through an emoji.
Reason: The patch restores valid character boundaries with an existing helper and preserves the established extraction contract.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete Unicode truncation bug still present on current main; the focused patch has no actionable findings.

Priority: P2
Reviewed head: c0c21b4be58b9a5c065fb009b42f98a8497ac00b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The browser plugin reads rendered text from Playwright locators for GET /text and returns bounded text plus a truncation flag through the Gateway.

flowchart LR
  A[Public CLI or browser tool] --> B[Gateway browser request]
  B --> C[GET text route]
  C --> D[Playwright page text]
  D --> E[SDK UTF16 truncation]
  E --> F[Bounded text result]
Loading

Technical review

Best possible solution:

Land the existing helper substitution and focused regression once the ordinary exact-head checks pass.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically splits A😀B at maxChars=2, and supplied real-Chromium baseline traces demonstrate that result; this read-only review ran no target code.

Is this the best way to solve the issue?

The shared helper substitution is the smallest complete repair: preserve surrogate pairs within the existing budget without changing selection, cancellation, limits, or result types.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0a0d601bf12d.

Provenance checked

  • Rendered page-text extraction keeps the original intent (61fc3d2: Expose guarded, bounded article/main/body text without caller-provided JavaScript; subsequent changes preserve cancellation and timeout ownership.)
  • Activity test consolidation keeps the original intent (test(agents,plugins,ui): remove low-value tests (batch d613) #184680: Remove redundant scaffolding while retaining owning-boundary scenarios; the current table extends the existing fixture with the Unicode regression and independent controls.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 61fc3d2 adds extensions/browser/src/browser/pw-tools-core.activity.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 61fc3d2d7957; files: extensions/browser/src/browser/pw-tools-core.activity.ts)

PR surface

Source 0, Tests -1, Docs +4. Total +3 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 16 17 -1
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 22 19 +3

Review metrics

Metric Value Why it matters
Production versus test LOC Production +2/-2; tests +16/-17. The repair reuses an existing owner without production growth, while the consolidated fixture retains selection and budget controls.

Root-cause cluster

Relationship: canonical
Canonical: #191899
Summary: This PR provides the active fix for the same page-text raw-slice defect addressed by earlier closed-unmerged work.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The bug corrupts extracted text only when a budget cuts through a surrogate pair, with limited blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-03T12:55:10.149Z sha 1f2e5d2 :: needs maintainer review before merge. :: none

Reviewed November 3, 2026, 9:29 AM ET / 14:29 UTC (Revision 2).

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway → real Chrome page-text proof

Candidate c0c21b4; frozen main df80ba7. Canonical runtime builds in secretless node:24.22.1 Docker; real Chromium 156.0.8078.4. Each independent run has an explicit task-owned profile, HOME, state, config, Gateway port and CDP port. The built config-file command resolves the owned config first. A normal authenticated public CLI gateway call browser.request requests GET /text on the actual target returned by GET /tabs. No extraction helper import, browser mock, model, or external credentials.

The real rendered page is <article>A😀B</article><aside id="ascii">ABCD</aside>. All CLI calls exit zero. Main twice returns A followed by a lone high surrogate at maxChars=2. Candidate twice returns A, omitting the entire emoji that cannot fit; it does not exceed the existing UTF-16-unit budget. At maxChars=3 both return the whole emoji (A😀), at 4 both return A😀B without truncation. ASCII at the same 2-unit cap remains AB. This preserves complete pairs, not grapheme clusters or preexisting invalid input.

Actual public output with independently computed UTF-16 code units:

[
  {
    "run": "base1",
    "chrome": "156.0.8078.4",
    "results": [
      {
        "selector": "article",
        "maxChars": 2,
        "ok": true,
        "targetId": "3189516EF39B1C44BB1D48FA2025A7CA",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A\ud83d",
        "truncated": true,
        "codeUnits": [
          65,
          55357
        ],
        "wellFormed": false
      },
      {
        "selector": "article",
        "maxChars": 3,
        "ok": true,
        "targetId": "3189516EF39B1C44BB1D48FA2025A7CA",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀",
        "truncated": true,
        "codeUnits": [
          65,
          55357,
          56832
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 4,
        "ok": true,
        "targetId": "3189516EF39B1C44BB1D48FA2025A7CA",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀B",
        "truncated": false,
        "codeUnits": [
          65,
          55357,
          56832,
          66
        ],
        "wellFormed": true
      },
      {
        "selector": "#ascii",
        "maxChars": 2,
        "ok": true,
        "targetId": "3189516EF39B1C44BB1D48FA2025A7CA",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "AB",
        "truncated": true,
        "codeUnits": [
          65,
          66
        ],
        "wellFormed": true
      }
    ]
  },
  {
    "run": "base2",
    "chrome": "156.0.8078.4",
    "results": [
      {
        "selector": "article",
        "maxChars": 2,
        "ok": true,
        "targetId": "50E088105BA00E922929063925F41E5E",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A\ud83d",
        "truncated": true,
        "codeUnits": [
          65,
          55357
        ],
        "wellFormed": false
      },
      {
        "selector": "article",
        "maxChars": 3,
        "ok": true,
        "targetId": "50E088105BA00E922929063925F41E5E",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀",
        "truncated": true,
        "codeUnits": [
          65,
          55357,
          56832
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 4,
        "ok": true,
        "targetId": "50E088105BA00E922929063925F41E5E",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀B",
        "truncated": false,
        "codeUnits": [
          65,
          55357,
          56832,
          66
        ],
        "wellFormed": true
      },
      {
        "selector": "#ascii",
        "maxChars": 2,
        "ok": true,
        "targetId": "50E088105BA00E922929063925F41E5E",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "AB",
        "truncated": true,
        "codeUnits": [
          65,
          66
        ],
        "wellFormed": true
      }
    ]
  },
  {
    "run": "candidate1",
    "chrome": "156.0.8078.4",
    "results": [
      {
        "selector": "article",
        "maxChars": 2,
        "ok": true,
        "targetId": "46C69821A6E039BAA8F307BDC1CD6F51",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A",
        "truncated": true,
        "codeUnits": [
          65
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 3,
        "ok": true,
        "targetId": "46C69821A6E039BAA8F307BDC1CD6F51",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀",
        "truncated": true,
        "codeUnits": [
          65,
          55357,
          56832
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 4,
        "ok": true,
        "targetId": "46C69821A6E039BAA8F307BDC1CD6F51",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀B",
        "truncated": false,
        "codeUnits": [
          65,
          55357,
          56832,
          66
        ],
        "wellFormed": true
      },
      {
        "selector": "#ascii",
        "maxChars": 2,
        "ok": true,
        "targetId": "46C69821A6E039BAA8F307BDC1CD6F51",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "AB",
        "truncated": true,
        "codeUnits": [
          65,
          66
        ],
        "wellFormed": true
      }
    ]
  },
  {
    "run": "candidate2",
    "chrome": "156.0.8078.4",
    "results": [
      {
        "selector": "article",
        "maxChars": 2,
        "ok": true,
        "targetId": "44F73E837550A72A21CD6795BF9BC808",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A",
        "truncated": true,
        "codeUnits": [
          65
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 3,
        "ok": true,
        "targetId": "44F73E837550A72A21CD6795BF9BC808",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀",
        "truncated": true,
        "codeUnits": [
          65,
          55357,
          56832
        ],
        "wellFormed": true
      },
      {
        "selector": "article",
        "maxChars": 4,
        "ok": true,
        "targetId": "44F73E837550A72A21CD6795BF9BC808",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "A😀B",
        "truncated": false,
        "codeUnits": [
          65,
          55357,
          56832,
          66
        ],
        "wellFormed": true
      },
      {
        "selector": "#ascii",
        "maxChars": 2,
        "ok": true,
        "targetId": "44F73E837550A72A21CD6795BF9BC808",
        "url": "data:text/html;charset=utf-8,%3Carticle%3EA%F0%9F%98%80B%3C%2Farticle%3E%3Caside%20id%3D%22ascii%22%3EABCD%3C%2Faside%3E",
        "text": "AB",
        "truncated": true,
        "codeUnits": [
          65,
          66
        ],
        "wellFormed": true
      }
    ]
  }
]

15 tests across activity and the public text route pass. The same final activity file on main has exactly one intended split-surrogate failure and 10 passes. Consolidated selection, article priority, body fallback, ASCII hard limit and emoji boundaries into the existing fixture, with no new production seam. Typed Oxlint: zero warnings/errors; Oxfmt passes. Production +2/-2 (net zero); test source +16/-17 (net -1); docs +4. Removed the proposed separate test allocation. Existing SDK UTF-16-safe truncation owner is reused; limits, result types and truncation flag are unchanged.

Setup note: an initial launch used a retired browser profile color field and was rejected before extraction; that setup attempt is not counted as a product verdict. The four completed runs above use valid normal configuration and stopped their Gateways and browsers.

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Nov 3, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Exact-head CI classification

Head c0c21b4be58b9a5c065fb009b42f98a8497ac00b has a 5/6 exact-head review with no findings, but ci-gate is red. No rerun or extra push requested.

Both substantive failures have the same-case independent pull-request CI witness at head f3f58517ea8395d8223de85403ba53e28cebc3ee (run 41652758517):

These unrelated UI source/ratchet inputs are untouched by this PR's browser activity owner, its focused fixture, and browser documentation. Its extension lint stripe passes; the hosted test-lines ratchet explicitly reports net delta -1 and passes. All other substantive jobs completed; one auxiliary job was cancelled. Runtime proof and 15 focused activity/route tests are already complete as linked above. Retaining the branch, worktree, container, build volume and harness for maintainer resumption.

@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the only reds are the UI auth shadowing lint and the config-secret-fields.test.ts mock-export ratchet. This PR touches neither file, and both fail the same way on main b018452 (#191538 (comment)) and in unrelated run 41652758517. Classification: #191899 (comment)

@obviyus
obviyus merged commit 0cd7e83 into openclaw:main Nov 3, 2026
103 of 108 checks passed
@obviyus

obviyus commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Landed in 0cd7e83. Thanks @zhangguiping-xydt. Browser page text no longer ends with a broken emoji.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…191899)

fix(browser): don't split emoji when truncating page text

When page text was cut at the browser tool's size budget, the cut could land inside an emoji's UTF-16 surrogate pair, leaving a broken lone surrogate in the result. The cut now keeps or drops each emoji whole and stays within the budget. Full text, whole emoji and ASCII text at the limit are unchanged.

Evidence: built Gateway and public CLI with real Chromium on Node 24.22.1. Main returned a lone high surrogate twice; with this change the emoji that did not fit was left out whole and the result stayed within budget, twice. Whole-emoji, full-text and ASCII controls were unchanged. Details: openclaw#191899 (comment).

Thanks @zhangguiping-xydt.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: browser P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants