Repository navigation
fix: wait for the entity query, not for the page to go quiet - #9
Merged
Merged
Conversation
/spotify failed the first time and worked the second. The logs from 0.2.0
named it in one line:
ExtractionSilentError navStatus:200 recorded:21 statuses:[200]
paths: /cdn/generated-locales/web-player/en...json, /api/token, /,
/api/114855/envelope/, /v1/clienttoken,
/remote-config-resolver/v3/unauth/configuration,
/gabo-receiver-service/public/v3/events, /consent/...json
Twenty-one responses captured and not one of them the pathfinder query.
Every path is first-run bootstrap -- locale bundle, access token, client
token, remote config, telemetry, consent. A cold browser context spends
its first page load completing that handshake, and it consumes the whole
window networkidle + scroll + settle was watching. The next request, on
the now-warm context, took LONGER (11.4s against 5.3s) and succeeded,
because it went straight to fetching data.
Never random: CONTEXT_MAX_USES recycles contexts, so the first extraction
after every recycle -- and after every restart -- met a cold one.
recordResponses now waits for the response the normalizers actually read.
PATHFINDER_URL moves from a private const in normalize.ts to an export,
since waiting for it and filtering on it are the same fact. The promise is
created BEFORE goto so a response arriving mid-navigation still counts;
waiting on it afterwards would hang for the full timeout.
ENTITY_DATA_TIMEOUT_MS bounds the wait and is its own knob at 15s rather
than borrowing the 45s NAV_TIMEOUT_MS. It covers the gap between "the page
went quiet" and "the data arrived"; a page that will never produce entity
data must still say so quickly, and reusing the nav timeout made every
genuinely silent extraction cost 45 seconds. Three existing tests timed
out the moment it did, which is how that was caught.
Warming contexts at creation was implemented alongside this and then
removed. Measured over two rounds and two ids, it saved ~600ms on the
first extraction and cost ~750ms to perform. Worse, recycle() runs inside
releaseRecord, which runExtraction awaits in its finally -- so warming is
paid by the recycling request itself, moving latency onto the request path
rather than off it. The wait alone is sufficient: a cold context's first
extraction now succeeds.
Verified against the real site: first extraction on a brand-new pool
returns 5 tracks in ~8s, warmed or not. Previously it failed.
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
The note claimed the warm request took longer 'because it went straight to fetching data', which would predict the opposite. The real mechanism is that the failing path is cheaper: with no entity data nothing renders, so the scroll loop finds nothing scrollable and exits on its first iteration (`if (!best) return true`) -- measured at 1 iteration / 353ms against 4 / 1421ms for a rendered list -- and `goto` skips the whole data cascade. Warmth's own cost points the other way: where a cold context does get its data in time, cold is SLOWER (8569ms vs 7153ms), entirely in goto (4152ms vs 2736ms). Two independent effects; in production the second inverted the ordering. Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/spotifyfailed the first time and worked the second. The 0.2.0 logs named it in one line.The log that solved it
{"kind":"playlist","id":"6FPDTIEcrb6EXUuWX2kBJz","error":"ExtractionSilentError", "evidence":{"navStatus":200,"recorded":21,"statuses":[200], "paths":["/cdn/generated-locales/web-player/en.aab0b7e4.json","/api/token","/", "/api/114855/envelope/","/v1/clienttoken", "/remote-config-resolver/v3/unauth/configuration", "/gabo-receiver-service/public/v3/events","/consent/50da44be-.../....json"]}} → 502 in 5286ms {"url":"/v1/playlist/6FPDTIEcrb6EXUuWX2kBJz","status":200,"durationMs":11415,"cache":"miss"}Twenty-one responses captured, and not one of them the pathfinder query. Every path is first-run bootstrap: locale bundle, access token, client token, remote config, telemetry, consent. That is a cold browser context completing its handshake, and it consumed the entire window
networkidle+ scroll + 3s settle was watching.Why the failing request was faster
The cold one took 5.3s and failed; the warm one took 11.4s and succeeded. That reads backwards until you notice the failing path is systematically cheaper:
goto→ networkidleThe scroll loop gives up on its first pass when there is nothing to scroll (
if (!best) return true), and with no data nothing renders. Measured live: rendered playlist = 4 iterations / 1421ms, dead page = 1 / 353ms.Warmth's own cost points the other way — where a cold context does get its data in time, cold is slower (8569ms vs 7153ms), entirely in
goto(4152ms vs 2736ms). Two independent effects; in production the second inverted the ordering. Duration is not a signal of success, which is also why a "call back in N seconds" estimate must be computed over successful extractions only.It was never random.
CONTEXT_MAX_USESrecycles contexts, so the first extraction after every recycle, and after every restart, met a cold one.Worth noting the 0.3.0 classification did its job here: that's a 502
extraction_silent, so it was never negative-cached and the retry was free to re-scrape. Under 0.2.0 it would have been a 404 and "confirmed absent" for ten minutes.The fix
recordResponsesnow waits for the response the normalizers actually read.PATHFINDER_URLmoves from a private const innormalize.tsto an export — waiting for it and filtering on it are the same fact. The promise is created beforegoto, so a response arriving mid-navigation still counts; waiting on it afterwards would hang for the full timeout.ENTITY_DATA_TIMEOUT_MS(15s) bounds it, deliberately its own knob rather than borrowing the 45sNAV_TIMEOUT_MS. It covers the gap between "the page went quiet" and "the data arrived"; a page that will never produce entity data must still say so quickly. Reusing the nav timeout made every genuinely silent extraction cost 45 seconds — three existing tests timed out the instant it did, which is how that got caught.Warming contexts: built, measured, deleted
The companion fix — warm each context at creation so bootstrap happens off the request path — was implemented and then removed, because the measurements did not support it:
~600ms saved on the first extraction, ~750ms to perform — a wash. And I had the cost in the wrong place:
recycle()runs insidereleaseRecord, whichrunExtractionawaits in itsfinally, so warming is paid by the recycling request itself, with the warm-up timeout as a worst-case tail. It moves latency onto the request path. The wait alone is sufficient.Verification
Against the real site, first extraction on a brand-new pool:
Both succeed. Previously the first failed.
npm test— 110 passed, 9 skipped.ExtractionSilentError ... loaded with 200 but nothing on the page matched.npx tsc --noEmitclean. Comment density 472/1322 = 0.36, in band.docs/design-notes.mdcarries both the fix and the negative result, so warming is not re-proposed from theory.Version 0.3.1 — bug fix, no API change.
🤖 Generated with Claude Code