Skip to content

2026-11-14: Taskbase database crash-loops on the queue sweep, Taskbase down

Kind: reference (incident report)

Severity: critical · Status: resolved · Resolved by: a recovery recorded under #3042 (API scaled to 0, on-demand backup, #3001's escalation reset; who ran it is not recorded), checked by the operator agent (#3041, #3042); code fix in #3210 (Taskbase v1.264.1, in prod since 11-15 00:04) · Duration: 2:29 from detection to resolution, 19:35–22:04 UTC (fault from 19:34:59; database stable from 21:50:53, Taskbase API back at 22:04:28) · Taskbase task: #3041

Summary

From 19:34:59 the PostgreSQL server of Taskbase prod (tasks-prod/tasks-prod-db-1) crashes about 10–18 s after every start: a client backend dies with signal 11: Segmentation fault while it runs the candidate query of Taskbase's queue sweep (SweepUnclaimable), and with restart_after_crash off the instance shuts down and the pod restarts. Taskbase prod was down for people and agent runners alike until 22:04.

The cause is PostgreSQL bug #19370 in 18.1: an array subscript that evaluates a correlated subquery crashes the backend. Since Taskbase v1.264.0 the query picked an escalated task's model with such a subscript, so task #3001, the first task escalated after that release, crashed every sweep. Task #3210 reproduced this on a disposable 18.1.

The crash loop ended when the API, which sends the query, was scaled to 0 at 21:48. After an on-demand backup, #3001's escalation was reset to 0, and the database has stayed up since Flux brought the API back at 22:04. Taskbase v1.264.1 (#3210) removed the subscript and has run in prod since 11-15 00:04. The PostgreSQL servers still run 18.1, so another query of the same shape could still crash them until they are upgraded (#3212's follow-ups).

Impact

  • Services: Taskbase prod: /api/health 503 and API calls 500, except for the few seconds in each crash cycle while the database is up. The UI, the MCP server and every agent runner depend on it.
  • Users: everyone who uses Taskbase. Agent runners cannot claim or report reliably; this run (#3041) was claimed in one of the short windows at 21:13:44 and could not read or update any task afterwards.
  • Data: none lost as far as the record shows. Each crash ends in crash recovery from WAL, which completes (database system is ready to accept connections). Writes Taskbase tried while the database was down failed and were not stored. Backups are current: daily base backup tasks-prod-db-daily-20261114023000 completed, ContinuousArchiving=True, restore drill drill-taskbase-prod passed 2026-11-08T07:03Z.
  • Duration: 2 h 29 min from detection (19:35:00) to the API answering again (22:04:28; taskbase-prod Ready at 22:04:41). Fault from 19:34:59. The last crash was at 21:45:48; the database has been up since 21:50:53.

Timeline

All times UTC, 2026-11-14 unless dated.

Time Event Source
11-13 17:58:13 Taskbase v1.264.0 promoted to prod: task #2901 (organization minimum model) wraps the task and review model expressions of the claim and sweep queries in the new SQL function model_at_least Skatzi/taskbase 17cd245, 00c12ea
17:33:20 Run 6490 of task #3001 (senior-developer, medium) starts task_runs
19:34:42 Run 6490 fails; #3001 is requeued with model_escalation = 1 (organization eloro, minimum_model = medium, escalate_models on). It is the only open task with an escalation, and no run since v1.264.0 escalated tasks, task_runs (read at 21:19 and 21:24)
19:34:59 First crash: client backend (PID …) was terminated by signal 11: Segmentation fault on the sweep's candidate query, then shutting down because "restart_after_crash" is off DR run report
19:35:00 Detected: the Mac mini watchdog's taskbase probe fails (HTTP 503) DR run report
19:40:33 ProbeFailed (critical) fires Alertmanager
19:41 DR session starts on the Mac mini; read-only triage only DR run report 2026-11-14T2005Z.md
19:51:03 KubePodCrashLooping for tasks-prod-db-1 fires (incident task #3008) Alertmanager
20:05 DR session gives up with four options and comments on DunkRing/bootstrap-cluster#5; no write to any cluster DR run report
20:36:01–20:41:03 TargetDown and KubePodNotReady fire in tasks-prod Alertmanager
21:13:44 Task #3041 (this report) claimed by the operator agent in an up window tasks.updated_at
21:13:48 Still crashing: the same segfault on the same query, 24 restarts kubectl logs --previous
21:25 Not resolved; handed to the owner with options this report
21:35:18 Still crashing: the same segfault on the same query, 28 restarts; taskbase-prod now not Ready (health check failed … Deployment/tasks-prod/platform-tasks-api status: 'InProgress') kubectl logs --previous, flux get
21:37 Not resolved; a third run of #3041 confirms the state and hands it to the owner again this report
21:45:48 Last crash: the same segfault 12 s after ready to accept connections at 21:45:36; 31st restart follows kubectl logs --previous
21:48:24 platform-tasks-api scaled from 1 to 0 replicas (not by Flux), so no client sends the sweep query ScalingReplicaSet event
21:50:53 tasks-prod-db-1 ready after its back-off; no crash since, restart count stays at 31 kubectl logs, pod status
21:52:14–21:52:30 On-demand Backup tasks-prod-db-incident-3042 (method plugin, annotated Taskbase #3042: fresh backup before repairing the crashing tasks row) completed Backup object
after 21:52:30 tasks.model_escalation of #3001 set to 0; the exact time and command are not recorded #3042, tasks row read at 22:12
22:04:25 Flux's scheduled reconcile of taskbase-prod (no manual request) restores the API to 1 replica; the pod starts at 22:04:28 ScalingReplicaSet event, Kustomization status
22:04:40–22:04:51 Resolved: Taskbase closes KubePodCrashLooping (#3008) and KubePodNotReady (#3140) as resolved by itself; taskbase-prod Ready at 22:04:41 #3008 comment, Flux events
22:05:40 #3001 (escalation 0) claimed by run 6632; the database stays up tasks, task_runs
22:06–22:11 A run of #3042 verifies the recovery and records follow-ups #3210 and #3211 #3042
22:12:58 Verified again by the fourth run of #3041: /api/health 200, restart count 31, no segfault since 21:50 this report
before 23:11 #3210 reproduces the crash on a disposable PostgreSQL 18.1 and finds the cause: bug #19370, an array subscript that evaluates a correlated subquery; it records follow-ups #3212 and #3213 Skatzi/taskbase PR #729, tasks #3212 and #3213 (created 23:11)
23:26:16 PR #729 merged: the escalated tier is picked with CASE, not the subscript; tagged v1.264.1 (9fee8dd) Skatzi/taskbase PR #729, tag v1.264.1
11-15 00:04:00 Taskbase v1.264.1 promoted to prod Skatzi/taskbase 7aecb07
11-15 00:05:45 Skatzi/platform PR #1469 (#3212) merged: Renovate now tracks a CNPG Cluster's imageName; the 18.1 upgrade itself is split into #3217–#3221 PR #1469
11-15 00:38:42 Skatzi/taskbase PR #733 (#3213) merged: CI's PostgreSQL tests run on postgres:18.1-trixie, not postgres:16 PR #733
11-15 00:40 https://taskbase.skatzi.com/api/version returns v1.264.1; /api/health returns ok this report

Root cause

The cause is PostgreSQL bug #19370: in PostgreSQL 18.0 and 18.1, an array subscript that evaluates a correlated subquery crashes the backend with signal 11. Upstream fixed it in 18.2 with commit bdc5dedfc, "Fix buggy interaction between array subscripts and subplan params" (18.2 release notes: "Fix expression evaluation bug for a sub-select within an array subscript"). Taskbase prod runs 18.1 (image postgresql:18.1-system-trixie, CNPG 1.30.1). Since v1.264.0 its sweep query had such a subscript. Task #3210 reproduced the crash on a disposable PostgreSQL 18.1 and found the cause. Its findings are in Skatzi/taskbase PR #729 (read 2026-11-15).

  • The query. SweepUnclaimable in api/internal/runner/store_pg.go selects queued candidates FOR UPDATE OF t SKIP LOCKED. The sweeper runs it every 15 s (SweepInterval), so it runs within seconds of every database start, which is why the database never stays up.
  • The crashing expression. effectiveModelSQL in escalation.go picked an escalated task's tier with an array subscript: (ARRAY['small', 'medium', 'large'])[LEAST(array_position(<tiers>, <own model>) + t.model_escalation, 3)]. The query evaluates it only in the escalation branch (p.escalate_models AND t.model_escalation > 0 AND <own model> IN ('small','medium')).
  • What changed in v1.264.0. The subscript was already there. Before #2901 the own model was COALESCE(t.model, <persona default subselect>), so the subscript ran a correlated subquery only for a task with no model of its own. v1.264.0 (11-13 17:58, #2901) wrapped the own model in model_at_least(…, (SELECT mo.minimum_model FROM organizations mo WHERE mo.id = p.organization_id)). From then on the subscript ran that correlated subquery for every escalated task.
  • Why at 19:34. Task #3001 got its first escalation at 19:34:42, 17 s before the first crash. It was the only open task with one, and no run since v1.264.0 had escalated. So 19:34 was the first time the sweep reached the subscript.
  • Not needed for the crash: FOR UPDATE … SKIP LOCKED, model_at_least and function inlining. On 18.1 the expression crashes without the lock, and with a plpgsql function that cannot be inlined. With a constant or an uncorrelated subquery in place of the correlated one, it does not crash (the table of variants in #729).
  • Same code, other queries. The claim query (Claim, store_pg.go) and the preferred-model check (preferred.go) use the same effectiveModelSQL. A runner claiming an escalated task would have crashed the server the same way (#729).
  • Why CI missed it. CI ran the API's PostgreSQL tests on postgres:16, which does not have the bug. #729 checked that the minimal case does not crash on 16.15 or 18.7.
  • Not the cause: Git of Skatzi/platform and Skatzi/taskbase after 11-13 17:58 other than v1.264.0, the image, the Cluster parameters, the CNPG operator, nodes, Flux (all unchanged or Ready); multixact and xid ages are healthy.

Here is the minimal case from #729, which crashes PostgreSQL 18.1 every time. It is copied from #729, where it ran on 18.1, 18.7 and 16.15; it was not run for this report. Do not run it on a server you need:

CREATE TABLE r3210 (id int); INSERT INTO r3210 VALUES (1);
SELECT (ARRAY[10, 20])[(SELECT x.id FROM r3210 x WHERE x.id = t.id)] FROM r3210 t;

The fix. #729 picks the escalated tier with CASE LEAST(array_position(<tiers>, <own model>) + t.model_escalation, 3) WHEN 2 THEN 'medium' ELSE 'large' END instead of the subscript (escalation.go at 9fee8dd). In the escalation branch the position is 2 or 3, so the results do not change. It is one shared constant, so the sweep, the claim and the preferred-model check are all fixed. The new test TestEscalatedTaskSweepAndClaimOnPostgres runs the sweep and the claim over escalated tasks. The fix shipped as v1.264.1 and has been in prod since 11-15 00:04.

What ended it. Not #3001 leaving the queue on its own and not a change in Git: a recovery recorded under #3042. The crash loop stopped because nothing sent the query: platform-tasks-api was scaled to 0 at 21:48:24, before the database's next start at 21:50:53. While it was down an on-demand backup was taken and #3001's model_escalation was set to 0; #3001 itself stayed queued until run 6632 claimed it at 22:05:40. Flux restored the API at 22:04:25, and the sweep has run every 15 s since then with no crash (no segfault in the log from 21:50:53 to 22:12:58). In each of the 31 cycles before, it crashed within 8–18 s of the start. With no escalated task left, the sweep no longer reached the subscript.

Can it come back. Not through this query: v1.264.1 has no array subscript left in the API's SQL (#729). The servers still run PostgreSQL 18.1, though, so any other query with a correlated subquery inside an array subscript can crash them the same way. The upgrade past 18.1 is split into #3217–#3221 (see Follow-ups).

What the agent did

The DR session (19:41–20:05) ran read-only checks only and wrote one comment on the DR issue; its commands are in task #3041 and the DR run report. The operator run of #3041 (21:13–21:25), all with --context admin@mgmt-cluster, following the DR runbook section E:

  1. kubectl -n tasks-prod get pods,cluster — tasks-prod-db-1 ½ CrashLoopBackOff, 24 restarts; the API, UI and MCP pods Running.
  2. Taskbase MCP get_task 3041, list_task_comments, list_task_links — all status 500: internal error.
  3. kubectl -n tasks-prod logs tasks-prod-db-1 -c postgres --previous — the same segfault at 21:13:48 on the sweep's candidate query (SELECT t.id, p.organization_id, t.priority, CASE WHEN … model_at_least(…), 10 s after ready to accept connections.
  4. Read-only clone of Skatzi/taskbase (temporary directory) — git log and git show 00c12ea: v1.264.0 added model_at_least to the claim and sweep queries.
  5. kubectl exec tasks-prod-db-1 -c postgres -- psql -d taskbase in an up window, BEGIN READ ONLY … ROLLBACK, statement_timeout 3s — open tasks with model_escalation > 0: only #3001 (queued, medium, escalation 1, updated 19:34:42); #3008 and #3041 escalation 0.
  6. The same in the next up window — task_runs since 11-13 17:58 with escalated_from set: none; run 6490 of #3001 failed 19:34:42; organizations.minimum_model: Skatzi and eloro both medium.
  7. kubectl -n tasks-prod get cluster tasks-prod-db conditions and get backups — ContinuousArchiving=True, LastBackupSucceeded=True, last daily backup 2026-11-14 02:30 completed.
  8. flux get kustomizations -A --status-selector ready=false — empty; taskbase-prod Ready at main@sha1:17cd245e.
  9. Alertmanager /api/v2/alerts?active=true through the Service proxy — KubePodCrashLooping, KubePodNotReady, TargetDown and KubePdbNotEnoughHealthyPods active in tasks-prod on hetzner-mgmt.

A third operator run of #3041 (21:35–21:45; Taskbase claimed the task again while it could not record the earlier runs) ran only read-only checks, with the same context:

  1. kubectl -n tasks-prod get pods,cluster — tasks-prod-db-1 ½ CrashLoopBackOff, 28 restarts.
  2. kubectl -n tasks-prod logs tasks-prod-db-1 -c postgres --previous — ready to accept connections at 21:35:10.377, the same segfault on the same query at 21:35:18.039 (8 s later), then the shutdown.
  3. flux get kustomizations -A --status-selector ready=false — taskbase-prod: health check failed after 4m30s: timeout waiting for: [Deployment/tasks-prod/platform-tasks-api status: 'InProgress'], a consequence of the database, not a separate root.
  4. Alertmanager through the Service proxy (.labels.cluster = hetzner-mgmt) — besides the four above, two ProbeFailed (critical) active since 19:40:33 and 21:25:03.
  5. Taskbase MCP get_task 3041 — still status 500: internal error.
  6. The PostgreSQL 18.2, 18.3 and 18.4 release notes (postgresql.org) — no fix that clearly matches a segfault in a FOR UPDATE … SKIP LOCKED query; 18.2 fixes rowmark pruning for subqueries under EvalPlanQual, which the notes call wrong results, not a crash. 18.5 is not published. (This missed the fix: the 18.2 notes list it as "Fix expression evaluation bug for a sub-select within an array subscript"; see Root cause.)

Write commands against the cluster by these three runs: none. No silence, suspension or annotation was added. They did not change the database: the step that would stop the crash writes Taskbase's data with no fresh backup from the database's backup gate, so they left it to the owner (see Follow-ups).

The recovery was made under task #3042 between 21:48 and 21:53. Its commands log is not recorded: the run of #3042 at 22:06–22:11 states it did not make these writes and could not read the earlier run's records. From the cluster's records:

  1. platform-tasks-api scaled from 1 to 0 at 21:48:24 (ScalingReplicaSet event) — stop the client that sends the crashing query, so the database stays up.
  2. kubectl apply of Backup tasks-prod-db-incident-3042 (skatzi.com/reason: "Taskbase #3042: fresh backup before repairing the crashing tasks row") — started 21:52:15, completed at 21:52:30.
  3. UPDATE of tasks row 3001 to model_escalation = 0 — read back as 0 at 22:12; time not recorded.
  4. No manual Flux action: taskbase-prod's scheduled reconcile at 22:04:25 restored the replica count from Git, so Git and the cluster match again.

The fourth operator run of #3041 (22:11–22:20), read-only, with the same context, to answer the review of pull request #1460:

  1. kubectl -n tasks-prod get pods,cluster and the pod's container status — tasks-prod-db-1 2/2 Running, 31 restarts, postgres started 21:50:52, last terminated 21:45:48; Cluster Cluster in healthy state; platform-tasks-api 1/1, started 22:04:28.
  2. kubectl -n tasks-prod logs tasks-prod-db-1 -c postgres (current and --previous) — last segfault 21:45:48; none since 21:50:53; a restore point barman_20261114T215215 at 21:52:32 (the on-demand backup).
  3. kubectl -n tasks-prod get backups and get events, get deploy platform-tasks-api --show-managed-fields, kubectl -n flux-system get kustomization taskbase-prod — the timeline entries from 21:48:24 to 22:04:41 above; the last manual reconcile request on taskbase-prod is from 11-07, so 22:04:25 was a scheduled one.
  4. kubectl exec tasks-prod-db-1 -c postgres -- psql -d taskbase, BEGIN READ ONLY … ROLLBACK, statement_timeout 3s — #3001 dispatched, medium, model_escalation 0, claimed by run 6632 at 22:05:40; open tasks with model_escalation > 0: 0.
  5. Taskbase MCP get_task 3042, 3175, 3176, 3210, 3211 and list_task_comments 3008 — the recovery as recorded, the follow-ups, and #3008 closed at 22:04:40 as resolved by itself.

Resolution and verification

Mitigated by the recovery under #3042 (see What ended it), and resolved in the code by #3210 (Taskbase v1.264.1). Checked at 22:07–22:10 by the run of #3042 and again at 22:12:58 by this run:

  • tasks-prod-db-1 2/2 Running; restart count 31, unchanged since 21:50:52 (22 minutes); no segfault in its log since then. CNPG Cluster tasks-prod-db: Cluster in healthy state.
  • curl -s https://taskbase.skatzi.com/api/health — 200. Taskbase MCP reads answer again. #3042 also saw probe_success 1 for every taskbase.skatzi.com target.
  • Alertmanager /api/v2/alerts?active=true through the Service proxy (.labels.cluster = hetzner-mgmt) — no active alert in tasks-prod and no ProbeFailed. Taskbase closed #3008 at 22:04:40 and #3140 at 22:04:51.
  • flux get kustomizations -A --status-selector ready=false — empty; nothing suspended.

The code fix was checked on 11-15 at 00:40 for the report's update (#3214): curl -s https://taskbase.skatzi.com/api/version returns {"version":"v1.264.1"}, and /api/health returns "status":"ok". No escalated task has been swept on prod since, so the fix has not yet been seen to work there. #729 tested it on a disposable 18.1.

Follow-ups

The first of the options this report gave the owner (stop the trigger after an on-demand backup) is what ended the crash loop. Done:

  • 3210 (Taskbase project) — reproduced the crash on a disposable PostgreSQL 18.1, found bug #19370, and replaced the

    subscript with CASE: Skatzi/taskbase PR #729, merged 23:26, v1.264.1.
  • 3212 (Platform) — Renovate now tracks a CNPG Cluster's imageName:

    Skatzi/platform PR #1469, merged 11-15 00:05. No backup gate runs before an image-only change, so the upgrade itself was split into the tasks below.
  • 3213 (Taskbase project) — CI's PostgreSQL tests run on postgres:18.1-trixie, prod's minor, instead of

    postgres:16. With #729's fix reverted, the new test fails on 18.1: Skatzi/taskbase PR #733, merged 11-15 00:38.
  • 3211 (Platform) — DR section E now has the case

    "the database crash-loops on one query", and the gap that the DR session's mac-mini context cannot list the ops-agent namespace: Skatzi/platform PR #1466, merged.

Open:

  • 3217 and #3218 — pin imageName of tasks-db and tasks-prod-db and add a backup gate keyed on it

    (Skatzi/taskbase, then the Flux Kustomizations in Skatzi/platform).
  • 3219 — upgrade tasks-db and tasks-prod-db from 18.1 to 18.7 behind that gate, drain-class.

  • 3220 — pin, gate and upgrade terraform-state-db and mattermost-db (18.1), and keycloak-db (15.19).

  • 3221 — pin, gate and upgrade emiliero-db (Skatzi/emiliero).

  • botyard-prod-db (Dupondforge/botyard-control) also runs 18.1; #1469 left it to a person to raise there.

References

  • Alert: KubePodCrashLooping for tasks-prod-db-1 (incident task #3008); watchdog probe taskbase
  • Taskbase incident task: #3041; the other DR sessions of the same outage #3042, #3173–#3176; trigger task #3001 (run 6490); alerts #3008, #3140; follow-ups #3210–#3213, #3217–#3221; this update #3214
  • Backup: tasks-prod/tasks-prod-db-incident-3042 (21:52:30, completed)
  • DR issue: DunkRing/bootstrap-cluster#5
  • Code: Skatzi/taskbase v1.264.0 (17cd245), task #2901, pull request #726; the fix v1.264.1 (9fee8dd), pull request #729; CI on 18.1, pull request #733
  • PostgreSQL: bug #19370, fixed in 18.2 by bdc5dedfc, 18.2 release notes
  • Platform pull requests: #1469 (Renovate tracks the CNPG image, #3212), #1466 (DR section E, #3211)
  • Runbook sections: DR section E, CloudNativePG

Open questions

  • Why the DR session's read-only run of the SELECT without FOR UPDATE … SKIP LOCKED returned its row on prod (step in the DR run report), while #729 found that the same expression without the lock crashes 18.1. #729 suggests the data or the version differed and did not check it. No backtrace was captured on prod or in #729; the match with bug #19370 rests on the minimal case and the upstream commit's diagnosis.
  • Who made the recovery writes recorded under #3042 (the scale-down, the backup, the UPDATE), with which exact commands, and when the UPDATE ran. The run of #3042 at 22:06–22:11 says it did not make them.
  • Whether pg_amcheck was run on tasks and its indexes after the recovery, as the recommended option said: no record shows it.
  • What Taskbase lost while the database was down: writes from runners and Alertmanager that failed were not retried as far as the record shows.