A half-drawn frame can be seen twice, so being seen twice is not evidence

The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.

The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.

Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.

`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.

Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.

On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.

What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
main
mula.liu 2026-10-16 12:02:21 +08:00
parent b2460d506f
commit 5515bab2d9
1 changed files with 74 additions and 17 deletions

View File

@ -169,7 +169,10 @@ def geometry(lines, cols):
def analyze(raw, echo=True):
"""重放整条流,量每一个画稳的画面,返回问题列表(空 = 没花屏)。"""
"""重放整条流,量每一个画稳的画面,返回问题列表(空 = 没花屏)。
"画稳"在这份文件里是有定义的:同一幅画面顶住 SETTLE 字节的写入不变。
"""
reported = re.search(r'MARK_STARTED\s+(\d{1,4})\s*x\s*(\d{1,4})', raw)
if reported:
cols, rows = int(reported.group(1)), int(reported.group(2))
@ -195,19 +198,35 @@ def analyze(raw, echo=True):
lines.pop()
return lines
# 只对"画稳了"的画面下判据。crossterm 一格一格补 diff,采样切在中间就是半张画:
# 半张画当然缺右边界,拿它判花屏是自己冤枉自己。半张画和整张画的区别不用猜 ——
# 同一个画面被采到第二次,说明这次绘制已经结束、终端停在那儿了。
step = 64
# 只对"画稳了"的画面下判据 —— 半张画当然缺右边界,拿它判花屏是自己冤枉自己。
#
# 这里原来写的是"同一个画面被采到第二次就算画稳",听着顺理成章,其实是错的:
# 一次绘制在流里是一整段连续的写入(实测切面板那一次是 34688→37376,2.7 KB 一个
# burst),而采样每 64 字节一刀;一行中文要占掉 190 字节上下,也就是三刀。半张画
# 被连着采到两三次是必然发生的事,根本不是"画完了"的证据。真机那条流里,"进程卡片
# 压在历史面板上"的半帧有 33 个,每一个只顶住 64~192 字节的写入;而真正画完的画面
# 在两次绘制之间稳稳站住 1024~3840 字节(界面每一拍都在重画同一幅画,只有样式在动,
# 屏上的字却没变)。所以判据看的是寿命:一幅画要顶住 SETTLE 字节的写入不变,才算
# 画完过、终端真的停在那儿过 —— 用户在屏上能看见的,只有这种画面。
#
# 不用时间戳:流里压根没有时刻,能信的只有字节数。这条判据还顺带挡掉一件事:
# 流尾长度不是 step 的整数倍时,最后几刀采到的是同一份字节,旧判据会把它们
# 当成"画稳了",等于给一条被切短的流发合格证。
step, SETTLE = 64, 512
frames = [tuple(render(raw[:cut])) for cut in range(step, len(raw) + step, step)]
seen, stable = {}, []
def painted(frame):
return sum(1 for l in frame if l.strip()) >= PAINTED
# 把采样按"同一幅画连着被采到"切成段:段长 = 这个画面顶住了多少字节的写入。
runs = []
for frame in frames:
if sum(1 for l in frame if l.strip()) < PAINTED:
continue
count = seen.get(frame, 0)
seen[frame] = count + 1
if count == 1:
stable.append(frame)
if runs and runs[-1][0] == frame:
runs[-1][1] += step
else:
runs.append([frame, step])
lived = [run for run in runs if painted(run[0])]
stable = [frame for frame, span in lived if span >= SETTLE]
# 退出时 TUI 会擦掉整屏(crossterm 的 Clear + LeaveAlternateScreen),所以"最后
# 一帧"必然是空的。给人看的那一帧取画稳的画面里内容最多的那个。
@ -261,15 +280,23 @@ def analyze(raw, echo=True):
last = geometry(list(stable[-1]), cols)[1] if stable else []
for note in last:
print(note)
print(f"[frame ] 采样 {len(frames)} 次 · 画稳的界面 {checked} 个全部量过 · "
f"其中 {len(failures)} 个不合格")
print(f"[frame ] 采样 {len(frames)} 次 · 画过的画面 {len(lived)} 幅 · "
f"顶住 {SETTLE} 字节不变的 {len(stable)} 幅 · 量过 {checked} 幅 · "
f"不合格 {len(failures)} 幅")
for index, probs in failures[:3]:
for problem in probs:
print(f"[frame ] 第 {index} 个画面: {problem}")
problems.extend(p for _, probs in failures for p in probs)
if not checked:
problems.append("屏上从来没有一个画稳、又画出了边框的界面可以判 "
f"(至少 {PAINTED} 行、边框行不短于 {MIN_ROW} 格)")
# 没有一幅画站得住,有三种可能,都得说清楚,否则下一位又会跑到真机上
# 去找一个根本不存在的花屏:抓的那块屏一直在动(扫描进度就是这样)、
# 抓得太短(程序刚画完第一帧就退了)、或者屏上真的没画框。
longest = max([span for _, span in lived], default=0)
problems.append(f"屏上没有一幅画顶住 {SETTLE} 字节的写入不变"
f"(最长的一幅只活了 {longest} 字节),所以没有可判的画面 —— "
"要么抓的那块屏一直在动(避开扫描进度这类带进度的面板),"
"要么抓得太短(把 TUI_DELAY / TUI_HOLD 调大),"
f"要么屏上根本没画出边框(至少 {PAINTED} 行、边框行不短于 {MIN_ROW} 格)")
return problems
@ -290,8 +317,21 @@ def selftest():
return ([top] + [mid] * right_rows + [bottom]
+ [only] * (left_rows - right_rows))
def mid_paint(good, half, invisible=20, repeats=2):
"""一幅整齐的画站定之后又画了第二幅,而第二幅只画到一半就没有下文。
invisible 段是纯粹的 SGR + 光标移动:屏上一个字都没改,却足够让"同一幅画
连着被采到"成立 —— 旧判据要的就是这个,可它采到的仍然是半张画。
"""
return ('MARK_STARTED 140x35\r\n'
+ ('\x1b[H' + '\r\n'.join(good)) * repeats
+ '\x1b[2J\x1b[H' + '\r\n'.join(half)
+ '\x1b[0m\x1b[?25l' * invisible
+ '\x1b[2J\r\nMARK_QUIT\r\n')
def stream(*screens, size='100x30'):
"""把若干画面写成一条流;每个画面写两遍,好让采样认出"画稳了"。"""
"""把若干画面写成一条流。每个画面写两遍:第二遍一个字都没改,于是这幅画
在流里站住了整整一遍画面的字节数 —— 这正是 SETTLE 要看见的那件事。"""
out = [f'MARK_STARTED {size}\r\n']
for screen in screens:
body = '\x1b[H' + '\r\n'.join(screen)
@ -321,6 +361,23 @@ def selftest():
("左栏比面板长", stream(side_by_side(31, 109, 14, 18), size='140x35'), False),
# 而"窄框接在宽框下面"在 140 列窗口里同样得报:第 69 列是凭空冒出来的。
("140 列上窄框叠宽框", stream(card(100, 8) + card(70, 6), size='140x35'), True),
# 同一幅"窄框叠在宽框上"的画,站得住就判、站不住就不判。
# 这是本轮真机上那次误报的现场还原:切面板那一次绘制是 2.7 KB 一个 burst,
# 采样每 64 字节一刀,于是两幅画叠在一起的中间态被连着采到了三次。旧判据把
# "连着采到"读成"画稳了",当场判下"进程卡片压在历史面板上";而那一帧只活了
# 192 字节,用户在那台 Windows 上从来没看见过它 —— 我们却照着它查了一整轮
# 根本不存在的绘制 bug。现在同一幅画只许在"顶得住 512 字节不变"时定罪:
# 上面那条窄框叠宽框(站得住)照旧要报,这一条(半路上被切走)必须安静。
("半张画不许下判词",
mid_paint(card(140, 12, fill=' 存储空间'), card(100, 6) + card(70, 4)), False),
# 反过来也必须成立:一幅画都没站住的流,判据要说"我判不了",不许趁乱发合格证。
# 这条是 SETTLE 自己的保险 —— 否则"只看寿命"会被误读成"寿命不够就挑一幅像样的
# 判",那条路通向的正是本轮那种没人见过的花屏。同一条流在旧判据下是安静通过的:
# 最后一幅画被那段看不见的写入连着采到三次,旧判据认它画稳了,而它干净,于是
# 整条流被判成"没问题"—— 一次什么都没证明的测量,被记成了一次通过。
("整条流没有一幅画站得住",
mid_paint(card(140, 12, fill=' 存储空间'),
card(140, 12, fill=' 系统状态'), repeats=1), True),
# 抓帧脚本自己炸了:远端 PowerShell 吐出一段它自己的报错,界面上一个字都没画。
# 这种流必须把"壳子坏了"单独说出来。否则"花屏"的罪名会扣在一个根本没启动的
# 界面上 —— 我们真的被这个假故障骗着去改过一版绘制代码。