Skip to content

Commit ee71809

Browse files
committed
feat: guard against out-of-order webhook delivery in deploy auto-promote
When webhooks arrive out of order (e.g. commit@11:40, commit@11:44, commit@11:39), the oldest commit could deploy last and get auto-promoted to live, overtaking a newer commit. This adds a timestamp comparison before auto-promoting: if the current live deployment has a newer git commit timestamp, the new deployment skips auto-promote. Only fires when both timestamps are valid (git-sourced deployments). CLI/docker uploads (no timestamp) are unaffected.
1 parent af854a8 commit ee71809

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

svc/ctrl/worker/deploy/deploy_handler.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,27 @@ func (w *Workflow) Deploy(ctx restate.WorkflowSharedContext, req *hydrav1.Deploy
495495
}
496496
}
497497

498+
// Guard against out-of-order webhook delivery: if the current live deployment
499+
// has a newer commit timestamp than this deployment, skip auto-promote.
500+
// Only applies when both timestamps are valid (git-sourced deployments).
501+
// CLI/docker uploads (Valid == false) skip this guard entirely.
502+
if autoPromote && app.LiveDeploymentID.Valid && deployment.GitCommitTimestamp.Valid {
503+
liveDeployment, liveErr := restate.Run(ctx, func(runCtx restate.RunContext) (db.Deployment, error) {
504+
return db.Query.FindDeploymentById(runCtx, w.db.RO(), app.LiveDeploymentID.String)
505+
}, restate.WithName("fetch live deployment for timestamp check"))
506+
if liveErr == nil && liveDeployment.GitCommitTimestamp.Valid {
507+
if deployment.GitCommitTimestamp.Int64 < liveDeployment.GitCommitTimestamp.Int64 {
508+
autoPromote = false
509+
logger.Info("skipping auto-promote: deployment commit is older than current live",
510+
"deployment_id", deployment.ID,
511+
"deployment_timestamp", deployment.GitCommitTimestamp.Int64,
512+
"live_deployment_id", liveDeployment.ID,
513+
"live_timestamp", liveDeployment.GitCommitTimestamp.Int64,
514+
)
515+
}
516+
}
517+
}
518+
498519
// Fetch sticky routes for this environment
499520
stickyTypes := []db.FrontlineRoutesSticky{db.FrontlineRoutesStickyEnvironment}
500521
if autoPromote {

0 commit comments

Comments
 (0)