Skip to content

fix(api): fail a deployment that cannot be planned instead of retrying it - #317

Merged
samuelmbabhazi merged 1 commit into
mainfrom
fix/314-unplannable-deployment-fails
Nov 16, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
fix/314-unplannable-deployment-fails

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

First of two changes for #314. This one removes the stuck deployment; the second will refuse, when a configuration is saved, the values that can never be deployed.

What changed

When the planner or the scheduler threw, the pipeline run threw too. pg-boss retried the job five times and gave up, and the deployment stayed in its current state. It also kept the application's single active deployment, so nothing else could be deployed until someone cancelled it.

  • A release that cannot be planned fails its deployment. A domain error from plan or from placement becomes deployment.failed with that reason, and recovery runs as for any other failure. Errors that are not about the release (a lost connection, for example) are still thrown, so the run is retried.
  • A node without capacity facts is skipped, not fatal. placeReplica threw Invalid scheduling state for a capacity of zero, so one such node made every placement of its organization throw. It is now rejected with cpu or memory (architecture when it reported none), even for a replica that reserves nothing, and the other nodes are still considered. A negative or fractional capacity still throws.
  • SPEC 5.1 and 6 describe both rules. The comment on schedulableNodes said such a node "only accepts unreserved replicas", which never was what happened.

How it was tested

  • Unit tests written first, for the scheduler, the placement adapter and the pipeline:
    • a value that passes the schema and overflows the planner (cpu: '9999999999999999') fails at placement;
    • a value only read after the replicas started (a health check interval) fails and removes the replica that was created;
    • an error that is not a domain error is still thrown;
    • a node without facts next to a ready node, and alone.
  • Integration tests with PostgreSQL and the real pipeline:
    • the unplannable deployment ends failed with its reason and its audit event, leaves no allocation, and a new deployment of the same application can be queued;
    • with one node without facts and one ready node, the replica lands on the ready node.
  • Five mutations of the fix, each caught by a unit test, and the two main ones by the integration tests as well.

Not run on the installation rig: both defects were found by reading the code and reproduced in tests, and the fix changes no agent action and no installer.

Security considerations

  • No new input, action or secret path. The failure reason is the domain error's message, which never contains the input value.
  • Availability: one unreadable stored value, or one server that reported no capacity, could block deployments (of one application, or of a whole organization). Neither can any more.
  • More secure choice where the code was ambiguous: a node of unknown capacity runs nothing, including replicas that reserve nothing.

Refs #314

Summary by CodeRabbit

  • Bug Fixes
    • Deployments with invalid release settings now fail with a clear reason instead of being retried.
    • If a release error is found after replicas start, those containers are removed and reserved resources are freed.
    • Nodes with missing or zero CPU, memory, or architecture capacity are skipped, while placement continues on eligible nodes.
    • Failures unrelated to release validation, such as node-store connection errors, continue to propagate without incorrectly failing the deployment.
  • Documentation
    • Updated deployment and scheduling guidance to reflect these behaviors.

…g it

When the planner or the scheduler threw, the pipeline run threw too. The
job was retried five times and the deployment stayed where it was,
holding the application's single active deployment.

- A domain error from the planner or from placement now fails the
  deployment with that reason. Other errors are still thrown and retried.
- A node without capacity facts is skipped with a reason instead of
  making placement throw for the whole organization.

Refs #314

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The deployment pipeline now fails deployments when planning or placement returns a domain error. The scheduler rejects nodes with missing or zero CPU and memory capacity, while continuing to consider other nodes.

Changes: Deployment placement and failure handling

Layer / File(s) Summary
Node capacity rejection
packages/domain/src/lib/scheduler.ts, packages/domain/src/lib/scheduler.spec.ts, apps/api/src/modules/deployments/domain/placement.ts, apps/api/src/modules/deployments/domain/placement.spec.ts, docs/SPEC.md
Zero CPU or memory capacity now returns a resource rejection, including for zero-resource requests. Placement skips nodes without required capacity facts and can select another eligible node. Tests and specifications cover these behaviors.
Deployment pipeline outcomes
apps/api/src/modules/deployments/application/deployment-pipeline.ts, apps/api/src/modules/deployments/application/deployment-pipeline.spec.ts, apps/api/src/modules/deployments/deployment-pipeline.integration.spec.ts, docs/SPEC.md
The pipeline fails deployments with domain error messages from planning or placement and propagates non-domain errors. Scheduling reports the first unplaced replica and its rejection reasons. Tests cover failure handling, cleanup, audit events, and placement on a capable node.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • shipkeepdev/shipkeep#314 — The changes handle planner errors as deployment failures and skip nodes without capacity facts. The configuration-validation objective is not addressed.
  • shipkeepdev/shipkeep#142 — The changes use CPU and memory rejection reasons for nodes without capacity. They do not add the requested human-readable describeRejection function.
Merge Risk: Minimal · up to 1f082

Unplannable deployments now fail with a clear reason instead of retrying indefinitely. Nodes without capacity facts are skipped while other nodes can still be used. No concrete defect was found, and tests cover the changed behavior. The changes were reportedly not run on the installation rig.

Security architecture risk: Minimal · up to 1f082

The change turns invalid-release failures into explicit failed deployments and prevents nodes without capacity information from blocking otherwise valid placement. The inspected paths reuse existing recovery and tenant controls; no introduced or worsened material security or ownership risk was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — An invalid stored release configuration reaches failure handling for its application's deployment. Agent-reported capacity facts influence placement across the organization's node pool; treating missing capacity as a node rejection reduces the ability of one incomplete node record to obstruct placement on other eligible nodes.

Trust Boundaries and Controls

  • observed — Failure handling retains the application's organization scope. The bound unit of work validates scope identity, rejects incompatible nested scopes and establishes transaction-local organization context. Scheduler eligibility still checks readiness, architecture, labels, node allow-list, volume placement, resources and ports; the capacity change does not bypass those checks.

Resilience and Maintainability Implications

  • inferred — The new deterministic configuration-error paths preserve the existing recovery model: planning finishes before its returned actions are enqueued, late health-check parsing occurs after replica startup, and cleanup targets persisted successful create steps using deployment-specific keys. Repeated runs on a failed deployment terminate without replanning its work. Recovery remains best-effort rather than proof that an agent completed removal.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: deployments that cannot be planned now fail instead of being retried. The changeset matches this. Domain errors from planning or placement now fail the deployment, non…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: deployments that cannot be planned now fail instead of being retried. The changeset matches this. Domain errors from planning or placement now fail the deployment, non-domain errors still throw, and nodes without capacity facts are skipped. The title is specific and conventional, and it does not list files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 55bda85 and 1f082e0.

Files selected for processing: 8

  • apps/api/src/modules/deployments/application/deployment-pipeline.spec.ts
  • apps/api/src/modules/deployments/application/deployment-pipeline.ts
  • apps/api/src/modules/deployments/deployment-pipeline.integration.spec.ts
  • apps/api/src/modules/deployments/domain/placement.spec.ts
  • apps/api/src/modules/deployments/domain/placement.ts
  • docs/SPEC.md
  • packages/domain/src/lib/scheduler.spec.ts
  • packages/domain/src/lib/scheduler.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@samuelmbabhazi
samuelmbabhazi merged commit 65bb5de into main Nov 16, 2026
16 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/314-unplannable-deployment-fails branch November 16, 2026 11:50
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.

1 participant