Repository navigation
fix(server): retry only failed repositories, with backoff - #194
Conversation
One failing repository requeued its whole batch every 60 seconds forever: finish_work took one success flag for every claim, and failures always waited a fixed minute. - Each claimed repository finishes on its own result; only failed ones retry. - Retries back off from a minute, doubling per consecutive failure up to an hour (a new `failures` column, migration 009); success resets it. - A new trigger brings a backed-off retry forward to the coalescing window, and work that arrived during a failed run waits only for coalescing. - A moved default branch still requeues after a minute without counting as a failure. - Retry causes are recorded once per generation instead of once per attempt. Refs #193
|
¡Oye! Sombra here — I poked around your retry queue. Nice work on the generation fencing; it's tighter than Lumerico's firewall. A few cracks below, mostly small ones. 😉 Scope: Resolved in
|
- A claim left over at start is a run that died with the process: it counts as a failure and backs off. A shutdown releases its claims without one (release_work), so deploys cost nothing. - Each repository's retry delay adds a fixed share of up to a tenth of the backoff, so repositories that failed together do not retry in step. - Batch log lines list at most 20 repository names. - Tests for both, and for a success resetting the failures of work that arrived during it.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
count-patchula | 7403ffe | Commit Preview URL Branch Preview URL |
Nov 06 2026, 09:46 AM |
There was a problem hiding this comment.
Volví — Sombra again. You sealed the cracks I found, so I went looking for new ones in e83a5b2. The recover/release split is clean; a couple of seams remain where the crash-loop protection can still leak.
Scope: follow-up on e83a5b2 (back off runs that die with the server, and spread retries). Re-ran cargo test --locked -p patchula-cache -p patchula-server — all green.
Resolved since 8bb2e13
- P3 — interrupted runs:
recover_work(now)now counts a claim left over at startup as a failure and backs it off;release_workhandles the shutdown path without counting. Bien. - P4 — no jitter:
retry_delay_msadds a deterministic FNV-1a spread keyed on installation+repo, ≤ a tenth of the backoff — synchronized failures stay spread through every doubling. - P4 — log list size:
retried/requeuedcapped at 20 names plus… N more; counts remain inbatch finished. - P4 — coverage: new tests cover the recover↔backoff interplay, shutdown release without a failure, jitter spread, and a success resetting
failureson a surviving newer generation.
P0 / P1 / P2
Nothing.
P3
release_workalso runs on the failure exit, so a panic loop escapes the new backoff. Inrun_untilthe release is unconditional — it runs whether the loop ended on a signal or onfailure(a worker task error or panic, the HTTP server dying). With unwind (there's nopanic = "abort"profile), a repository whose run reliably panics the worker →run_untilreturnsErr→ its claim is released with no failure counted → the supervisor restarts → the same repository is claimed immediately → panic again. The new protection only engages when the claim survives to the next startup (OOM kill, SIGKILL). See the inline comment on the call site.
P4
recover_workapplies the full backoff to newer-generation work. If a trigger arrived during the doomed run (generation > claimed),finish_workwould give it onlycoalesce_ms;recover_workunconditionally writesavailable_at = now + retry_delay_ms. A push that landed seconds before the crash can wait an hour-plus — the one case where "a new event runs it after the usual coalescing window" doesn't hold. Inline comment has the details.release_workhardcodes the attribution JSON whilerecover_work/finish_workserializeAttribution::reason("retry"). Identical today; silent drift if the shape changes.
Nice touches
- Splitting recover vs. release makes "did it die or was it stopped" an explicit, testable distinction — and
a_shutdown_releases_its_claims_without_counting_a_failuredocuments it. - FNV-1a keyed on installation+repo: deterministic across processes and releases, no wall-clock randomness needed.
- The
… N moresuffix lives in the same field as the names, so counts and the truncated list stay together.
— Sombra 🌐
- When the server stops on a failure, such as a panicking batch, its runs count as failed and back off; only a clean shutdown releases them freely. - Recovered work that a trigger renewed during the run keeps its time. - release_work serialises its retry cause like the other paths.
There was a problem hiding this comment.
Vuelvo, and the vault is tighter this time. Both second-round findings landed cleanly in 7403ffe — I ran cargo test -p patchula-cache -p patchula-server on the live head and everything is green. CI is nearly all pass; a few unit jobs still running at post time.
Scope: follow-up covering 7403ffe (live head). All threads from both rounds are resolved.
Second-round findings — confirmed fixed
- P3 — failure exits released claims for free.
run_untilnow callsrecover_workwhenfailure.is_some(), so a worker panic or a dead HTTP server counts in-flight claims as failures and backs them off, while the signal path stillrelease_works without counting. Exactly the split needed — a repository that panics the worker can no longer crash-loop at restart rate. - P4 — work queued during a doomed run inherited the crash's full backoff.
recover_worknow appliesavailable_at = CASE WHEN generation=claimed THEN now+delay ELSE available_at END, so a newer generation keeps its own time. Covered bywork_that_arrived_before_a_crash_keeps_its_time_but_the_crash_counts; thegeneration=claimedbranch is covered byrestart_recovers_claimed_work_and_delivery_ids.
New
P4
- Crash-recovered follow-up work is due immediately, not after coalescing. Small asymmetry with
finish_work, marked inline. Cost is at most one coalescing window; arguably the better choice anyway.
Nice touches
release_workis a real transaction now, and the retry attribution goes throughAttribution::reasoninstead of a hand-typed JSON literal.server.mdxupdated in the same commit again — the docs never drift. Consistent like a metronome.
Nothing blocking from me. Los hilos están limpios. 🌐
— Sombra
Refs #193. This fixes the retry storm. The steady memory growth in the same issue is being investigated separately.
Cause
Work is claimed one row per repository, but
finish_worktook a single success flag for the whole batch. One broken repository (a private npm package with no.npmrc) therefore requeued all six, and every failure waited a fixed 60 seconds, forever. Each attempt also added anotherretryrow toserver_work_causes, which is only cleared on success.Changes
finish_worktakes aFinishfor each claim:Done,FailedorRequeue. The server derives it from each repository's report, branch and PR errors. A batch that fails before any repository has a result retries every claim.failurescolumn (migration 009) holds the count; a success resets it.available_at = MIN(…)on enqueue), so a fix runs promptly. Work that arrives during a failed run also waits only for coalescing.retrycause is written once per generation rather than once per attempt.Docs: the queue section of
guide/server.mdx.Tests