Distributed Crawl — Resilience Hardening Plan
Status: All 4 phases delivered (Phase 4 = the 4a shared breaker; 4b concurrency leases deferred). The current distributed-crawl coordinator (see distributed-crawl-cluster.md) is a solid v1 data-partition coordinator: strong live aggregation/observability, idempotent worker lifecycle, assignment-time capacity routing (WorkerWeightFunction), per-worker LLM circuit breakers, and in-worker OOM avoidance (AIMD batch sizing + heap-pressure parallelism cuts). It is not yet durable or self-healing. This plan closes the four gaps, in priority order, keeping every behavior change additive and opt-in (matching the existing cluster* flags in ResourceSchedulerConfig).
Verified gaps (today)
| Gap | Evidence |
|---|---|
| Sessions are in-memory only → coordinator restart loses all in-flight crawls | DistributedCrawlCoordinator sessions = ConcurrentHashMap; no store/boot-restore |
Reassignment cold-restarts the partition (full crawlRequestJson re-sent; worker checkpoint discarded) | reassignWorkerPartition rebuilds metadata from scratch |
| Only silent loss (heartbeat-evicted / progress-stalled) is reassigned; a reported failure is terminal | PartitionLossReaper.scan only touches WorkerStatus.RUNNING; handleWorkerCallback(success=false) → workerFailed |
| Stall reaction is coarse — flat 300s progress timeout; GC overhead is collected but never an input | PartitionLossReaper.lossReason progress timeout; GC time only in telemetry/UI |
| Circuit breakers are per-JVM; a shared flaky backend trips N times; cap-scaling divides concurrency statically | CrawlLlmDispatcher per-instance ConcurrentHashMap<String,CircuitBreaker> |
Phase 1 — Durable sessions + checkpoint-aware reassignment (highest value) — ✅ DONE
Goal: a coordinator restart recovers in-flight sessions; reassignment reuses what the lost worker already finished instead of re-crawling it.
- Persist a lightweight
DistributedCrawlSessionmanifest (workers, partitions, per-partitioncrawlRequestJson, status,externalRef,lastProgressAt,reassignmentCount, lastsourceProgress) as JSON under the versioned data dir (data/distributed-crawl/sessions/<id>.json). Write on lifecycle transitions (dispatch / complete / fail / reassign / status) + a throttled periodic flush (~30s) of latest snapshots — not on every ~4s progress tick. NewDistributedCrawlSessionStore(write/load/delete); reuse the existing data-dir + Jackson conventions. - Boot reconcile (orchestrator-only
ApplicationReadyEvent): load non-terminal sessions; for each worker partition querydelegate.getJobStatus(externalRef)— still running → resume tracking; gone → queue for reassignment (or fail if reassign disabled). - Checkpoint-aware reassignment (80/20): workers already write graph/vector output to the shared stores scoped by
factSheetId, and reportsourceProgress. On reassign, drop sources the lost worker already completed from the re-dispatchedUnifiedCrawlRequestso finished sources aren't re-crawled. (Full document-cursor resume is a later refinement.) - Config:
clusterSessionPersistenceEnabled— proposed default ON (orchestrator-scoped, pure IO safety, no crawl-behavior change). ⚠️ This deviates from the all-opt-in convention; flagged for your call — a default-off persistence layer protects nobody from the crash it exists for. - Files:
DistributedCrawlSession(toManifest/fromManifest), newDistributedCrawlSessionStore,DistributedCrawlCoordinator(persist hooks + boot reconcile),reassignWorkerPartition(drop completed sources),ResourceSchedulerConfig(flag + dir). - Tests: manifest round-trip; boot reconcile (live external → resumed, dead → reassigned/failed); reassignment omits completed sources; persistence-disabled → no IO, in-memory behavior unchanged.
- Risk: hot-path IO (mitigate: transition-triggered + throttled async writes); shared-store double-write on resume (already idempotent via
factSheetId+ entity-resolution dedup).
Phase 2 — Reassign on reported failure (failure symmetry) (small, high leverage) — ✅ DONE
Implemented coordinator-side (no worker change): the /distributed-crawl/callback resultData.status already distinguishes FAILED/CANCELLED, so handleWorkerCallback classifies retriability (isRetriableFailure: explicit resultData.retriable wins, else CANCELLED/fatal-marker → not retriable, else retriable) and routes retriable failures to reassignWorkerPartition (bounded by clusterMaxReassignments). Config: clusterReassignOnFailure=false.
Goal: a worker that reports FAILED gets its partition retried (bounded), not just a worker that vanishes.
- In
handleWorkerCallback(success=false): if enabled andreassignmentCount < max, route toreassignWorkerPartitioninstead ofworkerFailed. Classify retriable (OOM/transient) vs fatal (bad request/auth) — only retriable retries. Add aretriableflag (or reason code) toCrawlClusterJobRunner.Resultso the worker, which knows the local failure, drives the classification. - Config:
clusterReassignOnFailure=false(default off, sibling ofclusterReassignOnLoss). - Files:
DistributedCrawlCoordinator.handleWorkerCallback,CrawlClusterJobRunner.Result. - Tests: retriable → bounded reassign; fatal → immediate terminal; max-reassign → terminal.
- Risk: retry storms (bounded by
maxReassignments+ fatal classification).
Phase 3 — Fast, GC-aware stall signal (congestion reaction) — ✅ DONE
Workers advertise gcOverheadFraction on WorkerCapabilities (ΔGarbageCollectorMXBean.getCollectionTime / Δwall across heartbeats; back-compat constructor defaults it to 0). WorkerWeightFunction down-weights (×0.4 at ≥0.3) and excludes (0 at ≥0.5) churning workers at assignment time; PartitionLossReaper reaps a GC-churning, non-progressing worker on clusterFastStallSeconds (60s) instead of the full 300s timeout when overhead ≥ clusterGcOverheadCriticalFraction.
Goal: detect a churning/stalled worker in ~seconds, not the flat 300s; feed both assignment and the reaper.
- Worker advertises
gcOverheadFractiononWorkerCapabilities(ΔGarbageCollectorMXBean.getCollectionTime/ wall over the heartbeat window — the worker already reads these beans). WorkerWeightFunction: GC overhead >clusterGcOverheadHighFraction→ down-weight; >...CriticalFraction→ weight 0 (treat like CRITICAL). Assignment avoids churning nodes immediately.PartitionLossReaper: agcStallloss reason — sustained high GC overhead with no snapshot progress delta across K heartbeats is reaped on a shortclusterFastStallSeconds(~60s), distinct from the 300s progress timeout.- Config:
clusterGcOverheadHighFraction=0.3,clusterGcOverheadCriticalFraction=0.5,clusterFastStallSeconds=60(fast path active only when reassignment is enabled). - Files:
WorkerCapabilities(+field),CrawlWorkerCapabilityService.localCapabilities(compute),WorkerWeightFunction,PartitionLossReaper, telemetry GC delta. - Tests: weight down-weight/zero on GC overhead; reaper fast-stall path; capability advertises the fraction.
- Risk: GC-fraction noise (smooth over a window; conservative thresholds; advisory until sustained).
Phase 4 — Cluster-shared backend breaker / budget (largest lift) — ✅ 4a DONE (4b deferred)
4a shipped: a ClusterBackendHealth SPI in crawl-graph (NOOP default → single-node behavior unchanged) lets CrawlLlmDispatcher treat a backend as open when the cluster has tripped it (OR'd with its local breaker) and mirror its failures via record. The app-main ClusterBackendHealthAdapter implements it role-aware: the orchestrator holds the authoritative per-backend breaker (opens after clusterBackendFailureThreshold aggregate failures, half-opens after clusterBackendCooldownSeconds); workers POST failures to /api/distributed-crawl/backend-health and cache the returned open-set. Gated by clusterSharedBackendBreakerEnabled (default off), advisory + fail-open. 4b (coordinator-issued concurrency leases replacing static cap-scaling) remains deferred.
Goal: a flaky/rate-limited shared LLM backend trips once for the cluster, not once per worker.
- 4a (cheaper, big win): coordinator-hosted per-backend health. Workers
POSTfailure/rate-limit/quota events to/api/distributed-crawl/backend-health; coordinator maintains a cluster-levelCircuitBreakerper backend and publishes open/closed state (heartbeat response or/topic/cluster/...).CrawlLlmDispatcherconsults an optionalClusterBackendHealthClientadvisorily alongside its local breaker — cluster-open → skip the backend without independently tripping. Fail-open if the coordinator is unreachable. - 4b (later): replace static cap-scaling with coordinator-issued per-backend concurrency leases (a true shared rate budget) instead of
global / workerCount. - Config:
clusterSharedBackendBreakerEnabled=false. - Files: new
CoordinatorBackendHealthService+ endpoint;CrawlLlmDispatcher(optional advisory client); worker event reporting. - Tests: worker failures → cluster breaker opens → peers observe open → closes after cooldown; coordinator down → fail-open to local breakers.
- Risk: coupling on the LLM hot path (keep advisory + fail-open); static cap-scaling stays as the floor.
Sequencing & verification
Order is by value/effort: 1 → 2 → 3 → 4. Phases 1–2 remove the worst data-loss/retry gaps with modest code; 3 sharpens reaction; 4 is the distributed-systems-hardest piece and is cleanly deferrable.
Per phase: unit tests + the existing 63-test distributed harness must stay green; a two-node local smoke (orchestrator + worker, kill/restart mid-crawl) validates the integration paths that unit tests can't.
Config summary (all new)
Property (ResourceSchedulerConfig) | Default | Phase |
|---|---|---|
clusterSessionPersistenceEnabled | true (proposed) | 1 |
clusterReassignOnFailure | false | 2 |
clusterGcOverheadHighFraction | 0.3 | 3 |
clusterGcOverheadCriticalFraction | 0.5 | 3 |
clusterFastStallSeconds | 60 | 3 |
clusterSharedBackendBreakerEnabled | false | 4 |