An open-source, faster Devin alternative
TypeScript
fix some migration bugs
Brian Reardon61ab6918e32f
diff --git a/deploy/packer/round.txt b/deploy/packer/round.txtindex 19793c84..c06b7a26 100644--- a/deploy/packer/round.txt+++ b/deploy/packer/round.txt@@ -1 +1 @@-round-1+round-2diff --git a/internal/controlplane/scaler.go b/internal/controlplane/scaler.goindex 650324ca..c046972f 100644--- a/internal/controlplane/scaler.go+++ b/internal/controlplane/scaler.go@@ -206,9 +206,12 @@ func (s *Scaler) evaluate() {ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)defer cancel()- // Refresh AMI from SSM every ~60s (every 2nd tick at 30s interval)+ // Refresh AMI from SSM/KV every ~60s. Also force a refresh on the very first+ // evaluate tick (refreshCount == 0) so targetWorkerVersion is known before+ // any scale-down decision — prevents the rolling-replace target from being+ // mistakenly drained when utilization is low.s.refreshCount++- if s.refreshCount%2 == 0 {+ if s.refreshCount == 1 || s.refreshCount%2 == 0 {if refresher, ok := s.pool.(AMIRefresher); ok {if _, version, err := refresher.RefreshAMI(ctx); err != nil {log.Printf("scaler: AMI refresh failed: %v", err)@@ -664,8 +667,19 @@ func (s *Scaler) smartScaleDown(_ context.Context, region string, workers []*Worreturn}- // Don't scale down while a rolling replace is in progress- if s.targetWorkerVersion != "" {+ // If workers report a WorkerVersion but our target version isn't known yet+ // (first boot, before the initial AMI/KV refresh), don't scale down — we+ // can't tell stale from current, and blindly picking the least-loaded+ // worker will happily delete a rolling-replace target that just launched+ // empty.+ if s.targetWorkerVersion == "" {+ for _, w := range workers {+ if w.WorkerVersion != "" {+ return+ }+ }+ } else {+ // Target version known: ensure no stale workers remain before scaling down.for _, w := range workers {if w.WorkerVersion != s.targetWorkerVersion && w.WorkerVersion != "" {return // stale workers still exist, let rolling replace handle it@@ -1173,8 +1187,13 @@ func (s *Scaler) liveMigrateSandbox(ctx context.Context, sandboxID, sourceWorkerlog.Printf("scaler: migrate %s: QMP migration complete (%dms)", sandboxID, time.Since(t0).Milliseconds())- // Step 4: Complete on target (reconnect agent, patch network)- completeCtx, completeCancel := context.WithTimeout(ctx, 30*time.Second)+ // Step 4: Complete on target (reconnect agent, patch network).+ // Agent socket reconnect is bounded to 10s and patchGuestNetwork runs+ // several guest-side exec commands that can be slow on a freshly resumed+ // VM (especially post-rebase). 30s was too tight — a 3min window is+ // generous but still bounded so we eventually fail loud if something is+ // truly stuck.+ completeCtx, completeCancel := context.WithTimeout(ctx, 3*time.Minute)defer completeCancel()_, err = targetClient.CompleteMigrationIncoming(completeCtx, &pb.CompleteMigrationIncomingRequest{SandboxId: sandboxID,diff --git a/internal/storage/blob.go b/internal/storage/blob.goindex 1217a4a7..8a81ca86 100644--- a/internal/storage/blob.go+++ b/internal/storage/blob.go@@ -10,11 +10,18 @@ package storageimport ("context"+ "errors""fmt""io""strings")+// ErrNotFound is returned by Head / Download when the object does not exist.+// Callers should use errors.Is(err, ErrNotFound) — other errors (auth, network,+// etc.) must not be treated as "not found" to avoid triggering spurious+// uploads/retries on real outages.+var ErrNotFound = errors.New("blob: object not found")+// BlobClient abstracts remote object storage operations.// Implementations: azureBlobClient (Azure Blob Storage), s3BlobClient (AWS S3).type BlobClient interface {diff --git a/internal/storage/blob_azure.go b/internal/storage/blob_azure.goindex 229d7c1d..d570c000 100644--- a/internal/storage/blob_azure.go+++ b/internal/storage/blob_azure.go@@ -7,6 +7,7 @@ import ("strings""github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"+ "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror")// azureBlobClient implements BlobClient using the native Azure Blob SDK.@@ -79,6 +80,9 @@ func (c *azureBlobClient) Head(ctx context.Context, container, key string) (int6}resp, err := c.client.ServiceClient().NewContainerClient(container).NewBlobClient(normalizeKey(container, key)).GetProperties(ctx, nil)if err != nil {+ if bloberror.HasCode(err, bloberror.BlobNotFound) {+ return 0, ErrNotFound+ }return 0, err}if resp.ContentLength == nil {diff --git a/internal/storage/blob_s3.go b/internal/storage/blob_s3.goindex 4c8711b6..aef46b2e 100644--- a/internal/storage/blob_s3.go+++ b/internal/storage/blob_s3.go@@ -2,6 +2,7 @@ package storageimport ("context"+ "errors""fmt""io""strings"@@ -10,6 +11,7 @@ import (awsconfig "github.com/aws/aws-sdk-go-v2/config""github.com/aws/aws-sdk-go-v2/credentials""github.com/aws/aws-sdk-go-v2/service/s3"+ s3types "github.com/aws/aws-sdk-go-v2/service/s3/types")// s3BlobClient implements BlobClient using the AWS S3 SDK.@@ -100,6 +102,11 @@ func (c *s3BlobClient) Head(ctx context.Context, bucket, key string) (int64, errKey: aws.String(key),})if err != nil {+ var nsk *s3types.NoSuchKey+ var nf *s3types.NotFound+ if errors.As(err, &nsk) || errors.As(err, &nf) {+ return 0, ErrNotFound+ }return 0, err}return aws.ToInt64(resp.ContentLength), nildiff --git a/internal/storage/s3.go b/internal/storage/s3.goindex e52f9ac1..cc8905b0 100644--- a/internal/storage/s3.go+++ b/internal/storage/s3.go@@ -3,6 +3,7 @@ package storageimport ("context""crypto/sha256"+ "errors""fmt""io""log"@@ -106,10 +107,13 @@ func (s *CheckpointStore) CacheHit(key string) bool {// Exists checks whether an object exists in S3/blob storage.func (s *CheckpointStore) Exists(ctx context.Context, key string) (bool, error) {_, err := s.blob.Head(ctx, s.bucket, key)- if err != nil {- return false, err+ if err == nil {+ return true, nil+ }+ if errors.Is(err, ErrNotFound) {+ return false, nil}- return true, nil+ return false, err}func (s *CheckpointStore) Upload(ctx context.Context, key, localPath string) (int64, error) {