Skip to content

feat: log requests, and what an extraction actually saw - #7

Merged
cycle-five merged 1 commit into
masterfrom
feat/request-logging
Aug 29, 2026
Merged

cycle-five merged 1 commit into
masterfrom
feat/request-logging

Conversation

@cycle-five

Copy link
Copy Markdown
Owner

Step 1 of two. This is the instrument; the classification fix it serves is the next PR, and ships against data this produces rather than a guess.

The service had no logger at all

buildServer constructed a bare Fastify(). Its default is logger: false, which makes app.log a no-op — so index.ts's startup line, its shutdown lines, and every in-request error went nowhere:

$ docker logs bots-sleevenote-1
$

Empty. Not "quiet" — the deployed instance has never emitted a single line, including its own "listening on :3000". Chasing a failed lookup today meant asking the user which URL they'd pasted, because nothing on the server side knew.

Two lines per request

request completed — an onResponse hook carrying method, url, status, durationMs and the X-Cache disposition:

{"level":30,"reqId":"req-1","method":"GET","url":"/v1/track/abc","status":200,"durationMs":8433,"cache":"miss","msg":"request completed"}

Fastify's own incoming/completed pair is suppressed with LogController({ disableRequestLogging: true }), so a request is exactly one line. cache sitting next to durationMs is what makes a cache hit distinguishable from a real resolve at a glance — the exact question that took four tool calls to answer this morning.

extraction failed — when an extraction throws:

{"level":40,"reqId":"req-1","kind":"playlist","id":"6FPDT...","error":"NotFoundError",
 "evidence":{"recorded":0,"statuses":[],"paths":[]},"msg":"extraction failed"}

Why evidence is the whole point

normalizeByKind returning null becomes a NotFoundError, which the HTTP layer answers 404 and negative-caches for TTL_NEGATIVE (600s). But null covers two unrelated situations:

  1. Spotify said the entity is gone.
  2. We captured nothing at all.

A live playlist was served as "not found" this morning because (2) was reported as (1) — and being negative-cached, it stayed that way. ExtractionEvidence records what the capture actually saw: how many JSON responses, which distinct statuses, which distinct paths. recorded: 0 is the signature of (2) — our failure, not evidence of absence.

Every throw inside runExtraction carries evidence, so a line without it means exactly one of two things, both documented at the log site: a failure relayed to a waiter (reviveFailure rebuilds from a wire form that does not carry the capture — read the holder's own line), or a timeout, which is rejected from outside the extraction and never had one.

ExtractionTimeoutError joins the same base class so every extraction failure produces one diagnostic line. The instanceof chain that maps 504 is unchanged — it tests leaf classes.

What is deliberately NOT here

No status codes change. A deleted playlist and a silent capture both still return 404. Splitting them is the next PR, and the open question it has to settle first is whether a genuinely deleted entity emits a capturable 4xx JSON response — if it doesn't, real 404s stop being negative-cached and every request for a dead id re-scrapes. That is a question for the logs, not for my model of Spotify's page.

These logs should also explain an anomaly from this morning: a second attempt re-scraped six minutes after a failure that should have written a live 600s negative marker.

Verification

  • npm test — 100 passed, 9 skipped (live suite). Suite output is silent again; the three server-building configs pass LOG_LEVEL: 'silent'.
  • npx tsc --noEmit — clean, and the logController route avoids the disableRequestLogging deprecation warning that the shorthand emits.
  • 8 new tests in tests/logging.test.ts. Mutation-checked: dropping evidence from the log line fails 2 of them.
  • Comment density 418/1263 = 0.33, inside the 0.3–0.5 band.
  • LOG_LEVEL (default info) documented in README and .env.example; the narrative is in docs/design-notes.md.

Version 0.2.0 — new observable behaviour and a new knob, no API change.

🤖 Generated with Claude Code

The service had no logger. `buildServer` constructed a bare `Fastify()`,
whose default is `logger: false`, which makes `app.log` a no-op -- so
index.ts's startup line, its shutdown lines and every in-request error
went nowhere. `docker logs bots-sleevenote-1` on the deployed instance
returned nothing at all. A failed lookup left no trace, and diagnosing
one meant reproducing it.

Two lines now come out of a request.

`request completed`, from an onResponse hook: method, url, status,
durationMs and the X-Cache disposition. Fastify's own incoming/completed
pair is suppressed via `LogController({ disableRequestLogging: true })`
so a request is exactly one line, with `cache` beside `durationMs` so a
hit is distinguishable from a resolve at a glance.

`extraction failed`, when an extraction throws: kind, id, error class,
and evidence.

The evidence is the point, and the reason this ships before the fix it
serves. `normalizeByKind` returning null becomes a NotFoundError, which
the HTTP layer answers 404 and negative-caches for TTL_NEGATIVE. But
null covers two unrelated situations -- Spotify said the entity is gone,
and we captured nothing at all. A live playlist was served as "not
found" because the second was reported as the first, and being
negative-cached it stayed that way.

ExtractionEvidence records what the capture saw: how many JSON
responses, which distinct statuses, which distinct paths. `recorded: 0`
is the signature of a capture that saw nothing -- our failure, not
evidence of absence. Every throw inside runExtraction carries it, so a
line without evidence means exactly one of two things: a failure relayed
to a waiter (reviveFailure rebuilds from a wire form that does not carry
the capture -- read the holder's own line), or a timeout, rejected from
outside the extraction and never having had one.

Splitting those two cases onto different status codes is the next
change. This one exists so that split is written against observed
evidence rather than a guess about what Spotify's page emits for a
deleted id.

ExtractionTimeoutError joins the same base class so every extraction
failure produces one diagnostic line; the instanceof chain that maps 504
is unchanged, since it tests leaf classes.

LOG_LEVEL (default `info`) is the one new knob. Tests pass `silent`, or
inject a recording logger through the new optional `logger` dep.

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