fix: stop capturing a fresh screenshot on every unchanged check#13
Open
Vision-jarvis wants to merge 1 commit into
Open
fix: stop capturing a fresh screenshot on every unchanged check#13Vision-jarvis wants to merge 1 commit into
Vision-jarvis wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces unnecessary context.dev screenshot captures during routine monitor checks by reusing the last stored screenshot when no change is detected, and simplifies LLM request timeout handling in the AI helpers.
Changes:
- Only capture a page screenshot on the first snapshot and when the relevant change signal (markdown hash / price change) indicates an update, instead of on every check.
- Replace manual
AbortController+setTimeoutpatterns withAbortSignal.timeout()in AI triage and change-summary helpers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/lib/scraper.ts | Gates screenshot capture so quiet checks reuse the last thumbnail instead of paying for a fresh screenshot every tick. |
| src/lib/ai-change-summary.ts | Uses AbortSignal.timeout() for LLM call timeouts to avoid manual timer management. |
| src/lib/ai-alert-triage.ts | Uses AbortSignal.timeout() for LLM call timeouts to avoid manual timer management. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
254
to
+258
| const prev = await latestSnapshot(website.id, "PRODUCT", page); | ||
| if (!prev) return; | ||
| if (!snap.is_product_page) return; | ||
| const prevData = JSON.parse(prev.payload) as ProductSnapshotData; | ||
| if (!prevData.is_product_page) return; | ||
| if (priceChangeKey(prevData) === priceChangeKey(snap)) return; | ||
| const prevData = prev ? (JSON.parse(prev.payload) as ProductSnapshotData) : null; | ||
| const priceChanged = | ||
| prevData !== null && | ||
| snap.is_product_page && |
Contributor
Author
There was a problem hiding this comment.
Good catch — done. The product screenshot now keys off the snapshot hash (prev.hash !== value.hash) so it refreshes on any payload change (name/platform/availability), matching the content handler, while alert emission stays gated on priceChanged. Pushed.
The scrape+diff pipeline took a fresh, billable context.dev screenshot on every content and product check, before the change comparison — even when nothing had changed. The screenshot only backs the "current version" thumbnail on the monitor card; change detection is the markdown/price hash, not the image. So a default content monitor (1h interval) spent 24 screenshot captures a day on a page that never changed, on top of the markdown scrape it actually needs. Capture the screenshot on the first snapshot and whenever the scraped content or product snapshot actually changes — keyed off the same snapshot hash the pipeline already computes — and keep the last screenshot on an identical check. That roughly halves context.dev calls for the common case of a quiet page, with no change to which alerts fire: the thumbnail tracks the snapshot, so it refreshes on any real change and never goes stale, while price alerts stay gated on an actual price change. Also drop the manual AbortController + setTimeout timeout in the two AI helpers in favour of AbortSignal.timeout(), which releases the timer on every path (the manual timer leaked on the error path). Matches the pattern already used in notify-outbound-webhook.ts.
9c63010 to
7e707e0
Compare
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.
What
Every content and product check captures a fresh, billable context.dev screenshot before the change comparison — even when nothing has changed. The screenshot only backs the "current version" thumbnail on the monitor card; change detection is the markdown/price hash, not the image. So a default content monitor (1h interval) spends ~24 screenshot captures a day on a page that never changes, on top of the markdown scrape it actually needs.
That's the other half of #11 ("burns 100+ credits without any change") — #12 fixed the brand-logo render burn; this fixes the per-check screenshot burn in the scrape pipeline.
How
scraper.ts— capture the screenshot on the first snapshot and whenever the content or price actually changes; an unchanged check keeps its last screenshot. Which alerts fire is unchanged — the gate reuses the same hash/price comparison that already decides the alert, so a viewer sees an identical thumbnail (the page didn't change). Roughly halves context.dev calls for the common case of a quiet page.ai-alert-triage.ts+ai-change-summary.ts— swap the manualAbortController+setTimeoutforAbortSignal.timeout(). The old timer was only cleared on the success path, so a thrown request left it pending for the full timeout (the review note on feat: AI relevance filter to hold noisy change alerts #10 — and the same pattern was already in the summary helper).AbortSignal.timeout()releases on every path and matches hownotify-outbound-webhook.tsalready does it.Verification
typecheck,lint(0 errors),npm test(12/12), andnext buildall pass. No schema or migration changes; no behavior change to alert emission or notifications.