Skip to content

fix(api): a deployment whose runs keep failing is tried again, never left without a job (closes #486) - #508

Merged
samuelmbabhazi merged 2 commits into
mainfrom
fix/486-reconcile-deployments
Nov 26, 2026
Merged

samuelmbabhazi merged 2 commits into
mainfrom
fix/486-reconcile-deployments

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

  • DeploymentWorker.handle (extracted from the queue callback): when pipeline.run throws, the worker no longer rethrows for pg-boss to retry. It queues the same deployment again, with a delay of 15 s that doubles up to 5 min, and counts consecutive failures in the job data (failures).
    • A run that returns wait resets the count, as before with the 15 s recheck.
    • If the enqueue itself fails, the job fails and pg-boss retries it.
    • Errors are still never logged or persisted.
  • DeploymentWorker.sweep, run at start and then every 5 minutes: it wakes each deployment whose latest deployment-run job is failed, up to 500, using one query on the jobs schema.
    • The wake is the usual stately, singleton send, so a deployment with a queued or active job gets nothing extra.
    • A finished deployment's run does nothing.
    • The interval is unref'd and cleared on shutdown.
  • SPEC 5.1 describes the behavior.

Why

Closes #486. A run that threw was left to pg-boss's five retries. When they were exhausted, for example while the database timed out repeatedly before the first agent action, nothing would wake that deployment again. It kept its application's single active slot until someone cancelled it, even after the dependency recovered.

How it was tested

  • deployment-worker.spec.ts (new). All four cases failed first, because handle and sweep did not exist.
    • Failed runs are queued again after 15, 30, then at most 300 s, with their count, without throwing.
    • A waiting run is queued again after 15 s, without a count.
    • Invalid identifiers are ignored.
    • The sweep wakes only rows with tenant ids, and passes the queue name and the bound.
  • deployment-pipeline.integration.spec.ts, with real PostgreSQL and pg-boss 12:
    • A first run issues an agent action, then its job is marked failed.
    • sweep() adds one created job. A second sweep adds nothing.
    • The resumed run issues no action twice.
  • The API unit suite passes (106 files, 907 tests), as do api:lint and api:typecheck.

Security considerations

The sweep reads only organizationId and deploymentId from the jobs schema, checks both as tenant ids, and each run reads its deployment in that organization's transaction, under row-level security. Nothing about the failure is stored.

…left without a job (closes #486)

A pipeline run that threw was left to pg-boss retries, which end after five; with no agent action left to wake it, the deployment kept its application's slot until someone cancelled it. The worker now queues a failed run again with a delay doubling from 15 s to 5 min, and at start and every 5 minutes queues again each deployment whose latest job failed for good.

Signed-off-by: samuel mbabhazi <[email protected]>
@samuelmbabhazi samuelmbabhazi added bug Something isn't working track:control-plane labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 83119ef and b47fd71.

Files selected for processing: 5

  • apps/api/src/modules/deployments/deployment-pipeline.integration.spec.ts
  • apps/api/src/modules/deployments/infrastructure/deployment-queue.ts
  • apps/api/src/modules/deployments/infrastructure/deployment-worker.spec.ts
  • apps/api/src/modules/deployments/infrastructure/deployment-worker.ts
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi
samuelmbabhazi merged commit 3c9f1b3 into main Nov 26, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/486-reconcile-deployments branch November 26, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working track:control-plane

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconcile nonterminal deployments after job retries are exhausted

1 participant