Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-6972 perf(server): sweep delegated recovery every five minutes (#7929)
Multica Evea6911a952040
diff --git a/server/cmd/server/main.go b/server/cmd/server/main.goindex 58cb13ed46..22fafd00ff 100644--- a/server/cmd/server/main.go+++ b/server/cmd/server/main.go@@ -647,6 +647,7 @@ func main() {// work, so there is no separate queue TTL to tune: a busy runtime keeps its// backlog, and a departed one retires everything it owned at once.go runRuntimeSweeper(sweepCtx, queries, liveness, taskSvc, bus, runtimeReconnectGrace)+ go runDelegatedFailureRecoverySweeper(sweepCtx, taskSvc)// Seven-day runtime retention does not share the 30-second liveness tick:// its bounded transactions run independently once per hour, so a slow GC// round cannot delay offline detection or task recovery.diff --git a/server/cmd/server/runtime_sweeper.go b/server/cmd/server/runtime_sweeper.goindex f12d6e16d5..550b88688f 100644--- a/server/cmd/server/runtime_sweeper.go+++ b/server/cmd/server/runtime_sweeper.go@@ -28,6 +28,9 @@ const (// latency-sensitive 30-second liveness path. GC remains independently// bounded by runtimeGCTickTimeout once each hourly round begins.runtimeGCSweepInterval = time.Hour+ // delegatedFailureRecoverySweepInterval keeps the low-probability durable+ // recovery scan off the latency-sensitive runtime liveness path.+ delegatedFailureRecoverySweepInterval = 5 * time.Minute// staleThresholdSeconds marks runtimes offline if no heartbeat for this// long. The heartbeat timing derivation lives with the shared service// constant so every task release path uses the same eligibility window.@@ -155,20 +158,23 @@ func runPeriodicSweep(ctx context.Context, interval time.Duration, sweep func())// stale window — that is the original behavior.func runRuntimeSweeper(ctx context.Context, queries *db.Queries, liveness handler.LivenessStore, taskSvc *service.TaskService, bus *events.Bus, reconnectGrace time.Duration) {runPeriodicSweep(ctx, sweepInterval, func() {- // These stages retain the existing cadence and ordering in PR1 so the- // rollout changes no business predicate or recovery semantics. Runtime- // GC is the one exception: its seven-day retention work now runs in the- // independent hourly loop below and cannot delay this liveness path.+ // These stages retain their existing cadence and ordering. Runtime GC and+ // delegated-failure recovery run in independent lower-frequency loops.sweepStaleRuntimes(ctx, queries, liveness, taskSvc, bus)sweepOfflineRuntimeTasks(ctx, queries, taskSvc, reconnectGrace)sweepExpiredRuntimeReconnectRetries(ctx, queries, taskSvc, reconnectGrace)sweepStaleTasks(ctx, queries, taskSvc, bus, reconnectGrace)sweepExpiredQueuedTasks(ctx, queries, taskSvc, reconnectGrace)- sweepPendingDelegatedFailureRecoveries(ctx, taskSvc)sweepDeferredChatFinalizations(ctx, queries, taskSvc)})}+func runDelegatedFailureRecoverySweeper(ctx context.Context, taskSvc *service.TaskService) {+ runPeriodicSweep(ctx, delegatedFailureRecoverySweepInterval, func() {+ sweepPendingDelegatedFailureRecoveries(ctx, taskSvc)+ })+}+func runRuntimeGCSweeper(ctx context.Context, txStarter runtimeGCTxStarter, queries *db.Queries, metrics *obsmetrics.BusinessMetrics, publisher runtimeGCEventPublisher) {runPeriodicSweep(ctx, runtimeGCSweepInterval, func() {gcRuntimes(ctx, txStarter, queries, metrics, publisher)@@ -176,9 +182,9 @@ func runRuntimeGCSweeper(ctx context.Context, txStarter runtimeGCTxStarter, quer}// sweepPendingDelegatedFailureRecoveries retries durable coordinator handoffs-// that were not acquired by an executable task. It runs even when no stale-// task was found in this tick, which is what repairs a recovery dispatch lost-// before a server restart.+// that were not acquired by an executable task. It runs independently of+// stale-task discovery, which is what repairs a recovery dispatch lost before+// a server restart.func sweepPendingDelegatedFailureRecoveries(ctx context.Context, taskSvc *service.TaskService) (stats runtimeSweepStageStats) {startedAt := time.Now()defer func() {