From 567fea4ae8f7aab80b8bfff72bcdf626ac02cec3 Mon Sep 17 00:00:00 2001 From: Daniel Genis Date: Tue, 21 Apr 2026 16:02:05 +0200 Subject: [PATCH 1/2] fix(workers): reduce GitHub API calls by excluding terminal tasks from polling - Resync sweep: exclude 'cancelled' and 'failed' states (covered by PR watcher or need user intent) - PR watcher: skip tasks where prState is already 'closed' or 'merged' Before: ~60 tasks swept every 5min, ~2000+ GitHub API calls/hour After: only active tasks with open PRs are polled --- apps/api/src/workers/pr-watcher-worker.ts | 2 +- apps/api/src/workers/reconcile-worker.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/workers/pr-watcher-worker.ts b/apps/api/src/workers/pr-watcher-worker.ts index e79d9c95..98ace1d9 100644 --- a/apps/api/src/workers/pr-watcher-worker.ts +++ b/apps/api/src/workers/pr-watcher-worker.ts @@ -96,7 +96,7 @@ export function startPrWatcherWorker() { .select() .from(tasks) .where( - sql`${tasks.state} IN ('pr_opened', 'failed') AND ${tasks.prUrl} IS NOT NULL AND (${tasks.taskType} = 'coding' OR ${tasks.taskType} IS NULL)`, + sql`${tasks.state} IN ('pr_opened', 'failed') AND ${tasks.prUrl} IS NOT NULL AND (${tasks.prState} IS NULL OR ${tasks.prState} = 'open') AND (${tasks.taskType} = 'coding' OR ${tasks.taskType} IS NULL)`, ); for (const task of openPrTasks) { diff --git a/apps/api/src/workers/reconcile-worker.ts b/apps/api/src/workers/reconcile-worker.ts index baf2eafd..4d79a8f3 100644 --- a/apps/api/src/workers/reconcile-worker.ts +++ b/apps/api/src/workers/reconcile-worker.ts @@ -118,7 +118,7 @@ export function startReconcileResyncWorker() { const nonTerminalTasks = await db .select({ id: tasks.id }) .from(tasks) - .where(sql`${tasks.state} NOT IN ('completed')`); + .where(sql`${tasks.state} NOT IN ('completed', 'cancelled', 'failed')`); const nonTerminalRuns = await db .select({ id: workflowRuns.id }) From 93488da23e007e4ae167707dc45103ca8fe013f1 Mon Sep 17 00:00:00 2001 From: Daniel Genis Date: Tue, 21 Apr 2026 16:03:08 +0200 Subject: [PATCH 2/2] chore(helm): increase PR watch interval to 120s Reduces GitHub API calls by polling PRs every 2 minutes instead of 30s. --- helm/optio/values.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/helm/optio/values.yaml b/helm/optio/values.yaml index eef3fc0c..b583f6dd 100644 --- a/helm/optio/values.yaml +++ b/helm/optio/values.yaml @@ -32,6 +32,7 @@ api: memory: 1Gi env: LOG_LEVEL: info + OPTIO_PR_WATCH_INTERVAL: "120000" # Pod anti-affinity spreads API replicas across nodes. # "soft" = preferredDuringSchedulingIgnoredDuringExecution (default) # "hard" = requiredDuringSchedulingIgnoredDuringExecution