Skip to content

fix: persist bearer scan_history on /api/check/stream cache hit#538

Open
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-54a6
Open

fix: persist bearer scan_history on /api/check/stream cache hit#538
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-54a6

Conversation

@cursor

@cursor cursor Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Bearer-authenticated GET /api/check/stream skipped persistBearerScanIfWatched on cache hits. When a Pro user's watched domain was scanned within the 5-minute edge cache TTL, the stream endpoint replayed cached SSE events successfully but never wrote to scan_history or updated domains.last_grade / last_scanned_at.

Concrete trigger: User watches example.com → any scan populates cache → within 5 minutes, same user calls /api/check/stream?domain=example.com with bearer auth → dashboard/history stay stale despite a "successful" streamed scan.

The JSON sibling GET /api/check already persisted on cache hits; only the stream path regressed.

Root cause

The cache-hit branch in /api/check/stream returned immediately after replaying SSE events. persistBearerScanIfWatched was only invoked on the cache-miss path after scanStreaming() completed.

Fix

Call persistBearerScanIfWatched in the cache-hit branch, mirroring /api/check.

Validation

  • New regression test: test/api-check-stream-bearer-persist.test.ts
  • Full suite: 1300 tests passing
  • npm run lint clean
Open in Web View Automation 

GET /api/check already calls persistBearerScanIfWatched on cache hits so
Pro API scans of watched domains update scan_history. The streaming sibling
returned early on cache hit without persisting, leaving last_grade and
scan_history stale for up to five minutes while the client saw a successful
scan.

Mirror the JSON endpoint: invoke persistBearerScanIfWatched after replaying
cached SSE events. Regression test drains the stream and asserts recordScan
runs for watched domains only.

Co-authored-by: schmug <schmug@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 13, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
dmarcheck 2e2cf7b Jun 13 2026, 11:09 AM

@schmug schmug marked this pull request as ready for review June 13, 2026 18:27
@schmug schmug self-requested a review as a code owner June 13, 2026 18:27
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