Background processing pipeline
The background processing pipeline moves slow or retryable work out of user requests and runs it through the worker service. It turns saved content into stored page data, enrichment results, and searchable records while also handling scheduled maintenance, automation, integrations, and backups.
System purpose
The worker service is the execution layer for work that does not need to finish before an API request returns. Producers create a typed job, a queue holds it until it is ready, and a worker applies the result to the system or starts the next stage.
This separation keeps browser fetches, file processing, model calls, external callbacks, and large exports from blocking interactive use. It also gives each kind of work its own capacity, retry policy, and operational view.
The main outcomes are:
- Content capture for links, images, PDFs, feeds, and optional video.
- Enrichment through summaries, tags, embeddings, and search updates.
- Automation through rules and outbound webhooks.
- Operations through backups and administrator maintenance tasks.
Work initiation
Work enters the pipeline from user actions, from one completed job starting another, or from a schedule. The producer supplies the business identifier and any options needed for that stage. The worker then reads current state when it runs instead of relying on a large copy of the original request.
Saved-content starts
Saving a link starts crawling. Saving an image or PDF starts asset preprocessing. Saving text can start embedding generation or tag inference, based on the configured enrichment path. When tagging has no user-curated tag list, it can use tags from similar saved items as context for the model. If a fresh embedding is available, this lookup can happen before the item reaches the vector index. A successful capture or preprocessing step can then start several independent jobs for enrichment, search indexing, media download, and webhooks.
The stages are intentionally separate. A slow search update does not need to repeat a crawl, and a vector-store failure does not need to repeat tagging. See Content ingestion and enrichment jobs for the content lifecycle.
References: packages/…/bookmarks.ts• L485-554 apps/…/crawlerWorker.ts• L261-331 apps/…/assetPreprocessingWorker.ts• L386-507 apps/…/tagging.ts• L536-693
Asset persistence
Crawler stages persist screenshots, PDFs, downloaded files, page archives, and large HTML as user assets. The storage path checks the user quota before each write and limits downloaded or decoded content before it can consume excessive memory or storage. Inline data images from archived pages can become local assets when they use a supported image type.
Asset preprocessing reads the current image or PDF asset and adds text or a PDF screenshot when the content supports it. When that work changes the bookmark, it starts the next enrichment and search stages with the original priority and the user as the work group. A crawler timeout remains a job failure so the queue can retry the crawl instead of reporting a partial download as complete.
References: apps/…/assetStorage.ts• L37-94 apps/…/assetStorage.ts• L149-223 apps/…/assetStorage.ts• L225-344 apps/…/assetPreprocessingWorker.ts• L386-507
Scheduled and operator starts
Schedules create work without a user request in progress. Feed refreshes run each hour, and backup scheduling runs each day. The schedulers spread jobs over time and use idempotency keys so one scheduling pass does not create duplicate work.
Administrator actions can enqueue reprocessing, re-enrichment, reindexing, or maintenance tasks. Rules enqueue work only when an event matches an enabled rule, while webhook delivery starts only when a user has a matching webhook. See Automation and operations jobs for these paths.
References: apps/…/feedWorker.ts• L60-113 apps/…/backupWorker.ts• L40-116 packages/…/admin.ts• L350-470 packages/…/ruleEngine.ts• L140-156 packages/…/webhooks.service.ts• L77-95
Dispatch and execution
The pipeline uses named queues as boundaries between producers and workers. Each queue has a payload contract, a retry policy, and a worker with a time limit and concurrency limit. The active queue backend supplies the same behavior to the application whether work runs locally or through a distributed service.
Queue selection
The queue layer hides the choice of execution backend from job producers. A local backend can run queue work in the worker process, while a service-based backend can keep dispatch and execution as separate roles. Both support delayed work, priority, user or task grouping, retries, and job status in the shared model.
The worker service prepares the queue provider before it creates queues for enabled workers. Queue definitions are created on demand, which lets API and worker code use the same job names and payload shapes without duplicating backend logic. See Queue execution backends for backend-specific behavior.
References: packages/…/queueing.ts• L20-104 packages/…/queues.ts• L19-78 packages/…/index.ts• L130-215
Job control
Dispatch controls which work may run and when. Lower numeric priority values run sooner. Group IDs support fair sharing, and idempotency keys prevent equivalent scheduled or follow-up work from running twice.
Normal errors consume the retry budget. A temporary rate limit can ask the queue to wait without consuming that budget. Each running job receives an abort signal for its time limit, so a stalled operation can release capacity and follow the failure path.
The normal job sequence is:
- A producer enqueues a typed payload and receives a job ID.
- The queue waits for any delay and available capacity.
- The worker validates and runs the job.
- Completion updates downstream state or starts follow-up jobs.
- An error retries while attempts remain, then records a final failure.
References: packages/…/queueing.ts• L10-72 packages/…/dispatcher.ts• L81-211 packages/…/runner.ts• L50-165 packages/…/semaphore.ts• L149-253
Worker service operation
The worker service starts only the enabled consumers, starts scheduled producers for feeds and backups when their workers are enabled, and serves a small operation interface. Worker modules load only when their consumers are enabled. This keeps optional worker dependencies out of processes that do not use them and lets a worker process scale by workload.
Worker lifecycle
Startup loads plugins, initializes tracing and event logs, prepares the queue backend, builds the selected workers, and starts queue execution. It starts feed and backup schedulers only when their workers are active. It starts the import polling worker under the same selection rules.
Shutdown stops schedulers and workers before it closes the operation interface and telemetry providers. If a running worker fails, the service records the error and begins this shutdown path so the process does not continue with only part of its workload.
Workers report completion and failure through the same lifecycle. Some failures only affect the job and its retry budget. A final failure can also clear a pending bookmark status or mark a backup as failed so stored state reflects the outcome.
References: apps/…/index.ts• L31-195 apps/…/crawlerWorker.ts• L127-201 apps/…/inferenceWorker.ts• L44-80 apps/…/backupWorker.ts• L118-169
Trace and event context
Each worker job can produce an OpenTelemetry span and an event log record. The record carries the job ID, priority, run number, and workload-specific fields such as bookmark, user, feed, or backup identity. Errors set the span to an error state and retain the failure details for later diagnosis.
Tracing and event logging are loaded only when their services are enabled. This context connects a queue attempt to the domain work it performs without making telemetry dependencies a requirement for every worker process. Follow-up work remains visible as separate jobs, which helps operators tell a slow stage from a failed stage.
References: apps/…/index.ts• L127-132 apps/…/workerTracing.ts• L10-64 packages/…/tracing.ts• L38-165 packages/…/eventLogger.ts• L126-227
Bookmark context
Bookmark context gives content workers the current link and asset state needed for a job. The shared worker utility reads the bookmark with its link and assets, then returns the URL, owner, dates, and relevant asset identities. Workers can use this current view to update or replace an asset as processing advances.
References: apps/…/workerUtils.ts• L7-58
Health and metrics
The worker service exposes a health endpoint and a protected metrics endpoint. Health shows that the process is responsive. Metrics show worker completion and failure counts, crawler response codes, and the latency from bookmark creation to first successful high-priority crawl.
Default process and runtime metrics are collected only when Prometheus metrics are enabled. These signals describe process and workload health, not the full state of every queue. Queue-specific inspection may be richer for a distributed backend, so operators should use the selected backend's status view when a job appears stuck or suspended.
References: apps/…/server.ts• L10-48 apps/…/metrics.ts• L6-39 packages/…/admin.ts• L3-80
Pipeline relationships
The pipeline is a graph of independent stages rather than one long transaction. A stage writes its own durable result before it asks another queue to continue the work. This keeps partial progress useful and limits the scope of retries.
The following diagram shows the common path from a saved item through capture, asset persistence, enrichment, discovery, and system side effects.
flowchart TD
A[User save or scheduled input] --> B{Input path}
B -->|Link| C[Crawl and capture]
B -->|Image or PDF| D[Asset preprocessing]
B -->|Text| E[Enrichment start]
B -->|Feed| F[Feed refresh]
F --> C
C --> G[Stored content and assets]
D --> G
G --> H[Embeddings]
G --> I[Summary and tags]
G --> J[Search index]
H --> K[Vector index]
I --> J
C --> L[Optional video and webhook jobs]
G --> M[Rules and other automation]
N[Daily backup or admin task] --> O[Operations queue]
Content stages and operations stages share the same dispatch model, but they have different business goals. Follow Content ingestion and enrichment jobs for saved-content work and Automation and operations jobs for rules, webhooks, feeds, backups, and maintenance.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep every queue name and payload shape aligned with all producers, worker runners, and the selected queue backend.
- If a stage starts follow-up work, preserve the user group, priority, and idempotency scope across that boundary.
- If a bookmark result or status changes, check the related search, vector, webhook, rule, and failure-state updates.
- If a scheduled producer changes its timing or identity key, verify that one schedule pass still creates one intended job per target.
- If worker selection changes, keep queue initialization, scheduler startup, shutdown, and deployment settings aligned.
- If job fields or worker names change, update trace attributes, event fields, metrics labels, and backend inspection names together.
- If worker startup imports change, verify that disabled workers do not load their worker modules or optional dependencies.
- If worker asset context changes, keep asset replacement and current bookmark lookup behavior aligned with content workers.
- If asset storage accepts a new source or type, keep size limits, content-type checks, quota checks, temporary-file cleanup, and downstream asset metadata aligned.
- If timeout handling changes in a crawler storage helper, preserve abort propagation so a canceled crawl remains retryable.
- If worker metrics change, keep metric names and labels stable for dashboards and alerts, and keep default collection behind the metrics enablement setting.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A queue name or payload changes on only one side of a producer-worker boundary | Jobs can be rejected, skipped, or sent to the wrong work path | Treat queue names and schemas as shared contracts. |
| A follow-up job loses its user group or uses a broad idempotency key | One user's work can crowd out another user's work, or different work can be deduplicated | Propagate group and priority, and include all work-changing fields in the key. |
| A normal job error is treated as a temporary rate limit | The job can wait without consuming retries and remain delayed longer than intended | Use the retry-after signal only for a known temporary wait. |
| The worker process starts without a usable queue provider | Consumers cannot start and asynchronous work remains pending | Load and verify the selected provider before queue preparation. |
| A disabled worker still loads its module or optional dependency | A process can fail at startup even though that workload is not enabled | Apply worker selection before dynamic import and queue initialization. |
| A final content job failure leaves a pending bookmark status | The user sees enrichment as still running even though no retry remains | Keep permanent-failure callbacks aligned with bookmark status cleanup. |
| A scheduler runs more than once for the same time window | Feeds or backups can repeat work and create duplicate downstream records | Preserve deterministic timing and idempotency keys. |
| Telemetry fields are removed from a worker wrapper | Operators lose the link between a queue attempt and its bookmark or user work | Keep job identity and domain identity in spans and event logs. |
| A bookmark no longer has a link when a content worker reads it | The job cannot identify its URL and fails instead of processing stale or invalid context | Treat link presence as a required content-job contract. |
| A downloaded or inline asset exceeds its allowed size or type | The asset is rejected before storage, and the related optional output is absent | Enforce the encoded and decoded size limits, supported image types, and stream size limit before saving. |
| A crawler timeout is swallowed by asset storage | The crawl can be reported as successful even though a required asset operation was canceled | Re-throw the abort signal after logging so the queue runner can retry the job. |
| Prometheus labels or names change without matching dashboards | Worker health views can lose data or show broken series | Treat metric names and label sets as monitoring contracts. |
Key files
| File | Why to read it |
|---|---|
| apps/…/index.ts | Shows worker selection, lazy worker loading, queue startup, scheduler startup, import polling, and shutdown. |
| apps/…/workerUtils.ts | Shows the shared bookmark and asset context used by content workers. |
| packages/…/queues.ts | Defines the named queues that connect producers to workers. |
| packages/…/queueing.ts | Defines the shared job, retry, priority, grouping, and runner model. |
| apps/…/workerTracing.ts | Shows the common trace and event-log boundary around job execution. |
| apps/…/crawlerWorker.ts | Shows the main saved-link path and how a completed crawl starts follow-up work. |
| apps/…/assetStorage.ts | Shows how crawl outputs become quota-checked assets and how timeout and size guards protect the job. |
| apps/…/assetPreprocessingWorker.ts | Shows how image and PDF assets become text or screenshots before enrichment continues. |
| apps/…/embeddingsWorker.ts | Shows how one enrichment stage separates vector generation, tagging, and vector storage. |
| apps/…/tagging.ts | Shows how tagging uses bookmark content and optional similarity context before it updates tags and starts downstream work. |
| apps/…/feedWorker.ts | Shows scheduled input and how new feed entries enter normal content processing. |
| apps/…/backupWorker.ts | Shows scheduled operational work and its durable success or failure state. |
| apps/…/adminMaintenanceWorker.ts | Shows the entry point for administrator maintenance tasks. |
| apps/…/metrics.ts | Defines worker, crawler response, crawl latency, and optional default process metrics. |
| apps/…/server.ts | Shows the worker health and protected metrics interface. |
| packages/…/dispatcher.ts | Shows distributed dispatch, capacity, retry, and completion behavior. |
| packages/…/runner.ts | Shows validation, timeout, execution, and callback behavior. |
| packages/…/admin.ts | Shows the richer operational status view for distributed queue invocations. |