carlos / platform Public

host: apply and rollback dry-check the guard before the drain ask

The activation guard (root protocol check on the binary, the moves floor
and hold rule) and the quiesce's group maintenance permit could refuse
after the verb had already asked for the ingress drain, leaving an armed
box with closed listeners until the 3-minute exit. Install and the
rollback's restore now run those refusals as a dry check just before the
ask, so a refusal never follows a drain. TestApplyAsksNoIngressDrain...
gains an armed-box case whose guard refuses: no ask (W6 final review F3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 000baaf317cb1522bed47cd468f729794830b56a parent 47e12e8
2 files changed, +43 −0
  • internal/host/systemapply.go +28 −0
  • internal/host/systemapply_ingress_test.go +15 −0
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go
index b034608f1..c1a8c08f4 100644
--- a/internal/host/systemapply.go
+++ b/internal/host/systemapply.go
@@ -327,6 +327,24 @@ func (a *systemApplier) ingressDrainBeforeSwap(ctx context.Context) {
}
}
+// refusalsBeforeDrain runs, as a dry check just before the ingress drain
+// ask, the refusals the quiesce and the activation guard can still make
+// after it: the group maintenance permit (quiesce), the root protocol
+// check on the binary to be put in place, and the activation rule (moves
+// floor and hold rule) read again now. The guard applies them again under
+// its locks; this only makes a refusal there unlikely to follow a drain.
+// rootFloorDowngradeIdle, which the guard runs only inside its ledger
+// transaction, is not repeated here.
+func (a *systemApplier) refusalsBeforeDrain(version, running, binary string) error {
+ if err := a.requireGroupMaintenance("apply", "rollback"); err != nil {
+ return err
+ }
+ if err := a.rootProtocolAllowsBinary(binary); err != nil {
+ return err
+ }
+ return a.activationRule(version, func() string { return running })
+}
+
func (a *systemApplier) rootDir() string { return systemRootDir(a.optDir) }
func (a *systemApplier) stagingDir() string { return filepath.Join(a.rootDir(), "staging") }
func (a *systemApplier) lockPath() string { return filepath.Join(a.rootDir(), systemLockFile) }
@@ -698,6 +716,11 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea
// The release on disk, for the activation guard at the rename: read now,
// because reading it runs the binary and the guard holds locks.
running := a.onDiskBuild(ctx)
+ // The activation guard's refusals, as a dry check, so the drain below
+ // never precedes one of them (W6 spec §5.3).
+ if err := a.refusalsBeforeDrain(target, running, staged); err != nil {
+ return a.record(req, fmt.Errorf("%w: %v", errSystemRefused, err))
+ }
// Every refusal is behind us and this install restarts the edge: out of
// the load balancer first (W6 spec §5.3). Before the journal, so an
// apply killed during the drain leaves nothing to recover; the agent's
@@ -2116,6 +2139,11 @@ func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal, drai
return bootstrapPlan{}, err
}
if drain {
+ // The guard's binary check and the quiesce's refusal too, before
+ // the ask: a refusal never follows a drain (W6 spec §5.3).
+ if err := a.refusalsBeforeDrain(prevVersion, running, prev); err != nil {
+ return bootstrapPlan{}, err
+ }
a.ingressDrainBeforeSwap(ctx)
}
// The same quiesce the install did: a root pass that is mid-flight
diff --git a/internal/host/systemapply_ingress_test.go b/internal/host/systemapply_ingress_test.go
index 7fb4d8cc9..00ea9bfea 100644
--- a/internal/host/systemapply_ingress_test.go
+++ b/internal/host/systemapply_ingress_test.go
@@ -10,6 +10,8 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/moves"
)
// ingressAsk is a fake agent behind the verbs' ingress drain call (spec
@@ -129,6 +131,19 @@ func TestApplyAsksNoIngressDrainWhenItWillNotRestartTheEdge(t *testing.T) {
delete(f.answer, "plan:"+systemPrevPath(f.a.optDir))
return f
},
+ // An armed box whose activation guard refuses at the rename (a
+ // floor armed during staging): the dry check before the ask
+ // refuses first, so no drain precedes the refusal (W6 final
+ // review F3).
+ "activation guard refuses on an armed box": func(t *testing.T) *applyFixture {
+ f, _ := floorFixture(t, "v0.31.0", "v0.32.0")
+ f.duringStaging(func() {
+ if err := writeLocalFloor(f.a.dataDir, moves.Floor{Min: 1, MinRelease: "v0.33.0"}); err != nil {
+ t.Error(err)
+ }
+ })
+ return f
+ },
}
for name, setup := range cases {
t.Run(name, func(t *testing.T) {