Periodic heartbeat recovery reconciles recovery actions of archived companies on every tick and stacks up without bound → server OOM every ~2 h (v2026.916.1)
Pre-submission checklist
- I have searched existing open and closed issues and this is not a duplicate.
- I am on the latest released version of Paperclip (or can reproduce on
master). - I have confirmed the error originates in Paperclip itself — not in my agent adapter, API provider, or local configuration.
What happened?
On a self-hosted instance (official Docker image ghcr.io/paperclipai/paperclip:2026.916.1, embedded Postgres, 4 active companies, 6 archived ones), the control-plane process dies with FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory every 2 h 05–2 h 13 (8 crashes on 2026-09-28 alone, with NODE_OPTIONS=--max-old-space-size=8192). Every crash kills all in-flight runs (process_lost) and leaves their issues blocked (see #13366).
Root cause, measured on the live process (V8 inspector: --trace-gc set at runtime, sampling heap profiler, 60 s CPU profile, pg_stat_* deltas):
reconcileActiveRecoveryActions(server/src/services/recovery/service.ts) selects everyissue_recovery_actionsrow inactive/escalatedstatus, with no company filter. On this instance, the startup recovery after the upgrade had created 9 482stranded_assigned_issue/board_escalationactions in archived companies (three archived companies: 7 196 + 2 272 + 14 — issues that were stilltodoin companies nobody works on any more). Each action costs ~10 queries (collectDispositionRepairSourceStatealone runs 7, plushealthyOpenChildIssuesandsourceHasNewPathOutsideRecoveryAction) → ≈ 90 000 queries per 30 s tick. Postgres sat at 1 140 transactions/s with the platform otherwise idle (0.1 inserts/s); the Node process was idle only 6.5 % of the time, mostly building Drizzle queries and parsing rows.- The periodic recovery chain in
server/src/index.ts(reapOrphanedRuns → promoteDueScheduledRetries → resumeQueuedRuns → reconcileStrandedAssignedIssues → reconcileResolvedDependencyWakes → reconcileTaskWatchdogs → scanSilentActiveRuns → sweepStaleIssueLocks) is started withtrackHeartbeatSchedulerWork(...)on every scheduler tick without checking whether the previous chain has finished (heartbeatSchedulerInFlightis only consulted at shutdown). One chain needs ~80 s of exclusive database throughput and a new one starts every 30 s, so the backlog grows without bound. Every in-flight chain keeps itsrowsarray alive (~9 500{ action, issue }pairs with full issue rows, descriptions included) plus the per-action query results.
Measured effect: the post-Mark-Compact live heap grew linearly at +1.1 MB/s (1 082 MB at t=709 s → 2 875 MB at t=2 373 s after a restart). A 10-minute sampling heap profile showed 736 MB of still-live allocations, 96 % of them Postgres result rows (postgres DataRow, drizzle mapResultRow / mapFromDriverValue / parse); the only application frames in those stacks were reconcileActiveRecoveryActions, sourceHasNewPathOutsideRecoveryAction, collectDispositionRepairSourceState and healthyOpenChildIssues.
Evidence that this is the cause:
- Cancelling the 9 482 actions of archived companies (
status = 'cancelled') stopped the floor growth within one minute (2 875 → 2 875 → 2 875 MB on the next three Mark-Compacts) while nothing else changed. - After restarting with a company filter on the query and an in-flight guard on the chain (patch in Additional context): Postgres at 39 tx/s (was 1 140), scavenges every ~10 s (was every 0.6 s), Mark-Compact floor flat at ~430 MB.
Not #958: a Caddy rewrite adding limit=100 to /heartbeat-runs changed nothing.
Expected behavior
- Recovery actions belonging to archived (and probably paused) companies should not be reconciled on every tick: there is nothing to recover there, and the Board that would act on a
board_escalationhas archived the company. - The periodic recovery chain should never run more than once at a time: if the previous tick's chain is still running, the tick should be skipped (and logged), so memory stays bounded whatever the database throughput.
- Archiving a company should probably resolve/cancel its active recovery actions, and the startup recovery should not create new ones in archived companies.
Steps to reproduce
- Run v2026.916.1 with a company that has a few thousand
todoissues assigned to agents, then archive that company (or restore a database dump of such a company and start the server: the startup recovery creates onestranded_assigned_issue/board_escalationrecovery action per issue — 9 482 here). - Let the heartbeat scheduler run (default 30 s tick).
- Watch
pg_stat_database.xact_commit(here ~1 140 tx/s at rest) and the live heap after each Mark-Compact (node --trace-gc, orv8.setFlagsFromString('--trace-gc')through the inspector): it grows linearly (~1 MB/s here) untilheap out of memory. - Cancel those actions (
update issue_recovery_actions set status = 'cancelled' where company_id in (<archived companies>) and status in ('active', 'escalated')): the growth stops within a minute.
Paperclip version or commit
v2026.916.1 (d554c4789ed3930f8a53ac9fdf6503b3187097da) — official image ghcr.io/paperclipai/paperclip:2026.916.1
Deployment mode
Docker
Installation method
Docker
Agent adapter(s) involved
- Claude Code
- Codex
- Cursor
- Droid
- Hermes
- Custom / external plugin adapter
- Not adapter-specific (core bug)
Database mode
Embedded PGlite (default — DATABASE_URL unset)
Access context
Unclear / not applicable
Node.js version
v24.21.0 (inside the official image)
Operating system
Debian 13 container (official image) on an Ubuntu VM, 8 vCPU / 32 GB
Relevant logs or output
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
(crash times on 2026-09-28, UTC: 06:46, 08:43, 10:44, 12:54, 15:01, 17:10, 19:20, 21:33)
Last GC before a crash:
[7:0x2c165000] 7916876 ms: Mark-Compact 8073.9 (8236.4) -> 8044.4 (8237.4) MB, pooled: 22 MB, 8139.77 / 0.00 ms (average mu = 0.061, current mu = 0.009) allocation failure; scavenge might not succeed
Live heap after each Mark-Compact on a fresh process (before the fix):
709 s: 1374.5 -> 1082.6 MB
915 s: 1730.8 -> 1335.8 MB
1140 s: 2811.7 -> 1558.1 MB
1482 s: 4254.9 -> 1994.3 MB
2014 s: 4595.5 -> 2536.6 MB
2341 s: 4242.8 -> 2875.0 MB <- the 9 482 archived-company actions were cancelled at ~2 320 s
2356 s: 3186.1 -> 2874.6 MB
2373 s: 3212.1 -> 2874.9 MB
After restart with the patch (company filter + in-flight guard):
111 s: 500.3 -> 445.8 MB
321 s: 485.3 -> 430.6 MB
665 s: 484.9 -> 430.6 MB
Sampling heap profile, 10-minute window, allocations still alive at the end (before the fix):
total 736 MB
365.6 MB 49.7 % DataRow postgres/src/connection.js:492
151.9 MB 20.6 % (anonymous) drizzle-orm/utils.js:10 (mapResultRow)
107.3 MB 14.6 % mapFromDriverValue drizzle-orm/pg-core/columns/timestamp.js:30
86.0 MB 11.7 % parse postgres/src/types.js:20
application frames present: reconcileActiveRecoveryActions (services/recovery/service.js:2142),
sourceHasNewPathOutsideRecoveryAction (:2119), collectDispositionRepairSourceState (disposition-repair.js:31),
healthyOpenChildIssues (:1750)
pg_stat_user_tables deltas per second at rest (before the fix):
issues 481 idx scans/s, 868 seq rows/s
agent_wakeup_requests 451 idx scans/s
heartbeat_runs 230 idx scans/s
issue_recovery_actions 1 121 seq rows/s (11 210 rows in the table -> one full scan per tick)
issue_relations / issue_thread_interactions / issue_approvals / issue_work_products ~110 idx scans/s eachRelevant config (if applicable)
Additional context
Suggested fixes
reconcileActiveRecoveryActions: joincompaniesand keep onlystatus = 'active'(or skip actions whose company is archived/paused).index.ts: guard the periodic recovery chain with an in-flight flag; skip the tick (and log) while the previous chain is still running. The same pattern applies torunRetentionSweep, which is also fired on every tick without waiting (related: #13367).- When a company is archived, resolve/cancel its active recovery actions; the startup recovery should not create new ones there.
Local patch applied on the built dist files (bind-mounted over the image), running since 2026-09-29 00:09 UTC
--- server/dist/services/recovery/service.js
+++ server/dist/services/recovery/service.js
@@ -2144,6 +2144,7 @@
.select({ action: issueRecoveryActions, issue: issues })
.from(issueRecoveryActions)
.innerJoin(issues, and(eq(issues.id, issueRecoveryActions.sourceIssueId), eq(issues.companyId, issueRecoveryActions.companyId)))
+ .innerJoin(companies, and(eq(companies.id, issueRecoveryActions.companyId), eq(companies.status, "active")))
.where(inArray(issueRecoveryActions.status, ["active", "escalated"]));
--- server/dist/index.js
+++ server/dist/index.js
@@ -877,6 +877,7 @@
let heartbeatSchedulerStopped = false;
+ let periodicRecoveryInFlight = false;
let heartbeatSchedulerInterval = null;
@@ -1433,6 +1436,11 @@
if (!(await heartbeat.resolveSchedulingSuppression()).suppressed) {
+ if (periodicRecoveryInFlight) {
+ logger.warn("periodic heartbeat recovery from a previous tick is still running; skipping this tick");
+ }
+ else {
+ periodicRecoveryInFlight = true;
trackHeartbeatSchedulerWork(heartbeat
.reapOrphanedRuns({ staleThresholdMs: 5 * 60 * 1000 })
@@ -1474,7 +1482,11 @@
.catch((err) => {
logger.error({ err }, "periodic heartbeat recovery failed");
+ })
+ .finally(() => {
+ periodicRecoveryInFlight = false;
}));
+ }
}Related: #13366 (consequence: an OOM converts in-flight runs into permanent blocks), #13367 (retention sweep rebuilt on every tick), #958 (not the cause here).
Privacy checklist
- I have reviewed all pasted output for PII (usernames, file paths, API keys, tokens, company names) and redacted where necessary.
Source: paperclipai/paperclip