Skip to content

fix(document): parse text responses with consistent decoding - #761

Merged
ldm0 merged 6 commits into
mainfrom
codex/pr640-reopen-text
Sep 29, 2026
Merged

ldm0 merged 6 commits into
mainfrom
codex/pr640-reopen-text

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

JSON 等文本响应被当作 HTML 解析,生成错误的节点结构,并可能执行脚本或触发资源预加载。编码、流式分块及主/子文档的不同处理路径又可能改变最终文本。本 PR 在文档构造边界统一 MIME 分类、解码和文本解析语义。

一图看懂

PR #761 · 文本按字面解析,HTML 保持正常语义

图示说明问题、修复机制与行为边界;点击可查看原图。验收归属不等于当前提交通过结果,版本和测试证据见下文。

行为与机制

声明 MIME 优先于 URL 后缀;文本内容按字面文本进入文档,不先转义包装再解析。decoder/parser/预加载策略使用一致模式,分块边界不改变结果。文本文档不生成 doctype,显式保持标准模式;保留 main 已有的纯文本子文档语义。

代码阅读路线

  1. moli-web-mime classification/sniffing 和 moli-encoding/src/document.rs:响应类型及编码/BOM。
  2. moli-parser/src/html.rs、session/stream 与 renderer 的 document_response_decoder.rs、live_document_parser:流式文本、换行与 DOM 构造。
  3. child documents commit/live_parser/loads/snapshots、phase_one bootstrap/streaming 及 moli-protocol/src/conn/runtime_load.rs:主/子文档统一入口与原始字节保留。
  4. encoding/MIME/parser、navigation streaming、Page/target/classic/fetch dump 测试:同时验证文档内容、结构及副作用。

Case 与回归契约

负责原第 11 类 784。测试应覆盖 JSON/text MIME、BOM 与编码、跨块换行、NUL、实体、字面的关闭 pre 内容、MIME/URL 后缀冲突、主文档/iframe 一致性。伪 HTML 不能执行脚本或请求图片;正常 HTML 必须有会执行脚本的正对照,防止通过禁用全部执行来通过文本测试。

历史受测 ca2a8d39572644de1211e3aba30d239abf0ffb17 的 784:10 个冻结动作全部完成、1/1、零重试。逐题审计。独立 HTTP + CDP 主/子文档 12 场景通过,浏览器场景结果、新增解析场景红绿证据。这些结果对应所列版本,不改标为最终 head 的复跑。

已合入;最后 head 50393080f266afb383fab210ebeb6a9a5ed2b863,base main,最终提交门禁见 Checks。来源 #740。旧报告中 #755 的分支依赖是历史状态。

Reviewer 重点

MIME 决策、decoder、parser 和预加载模式是否一致?分块、iframe 和字面伪 HTML 是否与主文档共享语义?正常 HTML/XML 等其他类型是否保持自身解析行为?

整组验收与证据入口

这组修复来自 #640,对应 1.1.9 的 34 个失败 case,加上 1.1.8 已失败的 386,共 35 个唯一 case。按最终职责分配为:#756 布局 27、#757 输入 4、#758 网络 3、#761 文本 1;#755、#759、#760 以各自独立功能契约验收,不重复认领这 35 个 case。

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Sequential Navigation Soak A/B

✅ HEAD completed the 200-navigation resilience and memory observation.

One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Page.navigate commands per binary.

Common ancestor bec8387729 → HEAD 50393080f2; benchmark order: base-first; workflow: success.

Session resilience

Metric Base HEAD
Attempted / planned 200 / 200 200 / 200
Direct observable pass 199 / 200 199 / 200
Failures / recovered 1 / 1 1 / 1
Recovery failures 0 0
Lifecycle order violations 0 0
Network order violations 0 0
Wall time 301.1 s 303.6 s

A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence.

Process-tree memory

Metric Base HEAD Δ
Boundary samples 200 200 0
Boundary RSS samples 200 200 0
Boundary PSS samples 200 200 0
Periodic peak RSS 218.9 MiB 244.8 MiB +25.9 MiB
Periodic peak PSS 216.2 MiB 241.8 MiB +25.6 MiB
RSS · first 10 avg 166.7 MiB 167.5 MiB +0.7 MiB
RSS · last 10 avg 134.6 MiB 162.2 MiB +27.6 MiB
RSS · last − first window -32.1 MiB -5.3 MiB +26.8 MiB
RSS · warm slope / 100 nav -3.3 MiB +2.6 MiB +5.8 MiB
PSS · first 10 avg 163.6 MiB 164.0 MiB +0.4 MiB
PSS · last 10 avg 131.6 MiB 158.8 MiB +27.2 MiB
PSS · last − first window -32.0 MiB -5.2 MiB +26.8 MiB
PSS · warm slope / 100 nav -3.3 MiB +2.6 MiB +5.8 MiB
Peak file descriptors 64 63 -1
Peak threads 31 31 0

HEAD memory by 50-navigation quarter

HEAD range Avg RSS Final RSS Peak RSS Avg PSS Final PSS Peak FD
1–50 161.3 MiB 150.8 MiB 224.6 MiB 157.9 MiB 147.4 MiB 58
51–100 161.4 MiB 146.8 MiB 192.1 MiB 158.1 MiB 143.5 MiB 52
101–150 165.4 MiB 152.5 MiB 245.7 MiB 162.2 MiB 149.3 MiB 53
151–200 163.6 MiB 144.2 MiB 203.7 MiB 160.3 MiB 140.9 MiB 60

Raw reports and per-navigation boundary samples: workflow run and full sequential-navigation-soak-results artifact.

Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Spider Bench A/B

✅ All benchmark browser service runs completed; results are informational.

Public HEAD: 189 / 240 rows; 39 / 48 sites produced rows; 9 unexpected empty sites.

✅ Deterministic fixture contract is clean.

Common ancestor bec83877294c → HEAD 50393080f266; benchmark order: base-first; workflow: success.

Public 48-site run · informational

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 184 / 240 189 / 240 +5 (+2.72%)
Contract fill 76.67% 78.75% +2.08 pp (+2.71%)
Sites with rows 38 / 48 39 / 48 +1 (+2.63%)
Sites meeting row contract 36 / 48 37 / 48 +1 (+2.78%)
Unexpected empty sites 10 9 -1 (-10.00%)
Partial-row sites 2 2 0 (0.00%)
Site outcomes extracted: 36; HTTP error + rows: 2; empty: 7; HTTP error + empty: 1; snapshot error + empty: 2 extracted: 38; HTTP error + rows: 1; empty: 6; HTTP error + empty: 1; snapshot error + empty: 2 —
Observed duration 50.91 s 57.48 s +6.57 s (+12.90%)
Estimated CPU 46.87 s 51.23 s +4.37 s (+9.32%)
Peak PSS 272.23 MiB 264.38 MiB -7.86 MiB (-2.89%)
Peak RSS 276.29 MiB 267.69 MiB -8.59 MiB (-3.11%)
Peak threads 26 26 0 (0.00%)
Mismatched sites 0 0 0
Timeout with items 0 0 0
Category rows Base HEAD Δ
news 35 / 40 35 / 40 0
stocks 20 / 40 20 / 40 0
tech 35 / 40 35 / 40 0
sports 27 / 40 32 / 40 +5
games 37 / 40 37 / 40 0
life 30 / 40 30 / 40 0

Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression.

CPU and memory timelines

These are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available.

Base

xychart-beta
    title "Base CPU"
    x-axis "Elapsed seconds" [1.543, 2.544, 3.045, 4.548, 5.55, 7.052, 8.554, 10.055, 11.558, 13.06, 14.061, 15.563, 17.068, 18.571, 20.075, 21.575, 22.576, 24.079, 25.582, 27.085, 28.086, 28.587, 30.089, 31.091, 32.593, 34.095, 35.597, 37.098, 38.601, 39.602, 41.104, 42.606, 44.109, 44.611, 45.614, 47.116, 48.117, 49.619]
    y-axis "CPU percent" 0 --> 200
    line [131.88, 97.87, 123.84, 101.81, 169.63, 151.59, 87.86, 167.8, 79.94, 91.73, 183.84, 39.98, 27.94, 21.97, 43.78, 4, 39.94, 101.87, 107.74, 131.71, 105.88, 105.87, 127.8, 151.72, 91.95, 123.85, 127.89, 35.97, 101.93, 7.98, 149.58, 73.91, 15.99, 0, 85.75, 137.61, 21.99, 105.88]
Loading
xychart-beta
    title "Base memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.042, 1.543, 2.544, 3.045, 4.548, 5.55, 7.052, 8.554, 10.055, 11.558, 13.06, 14.061, 15.563, 17.068, 18.571, 20.075, 21.575, 22.576, 24.079, 25.582, 27.085, 28.086, 28.587, 30.089, 31.091, 32.593, 34.095, 35.597, 37.098, 38.601, 39.602, 41.104, 42.606, 44.109, 44.611, 45.614, 47.116, 48.117, 49.619, 50.91]
    y-axis "Memory MiB" 0 --> 500
    line [11.89, 106.79, 115.53, 121.28, 139.5, 173.64, 186.18, 161.77, 168.95, 175.14, 163.53, 154.34, 156.86, 139.03, 148.06, 139.49, 145.36, 144.71, 140.39, 157.83, 170.48, 276.29, 207.42, 205.07, 172.16, 164.73, 164, 142.74, 143.55, 145.76, 141.27, 157.59, 152.77, 137.57, 137.57, 151.85, 151.37, 146.79, 166.69, 0]
    line [8.21, 102.75, 111.01, 117.25, 135.86, 170.03, 181.24, 157.62, 164.83, 171.01, 159.43, 150.2, 152.76, 134.9, 143.99, 135.38, 141.21, 140.55, 136.31, 153.71, 166.54, 272.23, 202.81, 201.01, 168.65, 159.8, 159.93, 138.63, 139.46, 141.7, 137.2, 153.13, 148.7, 133.51, 133.52, 147.8, 148.04, 142.83, 162.78, 0]
Loading

HEAD

xychart-beta
    title "HEAD CPU"
    x-axis "Elapsed seconds" [1.536, 3.039, 4.541, 5.042, 6.043, 6.543, 8.045, 9.548, 11.052, 13.054, 14.556, 16.059, 17.559, 19.06, 21.064, 22.566, 24.066, 25.568, 27.069, 29.072, 30.574, 32.075, 33.577, 35.078, 36.581, 38.584, 40.085, 41.588, 43.089, 44.59, 45.592, 46.593, 48.095, 49.597, 51.099, 52.602, 54.605, 56.106]
    y-axis "CPU percent" 0 --> 500
    line [123.9, 117.81, 153.67, 211.6, 147.98, 181.88, 91.83, 49.9, 159.68, 163.71, 83.86, 117.75, 24, 51.89, 59.91, 117.88, 137.94, 105.87, 151.73, 137.96, 125.67, 93.94, 93.76, 111.93, 21.97, 123.71, 47.9, 51.9, 21.98, 27.94, 0, 2, 21.95, 69.88, 13.98, 127.76, 73.79, 127.78]
Loading
xychart-beta
    title "HEAD memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.035, 1.536, 3.039, 4.541, 5.042, 6.043, 6.543, 8.045, 9.548, 11.052, 13.054, 14.556, 16.059, 17.559, 19.06, 21.064, 22.566, 24.066, 25.568, 27.069, 29.072, 30.574, 32.075, 33.577, 35.078, 36.581, 38.584, 40.085, 41.588, 43.089, 44.59, 45.592, 46.593, 48.095, 49.597, 51.099, 52.602, 54.605, 56.106, 57.478]
    y-axis "Memory MiB" 0 --> 500
    line [12.18, 107.98, 124.44, 146.7, 150.03, 185.79, 162.72, 173.78, 157.16, 167.68, 169.1, 167.21, 146.12, 156, 144.35, 135, 172.03, 158.88, 267.69, 205.01, 159.61, 167.77, 191.41, 145.59, 152.04, 151.82, 247.5, 236.48, 241.56, 241.11, 245.77, 242.41, 241.45, 241.4, 186.65, 173.25, 156.77, 147.23, 167.82, 0]
    line [8.87, 104.39, 121.21, 143.06, 146.48, 182.18, 159.12, 170.69, 153.73, 164.28, 165.25, 163.08, 142.57, 152.55, 140.9, 131.54, 168.59, 155.71, 264.38, 201.58, 156.55, 164.35, 188, 142.29, 148.64, 148.39, 244.04, 233.05, 238, 237.7, 242.35, 238.99, 238.02, 237.98, 183.23, 169.83, 154.17, 143.81, 164.42, 0]
Loading

Deterministic fixture · required contract

The fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 40 / 40 40 / 40 0 (0.00%)
Contract fill 100.00% 100.00% 0.00 pp (0.00%)
Sites with rows 8 / 15 8 / 15 0 (0.00%)
Sites meeting row contract 15 / 15 15 / 15 0 (0.00%)
Unexpected empty sites 0 0 0
Partial-row sites 0 0 0
Site outcomes extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 —
Observed duration 20.09 s 20.03 s -0.06 s (-0.31%)
Estimated CPU 0.37 s 0.42 s +0.05 s (+13.14%)
Peak PSS 58.30 MiB 56.70 MiB -1.60 MiB (-2.74%)
Peak RSS 62.16 MiB 60.59 MiB -1.58 MiB (-2.54%)
Peak threads 18 18 0 (0.00%)
Mismatched sites 0 0 0
Timeout with items 0 0 0

Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full spider-bench-results artifact.

The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking.

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

CI Regression Report

Source CI run · source state at render: in_progress · artifacts: 6/6

Check Status Signal
Release regression ✅ HEAD/base failures 0/0; raw binary −0.014607%
Frontend differential ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes ✅ 8/8 Moli episodes passed; 0 failures
Runtime/CDP contracts ✅ 26 contract cases; 0 failures
CDP smoke ✅ 50/50 groups passed; 574 scenarios
WebMainBench ✅ 545/545 completed; 0 unexpected failures
Release regression — ✅ HEAD/base failures 0/0; raw binary −0.014607%

Package and image size

Metric Base HEAD Delta Delta %
Raw binary 146.72 MiB 146.70 MiB −21.95 KiB −0.014607%
Stripped binary 100.68 MiB 100.66 MiB −20.00 KiB −0.019399%
gzip binary 50.22 MiB 50.21 MiB −4.54 KiB −0.008829%
Rootfs 153.62 MiB 153.60 MiB −20.00 KiB −0.012714%
gzip rootfs 59.00 MiB 59.00 MiB −6.52 KiB −0.010792%

Startup latency and PSS

Case Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta
Serve ready 27.24 ms 28.00 ms +0.76 ms 3.99 MiB 6.02 MiB +2.03 MiB
CDP first page 51.97 ms 56.84 ms +4.87 ms 4.38 MiB 8.48 MiB +4.09 MiB
CDP warm page 13.62 ms 21.16 ms +7.54 ms 48.88 MiB 48.75 MiB −138.00 KiB
CLI about:blank 14.48 ms 30.07 ms +15.58 ms 3.89 MiB 3.47 MiB −423.50 KiB
CLI local JS 28.32 ms 16.22 ms −12.10 ms 4.12 MiB 5.27 MiB +1.15 MiB

Concurrency matrix

Concurrency Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta HEAD failures Unstable B/H
1 16.46 ms 15.84 ms −0.63 ms 772.00 KiB 859.00 KiB +87.00 KiB 0 0/0
5 18.95 ms 19.75 ms +0.80 ms 12.68 MiB 21.08 MiB +8.40 MiB 0 0/0
10 19.59 ms 19.58 ms −0.02 ms 15.19 MiB 14.88 MiB −318.50 KiB 0 0/0
25 19.53 ms 19.60 ms +0.07 ms 20.18 MiB 27.19 MiB +7.02 MiB 0 0/0
100 19.16 ms 20.33 ms +1.17 ms 17.75 MiB 18.37 MiB +640.25 KiB 0 0/0
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Match DOM mismatch Diagnostic mismatch Moli error Reference error Infrastructure error Mismatched frames Duration
1,020 0 0 0 0 0 0 6m 32.22s
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Fast contract Episodes Passed Assertions Ready p50 Episode p50
Moli 8 8 47/47 4.01 ms 25.57 ms
Chromium 8 8 47/47 238.36 ms 81.68 ms
Operation p50 Chromium Moli Delta Delta %
navigate 39.66 ms 7.33 ms −32.34 ms −81.52%
observe 0.81 ms 0.86 ms +0.05 ms +5.63%
fill 2.76 ms 3.30 ms +0.54 ms +19.67%
click 5.25 ms 3.77 ms −1.49 ms −28.29%
Idle-resource episode Peak RSS Peak PSS Average CPU Peak CPU Peak processes Sampler
Moli 64.49 MiB 61.81 MiB 0.64% 10.00% 1 ✅
Chromium 1288.97 MiB 331.56 MiB 1.80% 93.84% 13 ⚠️ PSS partial
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
Suite Cases Failures Median case p50 Median case p95 Median peak PSS p50
Synthetic fetch 13 0 16.68 ms 17.54 ms 756.00 KiB
Long-lived CDP session 13 0 18.11 ms 18.47 ms —
CDP smoke — ✅ 50/50 groups passed; 574 scenarios

Workers: 4 · cumulative group time: 132.51 s · failed groups: 0

Slowest group Scenarios Duration Status
target-lifecycle 24 13.34 s ✅
dom-input 27 10.06 s ✅
chromium-cdp 56 9.46 s ✅
multi-page 45 9.32 s ✅
layout-screenshot 5 6.76 s ✅
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Completed Successful Expected DNS failure Unexpected failures Panics Crashes Timeouts Empty output
545/545 544 1 0 0 0 0 0

Frozen HTML · Linux · --wait done · 45 seconds per page · no retries. Content quality is evaluated separately.

Diagnostics: webmainbench-results — every page's Markdown, stderr, and exit status. Source run and artifacts

All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable.

@lanyue-llk
lanyue-llk force-pushed the codex/pr640-reopen-engineering branch from 19f651f to 7649f13 Compare September 24, 2026 04:21
@lanyue-llk
lanyue-llk force-pushed the codex/pr640-reopen-text branch from 15df7ed to f4fcb91 Compare September 24, 2026 04:23
@lanyue-llk
lanyue-llk force-pushed the codex/pr640-reopen-engineering branch from 7649f13 to 6185ba5 Compare September 24, 2026 05:10
@lanyue-llk
lanyue-llk force-pushed the codex/pr640-reopen-text branch from f4fcb91 to 877778e Compare September 24, 2026 05:10
@ldm0
ldm0 force-pushed the codex/pr640-reopen-engineering branch from 008b31d to 2009cd7 Compare September 28, 2026 20:51
@ldm0
ldm0 force-pushed the codex/pr640-reopen-text branch from 877778e to 116d497 Compare September 29, 2026 00:13
@ldm0
ldm0 changed the base branch from codex/pr640-reopen-engineering to main September 29, 2026 00:19
lanyue-llk and others added 6 commits September 29, 2026 15:40
Keep valid inherited text encodings ahead of heuristic detection while
preserving BOM, transport charset, and JSON default precedence. Share the
response decoder between streaming main documents, asynchronous child
loads, data URLs, and blocking child snapshots.

Classify navigation XML MIME types independently of DOMParser's allowlist,
including +xml subtypes in parser routing and text exclusions. Add
regressions for inherited UTF-8, literal encoding declarations, XML
namespaces, and DOMParser rejection of navigation-only XML types.

Validation:
- cargo fmt --all
- cargo clippy --workspace --all-targets --all-features -- -D warnings
- NEXTEST_TEST_THREADS=8 cargo nextest run --no-fail-fast
  18,952 passed, 16 skipped. Two existing timing tests failed under the
  default concurrency, then passed individually and in the full run above.
Keep network XML response bytes intact through the existing raw-body renderer
path. Decode both network and external XML bodies with the shared response
decoder, then install the selected encoding before document bootstrap.
Remove the obsolete ready-body capture variant used by the old XML path.

Cover matching main-document and iframe text, namespaces, and characterSet for
Atom, RSS, and text/*+xml responses with Windows-1252 headers, XML declarations,
and UTF-16LE/BE BOMs. Exercise the external input as single-byte chunks and
verify that BOMs override a conflicting transport charset.

Validation:
- Before the fix, the network regression returned caf� / UTF-8 instead of
  café / windows-1252.
- cargo fmt --all
- cargo clippy --workspace --all-targets --all-features -- -D warnings
- Six focused XML tests passed.
- NEXTEST_TEST_THREADS=8 cargo nextest run --no-fail-fast:
  18,954 passed, 16 skipped.
Give document decoding explicit HTML, XML, and text declaration policies.
XML ignores HTML meta elements, retains BOM and transport charset precedence,
and selects an initial XML declaration or UTF-16 signature before its UTF-8
default. Keep partial declarations and signatures buffered across chunks.

Cover conflicting meta declarations with and without an XML declaration,
including main documents, iframes, and external raw input. Adapt seven
Chromium XML/XHTML navigation scenarios and three decoder boundary tests
from Chromium a03603fe9af6230a12f1b2fb2c18a7d003a0d937; source paths are
recorded next to the tests. These include KOI8-R script inheritance, CP1251
XML, BOM-less UTF-16, supplementary Unicode characters, and BOM boundaries.

Validation:
- cargo fmt --all
- cargo clippy --workspace --all-targets --all-features -- -D warnings
- XML and Chromium regression tests passed.
- NEXTEST_TEST_THREADS=8 cargo nextest run --no-fail-fast:
  18,980 passed, 16 skipped.
@ldm0
ldm0 force-pushed the codex/pr640-reopen-text branch from c5a0275 to 5039308 Compare September 29, 2026 08:12
@ldm0
ldm0 merged commit 14cc979 into main Sep 29, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants