Repository navigation
fix(browser): avoid splitting surrogate pairs in page text - #191899
Conversation
|
Codex review: needs maintainer review before merge. What this changesThis PR preserves complete UTF-16 surrogate pairs when truncating extracted browser page text. Example: Extract article text A😀B with maxChars=2.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests -1, Docs +4. Total +3 across 3 files. Added test files: 0. 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. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 3, 2026, 9:29 AM ET / 14:29 UTC (Revision 2). |
Built Gateway → real Chrome page-text proofCandidate 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 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Exact-head CI classificationHead Both substantive failures have the same-case independent pull-request CI witness at head
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. |
|
Maintainer override: the only reds are the UI |
|
Landed in 0cd7e83. Thanks @zhangguiping-xydt. Browser page text no longer ends with a broken emoji. |
…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]>
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.