Skip to main content

Overview

The cron recrawl endpoint triggers automatic recrawls of all sites that are due for updates. This is an internal endpoint designed to be called by scheduled tasks (AWS Lambda, GitHub Actions, cron jobs, etc.) to maintain up-to-date llms.txt files for enrolled sites.
This endpoint runs recrawls in the background and returns immediately. It does not wait for crawls to complete.

Endpoint

Authentication

This endpoint requires authentication via the X-Cron-Secret header:
string
required
Secret token configured in the backend’s CRON_SECRET environment variable. This prevents unauthorized triggering of recrawls.

Request

No request body is required. Authentication is handled entirely through the header.

Example Request

Response

Success Response (200)

string
Always "triggered" when the recrawl background task is successfully queued.
string
Human-readable confirmation message.
The endpoint returns immediately after queuing the background task. It does not wait for recrawls to complete or report their results.

Error Response (401)

Returned when the cron secret is missing, invalid, or doesn’t match the configured value.

How It Works

1. Site Selection

The recrawl process:
  1. Queries the crawl_sites table for sites where next_crawl_at <= NOW()
  2. Retrieves site configuration (max_pages, desc_length, recrawl_interval_minutes)
  3. Processes each site sequentially

2. Change Detection

For each site, the system:
  1. Checks sentinel URL (typically sitemap.xml) for changes
  2. Compares hash of new content with stored latest_llms_hash
  3. Skips crawl if content hasn’t changed (optimization)
  4. Full recrawl if changes detected or sentinel unavailable

3. Scheduling

After each check:
  • Content unchanged: Updates next_crawl_at based on recrawl_interval_minutes
  • Content changed: Regenerates llms.txt, uploads to R2, updates database
  • Adaptive scheduling: Adjusts interval based on change frequency (future feature)

Background Task

The recrawl logic is implemented in /backend/main.py:37-43 as a FastAPI background task:
The actual recrawl implementation is in /backend/recrawl.py.

Scheduling Examples

AWS Lambda + EventBridge

Lambda Function (lambda_handler.py):
EventBridge Rule (Terraform):

GitHub Actions

Vercel Cron

vercel.json:
pages/api/trigger-recrawl.ts:

Traditional Cron

Configuration

Environment Variables

Generate a secure cron secret:

Recrawl Intervals

When users enable auto-update via the WebSocket endpoint, they can specify:
  • Default: 10080 minutes (7 days)
  • Common values:
    • 360 minutes (6 hours)
    • 1440 minutes (1 day)
    • 10080 minutes (7 days)
The cron job should run more frequently than the shortest interval you want to support.

Monitoring

Check logs to monitor recrawl status:
Expected log output:

Database Schema

The endpoint relies on the crawl_sites table structure:
Key fields:
  • next_crawl_at: Determines if site is due for recrawl
  • latest_llms_hash: Used for change detection
  • sentinel_url: Quick check endpoint (usually sitemap.xml)

Error Codes

Performance Considerations

  1. Background Processing: Returns immediately, doesn’t block
  2. Sequential Crawling: Processes sites one at a time to manage resources
  3. Smart Skipping: Avoids full crawls when content unchanged
  4. Timeout Handling: Long-running crawls may timeout; monitor logs

Best Practices

  1. Run frequently: Schedule every 1-6 hours to ensure timely updates
  2. Monitor logs: Set up alerts for recrawl errors
  3. Secure the secret: Use environment variables, never commit to git
  4. Idempotent calls: Safe to call multiple times; won’t duplicate work
  5. Database backups: Ensure Supabase backups are enabled
  • WebSocket Crawl - Enable auto-update when generating llms.txt
  • Webhooks - Trigger immediate recrawl for specific site