world-postgres: startup recovery enqueues the entire active set on every boot — bound it with a recovery batch size
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 62/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, postgresql, typescript
调研方向
Read reenqueueActiveRuns() and the createRunsList pagination path in world-postgres, then check how recovery configuration is loaded and tested. Add a configurable per-boot recovery bound while preserving the current unbounded default. Done means startup enqueues no more than the configured number of active runs and leaves the rest eligible for recovery on a later boot.
由索引模型根据 Issue 内容生成。
描述
Summary
reenqueueActiveRuns() walks every non-terminal run on world.start(), enqueuing one Graphile job each, with no bound on how many are enqueued in a single boot. When the active set is large, a restart turns into a burst of thousands of jobs, which drives the process into memory pressure and, in our case, an out-of-memory crash loop the restart cannot escape.
Recovery already pages its read (createRunsList defaults to limit ?? 20) and awaits enqueue() one run at a time — so the loop is inherently a batch loop today. The only thing missing is a way to stop after N runs instead of draining every page.
Versions: @workflow/[email protected], @workflow/[email protected], [email protected], [email protected], Node 24.
Relationship to existing issues
Not a duplicate of the three open reports on this function; all three ask for something different:
- #3119 — which runs get selected (parked runs are replayed; duplicate jobs accumulate).
- #3968 — a producer-only World that does no startup recovery at all.
- #5129 — an enqueue-only process (
queueConcurrency: 0) that also does no startup recovery.
All three are binary: recover everything, or recover nothing. This issue is about recovering all of it, a batch at a time. A predicate fix (#3119) does not help here — the runs we hit were genuinely running with real progress records, so any correct runnable predicate still selects them. A recovery-off switch (#3968 / #5129) is also wrong for us: we want recovery, we just cannot afford 1,500 jobs in one boot.
What happens
Single-pod deployment, 4 GiB limit, FAT environment. A load test left 1,512 runs in status='running' plus a job backlog. Each restart then:
world.start()→reenqueueActiveRuns()→ lists all 1,512, enqueues 1,512 jobs.- The process works through them; RSS climbs to ~
2.8 GiBwithin a few minutes. - At the old 1 GiB limit this became an OOM crash loop: process dies → pm2 restarts → recovery re-enqueues everything again → dies again.
SIGKILLrepeated ~58 times in 30 minutes, CPU pinned at ~200% while nothing user-visible was happening.
Raising the limit to 4 GiB stopped the crash, but each boot still pushes RSS from ~600 MiB to ~2.8 GiB before settling. On a smaller instance, or with a larger active set, the same shape returns.
The amplification is in the interaction with per-job retry budgets: every recovered run gets a fresh max_attempts (MAX_GRAPHILE_JOB_ATTEMPTS = 49 + 24 in queue.ts), so a run that fails deterministically never exhausts its budget and never leaves the active set. Each restart therefore re-creates the same burst rather than draining it. (Details of that in #3119 — mentioned only because it is what makes the active set stay large.)
Reproduction
- Insert N runs with
status='running'inworkflow.workflow_runs(any N well above a few hundred reproduces the burst). - Start the World once and watch
graphile_worker._private_jobs: it gains N jobs. - Watch RSS across the first few minutes of the boot.
We observed N = 1,512 → ~1,790 jobs and RSS 600 MiB → 2.8 GiB.
Proposal
Bound the number of runs recovered per boot. Two shapes, either would work:
a) A batch size option — recover at most recoveryBatchSize runs, continue from the same cursor on the next boot:
await reenqueueActiveRuns(runs, queue.queue, 'world-postgres', namespace, {
limit: config.recoveryBatchSize, // default: unbounded (current behavior)
// the remaining runs stay non-terminal and are picked up next start
});
Because the read is already paginated and enqueue() is already awaited per run, this is a small change inside the existing loop — stop when the counter reaches the limit, leave the cursor implicit (the next boot re-reads from the beginning).
b) Page-level pacing — process at most one page per boot, or pause between pages:
for (let page = 0; hasMore; page += 1) {
if (page >= maxPagesPerBoot) break;
...
}
Either way the important property is: a bounded boot may leave runs un-recovered, and that is fine — they are still pending/running, so the next start() sees them again. Nothing is lost; the burst is spread across boots instead of landing on one.
A bounded recovery also composes with the existing per-job retry accounting: runs that do not get recovered in a given boot keep accumulating nothing, which (together with a durable enqueue identity, see #3119) would let the retry ceiling do its job.
Environment variable suggestion
Following the package's existing convention:
WORKFLOW_POSTGRES_RECOVERY_BATCH_SIZE (default: 0 = unbounded, current behavior)
Defaulting to unbounded keeps the change backwards compatible.
Current workaround
We sweep workflow_runs before eve start and flip runs that have been replayed too many times to failed, so they stop being selected. That caps the eventual damage but does not bound a single boot: while the counter is below the threshold, every boot still recovers the whole active set at once. We also tried deferring a subset without persisting any marker — that does nothing, because world.start() selects purely on status, so the "deferred" runs are recovered anyway. A recovery limit is the only way to bound the burst from outside the package, and it needs to live inside reenqueueActiveRuns.
Happy to test a branch against our environment if that helps.
- 主要语言
- TypeScript
- 星标
- 2.5k
- 派生
- 401
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 201
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vercel/workflow 的其他 Issue
-
getPortLazy re-runs OS port discovery on every call when it finds no port可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
node-module-esbuild-plugin: getImportedIdentifier only checks the first named import when locating a violation可能已有人在做 @div-cowboy 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
vercel/workflow#5057 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
code-transform.mdx §ID Generation omits the package-shipped `name@version` ID form可能已有人在做 @Mohith26 于 113 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
solidjs/solid-docs#1716 ·
维护者通常 1 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Progress indicated by console logs is off by one可能已有人在做 @marceliwac 今天认领。 未关闭bug needs-triage
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/aws-cdk-examples#1336 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
melgarafael/DeskcommCRM#4999 · 1 条评论 ·
维护者通常 1 天内回复
-
type: bug
难度 2/5 1-3 小时 新手友好度 78/100
nrwl/nx#37955 · 1 个 reaction ·
维护者通常 2 天内回复