← Back to Pull requests

Refuse to cancel an enrollment once Cloud may have sent its join #3315

Closed
unknown closed this pull request without merging on Oct 23, 2026 20:31 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 19:34 UTC
Author

Fixes #3280. Cancel (the dashboard button and POST /api/cli/enrollments/:id/cancel) now refuses once Cloud may have sent the Server's join. Before, the attempt read cancelled while the Server stayed in the mesh, holding the Sealing Key.

web-a may already be in the Cluster: Cloud sent its join. Nothing cancelled. Once it has joined, remove it with ployz server rm web-a.

The issue offered two fixes: refuse after Register, or remove the Server and rotate the key. This takes the first.

How

Cloud saves a join's assignment (enrollment_allocation) holding the enroll token's row lock, commits, and only then sends Register. The token is the point where cancel and join meet.

 cancelServerEnrollments(attempts)               # Cancel, Reject, the founder replan
   lock attempts                                 # unchanged
+  lock their enroll tokens, then in a new statement:
+    joined, or claimed Machine has an assignment under the CURRENT pairing → spare, return it
+  expire the other tokens now (was: only when the run ends a bound attempt)
   end unbound / enqueue cancel events           # only for the ones not spared

 enrollMachine → prepareJoin (one transaction)
-  requireUnspentClaim; holdJoinSlot
+  holdJoinSlot (takes the token's row lock); requireUnspentClaim (sees a cancel's expiry)
   reserve assignment → commit → Register

The two possible orders:

  • The join commits first. The cancel waits on the token, then sees the assignment and refuses.

  • The cancel commits first. The join waits on the token, then requireUnspentClaim sees it expired and returns Unauthorized before any assignment is saved.
  • Expiring the token at cancel, not when the run later ends the attempt, closes the case where an attempt bound to a run stays open after Cancel was accepted.

    Scoping.

  • Assignments count only under the current pairing's cluster key, as prepareJoin and releaseUnsentJoinSlot already scope them. A Machine keeps its ID across a forgotten pairing.

  • Only a claimed token can hold one. A queued attempt hasn't claimed its token, so an earlier assignment of the same Machine doesn't block it.
  • Reject (reject.server.ts, unchanged) already spares attempts whose join the host reported as committed. It now also spares the ones the new check finds, since it goes through the same function.

    Bets touched (core/DESIGN.md).

  • 8. Evidence over claims. "Cancelled" no longer claims a Server wasn't admitted when Cloud sent its join. The refusal says "may", because Cloud can't tell whether Register reached the Entry.

  • 4. Partial results are outcomes. No rollback or eviction is attempted. The user gets the fact and the command that undoes it.
  • Stable promise. Additive. No schema, migration or wire change.

  • cancelServerEnrollments now returns the attempts it spared. Its other two callers ignore the result.

  • Cancel can now answer Conflict, through the existing public-error path. The dashboard already toasts Conflict messages.
  • Evidence

  • Failing first. On main's code, two new tests fail. On a refused Cancel, main returned { cancelling: true } and left the token live. On an accepted Cancel of an attempt bound to a run, main left the token live.

  • New tests (enroll.server.postgres.test.ts):

  • - a saved assignment makes Cancel refuse and Reject spare the attempt;
    - an accepted Cancel of a bound attempt expires the token at once;
    - an assignment saved under a forgotten pairing doesn't block Cancel;
    - an earlier assignment doesn't block a later attempt that hasn't claimed its token.
  • Suites. The enroll, enrollment, check-in and CLI-handler postgres suites pass (282). Typecheck and lint are clean for the changed files.

  • Not run on real Machines. I booted 2 Incus Machines enrolled through this checkout's local Cloud, to turn machine-2 back into a waiting host and cancel right after its assignment was saved. server rm machine-2 there never got past "Waiting for approval in Ployz Cloud", so I tore the run down. The interleavings above are proven at the database level only.

  • Independent review, three rounds:

  • - Round 1. codex/gpt-6.1-sol and claudeAgent/claude-opus-5-5 reviewed an earlier design that marked the attempt's stage joining before Register. They found a P1: Cancel on an attempt bound to a run didn't stop a later Register. They also found a P2: the host reports storage after Register, so its heartbeats would repeat that report and could exhaust the run's event budget. Both were fixed by replacing the design with the token gate above.
    - Round 2. Codex found one P2: assignments from a forgotten pairing counted. Fixed by scoping to the current pairing. Claude raised a P2: one saved assignment would block every later attempt of that Machine. Dismissed, because a queued attempt hasn't claimed its token, and a test pins it. Codex confirmed in round 3 that the dismissal holds for a fresh queued attempt.
    - Round 3. Codex found nothing new.

    Known limits

  • If Register fails after the assignment commits, Cancel refuses until the attempt's run ends it. That takes one check-in while the host is alive, or up to the run's 30-minute wait if the host has gone.

  • A token that is both expired and past its join slot now gets "The join slot was given up" before Unauthorized, at the cost of one extra request from the host.

  • Cloud-access removal (cancelOpenServerEnrollments) and the stale sweep still end attempts without checking for a sent join, as before.
  • Merge Danger

    Door: two-way. Blast Radius: Cloud's Cancel and Reject of enrollment attempts, and the order of two token checks in enrollMachine.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: nick-potts Review duration: 56m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3315"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%
    Repository