Skip to content

fix(core): terminalize permanently stalled tasks through whenExhausted - #713

Merged
jumski merged 5 commits into
mainfrom
689-terminalize-stalled
Nov 24, 2026
Merged

jumski merged 5 commits into
mainfrom
689-terminalize-stalled

Conversation

@jumski

@jumski jumski commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #689. Keeps recovery task locks and the existing failure path in separate transactions.

recovery transaction
  retry budget exhausted → mark permanently stalled + archive message
  COMMIT

separate escalation cron transaction
  lock and recheck run → step → task
  marked started/queued task → fail_task()
    apply whenExhausted: fail | skip | skip-cascade
    preserve attempts_count as committed claims

The existing recovery setup configures both jobs with one interval. On upgrade, escalation inherits the scheduled recovery job's interval and active state for the migration role and current database. If that job is absent, the migration schedules nothing. Historical eligible rows with a marker are included; unmarked queued and terminal tasks stay unchanged.

This branch includes #711 from main. The escalation migration, 20261124094756_pgflow_escalate_permanently_stalled.sql, follows the startup handshake without changing prior migration checksums.

Evidence

  • Before: recovery archived the message but left the task active. Late failure callbacks could retry an archived task below max_attempts.
    After: the stall marker exhausts the task without creating synthetic claims. The existing policy handles failure, skip, cascade, and private queue cleanup.
  • Before: another cron owner could use the same job name and make the upgrade abort with more than one row returned by a subquery used as an expression.
    After: the upgrade fixtures pass with both owners present and cover active, paused, and absent recovery.
  • The combined branch passed 325 pgTAP files (1,771 assertions), all upgrade fixtures, and the website build and link check. The final race test passes with both an uncommitted recovery marker and a waiting failure callback. Generated types still match after the race test drops its test queue. The normal pre-push gate passed on 90de4845b.
  • CI for the updated branch: https://github.com/pgflow-dev/pgflow/actions/runs/45372246475

Merge Danger

Door: one-way for data effects after escalation runs. Reverting code does not undo completed transitions or downstream side effects.

Blast Radius: recovery

Historical marked tasks follow the configured exhaustion policy after upgrade. In particular, skip can start dependent business work. Inspect the documented backlog before upgrading. If downstream execution must stay paused, pause both scheduled jobs and the relevant workers and callbacks, then restore each saved state. Pausing cron alone does not stop marker-aware failure callbacks. This PR does not run a production database migration.

@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 90de484

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@pgflow/core Minor
pgflow Minor
@pgflow/client Minor
@pgflow/edge-worker Minor
@pgflow/dsl Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jumski commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@nx-cloud

nx-cloud Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 90de484

Command Status Duration Result
nx run edge-worker:e2e ✅ Succeeded 2m 27s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-24 10:37:39 UTC

@jumski
jumski force-pushed the 689-terminalize-stalled branch from daa1753 to 3668bbf Compare November 3, 2026 18:43
@jumski
jumski force-pushed the 689-terminalize-stalled branch from 3668bbf to c0fa0d1 Compare November 3, 2026 18:58
Add focused coverage for private step queues, archived messages, counters, realtime events, and late callbacks after escalation. Add a deterministic dblink race covering recovery, escalation, and a late completion callback competing for parent locks. Keep the cron comment accurate when both jobs overlap, and refresh the generated migration checksum.
@jumski
jumski force-pushed the 689-terminalize-stalled branch from c0fa0d1 to 35ac37a Compare November 4, 2026 00:15
Sqruff 0.44.0 rejects whitespace before array brackets. Match the existing compact type spelling so core SQL lint passes without changing schema behavior or migrations.
Agent added 3 commits November 24, 2026 10:50
Apply the unpublished stalled-task escalation migration after the worker startup handshake. Rebuild atlas.sum and run the upgrade fixture from the handshake baseline so databases that already applied it can upgrade without inserting an older migration.
A same-name recovery job under another role made the scalar schedule lookup abort the upgrade. Copy the current role and database’s job schedule and activation in one call. Cover active, paused, and absent recovery alongside a foreign job. Scope the maintenance runbook to those same rows and separate pausing from restoration.
Do not depend on SQL operand evaluation order. Check that escalation cannot see an uncommitted marker and that a failure callback waiting on recovery exhausts the archived task. Drop the test’s committed queue objects as well as its rows so later type generation stays clean.
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Preview Deployment: Website

✅ Deployment successful!

🔗 Preview URL: https://pr-713.pgflow.pages.dev

📝 Details:

  • Branch: 689-terminalize-stalled
  • Commit: 23b5b17db24aac53f5c92e17ef0ff1573ab57894
  • View Logs

_Last updated: _

jumski commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Nov 24, 12:13 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 24, 12:13 PM UTC: @jumski merged this pull request with Graphite.

@jumski
jumski merged commit c8703a4 into main Nov 24, 2026
39 of 41 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Production Deployment: Website

✅ Successfully deployed to production!

🔗 Production URL: https://pgflow.dev

📝 Details:

  • Commit: c8703a4fe64a9fbf8ba473cf95a8e97d0a4e1223
  • View Logs

Deployed at: 2026-11-24T13:13:36+01:00

jumski added a commit that referenced this pull request Nov 24, 2026
## Summary

```diff
- Prepare the pgflow 0.17.3 worker reliability notes.
+ Prepare the pgflow 0.18.0 notes with the stalled-task recovery fix and upgrade guidance.
```

The minor changeset in #713 moves the fixed package group to 0.18.0 in the release PR: #709. The article covers pending Supabase starts, task result reporting, and how `whenExhausted` now handles permanently stalled tasks.

## Evidence

- **Before:** The preview build omitted the draft article's HTML page.
  **After:** The website build renders the finished article and resolves its link to the stalled-task backlog check.
- Website build, internal links, website lint, and article formatting pass locally.

## Merge Danger

**Door:** two-way  
**Blast Radius:** docs

Keep this PR open until 0.18.0 ships. Set the actual publication date before merging; the current date is for the preview. This PR does not release packages or run a database migration.

This branch was successfully deployed

1 active deployment
preview — 90de4845 Deployed Nov 24, 2026 by jumski via deploy-website #3437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminalize tasks after the stalled-task requeue limit

1 participant