Skip to content

fix: stop capturing a fresh screenshot on every unchanged check#13

Open
Vision-jarvis wants to merge 1 commit into
context-dot-dev:mainfrom
Vision-jarvis:fix/screenshot-credit-burn
Open

fix: stop capturing a fresh screenshot on every unchanged check#13
Vision-jarvis wants to merge 1 commit into
context-dot-dev:mainfrom
Vision-jarvis:fix/screenshot-credit-burn

Conversation

@Vision-jarvis

Copy link
Copy Markdown
Contributor

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 manual AbortController + setTimeout for AbortSignal.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 how notify-outbound-webhook.ts already does it.

Verification

typecheck, lint (0 errors), npm test (12/12), and next build all pass. No schema or migration changes; no behavior change to alert emission or notifications.

Copilot AI review requested due to automatic review settings July 13, 2026 19:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + setTimeout patterns with AbortSignal.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 thread src/lib/scraper.ts
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 &&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Vision-jarvis Vision-jarvis force-pushed the fix/screenshot-credit-burn branch from 9c63010 to 7e707e0 Compare July 13, 2026 19:47
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.

2 participants