跳到正文
DEV Community· minia2a·· 54 分鐘前AI 評分52

無法量度的驗證器不能判定部署通過

A verifier that cannot measure is not a passing verifier

AI 導讀

minia2a 根據部署流水線事故提出,驗證器應以 0、1、3 分別代表通過、發現問題及無法量度,避免把量度失敗誤判為程式故障或成功。文中記錄兩次正確程式碼被回滾,以及部署腳本只傳送三個檔案中的一個卻回報全部完成。修正措施包括逐檔比對 MD5、明確標示無法量度,並以自測確保第三種狀態不被合併。

正文

This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail.

A verifier that cannot measure is not a passing verifier

2026-11-27 · measured on a live deployment pipeline

Every deploy pipeline with a post-deploy gate has the same two-way contract: the gate exits 0, keep the new code; the gate exits non-zero, roll back. That contract is fine as long as the gate has exactly two outcomes. It doesn't. A verification script can also fail to run — crash, miss a file, lose its config — and in a two-way contract that third outcome has to be squeezed into one of the two. Whichever one you pick, you are wrong half the time.

On 2026-11-27 this pipeline squeezed it into "non-zero means the patch is broken" and rolled back two correct patches, then — in the mirror-image failure — printed OK after shipping one of three files. All three incidents are below, with the exit codes and the timestamps the host recorded.

Case 1: the verifier crashed between listing and reading

The patch added two keys to a paid endpoint's response envelope, with ok written after the spread so a model-supplied object could not override it:

return { ...out, ok: true, ...rest };   // ok wins over any payload key

The gate walked the deployed handler directory, then opened each file to scan it. Between the glob and the open — a window of milliseconds — a file that the deploy had just replaced was not there under its old name. The guard raised FileNotFoundError, Python exited with rc=1, and the wrapper read that exactly as it reads a real finding: verification failed. Three files were restored from backup at 10:05:46Z. The bytes that had just been deployed were correct, and had already been diffed against the staged copies.

The important part is not the race. It is that a crash and a finding shared one exit code, so the wrapper had no way to tell "this patch is wrong" from "I could not look at this patch".

Case 2: the verifier could not find its own manifest

Seventeen minutes later, a different guard rolled back a different correct patch. Its default manifest path was relative:

DEFAULT_MANIFEST = "patches/compat-deployed-manifest.json"

The deploy ran as a one-shot systemd unit. The daily timer's unit sets WorkingDirectory; this ad-hoc unit did not, so the process started in /, the manifest was unreadable, the guard printed CONFIG — manifest unreadable and exited non-zero — square into the same "the patch is broken" bucket. 10:20:18Z, another rollback of code that was fine.

Neither case needed a smarter verifier. Both needed the wrapper to stop treating "I have no measurement" as a measurement.

The mirror image: a success that measured one third of its population

Ten minutes earlier the same class of bug had failed in the opposite direction. The deploy script shipped three files through a shell loop:

while read -r local_name remote_path; do
  rm=$(ssh "$HOST" "md5sum $remote_path")      # ← ssh reads stdin, and stdin is the loop
  scp "$local_name" "$HOST:$remote_path"
done 

ssh consumes standard input unless told not to. Standard input here was the here-string holding the remaining lines, so the first ssh swallowed them and the loop ended after one iteration. The script printed OK — 3 file(s) live (it was printing the length of the list it intended to ship), and every behaviour probe was green, because the probes only exercised the path through the one file that actually landed. The other two files were never uploaded. The rollback loop had the identical shape, which means a real failure would have restored one file and left two on new bytes — harder to notice than not rolling back at all.

The fix is ssh -n on every call inside such a loop, and a guard that scans for the shape: 48 shell scripts in tools/ and scripts/, every while read block, any ssh not followed by -n. Six controls, including a ssh-keygen false positive and a for-loop exemption.

The rule that came out of the day. A verifier's exit code must carry three states, not two: 0 clean, 1 finding, 3 could not measure. A caller that only knows clean/not-clean is a caller that will one day roll back good work or keep bad work, and will have no record of which.

What the three-state contract looks like in practice

Every guard in this repo now separates "measured and found a problem" from "did not measure":

if not os.path.exists(p):
    print("STATUS: CANNOT MEASURE — no such file: %s" % p)
    return 3
try:
    src = open(p, encoding="utf-8").read()
except OSError:
    print("STATUS: CANNOT MEASURE — vanished while reading: %s" % p)
    return 3

and the selftest has a control that drives exactly that path — unreadable-file-rc3 — so the third state cannot be quietly folded back into 1 in a future refactor. The manifest lookup resolves from the tool's own location, all deploy wrappers cd to the repo root first, and every deploy now compares md5 per file against the staged bytes rather than trusting a count — across 1,752 deployed files.

The daily report uses the same split. Its status lines print RED, clean, or UNMEASURED — rc=2/3, and UNMEASURED is explicitly neither. This is not pedantry: a job that says "clean" because the endpoint returned 429 to its edge probe is a job that will hide a real regression, and one that says "red" because it could not reach anything will train its reader to ignore red.

Why agent-facing paid APIs need this more than most

An agent buying a call has no view of your pipeline. It sees two things: the 402 challenge, and the response it paid for. So every claim between those two points has to be produced by something that ran. A health sweep whose edge probe gets rate-limited and reports "up"; a delivery ledger where a settlement check crashed and the row defaults to delivered; a catalogue check that reports "all listings priced correctly" over an empty population — all three are the same bug wearing different clothes. The dangerous output is not a false alarm. It is a confident pass over a population nobody actually measured.

If you are building x402 endpoints, the cheap version of this discipline is:

  • Make "no measurement" a distinct, loud status — never let it serialise as success or as a finding.
  • Have every guard print its population count. An empty population is not a clean run; it is a run that judged nothing.
  • Verify deploys by comparing bytes per file, not by counting files the script intended to send.
  • Put a selftest control on the cannot-measure path, so the third state survives refactors.

The marketplace is at minia2a.uk — 1,958 pay-per-call endpoints in USDC on Base, 5 free trial calls per signed wallet on the endpoints that offer trials, no registration. If you want to see what an honest 402 refusal and a measured delivery record look like from the buyer's side, start with the trial path and read the headers it returns.


Originally published at minia2a.uk.

來源:DEV Community · dev.to