Remove canonical cache auto-refresh (sweep + on-read TTL)#83
Merged
Conversation
The 30-min background sweep (StartCanonicalBackgroundTasks / refreshStaleCanonicals) re-scraped >TTL-stale canonical entries every cycle, and a failed refresh never advanced FetchedAt — so blocked-site entries retried via Firecrawl forever, draining the Firecrawl free tier (1000 credits) in ~5 days and surfacing as "Website blocked access" (Firecrawl HTTP 402) across the app. Canonical extractions are near-static, so re-fetching is wasteful. Remove both the background sweep and the on-read canonicalTTL re-fetch: a cached URL is served permanently and only extracted on a true cache miss (or manually if a problem is reported). Strip the now-dead GetStaleEntries from the repo interface, implementation, and mock. Tests: the two *_StaleCanonicalSkipped tests become *_OldCanonicalStillServed, asserting an old entry is served from cache without re-fetching. Full suite green (go test ./... -count=1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BU4UWZutHd1AnK3XAf7H19
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Problem
The app showed "Website blocked access" on recipe imports/previews. Root cause: our Firecrawl account was returning HTTP
402— the free tier (1000 credits/mo) was fully exhausted.The drain was self-inflicted, not abuse (the app is unreleased). The canonical-cache background refresh ran every 30 min, re-scraping entries stale for >7 days. For bot-blocked sites it routed to Firecrawl, but a failed refresh never advanced
FetchedAt, so the same handful of blocked URLs retried every 30 min forever (~5 URLs × 48 cycles/day ≈ 240 Firecrawl calls/day → 1000 credits gone in ~5 days). Logs confirmed it: 124/124 Firecrawl calls in 14h were402, across only 4–7 distinct URLs/day.Change
Re-fetching imported recipes is wasteful — recipe pages are near-static — so this removes automatic re-fetch entirely:
StartCanonicalBackgroundTasks/refreshStaleCanonicals) and its router wiring.canonicalTTLre-fetch fromImportFromURL,PreviewFromURL, andPreviewFromURLWithMultiCheck. A cached URL is now served permanently; re-extraction happens only on a true cache miss (or manually if a problem is reported).canonicalTTLconst + orphanedtimeimport, andGetStaleEntriesacross the repo interface, implementation, and mock.Behavior after
Tests
The two
*_StaleCanonicalSkippedtests become*_OldCanonicalStillServed, asserting a year-old entry is served from cache without re-fetching.go test ./... -count=1→ green (11 packages, 0 failures).Follow-up (not in this PR)
Firecrawl credits stay at 0 until the Jul 15 reset (or a manual top-up); with this loop gone the free tier is sufficient going forward. Optional: a CloudWatch alarm on Firecrawl
402so exhaustion can't go unnoticed again.🤖 Generated with Claude Code
https://claude.ai/code/session_01BU4UWZutHd1AnK3XAf7H19