Skip to content

fix: absence has to be evidenced, not assumed - #8

Merged
cycle-five merged 1 commit into
masterfrom
fix/absence-needs-evidence
Aug 30, 2026
Merged

cycle-five merged 1 commit into
masterfrom
fix/absence-needs-evidence

Conversation

@cycle-five

Copy link
Copy Markdown
Owner

Step 2. The rule is not the one we sketched — the probe #7 enabled disproved it, which is exactly why that PR shipped first.

The bug

normalizeByKind returning null became a NotFoundError → 404, negative-cached for TTL_NEGATIVE. But null covers two unrelated situations:

  1. Spotify says the entity is gone.
  2. We recognised nothing on a page that loaded fine.

A live playlist was served as "not found" this morning because (2) was reported as (1) — and the negative cache then kept serving it that way after extraction had recovered.

The discriminator we planned does not work

We agreed on recorded === 0 → 502. Measured against the real site, a genuinely dead entity records no JSON responses at all — byte-for-byte the evidence a silent capture leaves:

playlist/zzzzzzzzzzzzzzzzzzzzzz  →  NotFoundError  evidence={"recorded":0,"statuses":[],"paths":[]}
track/zzzzzzzzzzzzzzzzzzzzzz     →  NotFoundError  evidence={"recorded":0,"statuses":[],"paths":[]}

Identical. That rule would have classified every dead entity as a scraper failure and stopped negative-caching entirely.

What does work: the navigation status

Positive evidence rather than the absence of it. Spotify answers the document itself:

request nav status page title
dead track 404 "Page not found"
dead album 404 "Page not found"
dead playlist 400 "Page not available"
live entity 200 the real title

Hence navStatus >= 400, never === 404 — a dead playlist answers 400, and a rule written against 404 alone would call every dead playlist a scraper failure. recordResponses was already discarding this: it filters to content-type: json, so the navigation response never survived.

Validated end-to-end against the live site with the rule in place:

playlist/zzzzzzzz -> NotFoundError      1040ms  ev={"navStatus":400,"recorded":0,...}
track/zzzzzzzz    -> NotFoundError       664ms  ev={"navStatus":404,...}
album/zzzzzzzz    -> NotFoundError       628ms  ev={"navStatus":404,...}
playlist/6FPDTIEc -> OK playlist        8027ms
track/4cOdK2wG    -> OK track           9217ms

Three things fall out

Correctness. ExtractionSilentError covers "loaded fine, matched nothing": 502, never cached, wire code extraction_silent, relayed through the failure codec with its identity intact. Distinct from ExtractionEmptyError, which found the entity and saw zero items in it — a wholesale shape change versus one broken list. It is also the only class that fits a track, which has no track list to be empty.

Speed. A dead entity is rejected straight after navigation, skipping the scroll loop and its 3s settle on a page with no list to page through. 1040ms against 4146ms.

A monitoring blind spot closes. recordFailureMetrics returns early for NotFoundError — so while a silent extraction was reported as absence, total extraction failure recorded zero failures while answering 404 to everything. It now increments scrape_failures_total{reason="extraction_silent"}.

Compatibility

crack-sleevenote already models unknown wire codes as ErrorCode::Unrecognized(String) with #[serde(untagged)], so an unupgraded client preserves extraction_silent verbatim rather than breaking, and cracktunes' error_embed catch-all handles it. Adding the variant properly is a follow-up in that repo, after #421.

Verification

  • npm test — 109 passed, 9 skipped (was 100). 9 new tests.
  • Mutation-checked twice: weakening the rule to >= 500 fails 4 tests; removing the early bail fails the timing test.
  • npx tsc --noEmit clean. Comment density 446/1297 = 0.34, in band.
  • docs/design-notes.md: "The four extraction failures" → five, plus an "Absence has to be evidenced" section carrying the measurements. The src/extract.ts cross-reference to the old heading is updated — no dangling pointer.

Version 0.3.0 — a status code changes for a case callers can observe.

🤖 Generated with Claude Code

`normalizeByKind` returning null became a NotFoundError -- 404, and
negative-cached for TTL_NEGATIVE. But null covers two unrelated
situations: Spotify says the entity is gone, and we recognised nothing on
a page that loaded fine. A live playlist was served as "not found"
because the second was reported as the first, and the negative cache then
kept serving it that way after extraction had recovered.

The obvious discriminator does not work. Measured against the real site,
a dead entity records NO JSON responses at all -- byte-for-byte the
evidence a silent capture leaves:

    playlist/zzzzzzzzzzzzzzzzzzzzzz -> {"recorded":0,"statuses":[],"paths":[]}

The navigation status does work, because it is positive evidence rather
than the absence of it. Spotify answers the document itself:

    dead track     404   "Page not found"
    dead album     404   "Page not found"
    dead playlist  400   "Page not available"
    live entity    200   the real title

Hence `navStatus >= 400` and never `=== 404`: a dead playlist answers
400, and a rule written against 404 alone would call every dead playlist
a scraper failure.

`recordResponses` now returns a Capture -- the navigation status
alongside the responses -- and stops immediately when the navigation was
not ok, since there is no virtualized list to page through on a "Page not
found" shell. A dead id costs 1040ms instead of 4146ms.

The new ExtractionSilentError covers "loaded fine, matched nothing":
502, never cached, wire code `extraction_silent`, relayed through the
failure codec with its identity intact. It is distinct from
ExtractionEmptyError, which found the entity and saw zero items in it --
a wholesale shape change versus one broken list -- and it is the only
class that fits a track, which has no track list to be empty.

This also closes a monitoring blind spot. `recordFailureMetrics` returns
early for NotFoundError, so while a silent extraction was reported as
absence, TOTAL extraction failure recorded ZERO failures while answering
404 to everything.

crack-sleevenote already models unknown wire codes as
ErrorCode::Unrecognized, so an unupgraded client preserves
`extraction_silent` verbatim rather than breaking; adding the variant
there is a follow-up.

Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
@cycle-five
cycle-five merged commit 13865f6 into master Aug 30, 2026
2 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.

1 participant