Skip to content

fix(browser): UTF-16-safe page text truncation - #146131

Closed
nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/browser-page-text-utf16
Closed

nocodet888-arch wants to merge 1 commit into
openclaw:mainfrom
nocodet888-arch:fix/browser-page-text-utf16

Conversation

@nocodet888-arch

Copy link
Copy Markdown
Contributor

What Problem This Solves

getPageTextViaPlaywright truncated visible page text with raw .slice(0, maxChars). Emoji/CJK at the budget boundary can split a UTF-16 surrogate pair, producing a lone high/low surrogate in model-facing text. Sibling snapshot/responses paths already use truncateUtf16Safe.

Why This Change Was Made

Replace .slice with truncateUtf16Safe from openclaw/plugin-sdk/text-utility-runtime, matching pw-tools-core.responses.ts / pw-tools-core.snapshot.ts.

User Impact

Before: Page-text truncation could emit a broken trailing surrogate.

After: Truncation backs up to a code-unit boundary; emoji at the edge is dropped whole.

Evidence

  • Changed: extensions/browser/src/browser/pw-tools-core.activity.ts, extensions/browser/src/browser/pw-tools-core.activity.test.ts
  • Production path: browser page-text tool → getPageTextViaPlaywright → truncateUtf16Safe

Real behavior proof

Behavior or issue addressed

maxChars=5 on "abcd😀" returns "abcd" with no lone surrogate (raw .slice would keep a high surrogate).

Canonical reachability path

getPageTextViaPlaywright → locator.innerText → truncateUtf16Safe(text, maxChars)

Shared helper / provider constraint check

Reuses shared truncateUtf16Safe already used by snapshot/responses.

Real environment tested

Local Vitest with Playwright page mocks (installTextPage).

Exact steps or command run after this patch

node scripts/run-vitest.mjs extensions/browser/src/browser/pw-tools-core.activity.test.ts -t "surrogate pair" --reporter=verbose

Evidence after fix

[browser page-text utf16 proof] maxChars=5 input="abcd😀" output="abcd" truncated=true

 ✓ |extension-browser| ... > does not split a trailing surrogate pair when truncating page text 182ms

 Test Files  1 passed (1)
      Tests  1 passed | 12 skipped (13)

Observed result after fix

Output is "abcd" (emoji dropped whole); no lone surrogate remains.

What was not tested

Live Playwright against a real Chrome page with emoji near the char budget.

Fix classification

Root cause fix

  • AI-assisted (Cursor)
  • I understand what the code does
  • Change is focused and does not mix unrelated concerns

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This PR still needs the requested real-behavior proof, and the branch has been idle since that ask.

Close as stalled awaiting real behavior proof: the dated proof request and head activity are over three weeks old, evidence remains mock-only, and no maintainer engagement or protected signal is present. The underlying fix remains useful.

So I’m closing this for now to keep the review queue honest. Please reopen or open a fresh PR with real-behavior proof (a live run, logs, or a reproducible validation transcript) and it will be reviewed again.

Review details

Best possible solution:

Retain the shared UTF-16 helper approach in a refreshed patch with Chrome-backed output proving the complete-character boundary behavior.

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

Yes, from source: the current Playwright page-text path slices abcd😀 at five UTF-16 units, retaining a lone high surrogate. A real Chrome-backed reproduction was not executed.

Is this the best way to solve the issue?

Yes, reusing the existing SDK truncation helper is the narrow repair and preserves the current budget and truncation flag.

Security review:

Security review cleared: The patch reuses an existing text helper without changing authorization, execution, dependencies, or sensitive-data handling.

AGENTS.md: found and applied where relevant.

What I checked:

  • Verified introduced change: The pinned merge-base-to-head patch replaces raw slicing with the existing SDK truncation helper and adds a regression using a mocked page. It introduces no authority, configuration, dependency, or persistence changes. (extensions/browser/src/browser/pw-tools-core.activity.ts:47, 6f76a21315f8)
  • Current main still needs the fix: Current main retains text.slice(0, maxChars), within its newer cancellation and timeout handling. Reading abcd😀 with maxChars=5 therefore still cuts between the surrogate halves. The related merged browser reliability work did not implement this change. (extensions/browser/src/browser/pw-tools-core.activity.ts:66, 78e406060b56)
  • Existing shared truncation owner: The SDK re-exports the repository's normalization helper, which moves a slicing endpoint backward when it splits a surrogate pair. The response-body path already consumes the same SDK helper; this PR appropriately reuses that owner. (packages/normalization-core/src/utf16-slice.ts:59, 6f76a21315f8)
  • Captured proof remains mock-only: The supplied complete PR body explicitly identifies mocked Playwright locators and states that real Chrome was not tested. Its abcd result matches the added Vitest test, rather than a Chrome-backed /text request. The captured context sourceRevision is ada7c2715dd55045b9ff3323f4d644ec40f204b91c4aab43d01011fb4203bc1d. (extensions/browser/src/browser/pw-tools-core.activity.test.ts:90, 6f76a21315f8)
  • Proof request exceeded its response window: Live timeline inspection confirms status: 📣 needs proof was applied on 2026-09-12T15:46:50Z, more than 22 days before this review. The prior completed review again requested Chrome-backed page-text output; its recorded findings were empty.
  • Head inactivity independently verified: The pinned head's committer timestamp is 2026-09-12T15:40:30Z. All returned head check runs date to September 12, with the latest completion at 15:49:35Z; commit, status, and check activity therefore exceed the required 14-day inactivity window. (6f76a21315f8)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Codex review notes: model internal, reasoning medium; reviewed against 78e406060b56.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper recorded closeout evidence for this proposed close.

  • Action: close remains subject to final live verification.
  • Close reason: stalled PR without requested real-behavior proof.
    Review evidence: durable ClawSweeper review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS 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.

1 participant