Documentation
¶
Overview ¶
Package stallwatcher is the Pilot-side consumer of Haul's stall detection.
Every 60 seconds it polls Haul's /api/v1/stalls endpoint, correlates each stalled torrent with a grab_history row (via info_hash), writes a blocklist entry for the release (reason tagged with the stall type), and marks the grab as stalled. If the grab was triggered by auto-search, the watcher also triggers a re-search for the episode, capped by a circuit breaker to avoid loops when every release for an episode is dead.
Design notes in plans/dead-torrent-phase0.md. Specifically: this is pull-based (not webhooks), runs entirely in Pilot, and tolerates Haul being briefly unreachable without fallout. The watcher does NOT blocklist during its own first 2 minutes of uptime — that's to absorb restart races where grabs from before the restart look "stalled" because we just haven't observed them yet.
⚠ Before changing anything in this file, run:
go test ./internal/core/stallwatcher/...
The tests (service_test.go) pin every critical contract:
- startup grace suppression
- circuit breaker behavior
- interactive-vs-auto_search retry gating
- unique-info_hash cross-indexer dedup
- idempotency on already-stalled grabs
- graceful degradation when Haul is down
See pilot/CLAUDE.md for the full regression-guard rationale.
Index ¶
Constants ¶
const MaxStallRetriesPerEpisode = 3
MaxStallRetriesPerEpisode is the circuit breaker: after this many stall-reason blocklist entries for a (series, episode) in the last 24 hours, auto-re-search stops. Prevents infinite loops when every release for an episode happens to be dead.
const StaleGrabAge = 24 * time.Hour
StaleGrabAge is how long a grab can sit in `downloading` / `queued` / `pending` without an info_hash before the sweep marks it failed. The info_hash-less branch is invisible to the haul-stall path (haul keys stalls by info_hash), so the only signal we have is age. 24h is well past any normal "metadata fetch + tracker announce + first peer" startup, and it leaves a generous window for genuinely-slow first connects on remote VPN endpoints.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service polls Haul for stalled torrents and reacts by blocklisting the corresponding release.
func NewService ¶
func NewService( q db.Querier, blocklist *blocklist.Service, downloader *downloader.Service, bus *events.Bus, logger *slog.Logger, ) *Service
NewService constructs a stallwatcher Service. Call Run in a goroutine.