feat(install): 三道防坏防丢门禁 —— 尾部实包解码 / 同卷隔离区两阶段提交 / 无缓冲回读

§10.161 的复盘结论不是「再查一遍」,是三个结构性缺口,逐个补上:

① tail_decode_gate():上传后真解码远端副本的最后几秒。
   `+faststart` 把 moov 放在文件头,所以 ffprobe 对截断文件照样报全长 ——
   抽检 1,340 件成品里 6 件截断(1.4 GB 只剩 36.9 MB)全都过了既有门禁。
   窗口 min(5s, dur/2),短片不假阳性;`-map 0:v:0?` 让无视频流不误红。

② 隔离区两阶段提交(move_to_trash / restore_from_trash / purge_trash / publish_staged):
   安装段不再 `os.replace` 覆盖 + `os.remove(src)` 删原件,而是
   目标名上的文件同卷 rename 进 `<dir>/.transcode_trash/<date>/`(0 字节拷贝、可回滚),
   发布成功才让它留在那儿;发布或装后任一闸门失败就地回滚。
   GC 72 h 后回收,且**旁注里的 live 已消失时绝不删**(那是最后一份)。

③ _win_unbuffered_read / _sha_sample_nocache / _sha_remote_sample_nocache:
   抽样回读走 FILE_FLAG_NO_BUFFERING,Dokan/RaiDrive 的缓存池再也答不上话。
   读窗按扇区对齐并按 GetFileSizeEx 裁到最后一个整扇区(无缓冲读不许跨 EOF,
   越过末尾是 ERROR_INVALID_PARAMETER 而不是 EOF);末尾 < 4 KB 的零头用普通读补。
   短读抛 _ShortRead 并**不许**退回缓存读;只有文件系统拒绝该 flag 才降级,
   并把 bypassed=False 写进回执。

隔离区对引擎 collect() 不可见(否则退休的原件会被重新入队)。
门禁默认全开,`--no-tail-gate` 只是紧急刹车,`--trash-ttl-hours` 默认 72。
真共享盘端到端实测:源 213,827 B → hvc1 25,854 B,原件逐字节躺在隔离区,cache_bypass=true。
版本 1.2.0 → 1.3.0(contract 3 不变)。
This commit is contained in:
hoelee committed 2026-11-01 14:15:29 +08:00
1 parent 005b824e4f
commit 46c9177386
3 files changed
+476 -64

No files matched your search

+18 -6
View File
@@ -142,10 +142,20 @@ Per item, in this order:
4. **SSIM vs the source window >= target** (section 2).
5. **Size assertion**, per the regime in section 1: hard `out <= src` where the source has
headroom; runaway guard `out <= 1.25x src` where the pre-flight says it is already compressed.
6. **Upload to a temp name, read the share copy back end-to-end, compare SHA-256 + byte count**,
then replace atomically. A duration probe is not enough: with `+faststart` the `moov` is written
first, so a truncated upload still reports the full duration.
7. **Re-probe on the share** after the replace.
6. **Upload to a temp name, then read it back with the Windows cache bypassed**
(`FILE_FLAG_NO_BUFFERING`) and compare SHA-256 + byte count. A duration probe is not enough:
with `+faststart` the `moov` is written first, so a truncated upload still reports the full
duration — and a *buffered* read can be answered from the Dokan/RaiDrive cache pool while the
server holds a fraction of the file.
7. **Decode the last seconds of the uploaded copy** (`ffmpeg -v error -xerror -sseof -5 -i TMP
-map 0:v:0? -f null -`). This is the only check that forces ffmpeg to the physical tail; a
short file ends in `partial file` / `Invalid NAL unit size` instead of silence.
8. **Two-phase commit, never `os.replace` over the original**: move whatever occupies the target
name into a same-volume quarantine `<dir>/.transcode_trash/<date>/` (an inode rename: 0 bytes
copied, reversible), publish the verified file, and roll the original straight back if the
publish or any post-install gate fails. The quarantine is collected after 72 h — and an entry
whose installed file is gone is never collected, because that is the last copy.
9. **Re-probe on the share** after the publish.
Cheap confidence check on a healthy file, one distinct value expected:
@@ -278,8 +288,10 @@ Measured audit of such a set (54 files converted at `-cq 27` + a fixed 256k audi
* the encode reads the **original**, the tier is classified from the **original's** bpp, and the
gates compare against the **original** - the converted file is never used as a reference;
* `dst` stays the live path, so the output replaces the (bloated) converted file;
* **the original is never modified or deleted** - `os.remove(src)` is suppressed whenever the
source came from the origin tree. Getting this backwards would destroy the only clean copy.
* **the original is never modified or deleted** - the quarantine move is suppressed whenever the
source came from the origin tree (and so is `--keep-source`). Getting this backwards would
destroy the only clean copy. For a normal in-place install the source is *retired into the
quarantine*, not deleted: `purge_trash()` is the only thing that ever unlinks one, 72 h later.
## 9. CPU and GPU tiers in parallel