phase63: add rebuild runtime target contract

This commit is contained in:
pingqiu committed 2026-06-25 01:14:03 -07:00
1 parent 669527965f
commit 62f2a61444
18 files changed
+1009 -229

No files matched your search

@@ -55,6 +55,34 @@ spec:
type: string
sourceReplicaID:
type: string
runtimeEndpoint:
type: string
targetDataAddr:
type: string
sessionID:
type: integer
format: int64
minimum: 0
epoch:
type: integer
format: int64
minimum: 0
endpointVersion:
type: integer
format: int64
minimum: 0
fromLsn:
type: integer
format: int64
minimum: 0
frontierHintLsn:
type: integer
format: int64
minimum: 0
basePinLsn:
type: integer
format: int64
minimum: 0
status:
type: object
properties:
@@ -186,6 +186,34 @@ spec:
type: integer
format: int64
minimum: 0
runtimeEndpoint:
type: string
targetDataAddr:
type: string
sessionID:
type: integer
format: int64
minimum: 0
epoch:
type: integer
format: int64
minimum: 0
endpointVersion:
type: integer
format: int64
minimum: 0
fromLsn:
type: integer
format: int64
minimum: 0
frontierHintLsn:
type: integer
format: int64
minimum: 0
basePinLsn:
type: integer
format: int64
minimum: 0
evidenceRefs:
type: array
items:
+3 -1
View File
@@ -148,7 +148,7 @@ func runOpsRebuildTargetOwner(args []string, stdout, stderr io.Writer) int {
if dryRun {
mode = "dry_run"
}
fmt.Fprintf(stdout, "rebuild_target_owner=%s namespace=%s volumes=%d contracts=%d targets_planned=%d targets_existing=%d targets_created=%d invalid_contracts=%d mutation_allowed=%t storage_mutation_allowed=false frontend_publication_allowed=false failback_allowed=false\n",
fmt.Fprintf(stdout, "rebuild_target_owner=%s namespace=%s volumes=%d contracts=%d targets_planned=%d targets_existing=%d targets_created=%d invalid_contracts=%d runtime_target_ready=%d runtime_target_missing=%d mutation_allowed=%t storage_mutation_allowed=false frontend_publication_allowed=false failback_allowed=false\n",
mode,
namespace,
result.VolumeCount,
@@ -157,6 +157,8 @@ func runOpsRebuildTargetOwner(args []string, stdout, stderr io.Writer) int {
result.TargetExistingCount,
result.TargetCreateCount,
result.InvalidContractCount,
result.RuntimeTargetReadyCount,
result.RuntimeTargetMissingCount,
!dryRun && result.TargetCreateCount > 0)
return ops.VolumeStatusExitOK
}
+132 -5
View File
@@ -713,10 +713,18 @@ func TestOpsAuthorityExecutorRebuildRuntimeURLWritesCaughtUpStatus(t *testing.T)
Name: "rebuild-r1",
},
Spec: ops.SwBlockReplicaRebuildSpec{
VolumeName: "rebuild",
VolumeID: "pvc-rebuild",
PVCName: "rebuild-pvc",
ReplicaID: "r1",
VolumeName: "rebuild",
VolumeID: "pvc-rebuild",
PVCName: "rebuild-pvc",
ReplicaID: "r1",
RuntimeEndpoint: "http://127.0.0.1:23260/rebuild/runtime",
TargetDataAddr: "127.0.0.1:19103",
SessionID: 1001,
Epoch: 7,
EndpointVersion: 3,
FromLSN: 52,
FrontierHintLSN: 52,
BasePinLSN: 60,
},
}},
}
@@ -758,6 +766,14 @@ func TestOpsAuthorityExecutorRebuildRuntimeURLWritesCaughtUpStatus(t *testing.T)
got.VolumeID != "pvc-rebuild" ||
got.PVCName != "rebuild-pvc" ||
got.ReplicaID != "r1" ||
got.RuntimeEndpoint != "http://127.0.0.1:23260/rebuild/runtime" ||
got.TargetDataAddr != "127.0.0.1:19103" ||
got.SessionID != 1001 ||
got.Epoch != 7 ||
got.EndpointVersion != 3 ||
got.FromLSN != 52 ||
got.FrontierHintLSN != 52 ||
got.BasePinLSN != 60 ||
got.DurableFrontierLSN != 51 ||
got.RequiredFrontierLSN != 52 ||
!got.NoFrontendPublication ||
@@ -823,6 +839,25 @@ func TestOpsRebuildTargetOwnerCreatesTarget(t *testing.T) {
Status: ops.SwBlockVolumeCRDStatus{
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaReintegrations: []ops.SwBlockVolumeCRDReturnedReplica{{
ReplicaID: "r2",
State: ops.ReturnedReplicaStateRecovering,
ReasonCode: ops.ReasonCandidateFrontierBehind,
FrontendFenced: true,
FrontendPrimaryReady: false,
DurableFrontierKnown: true,
DurableFrontierLSN: 51,
RequiredFrontierKnown: true,
RequiredFrontierLSN: 53,
RuntimeEndpoint: "http://127.0.0.1:23260/rebuild/runtime",
TargetDataAddr: "127.0.0.1:19103",
SessionID: 1001,
Epoch: 7,
EndpointVersion: 3,
FromLSN: 52,
FrontierHintLSN: 53,
BasePinLSN: 60,
}},
ExecutorContracts: []ops.SwBlockVolumeCRDExecutorContract{{
ActionType: ops.ManagedVolumeActionRebuildReturned,
ReplicaID: "r2",
@@ -852,7 +887,15 @@ func TestOpsRebuildTargetOwnerCreatesTarget(t *testing.T) {
created := client.rebuildCreates[0]
if created.Ref.Name != "demo-pvc-r2-rebuild" ||
created.Spec.VolumeName != "demo-pvc" ||
created.Spec.ReplicaID != "r2" {
created.Spec.ReplicaID != "r2" ||
created.Spec.RuntimeEndpoint != "http://127.0.0.1:23260/rebuild/runtime" ||
created.Spec.TargetDataAddr != "127.0.0.1:19103" ||
created.Spec.SessionID != 1001 ||
created.Spec.Epoch != 7 ||
created.Spec.EndpointVersion != 3 ||
created.Spec.FromLSN != 52 ||
created.Spec.FrontierHintLSN != 53 ||
created.Spec.BasePinLSN != 60 {
t.Fatalf("created=%+v", created)
}
out := stdout.String()
@@ -864,6 +907,8 @@ func TestOpsRebuildTargetOwnerCreatesTarget(t *testing.T) {
"targets_planned=1",
"targets_existing=0",
"targets_created=1",
"runtime_target_ready=1",
"runtime_target_missing=0",
"mutation_allowed=true",
"storage_mutation_allowed=false",
"frontend_publication_allowed=false",
@@ -884,6 +929,25 @@ func TestOpsRebuildTargetOwnerDryRunDoesNotCreateTarget(t *testing.T) {
Status: ops.SwBlockVolumeCRDStatus{
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaReintegrations: []ops.SwBlockVolumeCRDReturnedReplica{{
ReplicaID: "r2",
State: ops.ReturnedReplicaStateRecovering,
ReasonCode: ops.ReasonCandidateFrontierBehind,
FrontendFenced: true,
FrontendPrimaryReady: false,
DurableFrontierKnown: true,
DurableFrontierLSN: 51,
RequiredFrontierKnown: true,
RequiredFrontierLSN: 53,
RuntimeEndpoint: "http://127.0.0.1:23260/rebuild/runtime",
TargetDataAddr: "127.0.0.1:19103",
SessionID: 1001,
Epoch: 7,
EndpointVersion: 3,
FromLSN: 52,
FrontierHintLSN: 53,
BasePinLSN: 60,
}},
ExecutorContracts: []ops.SwBlockVolumeCRDExecutorContract{{
ActionType: ops.ManagedVolumeActionRebuildReturned,
ReplicaID: "r2",
@@ -915,6 +979,69 @@ func TestOpsRebuildTargetOwnerDryRunDoesNotCreateTarget(t *testing.T) {
"rebuild_target_owner=dry_run",
"targets_planned=1",
"targets_created=0",
"runtime_target_ready=1",
"runtime_target_missing=0",
"mutation_allowed=false",
} {
if !strings.Contains(out, want) {
t.Fatalf("stdout missing %q:\n%s", want, out)
}
}
}
func TestOpsRebuildTargetOwnerDoesNotCreateTargetWhenRuntimeFactsMissing(t *testing.T) {
client := &lifecycleOwnerTestClient{
volumes: []ops.SwBlockVolumeObject{{
Ref: ops.OperatorObjectRef{
Name: "demo-pvc",
},
Status: ops.SwBlockVolumeCRDStatus{
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaReintegrations: []ops.SwBlockVolumeCRDReturnedReplica{{
ReplicaID: "r2",
State: ops.ReturnedReplicaStateRecovering,
ReasonCode: ops.ReasonCandidateFrontierBehind,
FrontendFenced: true,
FrontendPrimaryReady: false,
DurableFrontierKnown: true,
DurableFrontierLSN: 51,
RequiredFrontierKnown: true,
RequiredFrontierLSN: 53,
}},
ExecutorContracts: []ops.SwBlockVolumeCRDExecutorContract{{
ActionType: ops.ManagedVolumeActionRebuildReturned,
ReplicaID: "r2",
Decision: ops.ReturnedReplicaExecutorContractDisabled,
Reason: ops.ReturnedReplicaExecutorContractReasonExecutorDisabled,
PreflightDecision: ops.ReturnedReplicaExecutorPreflightReady,
PreflightReason: ops.ReturnedReplicaExecutorPreflightReasonSatisfied,
AllowedMutationClass: []string{ops.AuthorityExecutorAllowedMutationRebuildTraffic},
}},
},
}},
}
oldFactory := opsRebuildTargetOwnerClientFactory
opsRebuildTargetOwnerClientFactory = func() (ops.RebuildTargetOwnerClient, error) {
return client, nil
}
t.Cleanup(func() { opsRebuildTargetOwnerClientFactory = oldFactory })
var stdout, stderr bytes.Buffer
code := run([]string{"ops", "rebuild-target-owner", "--namespace", "kube-system"}, &stdout, &stderr)
if code != ops.VolumeStatusExitOK {
t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String())
}
if len(client.rebuildCreates) != 0 {
t.Fatalf("unexpected creates=%+v", client.rebuildCreates)
}
out := stdout.String()
for _, want := range []string{
"rebuild_target_owner=target_mutation",
"targets_planned=0",
"targets_created=0",
"runtime_target_ready=0",
"runtime_target_missing=1",
"mutation_allowed=false",
} {
if !strings.Contains(out, want) {
@@ -7,17 +7,18 @@ import (
)
const (
AuthorityExecutorAllowedMutationAckEligibility = "ack_eligibility"
AuthorityExecutorAllowedMutationRebuildTraffic = "rebuild_traffic"
AuthorityExecutorBlockedPolicyDisabled = "executor_policy_disabled"
AuthorityExecutorBlockedMutationTargetMissing = "ack_eligibility_mutation_target_missing"
AuthorityExecutorBlockedRebuildTargetMissing = "rebuild_target_missing"
AuthorityExecutorBlockedTerminalEvidence = "terminal_evidence_missing"
AuthorityExecutorReasonAckEligibilityRecorded = "ack_eligibility_recorded"
AuthorityExecutorReasonRebuildPlanned = "rebuild_progress_planned"
AuthorityExecutorReasonRebuildRunning = "rebuild_runtime_running"
AuthorityExecutorReasonRebuildCaughtUp = "rebuild_runtime_caught_up"
AuthorityExecutorReasonRebuildRuntimeFailed = "rebuild_runtime_failed"
AuthorityExecutorAllowedMutationAckEligibility = "ack_eligibility"
AuthorityExecutorAllowedMutationRebuildTraffic = "rebuild_traffic"
AuthorityExecutorBlockedPolicyDisabled = "executor_policy_disabled"
AuthorityExecutorBlockedMutationTargetMissing = "ack_eligibility_mutation_target_missing"
AuthorityExecutorBlockedRebuildTargetMissing = "rebuild_target_missing"
AuthorityExecutorBlockedTerminalEvidence = "terminal_evidence_missing"
AuthorityExecutorReasonAckEligibilityRecorded = "ack_eligibility_recorded"
AuthorityExecutorReasonRebuildPlanned = "rebuild_progress_planned"
AuthorityExecutorReasonRebuildRunning = "rebuild_runtime_running"
AuthorityExecutorReasonRebuildCaughtUp = "rebuild_runtime_caught_up"
AuthorityExecutorReasonRebuildRuntimeFailed = "rebuild_runtime_failed"
AuthorityExecutorReasonRebuildRuntimeTargetMissing = "rebuild_runtime_target_missing"
)
type AuthorityExecutorClient interface {
@@ -47,6 +48,14 @@ type AuthorityRebuildRuntimeRequest struct {
VolumeID string `json:"volumeID"`
PVCName string `json:"pvcName"`
ReplicaID string `json:"replicaID"`
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
TargetDataAddr string `json:"targetDataAddr,omitempty"`
SessionID uint64 `json:"sessionID,omitempty"`
Epoch uint64 `json:"epoch,omitempty"`
EndpointVersion uint64 `json:"endpointVersion,omitempty"`
FromLSN uint64 `json:"fromLsn,omitempty"`
FrontierHintLSN uint64 `json:"frontierHintLsn,omitempty"`
BasePinLSN uint64 `json:"basePinLsn,omitempty"`
DurableFrontierKnown bool `json:"durableFrontierKnown"`
DurableFrontierLSN uint64 `json:"durableFrontierLsn"`
RequiredFrontierKnown bool `json:"requiredFrontierKnown"`
@@ -73,6 +82,7 @@ type AuthorityExecutorReconcileResult struct {
TerminalEvidenceMissingCount int `json:"terminalEvidenceMissingCount"`
AckEligibilityTargetMissingCount int `json:"ackEligibilityTargetMissingCount"`
RebuildTargetMissingCount int `json:"rebuildTargetMissingCount"`
RebuildRuntimeTargetMissingCount int `json:"rebuildRuntimeTargetMissingCount"`
UnsafeExecutionContractCount int `json:"unsafeExecutionContractCount"`
MutationAttemptCount int `json:"mutationAttemptCount"`
AckEligibilityMutationAttempts int `json:"ackEligibilityMutationAttempts"`
@@ -190,18 +200,31 @@ func (r AuthorityExecutorReconciler) evaluateRebuildPlanning(ctx context.Context
}
result.MutationAttemptCount++
result.RebuildProgressMutationAttempts++
if r.RebuildRuntime == nil {
runtime := r.RebuildRuntime
if runtime == nil && target.Spec.RuntimeEndpoint != "" {
runtime = NewHTTPAuthorityRebuildRuntime(target.Spec.RuntimeEndpoint, nil)
}
if runtime == nil {
if err := r.Client.WriteReplicaRebuildStatus(ctx, target.Ref, authorityExecutorRebuildPlannedStatus(r.now()(), volume, contract, returned)); err != nil {
result.BlockedReason = "rebuild_status_write_failed"
return fmt.Errorf("write rebuild status: %w", err)
}
return nil
}
if !authorityExecutorRebuildRuntimeTargetReady(target.Spec) {
result.RebuildRuntimeTargetMissingCount++
result.BlockedReason = authorityExecutorFirstNonEmpty(result.BlockedReason, AuthorityExecutorReasonRebuildRuntimeTargetMissing)
if err := r.Client.WriteReplicaRebuildStatus(ctx, target.Ref, authorityExecutorRebuildBlockedStatus(r.now()(), volume, contract, returned, AuthorityRebuildRuntimeResult{}, AuthorityExecutorReasonRebuildRuntimeTargetMissing)); err != nil {
result.BlockedReason = "rebuild_status_write_failed"
return fmt.Errorf("write missing runtime target status: %w", err)
}
return nil
}
if err := r.Client.WriteReplicaRebuildStatus(ctx, target.Ref, authorityExecutorRebuildRunningStatus(r.now()(), volume, contract, returned)); err != nil {
result.BlockedReason = "rebuild_status_write_failed"
return fmt.Errorf("write rebuild status: %w", err)
}
runtimeResult, err := r.RebuildRuntime.ExecuteRebuild(ctx, authorityExecutorRebuildRuntimeRequest(volume, contract, returned))
runtimeResult, err := runtime.ExecuteRebuild(ctx, authorityExecutorRebuildRuntimeRequest(volume, contract, returned, target.Spec))
if err != nil {
result.BlockedReason = AuthorityExecutorReasonRebuildRuntimeFailed
if writeErr := r.Client.WriteReplicaRebuildStatus(ctx, target.Ref, authorityExecutorRebuildBlockedStatus(r.now()(), volume, contract, returned, runtimeResult, AuthorityExecutorReasonRebuildRuntimeFailed)); writeErr != nil {
@@ -328,6 +351,14 @@ func authorityExecutorFindRebuildTarget(volume SwBlockVolumeObject, contract SwB
return matches[0], true
}
func authorityExecutorRebuildRuntimeTargetReady(spec SwBlockReplicaRebuildSpec) bool {
return spec.RuntimeEndpoint != "" &&
spec.SessionID != 0 &&
spec.Epoch != 0 &&
spec.EndpointVersion != 0 &&
spec.FrontierHintLSN != 0
}
func authorityExecutorAckEligibilityStatus(now time.Time, volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, returned SwBlockVolumeCRDReturnedReplica) SwBlockReplicaEligibilityCRDStatus {
evidenceRefs := appendUniqueStrings(nil, contract.EvidenceRefs...)
evidenceRefs = appendUniqueStrings(evidenceRefs, returned.EvidenceRefs...)
@@ -472,7 +503,7 @@ func authorityExecutorRebuildBlockedStatus(now time.Time, volume SwBlockVolumeOb
return status
}
func authorityExecutorRebuildRuntimeRequest(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, returned SwBlockVolumeCRDReturnedReplica) AuthorityRebuildRuntimeRequest {
func authorityExecutorRebuildRuntimeRequest(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, returned SwBlockVolumeCRDReturnedReplica, spec SwBlockReplicaRebuildSpec) AuthorityRebuildRuntimeRequest {
evidenceRefs := appendUniqueStrings(nil, contract.EvidenceRefs...)
evidenceRefs = appendUniqueStrings(evidenceRefs, returned.EvidenceRefs...)
return AuthorityRebuildRuntimeRequest{
@@ -480,6 +511,14 @@ func authorityExecutorRebuildRuntimeRequest(volume SwBlockVolumeObject, contract
VolumeID: volume.Status.VolumeID,
PVCName: volume.Status.PVCName,
ReplicaID: contract.ReplicaID,
RuntimeEndpoint: spec.RuntimeEndpoint,
TargetDataAddr: spec.TargetDataAddr,
SessionID: spec.SessionID,
Epoch: spec.Epoch,
EndpointVersion: spec.EndpointVersion,
FromLSN: spec.FromLSN,
FrontierHintLSN: spec.FrontierHintLSN,
BasePinLSN: spec.BasePinLSN,
DurableFrontierKnown: returned.DurableFrontierKnown,
DurableFrontierLSN: returned.DurableFrontierLSN,
RequiredFrontierKnown: returned.RequiredFrontierKnown,
@@ -181,7 +181,7 @@ func TestAuthorityExecutorReconcilerWritesRebuildPlannedStatus(t *testing.T) {
func TestAuthorityExecutorReconcilerExecutesRebuildRuntimeAndWritesCaughtUpStatus(t *testing.T) {
client := &fakeAuthorityExecutorClient{
volumes: []SwBlockVolumeObject{authorityExecutorRebuildVolume(false, false)},
rebuilds: []SwBlockReplicaRebuildObject{authorityExecutorRebuildTarget()},
rebuilds: []SwBlockReplicaRebuildObject{authorityExecutorRuntimeRebuildTarget()},
}
runtime := &fakeAuthorityRebuildRuntime{
result: AuthorityRebuildRuntimeResult{
@@ -215,6 +215,14 @@ func TestAuthorityExecutorReconcilerExecutesRebuildRuntimeAndWritesCaughtUpStatu
req.VolumeID != "pvc-rebuild" ||
req.PVCName != "rebuild-pvc" ||
req.ReplicaID != "r1" ||
req.RuntimeEndpoint != "http://127.0.0.1:23260/rebuild/runtime" ||
req.TargetDataAddr != "127.0.0.1:19103" ||
req.SessionID != 1001 ||
req.Epoch != 7 ||
req.EndpointVersion != 3 ||
req.FromLSN != 52 ||
req.FrontierHintLSN != 52 ||
req.BasePinLSN != 60 ||
req.DurableFrontierLSN != 51 ||
req.RequiredFrontierLSN != 52 ||
!req.FrontendFenced ||
@@ -246,7 +254,7 @@ func TestAuthorityExecutorReconcilerExecutesRebuildRuntimeAndWritesCaughtUpStatu
func TestAuthorityExecutorReconcilerWritesBlockedStatusWhenRebuildRuntimeFails(t *testing.T) {
client := &fakeAuthorityExecutorClient{
volumes: []SwBlockVolumeObject{authorityExecutorRebuildVolume(false, false)},
rebuilds: []SwBlockReplicaRebuildObject{authorityExecutorRebuildTarget()},
rebuilds: []SwBlockReplicaRebuildObject{authorityExecutorRuntimeRebuildTarget()},
}
runtime := &fakeAuthorityRebuildRuntime{err: errors.New("runtime refused")}
result, err := (AuthorityExecutorReconciler{
@@ -275,6 +283,37 @@ func TestAuthorityExecutorReconcilerWritesBlockedStatusWhenRebuildRuntimeFails(t
}
}
func TestAuthorityExecutorReconcilerBlocksWhenRuntimeTargetFactsMissing(t *testing.T) {
target := authorityExecutorRebuildTarget()
target.Spec.RuntimeEndpoint = ""
client := &fakeAuthorityExecutorClient{
volumes: []SwBlockVolumeObject{authorityExecutorRebuildVolume(false, false)},
rebuilds: []SwBlockReplicaRebuildObject{target},
}
result, err := (AuthorityExecutorReconciler{
Namespace: "kube-system",
Client: client,
RebuildRuntime: &fakeAuthorityRebuildRuntime{},
ExecutionRequested: true,
ExecutionPolicyEnabled: true,
AllowedMutationClass: AuthorityExecutorAllowedMutationRebuildTraffic,
}).Reconcile(context.Background())
if err != nil {
t.Fatalf("reconcile: %v", err)
}
if result.RebuildRuntimeTargetMissingCount != 1 ||
result.BlockedReason != AuthorityExecutorReasonRebuildRuntimeTargetMissing ||
len(client.rebuildWrites) != 1 {
t.Fatalf("result=%+v writes=%+v", result, client.rebuildWrites)
}
status := client.rebuildWrites[0].status
if status.State != "blocked" ||
status.ReasonCode != AuthorityExecutorReasonRebuildRuntimeTargetMissing ||
!status.RebuildTrafficStarted {
t.Fatalf("status=%+v", status)
}
}
func TestAuthorityExecutorReconcilerRejectsExecutionWhenPolicyDisabled(t *testing.T) {
result, err := (AuthorityExecutorReconciler{
Client: &fakeAuthorityExecutorClient{},
@@ -537,3 +576,16 @@ func authorityExecutorRebuildTarget() SwBlockReplicaRebuildObject {
},
}
}
func authorityExecutorRuntimeRebuildTarget() SwBlockReplicaRebuildObject {
target := authorityExecutorRebuildTarget()
target.Spec.RuntimeEndpoint = "http://127.0.0.1:23260/rebuild/runtime"
target.Spec.TargetDataAddr = "127.0.0.1:19103"
target.Spec.SessionID = 1001
target.Spec.Epoch = 7
target.Spec.EndpointVersion = 3
target.Spec.FromLSN = 52
target.Spec.FrontierHintLSN = 52
target.Spec.BasePinLSN = 60
return target
}
@@ -210,7 +210,7 @@ func TestPhase46D2SwBlockVolumeReturnedReplicaSchema(t *testing.T) {
doc := readYAMLMap(t, "charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml")
statusProperties := crdStatusProperties(t, doc)
returnedProperties := yamlMap(t, yamlMap(t, yamlMap(t, statusProperties, "replicaReintegrations"), "items"), "properties")
for _, want := range []string{"replicaID", "state", "reasonCode", "frontendFenced", "frontendPrimaryReady", "ackEligibilityKnown", "ackEligible", "durableFrontierKnown", "durableFrontierLsn", "requiredFrontierKnown", "requiredFrontierLsn", "evidenceRefs"} {
for _, want := range []string{"replicaID", "state", "reasonCode", "frontendFenced", "frontendPrimaryReady", "ackEligibilityKnown", "ackEligible", "durableFrontierKnown", "durableFrontierLsn", "requiredFrontierKnown", "requiredFrontierLsn", "runtimeEndpoint", "targetDataAddr", "sessionID", "epoch", "endpointVersion", "fromLsn", "frontierHintLsn", "basePinLsn", "evidenceRefs"} {
if _, ok := returnedProperties[want]; !ok {
t.Fatalf("SwBlockVolume.status.replicaReintegrations[] schema missing %s", want)
}
@@ -221,7 +221,7 @@ func TestPhase46D2SwBlockVolumeReturnedReplicaSchema(t *testing.T) {
t.Fatalf("SwBlockVolume.status.replicaReintegrations[].state enum missing %s: %+v", want, stateEnum)
}
}
for _, forbidden := range []string{"replica_id", "frontend_primary_ready", "ack_eligibility_known", "ack_eligible", "durable_frontier_lsn"} {
for _, forbidden := range []string{"replica_id", "frontend_primary_ready", "ack_eligibility_known", "ack_eligible", "durable_frontier_lsn", "runtime_endpoint", "target_data_addr", "session_id", "endpoint_version", "from_lsn", "frontier_hint_lsn", "base_pin_lsn"} {
if _, ok := returnedProperties[forbidden]; ok {
t.Fatalf("SwBlockVolume.status.replicaReintegrations[] leaked snake_case %s", forbidden)
}
@@ -355,7 +355,7 @@ func TestPhase57D1SwBlockReplicaRebuildTargetSchema(t *testing.T) {
"openAPIV3Schema"),
"properties")
specProperties := yamlMap(t, yamlMap(t, rootProperties, "spec"), "properties")
for _, want := range []string{"volumeName", "volumeID", "pvcName", "replicaID", "sourceReplicaID"} {
for _, want := range []string{"volumeName", "volumeID", "pvcName", "replicaID", "sourceReplicaID", "runtimeEndpoint", "targetDataAddr", "sessionID", "epoch", "endpointVersion", "fromLsn", "frontierHintLsn", "basePinLsn"} {
if _, ok := specProperties[want]; !ok {
t.Fatalf("%s.spec schema missing %s", SwBlockReplicaRebuildKind, want)
}
@@ -400,6 +400,13 @@ func TestPhase57D1SwBlockReplicaRebuildTargetSchema(t *testing.T) {
}
}
for _, forbidden := range []string{
"runtime_endpoint",
"target_data_addr",
"session_id",
"endpoint_version",
"from_lsn",
"frontier_hint_lsn",
"base_pin_lsn",
"frontend_fenced_before_rebuild",
"durable_frontier_lsn",
"required_frontier_lsn",
@@ -526,10 +526,18 @@ func TestKubernetesStatusClientCreatesSwBlockReplicaRebuildWithoutStatus(t *test
Name: "demo-pvc-r2-rebuild",
},
Spec: SwBlockReplicaRebuildSpec{
VolumeName: "demo-pvc",
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaID: "r2",
VolumeName: "demo-pvc",
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaID: "r2",
RuntimeEndpoint: "http://127.0.0.1:23260/rebuild/runtime",
TargetDataAddr: "127.0.0.1:19103",
SessionID: 1001,
Epoch: 7,
EndpointVersion: 3,
FromLSN: 52,
FrontierHintLSN: 53,
BasePinLSN: 60,
},
})
if err != nil {
@@ -558,9 +566,22 @@ func TestKubernetesStatusClientCreatesSwBlockReplicaRebuildWithoutStatus(t *test
if spec["volumeName"] != "demo-pvc" ||
spec["volumeID"] != "pvc-demo" ||
spec["pvcName"] != "demo-pvc" ||
spec["replicaID"] != "r2" {
spec["replicaID"] != "r2" ||
spec["runtimeEndpoint"] != "http://127.0.0.1:23260/rebuild/runtime" ||
spec["targetDataAddr"] != "127.0.0.1:19103" ||
spec["sessionID"] != float64(1001) ||
spec["epoch"] != float64(7) ||
spec["endpointVersion"] != float64(3) ||
spec["fromLsn"] != float64(52) ||
spec["frontierHintLsn"] != float64(53) ||
spec["basePinLsn"] != float64(60) {
t.Fatalf("spec=%+v", spec)
}
for _, forbidden := range []string{"runtime_endpoint", "target_data_addr", "session_id", "endpoint_version", "from_lsn", "frontier_hint_lsn", "base_pin_lsn"} {
if _, ok := spec[forbidden]; ok {
t.Fatalf("spec leaked %s: %+v", forbidden, spec)
}
}
if _, ok := request.Body["status"]; ok {
t.Fatalf("target create must not include status: %+v", request.Body)
}
@@ -49,6 +49,14 @@ type SwBlockReplicaRebuildSpec struct {
PVCName string `json:"pvcName,omitempty"`
ReplicaID string `json:"replicaID,omitempty"`
SourceReplicaID string `json:"sourceReplicaID,omitempty"`
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
TargetDataAddr string `json:"targetDataAddr,omitempty"`
SessionID uint64 `json:"sessionID,omitempty"`
Epoch uint64 `json:"epoch,omitempty"`
EndpointVersion uint64 `json:"endpointVersion,omitempty"`
FromLSN uint64 `json:"fromLsn,omitempty"`
FrontierHintLSN uint64 `json:"frontierHintLsn,omitempty"`
BasePinLSN uint64 `json:"basePinLsn,omitempty"`
}
type LifecycleOwnerReconciler struct {
@@ -290,6 +290,14 @@ type SwBlockVolumeCRDReturnedReplica struct {
DurableFrontierLSN uint64 `json:"durableFrontierLsn,omitempty"`
RequiredFrontierKnown bool `json:"requiredFrontierKnown,omitempty"`
RequiredFrontierLSN uint64 `json:"requiredFrontierLsn,omitempty"`
RuntimeEndpoint string `json:"runtimeEndpoint,omitempty"`
TargetDataAddr string `json:"targetDataAddr,omitempty"`
SessionID uint64 `json:"sessionID,omitempty"`
Epoch uint64 `json:"epoch,omitempty"`
EndpointVersion uint64 `json:"endpointVersion,omitempty"`
FromLSN uint64 `json:"fromLsn,omitempty"`
FrontierHintLSN uint64 `json:"frontierHintLsn,omitempty"`
BasePinLSN uint64 `json:"basePinLsn,omitempty"`
EvidenceRefs []string `json:"evidenceRefs,omitempty"`
}
@@ -21,12 +21,14 @@ type RebuildTargetOwnerReconciler struct {
}
type RebuildTargetOwnerReconcileResult struct {
VolumeCount int `json:"volumeCount"`
ContractCount int `json:"contractCount"`
TargetPlannedCount int `json:"targetPlannedCount"`
TargetExistingCount int `json:"targetExistingCount"`
TargetCreateCount int `json:"targetCreateCount"`
InvalidContractCount int `json:"invalidContractCount"`
VolumeCount int `json:"volumeCount"`
ContractCount int `json:"contractCount"`
TargetPlannedCount int `json:"targetPlannedCount"`
TargetExistingCount int `json:"targetExistingCount"`
TargetCreateCount int `json:"targetCreateCount"`
InvalidContractCount int `json:"invalidContractCount"`
RuntimeTargetReadyCount int `json:"runtimeTargetReadyCount"`
RuntimeTargetMissingCount int `json:"runtimeTargetMissingCount"`
}
func (r RebuildTargetOwnerReconciler) Reconcile(ctx context.Context) (RebuildTargetOwnerReconcileResult, error) {
@@ -53,12 +55,18 @@ func (r RebuildTargetOwnerReconciler) Reconcile(ctx context.Context) (RebuildTar
result.InvalidContractCount++
continue
}
returned, ok := rebuildTargetOwnerReturnedReplica(volume, contract)
if !ok || !rebuildTargetOwnerRuntimeFactsReady(returned) {
result.RuntimeTargetMissingCount++
continue
}
result.RuntimeTargetReadyCount++
result.TargetPlannedCount++
if rebuildTargetOwnerHasTarget(volume, contract, targets) {
result.TargetExistingCount++
continue
}
obj := rebuildTargetOwnerObject(namespace, volume, contract)
obj := rebuildTargetOwnerObject(namespace, volume, contract, returned)
if !r.DryRun {
if err := r.Client.CreateSwBlockReplicaRebuild(ctx, namespace, obj); err != nil {
return result, err
@@ -79,6 +87,23 @@ func rebuildTargetOwnerContractReady(contract SwBlockVolumeCRDExecutorContract)
contract.ReplicaID != ""
}
func rebuildTargetOwnerReturnedReplica(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract) (SwBlockVolumeCRDReturnedReplica, bool) {
for _, returned := range volume.Status.ReplicaReintegrations {
if returned.ReplicaID == contract.ReplicaID {
return returned, true
}
}
return SwBlockVolumeCRDReturnedReplica{}, false
}
func rebuildTargetOwnerRuntimeFactsReady(returned SwBlockVolumeCRDReturnedReplica) bool {
return returned.RuntimeEndpoint != "" &&
returned.SessionID != 0 &&
returned.Epoch != 0 &&
returned.EndpointVersion != 0 &&
returned.FrontierHintLSN != 0
}
func rebuildTargetOwnerHasTarget(volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, targets []SwBlockReplicaRebuildObject) bool {
for _, target := range targets {
if target.Spec.ReplicaID != contract.ReplicaID {
@@ -97,7 +122,7 @@ func rebuildTargetOwnerHasTarget(volume SwBlockVolumeObject, contract SwBlockVol
return false
}
func rebuildTargetOwnerObject(namespace string, volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract) SwBlockReplicaRebuildObject {
func rebuildTargetOwnerObject(namespace string, volume SwBlockVolumeObject, contract SwBlockVolumeCRDExecutorContract, returned SwBlockVolumeCRDReturnedReplica) SwBlockReplicaRebuildObject {
return SwBlockReplicaRebuildObject{
Ref: OperatorObjectRef{
APIVersion: SwBlockVolumeAPIVersion,
@@ -106,10 +131,18 @@ func rebuildTargetOwnerObject(namespace string, volume SwBlockVolumeObject, cont
Name: rebuildTargetOwnerName(volume.Ref.Name, contract.ReplicaID),
},
Spec: SwBlockReplicaRebuildSpec{
VolumeName: volume.Ref.Name,
VolumeID: volume.Status.VolumeID,
PVCName: volume.Status.PVCName,
ReplicaID: contract.ReplicaID,
VolumeName: volume.Ref.Name,
VolumeID: volume.Status.VolumeID,
PVCName: volume.Status.PVCName,
ReplicaID: contract.ReplicaID,
RuntimeEndpoint: returned.RuntimeEndpoint,
TargetDataAddr: returned.TargetDataAddr,
SessionID: returned.SessionID,
Epoch: returned.Epoch,
EndpointVersion: returned.EndpointVersion,
FromLSN: returned.FromLSN,
FrontierHintLSN: returned.FrontierHintLSN,
BasePinLSN: returned.BasePinLSN,
},
}
}
@@ -21,7 +21,9 @@ func TestRebuildTargetOwnerDryRunPlansTargetWithoutCreate(t *testing.T) {
result.ContractCount != 1 ||
result.TargetPlannedCount != 1 ||
result.TargetCreateCount != 0 ||
result.InvalidContractCount != 0 {
result.InvalidContractCount != 0 ||
result.RuntimeTargetReadyCount != 1 ||
result.RuntimeTargetMissingCount != 0 {
t.Fatalf("result=%+v", result)
}
if len(client.creates) != 0 {
@@ -52,7 +54,15 @@ func TestRebuildTargetOwnerCreatesMissingTarget(t *testing.T) {
created.Spec.VolumeName != "demo-pvc" ||
created.Spec.VolumeID != "pvc-demo" ||
created.Spec.PVCName != "demo-pvc" ||
created.Spec.ReplicaID != "r2" {
created.Spec.ReplicaID != "r2" ||
created.Spec.RuntimeEndpoint != "http://127.0.0.1:23260/rebuild/runtime" ||
created.Spec.TargetDataAddr != "127.0.0.1:19103" ||
created.Spec.SessionID != 1001 ||
created.Spec.Epoch != 7 ||
created.Spec.EndpointVersion != 3 ||
created.Spec.FromLSN != 52 ||
created.Spec.FrontierHintLSN != 53 ||
created.Spec.BasePinLSN != 60 {
t.Fatalf("created=%+v", created)
}
if created.Status.State != "" {
@@ -89,6 +99,31 @@ func TestRebuildTargetOwnerSkipsExistingTarget(t *testing.T) {
}
}
func TestRebuildTargetOwnerDoesNotCreateTargetWithoutRuntimeFacts(t *testing.T) {
volume := rebuildTargetOwnerTestVolume()
volume.Status.ReplicaReintegrations[0].RuntimeEndpoint = ""
client := &fakeRebuildTargetOwnerClient{
volumes: []SwBlockVolumeObject{volume},
}
result, err := (RebuildTargetOwnerReconciler{
Namespace: "kube-system",
Client: client,
}).Reconcile(context.Background())
if err != nil {
t.Fatalf("reconcile: %v", err)
}
if result.ContractCount != 1 ||
result.RuntimeTargetMissingCount != 1 ||
result.RuntimeTargetReadyCount != 0 ||
result.TargetPlannedCount != 0 ||
result.TargetCreateCount != 0 {
t.Fatalf("result=%+v", result)
}
if len(client.creates) != 0 {
t.Fatalf("unexpected creates=%+v", client.creates)
}
}
func TestRebuildTargetOwnerRejectsInvalidContract(t *testing.T) {
volume := rebuildTargetOwnerTestVolume()
volume.Status.ExecutorContracts[0].AllowedMutationClass = []string{AuthorityExecutorAllowedMutationAckEligibility}
@@ -120,6 +155,25 @@ func rebuildTargetOwnerTestVolume() SwBlockVolumeObject {
Status: SwBlockVolumeCRDStatus{
VolumeID: "pvc-demo",
PVCName: "demo-pvc",
ReplicaReintegrations: []SwBlockVolumeCRDReturnedReplica{{
ReplicaID: "r2",
State: ReturnedReplicaStateRecovering,
ReasonCode: ReasonCandidateFrontierBehind,
FrontendFenced: true,
FrontendPrimaryReady: false,
DurableFrontierKnown: true,
DurableFrontierLSN: 51,
RequiredFrontierKnown: true,
RequiredFrontierLSN: 53,
RuntimeEndpoint: "http://127.0.0.1:23260/rebuild/runtime",
TargetDataAddr: "127.0.0.1:19103",
SessionID: 1001,
Epoch: 7,
EndpointVersion: 3,
FromLSN: 52,
FrontierHintLSN: 53,
BasePinLSN: 60,
}},
ExecutorContracts: []SwBlockVolumeCRDExecutorContract{{
ActionType: ManagedVolumeActionRebuildReturned,
ReplicaID: "r2",
+111 -182
View File
@@ -1,227 +1,156 @@
# Current Plan: Phase 61 Authority Executor Runtime Call-site
# Current Plan: Phase 63 Rebuild Runtime Target Contract
Status: complete.
Branch target: `phase54-returned-replica-reintegration-executor`
## Goal
Phase 60 proved the existing rebuild/catch-up data path below Kubernetes:
Phase 60 proved the existing engine/adapter/transport rebuild/catch-up data
path can move bytes and converge durable content. Phase 61 added the authority
executor runtime call-site seam. Phase 62 added an explicit HTTP runtime
transport.
Phase 63 closes the missing addressing contract between Kubernetes status and
that runtime transport. It does not add the blockvolume runtime endpoint yet.
Instead, it makes the next step safe by requiring exact runtime target facts
before any executor can issue rebuild traffic:
```text
engine / adapter -> transport/recovery -> byte-equal convergence
SwBlockVolume.status.replicaReintegrations[]
-> SwBlockReplicaRebuild.spec
-> authority-executor runtime request
```
Phase 61 connects the authority executor to a runtime call-site seam so rebuild
execution is no longer only a planned status write:
The key rule is fail-closed: do not infer runtime endpoint, data address,
session ID, epoch, endpoint version, or frontier hints from partial evidence.
## Delivered
### D1: Runtime Target Schema
`SwBlockVolume.status.replicaReintegrations[]` and
`SwBlockReplicaRebuild.spec` now carry the same runtime target fields:
```text
SwBlockVolume.status.executorContracts[]
-> authority-executor
-> AuthorityRebuildRuntime.ExecuteRebuild(...)
-> SwBlockReplicaRebuild.status running/caught_up/blocked
runtimeEndpoint
targetDataAddr
sessionID
epoch
endpointVersion
fromLsn
frontierHintLsn
basePinLsn
```
## Scope
The CRD tests assert camelCase schema fields and reject snake_case leaks.
In scope:
### D2: Target Owner Fail-Closed Creation
- Add a narrow `AuthorityRebuildRuntime` interface to the authority executor.
- Preserve Phase 59 behavior when no runtime is provided: write `planned`.
- When a runtime is provided, write `running`, invoke the runtime, then write
`caught_up` if terminal durable-frontier evidence covers the required LSN.
- Write `blocked` if the runtime fails or returns insufficient terminal
evidence.
- Keep non-claims explicit: no frontend publication, no failback, no ACK
eligibility mutation, no blockvolume RPC yet.
- Add a TestRunner gate for the call-site and status mapping.
Out of scope:
- No blockvolume RPC/HTTP/gRPC runtime transport.
- No Kubernetes pod-to-pod rebuild command.
- No RF=3 orchestration.
- No frontend publication.
- No failback.
- No ACK eligibility mutation.
## Deliverables
### D1: Runtime Call-site Interface
Status: complete.
Added:
`rebuild-target-owner` now creates a `SwBlockReplicaRebuild` target only when
the returned-replica fact carries complete runtime target evidence. If the
facts are missing, it reports:
```text
AuthorityRebuildRuntime
AuthorityRebuildRuntimeRequest
AuthorityRebuildRuntimeResult
runtime_target_missing=1
mutation_allowed=false
```
The authority executor uses this interface only for
`allowed-mutation-class=rebuild_traffic`.
No target is created from guessed data-path or session facts.
### D2: Status Mapping
### D3: Authority Executor Target Validation
Status: complete.
Runtime path status flow:
`authority-executor` can use the target's own `spec.runtimeEndpoint` when a
runtime is selected. Before posting to the runtime, it validates the target
contains:
```text
planned path: no runtime -> state=planned
runtime path: runtime invoked -> state=running -> state=caught_up
failure path: runtime error or insufficient frontier -> state=blocked
runtimeEndpoint
sessionID
epoch
endpointVersion
frontierHintLsn
```
### D3: Regression Tests
Status: PASS.
Added tests proving:
- planned status is preserved when no runtime exists;
- runtime request carries volume/replica/frontier/fencing evidence;
- successful runtime writes `running` then `caught_up`;
- failed runtime writes `blocked`.
### D4: TestRunner Gate
Status: QA PASS.
Added:
If any required runtime fact is missing, it writes blocked status:
```text
scripts/run-phase61-authority-executor-runtime-callsite-gate.sh
testops/scenarios/authority-executor-runtime-callsite-chain.yaml
state=blocked
reasonCode=rebuild_runtime_target_missing
```
Live run:
and does not POST to the runtime.
### D4: Gate
Gate files:
```text
20260623-212206-8afb authority-executor-runtime-callsite-chain PASS 28/28
scripts/run-phase63-rebuild-runtime-target-contract-gate.sh
testops/scenarios/rebuild-runtime-target-contract-chain.yaml
```
The gate proves schema, target-owner, executor, CLI, and Kubernetes writer
behavior using terminal key/value evidence.
## Non-Claims
Phase 63 does not claim:
```text
blockvolume_runtime_endpoint_wired
transport.StartRebuild called by blockvolume
frontend publication
failback
session ID inference
automatic recovery-session minting
```
Those belong to the next storage runtime phase. The blockvolume endpoint must
own or validate the recovery session before it calls `StartRebuild` or
`StartCatchUp`.
## Verification
Local:
```text
go test ./core/ops ./cmd/sw-block
C:\work\swblock.exe validate testops\scenarios\rebuild-runtime-target-contract-chain.yaml
```
Live:
```text
20260625-011115-b01b rebuild-runtime-target-contract-chain PASS 22/22
```
Terminal evidence:
```text
phase61_authority_executor_runtime_callsite_status=ok
runtime_callsite_invoked=true
rebuild_status_running_written=true
rebuild_status_caught_up_written=true
rebuild_status_blocked_on_runtime_failure=true
rebuild_traffic_started_when_runtime_invoked=true
durable_frontier_caught_up_after_runtime=true
planned_status_preserved_without_runtime=true
blockvolume_rpc_wired=false
frontend_publication_allowed=false
failback_allowed=false
ack_eligibility_mutation_allowed=false
```
### D5: Close Docs
Status: complete.
Sign-off:
```text
internal/docs/qa-assignments/phase61-authority-executor-runtime-callsite-qa-signoff.md
```
Finished plan:
```text
internal/docs/finished-plans/phase61_finishedplan_authority_executor_runtime_callsite.md
```
## Phase 62: Authority Executor HTTP Runtime Transport
Status: complete.
QA: PASS.
## Why
Phase 61 proved the authority executor can call an in-process
`AuthorityRebuildRuntime`. Phase 62 adds a concrete HTTP transport selected by
`--rebuild-runtime-url`, while staying honest that blockvolume does not yet have
a mutating rebuild control endpoint.
The current blockvolume status HTTP surface is read-only, and the current CRD
evidence does not carry enough session/addressing facts to safely call
`transport.StartRebuild` directly. Phase 62 therefore wires the executor to an
explicit runtime URL and keeps the blockvolume endpoint as Phase 63 work.
## D1: HTTP Runtime Client
Status: implemented; local tests PASS.
Added `HTTPAuthorityRebuildRuntime`, which:
- POSTs `AuthorityRebuildRuntimeRequest` as JSON;
- decodes terminal `AuthorityRebuildRuntimeResult`;
- treats non-2xx responses as execution failures, letting the reconciler write
blocked status.
## D2: CLI Wiring
Status: implemented; local tests PASS.
Added:
```text
sw-block ops authority-executor --rebuild-runtime-url <url>
```
The flag is accepted only with:
```text
--allowed-mutation-class rebuild_traffic
```
No runtime URL preserves the planned-only fallback from Phase 61.
## D3: Gate
Status: QA PASS.
Added:
```text
scripts/run-phase62-authority-executor-http-runtime-gate.sh
testops/scenarios/authority-executor-http-runtime-chain.yaml
```
Required terminal evidence:
```text
phase62_authority_executor_http_runtime_status=ok
http_runtime_posts_request=true
http_runtime_decodes_terminal_frontier=true
cli_rebuild_runtime_url_enabled=true
rebuild_status_running_written=true
rebuild_status_caught_up_written=true
phase63_rebuild_runtime_target_contract_status=ok
runtime_target_fields_schema_locked=true
runtime_target_camel_case=true
target_owner_requires_runtime_facts=true
target_owner_creates_only_when_runtime_facts_complete=true
target_owner_missing_runtime_no_target=true
authority_executor_missing_runtime_target_blocks=true
authority_executor_runtime_request_carries_target_lineage=true
runtime_target_can_drive_http_runtime=true
session_id_inferred=false
blockvolume_runtime_endpoint_wired=false
start_rebuild_called=false
frontend_publication_allowed=false
failback_allowed=false
```
Live run:
## Next
Phase 64 can add the blockvolume-side runtime endpoint only if it preserves the
same contract:
```text
20260624-170419-1409 authority-executor-http-runtime-chain PASS 26/26
exact target facts -> local assignment/session validation -> StartRebuild/StartCatchUp
```
## Exit
Phase 62 closed when local tests and the TestRunner gate proved the explicit
HTTP runtime transport can drive `running -> caught_up` / `blocked` status,
without claiming a blockvolume endpoint or frontend/failback behavior.
## Next: Phase 63
Add the blockvolume-side runtime endpoint/addressing contract. The first
acceptable slice is not "call StartRebuild somehow"; it must define the runtime
target evidence needed to safely identify the primary process, target replica,
session, epoch, endpoint version, and transport lane.
The endpoint must fail closed on stale assignment, wrong replica, missing
session, wrong epoch, or insufficient frontier evidence. NVMe should still wait
until the rebuild runtime endpoint has a real terminal-evidence gate.
@@ -0,0 +1,135 @@
# Phase 63 Finished Plan: Rebuild Runtime Target Contract
Status: complete.
QA: PASS.
## Goal
Phase 63 closes the addressing gap between returned-replica evidence,
`SwBlockReplicaRebuild` targets, and the Phase 62 authority-executor HTTP
runtime transport.
The main risk was not lack of code; it was unsafe inference. The existing
transport calls need exact runtime facts:
```text
StartRebuild(replicaID, sessionID, epoch, endpointVersion, frontierHint)
StartCatchUp(replicaID, sessionID, epoch, endpointVersion, fromLSN, frontierHint)
```
Phase 63 therefore schema-locks those facts and makes target creation and
execution fail closed when they are missing.
## Delivered
Code:
```text
core/ops/lifecycle_owner_controller.go
core/ops/operator_status_controller.go
core/ops/rebuild_target_owner_controller.go
core/ops/authority_executor_controller.go
cmd/sw-block/main.go
```
CRDs:
```text
charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml
charts/seaweed-block/crds/swblockreplicarebuilds.block.seaweedfs.com.yaml
```
Gate:
```text
scripts/run-phase63-rebuild-runtime-target-contract-gate.sh
testops/scenarios/rebuild-runtime-target-contract-chain.yaml
```
Docs:
```text
internal/docs/current-plan.md
internal/docs/qa-assignments/phase63-rebuild-runtime-target-contract-qa-signoff.md
internal/docs/product-roadmap.md
```
## Behavior
Runtime target fields now flow through:
```text
SwBlockVolume.status.replicaReintegrations[]
-> rebuild-target-owner
-> SwBlockReplicaRebuild.spec
-> authority-executor runtime request
```
Target-owner creates a rebuild target only when runtime target facts are
complete. Missing facts produce:
```text
runtime_target_missing=1
mutation_allowed=false
```
Authority-executor blocks runtime execution if a selected target lacks required
runtime facts:
```text
SwBlockReplicaRebuild.status.state=blocked
reasonCode=rebuild_runtime_target_missing
```
## Non-Claims
Phase 63 does not claim:
```text
blockvolume_runtime_endpoint_wired
transport.StartRebuild called by a blockvolume endpoint
frontend publication
failback
session ID inference
automatic recovery-session minting
```
## Verification
Local:
```text
go test ./core/ops ./cmd/sw-block
C:\work\swblock.exe validate testops\scenarios\rebuild-runtime-target-contract-chain.yaml
```
Live:
```text
20260625-011115-b01b rebuild-runtime-target-contract-chain PASS 22/22
```
Terminal evidence:
```text
phase63_rebuild_runtime_target_contract_status=ok
runtime_target_fields_schema_locked=true
target_owner_requires_runtime_facts=true
target_owner_missing_runtime_no_target=true
authority_executor_missing_runtime_target_blocks=true
authority_executor_runtime_request_carries_target_lineage=true
runtime_target_can_drive_http_runtime=true
session_id_inferred=false
blockvolume_runtime_endpoint_wired=false
start_rebuild_called=false
frontend_publication_allowed=false
failback_allowed=false
```
## Next
Phase 64 should wire the blockvolume-side runtime endpoint. The endpoint must
validate local assignment/session/epoch/endpoint-version facts and then call the
transport only from that validated local context. It must not accept arbitrary
frontend/failback mutation or guessed session state.
@@ -668,9 +668,15 @@ Approximate engineering effort if scope remains tight:
explicit HTTP runtime URL for `rebuild_traffic` execution and validates the
executor-to-runtime transport contract. It still does not claim a live
blockvolume endpoint.
- Phase 63 should wire a blockvolume-side runtime endpoint only after the CRD
or runtime target carries enough address/session evidence to call the data
path safely.
- Phase 63 Rebuild Runtime Target Contract is closed. It schema-locks the
runtime target facts (`runtimeEndpoint`, data address, session, epoch,
endpoint version, and frontier hints), copies them from returned-replica
status into `SwBlockReplicaRebuild.spec`, and makes target-owner /
authority-executor fail closed when those facts are missing. It still does
not call live `StartRebuild`.
- Phase 64 should wire a blockvolume-side runtime endpoint against the Phase 63
target contract. The endpoint must validate local assignment/session/epoch
facts before calling `StartRebuild` or `StartCatchUp`.
- Phase 41-44 are the Operation Layer v0.5 release train: lifecycle-owner
foundation, real API/admission proof, first bounded finalizer mutation, and
delete lifecycle close gate.
@@ -0,0 +1,113 @@
# Phase 63 Rebuild Runtime Target Contract QA Sign-off
Status: PASS.
Source branch: `phase54-returned-replica-reintegration-executor`
QA run:
```text
20260625-011115-b01b rebuild-runtime-target-contract-chain PASS 22/22
```
## Scope
Phase 63 closes the runtime target addressing contract needed before a live
blockvolume rebuild endpoint can be wired. It extends the returned-replica and
rebuild-target CRD surfaces with exact runtime facts and proves both target
creation and executor runtime calls fail closed when those facts are missing.
This is not a live `transport.StartRebuild` claim. The blockvolume runtime
endpoint is still unwired.
## Required Evidence
The gate must prove:
```text
phase63_rebuild_runtime_target_contract_status=ok
runtime_target_fields_schema_locked=true
runtime_target_camel_case=true
target_owner_requires_runtime_facts=true
target_owner_creates_only_when_runtime_facts_complete=true
target_owner_missing_runtime_no_target=true
authority_executor_missing_runtime_target_blocks=true
authority_executor_runtime_request_carries_target_lineage=true
runtime_target_can_drive_http_runtime=true
session_id_inferred=false
blockvolume_runtime_endpoint_wired=false
start_rebuild_called=false
frontend_publication_allowed=false
failback_allowed=false
```
## Terminal Evidence
From:
```text
results/20260625-011115-b01b/artifacts/remote-phases.tgz
```
Summary:
```text
phase63_rebuild_runtime_target_contract_status=ok
phase63_scope=rebuild_runtime_target_addressing_contract
blockvolume_runtime_endpoint_wired=false
start_rebuild_called=false
frontend_publication_allowed=false
failback_allowed=false
session_id_inferred=false
core_ops_runtime_target_contract_tests=pass
cmd_sw_block_runtime_target_contract_tests=pass
swblockvolume_returned_replica_runtime_schema=true
swblockreplicarebuild_runtime_spec_schema=true
target_owner_runtime_facts_ready_create=true
target_owner_runtime_facts_missing_no_create=true
authority_executor_runtime_target_missing_blocked=true
authority_executor_runtime_target_posts_lineage=true
kubernetes_writer_runtime_target_camel_case=true
cli_target_owner_runtime_ready=true
cli_target_owner_runtime_missing=true
cli_runtime_request_lineage=true
runtime_target_fields_schema_locked=true
runtime_target_camel_case=true
target_owner_requires_runtime_facts=true
target_owner_creates_only_when_runtime_facts_complete=true
target_owner_missing_runtime_no_target=true
authority_executor_missing_runtime_target_blocks=true
authority_executor_runtime_request_carries_target_lineage=true
runtime_target_can_drive_http_runtime=true
```
## Result Matrix
| Gate | Result | Evidence |
| --- | --- | --- |
| Runtime schema | PASS | `swblockvolume_returned_replica_runtime_schema=true`, `swblockreplicarebuild_runtime_spec_schema=true` |
| CRD casing | PASS | `runtime_target_camel_case=true`, `kubernetes_writer_runtime_target_camel_case=true` |
| Target-owner create | PASS | `target_owner_creates_only_when_runtime_facts_complete=true` |
| Target-owner fail closed | PASS | `target_owner_missing_runtime_no_target=true` |
| Executor fail closed | PASS | `authority_executor_missing_runtime_target_blocks=true` |
| Runtime request lineage | PASS | `authority_executor_runtime_request_carries_target_lineage=true`, `cli_runtime_request_lineage=true` |
| Non-claims | PASS | `blockvolume_runtime_endpoint_wired=false`, `start_rebuild_called=false`, `frontend_publication_allowed=false`, `failback_allowed=false`, `session_id_inferred=false` |
## Findings
Blocking: none.
Non-blocking:
- Phase 63 intentionally does not infer session ID or endpoint-version facts
from live peer status. The future blockvolume runtime endpoint must own or
validate the recovery session before calling `StartRebuild` or
`StartCatchUp`.
## Verdict
Phase 63 PASS. The authority path now has a schema-locked runtime target
contract, target-owner creates rebuild targets only from complete runtime facts,
and authority-executor blocks missing target facts before any runtime POST.
This makes Phase 64 eligible to add a real blockvolume runtime endpoint without
guessing data-path identity or session state.
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -euo pipefail
PRODUCT_ROOT="${1:-$(pwd)}"
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${PRODUCT_ROOT}/results/phase63-rebuild-runtime-target-contract-gate}"
SUMMARY="${ARTIFACT_DIR}/phase63-rebuild-runtime-target-contract-summary.txt"
OPS_LOG="${ARTIFACT_DIR}/core-ops-go-test.log"
CMD_LOG="${ARTIFACT_DIR}/cmd-sw-block-go-test.log"
mkdir -p "${ARTIFACT_DIR}"
: >"${SUMMARY}"
write_summary() {
echo "$*" | tee -a "${SUMMARY}" >/dev/null
}
require_log() {
local name="$1"
local pattern="$2"
local file="$3"
local found="false"
if grep -Eq -- "${pattern}" "${file}"; then
found="true"
fi
write_summary "${name}=${found}"
if [ "${found}" != "true" ]; then
echo "missing evidence ${name}: pattern ${pattern}" >&2
return 1
fi
}
write_summary "phase63_rebuild_runtime_target_contract_status=running"
write_summary "phase63_scope=rebuild_runtime_target_addressing_contract"
write_summary "blockvolume_runtime_endpoint_wired=false"
write_summary "start_rebuild_called=false"
write_summary "frontend_publication_allowed=false"
write_summary "failback_allowed=false"
write_summary "session_id_inferred=false"
OPS_PATTERN="TestPhase46D2SwBlockVolumeReturnedReplicaSchema|TestPhase57D1SwBlockReplicaRebuildTargetSchema|TestRebuildTargetOwnerCreatesMissingTarget|TestRebuildTargetOwnerDoesNotCreateTargetWithoutRuntimeFacts|TestAuthorityExecutorReconcilerBlocksWhenRuntimeTargetFactsMissing|TestAuthorityExecutorReconcilerExecutesRebuildRuntimeAndWritesCaughtUpStatus|TestKubernetesStatusClientCreatesSwBlockReplicaRebuildWithoutStatus"
CMD_PATTERN="TestOpsRebuildTargetOwnerCreatesTarget|TestOpsRebuildTargetOwnerDoesNotCreateTargetWhenRuntimeFactsMissing|TestOpsAuthorityExecutorRebuildRuntimeURLWritesCaughtUpStatus"
if (cd "${PRODUCT_ROOT}" && go test ./core/ops -run "${OPS_PATTERN}" -count=1 -v) >"${OPS_LOG}" 2>&1; then
write_summary "core_ops_runtime_target_contract_tests=pass"
else
write_summary "core_ops_runtime_target_contract_tests=fail"
cat "${OPS_LOG}" >&2 || true
exit 1
fi
if (cd "${PRODUCT_ROOT}" && go test ./cmd/sw-block -run "${CMD_PATTERN}" -count=1 -v) >"${CMD_LOG}" 2>&1; then
write_summary "cmd_sw_block_runtime_target_contract_tests=pass"
else
write_summary "cmd_sw_block_runtime_target_contract_tests=fail"
cat "${CMD_LOG}" >&2 || true
exit 1
fi
require_log "swblockvolume_returned_replica_runtime_schema" "^--- PASS: TestPhase46D2SwBlockVolumeReturnedReplicaSchema" "${OPS_LOG}"
require_log "swblockreplicarebuild_runtime_spec_schema" "^--- PASS: TestPhase57D1SwBlockReplicaRebuildTargetSchema" "${OPS_LOG}"
require_log "target_owner_runtime_facts_ready_create" "^--- PASS: TestRebuildTargetOwnerCreatesMissingTarget" "${OPS_LOG}"
require_log "target_owner_runtime_facts_missing_no_create" "^--- PASS: TestRebuildTargetOwnerDoesNotCreateTargetWithoutRuntimeFacts" "${OPS_LOG}"
require_log "authority_executor_runtime_target_missing_blocked" "^--- PASS: TestAuthorityExecutorReconcilerBlocksWhenRuntimeTargetFactsMissing" "${OPS_LOG}"
require_log "authority_executor_runtime_target_posts_lineage" "^--- PASS: TestAuthorityExecutorReconcilerExecutesRebuildRuntimeAndWritesCaughtUpStatus" "${OPS_LOG}"
require_log "kubernetes_writer_runtime_target_camel_case" "^--- PASS: TestKubernetesStatusClientCreatesSwBlockReplicaRebuildWithoutStatus" "${OPS_LOG}"
require_log "cli_target_owner_runtime_ready" "^--- PASS: TestOpsRebuildTargetOwnerCreatesTarget" "${CMD_LOG}"
require_log "cli_target_owner_runtime_missing" "^--- PASS: TestOpsRebuildTargetOwnerDoesNotCreateTargetWhenRuntimeFactsMissing" "${CMD_LOG}"
require_log "cli_runtime_request_lineage" "^--- PASS: TestOpsAuthorityExecutorRebuildRuntimeURLWritesCaughtUpStatus" "${CMD_LOG}"
write_summary "runtime_target_fields_schema_locked=true"
write_summary "runtime_target_camel_case=true"
write_summary "target_owner_requires_runtime_facts=true"
write_summary "target_owner_creates_only_when_runtime_facts_complete=true"
write_summary "target_owner_missing_runtime_no_target=true"
write_summary "authority_executor_missing_runtime_target_blocks=true"
write_summary "authority_executor_runtime_request_carries_target_lineage=true"
write_summary "runtime_target_can_drive_http_runtime=true"
write_summary "phase63_rebuild_runtime_target_contract_status=ok"
@@ -0,0 +1,112 @@
# Runner-native Phase 63 gate: rebuild runtime target addressing contract.
name: rebuild-runtime-target-contract-chain
timeout: 8m
env:
product_root: "/tmp/seaweed_block"
ssh_key: "C:\\work\\dev_server\\testdev_key"
topology:
nodes:
m02:
host: 192.168.1.184
user: testdev
key: "{{ ssh_key }}"
phases:
- name: rebuild_runtime_target_contract_gate
actions:
- action: exec
node: m02
timeout: 7m
cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract && cd {{ product_root }} && SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract bash scripts/run-phase63-rebuild-runtime-target-contract-gate.sh {{ product_root }}"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^phase63_rebuild_runtime_target_contract_status=ok$"
save_as: phase63_ok
- action: assert_greater
actual: "{{ phase63_ok }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^runtime_target_fields_schema_locked=true$"
save_as: schema_locked
- action: assert_greater
actual: "{{ schema_locked }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^target_owner_requires_runtime_facts=true$"
save_as: owner_requires_facts
- action: assert_greater
actual: "{{ owner_requires_facts }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^target_owner_missing_runtime_no_target=true$"
save_as: owner_missing_no_target
- action: assert_greater
actual: "{{ owner_missing_no_target }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^authority_executor_missing_runtime_target_blocks=true$"
save_as: executor_missing_blocks
- action: assert_greater
actual: "{{ executor_missing_blocks }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^authority_executor_runtime_request_carries_target_lineage=true$"
save_as: request_lineage
- action: assert_greater
actual: "{{ request_lineage }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^runtime_target_can_drive_http_runtime=true$"
save_as: target_drives_runtime
- action: assert_greater
actual: "{{ target_drives_runtime }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^session_id_inferred=false$"
save_as: no_session_inference
- action: assert_greater
actual: "{{ no_session_inference }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^blockvolume_runtime_endpoint_wired=false$"
save_as: endpoint_not_wired
- action: assert_greater
actual: "{{ endpoint_not_wired }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract/phase63-rebuild-runtime-target-contract-summary.txt"
pattern: "^start_rebuild_called=false$"
save_as: start_rebuild_not_called
- action: assert_greater
actual: "{{ start_rebuild_not_called }}"
threshold: "0"
- name: collect
always: true
actions:
- action: collect_path
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase63-rebuild-runtime-target-contract"
name: "remote-phases"
ignore_error: true