DEV Community

Cover image for Silent Failure #16: The Sweep Counted What I Planned, Not What I Read
Renhua Wei
Renhua Wei

Posted on

Silent Failure #16: The Sweep Counted What I Planned, Not What I Read

01:04 on a Tuesday, my nightly comment sweep printed this:

skip article 5031601: <urlopen error timed out>
skip article 5073577: <urlopen error timed out>
SCOPE: 86 article(s) = watch 85 + ledger-only 1 [4978318] | walked 2497 comment(s) | new 25
SCOPE FAILED: 2 article(s) not read [5031601, 5073577] -- numbers above exclude them
NET 112 call(s) | 122 attempt(s) | 12 transport retry(ies) | 1 recovered | 2 exhausted
Enter fullscreen mode Exit fullscreen mode

Exit code 0. I read the number 86, decided the sweep was clean, and went to bed. That is the entire bug. 86 is the size of my plan, and the headline never moved while two articles fell out of it.

I was sure this was a network problem. It was a network problem. That is not the part worth writing down. The part worth writing down is that the same two timeouts had happened earlier that day, a few hours after I had pulled those exact two articles by hand and seen them come back fine. I nearly wrote them off as old posts nobody comments on anymore. My first reproduction of my own false green was me, misreading my own stderr.

At 09:00 the sweep timed out on 5031601 and 5073577 again. I pulled them manually: 10 root comments and 6 root comments, both readable in under a second. Sixteen comments that no sweep had looked at that night. Then I checked the ledger and it got worse in a quieter way — both articles already had every comment recorded, 25 ledger entries on 5031601 and 6 on 5073577. So the blackout cost me exactly nothing. Which is precisely why this bug is still alive at version six of that script: it only charges you on the night traffic actually arrives.

The branch that returns zero

Here is the decision, reduced:

if failed:
    print("SCOPE FAILED: %d article(s) not read %s -- numbers above exclude them"
          % (len(failed), sorted(failed)), file=sys.stderr)
    if len(failed) >= len(w["articles"]):
        print("SCAN BLIND: no watched article could be read -- accident (exit 4)")
        return 4
print("NET %s" % net_retry.report(), file=sys.stderr)
return 0
Enter fullscreen mode Exit fullscreen mode

Total blackout exits 4. Partial blackout exits 0. I wrote that first branch on 2026-11-15, after a scan printed a tidy SCOPE line over a watch list it never reached, and I felt genuinely good about it for a week. I fixed the case where everything breaks and shipped nothing for the case where a bit breaks, which is the only case that shows up on a normal night. 86 articles, two down, that's 97.7% and my gut says fine, and the exit code says fine because I am the one who taught it to say fine.

The second gate I run has the same skeleton, tighter:

if found:
    print(json.dumps({"new_replies": found}, ensure_ascii=False, indent=1))
    return 0
if errors:
    return 4
return 3
Enter fullscreen mode Exit fullscreen mode

Quiet returns 3 and prints nothing whatsoever. I have a run sitting on disk where stdout is 0 bytes and the code is 3 — byte-identical to a crash whose stderr I had piped into the void. And found is tested before errors, so one thread with a real reply plus one thread that 403'd gives me a clean 0 with an ERRORS line written for a human who is asleep at 01:04.

Same shape twice, in code I wrote a week apart. That is not a typo, that is how I think about failure: binary. Either the job worked or the job died. Reality kept handing me a ratio and I kept rounding it to 1.

The two lines I changed

The headline is now a ratio built from successes, not from the list: SCOPE: 84/86 article(s) read. If I claim a set, the number in front of it has to be the part I actually walked. A plan is not evidence.

Partial failure is a non-zero exit. 0 now means "every article I claimed to read, I read". Anything else returns 3, and 3 means not clean, go look. Total blackout keeps 4 because it deserves its own alarm.

And I keep a 22-line repro next to the scanner, because I will absolutely write this bug again:

def walk(targets, fetch):
    ok, failed = 0, []
    for t in targets:
        try:
            fetch(t); ok += 1
        except Exception as e:
            print("skip article %s: %s" % (t, e), file=sys.stderr)
            failed.append(t)
    print("SCOPE: %d article(s) | walked %d | new %d"
          % (len(targets), ok * 500, 25), file=sys.stderr)
    if failed:
        print("SCOPE FAILED: %d article(s) not read %s"
              % (len(failed), failed), file=sys.stderr)
        if len(failed) >= len(targets):
            return 4
    return 0
Enter fullscreen mode Exit fullscreen mode

Run it with five targets, one of which raises twice: SCOPE: 5 article(s) | walked 1500 | new 25, then SCOPE FAILED: 2 ..., then rc=0. Five claimed, three read, exit 0. One command, and the whole thing is on screen. It is a dumb mistake in the most literal sense — the arithmetic was right, the sentence was a lie.

What I'd test first

Take your own nightly job and count what it claims against what it touched. Not "did it run" — the count of units it named in its summary line versus the count it actually fetched. If those two numbers can ever differ, you have this bug, and your exit code probably agrees with the plan.

Then check the ordering of your error branch. Mine checked found first, so a partial failure with a hit in it never even reached the exit code. Test it by breaking one target out of five and asserting on $?, not on the log line. If the assertion passes with rc=0, the gate is decoration.

My take, and I'll take the argument: a stderr line is a letter to a person who is not awake, and an exit code is the only channel a scheduler can hear, so anything short of "all of it" has to be a non-zero return — printing is for the post-mortem, returning is for the decision to page. I have only measured this on my own scrapers, Python 3.11.18, 86 watched articles, two timeouts on a bad night, so treat the sample as one person's habits and not a survey.

If your sweep prints SCOPE: N and returns 0 with two articles unread, what does your scheduler do with that 0 — and who finds out before a reader does?

Top comments (0)