feat(agentcompat): add shared runtime contracts

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
naiba
2026-07-20 04:25:03 +00:00
co-authored by naiba/CloudCode
parent a416e3bf29
commit 8b47ff141f
8 changed files with 836 additions and 64 deletions
+4 -4
View File
@@ -30,10 +30,10 @@ func NewServerClass() *ServerClass {
var servers []model.Server
DB.Find(&servers)
for _, s := range servers {
innerS := s
model.InitServer(&innerS)
sc.list[innerS.ID] = &innerS
for i := range servers {
innerS := &servers[i]
model.InitServer(innerS)
sc.list[innerS.ID] = innerS
sc.uuidToID[innerS.UUID] = innerS.ID
}
sc.sortList()
+10 -6
View File
@@ -79,9 +79,9 @@ const defaultRevertDeliveryRecoveryWindow = defaultServerTransferTimeout
// subscribers. All mutating operations go through methods so DB and in-memory
// state stay in sync.
type ServerTransferClass struct {
mu sync.RWMutex
pending map[uint64]*model.ServerTransfer
revertDeliveries map[uint64]*model.ServerTransfer
mu sync.RWMutex
pending map[uint64]*model.ServerTransfer
revertDeliveries map[uint64]*model.ServerTransfer
// revertRecovery holds RevertHandshakeSecrets the dashboard has pushed
// but the agent has not yet acknowledged, in the window between Cancel/
// Fail/Timeout and either the agent's reconnect (which MarkRevertDelivered
@@ -179,10 +179,14 @@ var ErrAgentTooOldForTransfer = fmt.Errorf("agent build older than %s does not s
// never reported) so callers can defer the decision; PushIfOnline re-checks
// at push time.
func agentSupportsTransfer(s *model.Server) bool {
if s == nil || s.Host == nil {
if s == nil {
return true
}
v := strings.TrimSpace(s.Host.Version)
runtime := s.RuntimeSnapshot()
if runtime.Host == nil {
return true
}
v := strings.TrimSpace(runtime.Host.Version)
if v == "" {
return true
}
@@ -1103,7 +1107,7 @@ func (c *ServerTransferClass) revertTransition(transferID uint64, newStatus mode
// back to a possibly-deleted FromUserID (regression pinned by
// TestOnUserDeleteCancelsPendingTransfersAwayFromDeletedUser).
var transitionedByThisCall bool
err := DB.Transaction(func(tx *gorm.DB) error {
err := DB.Transaction(func(tx *gorm.DB) error {
if err := tx.First(&t, transferID).Error; err != nil {
return err
}