An open-source, faster Devin alternative
TypeScript
fixes
Brian Reardon07fa499f9fbf
diff --git a/.github/workflows/deploy-server.yml b/.github/workflows/deploy-server.ymlindex 11e02956..750a8348 100644--- a/.github/workflows/deploy-server.yml+++ b/.github/workflows/deploy-server.yml@@ -20,6 +20,9 @@ jobs:deploy:name: Blue-Green Deployruns-on: ubuntu-latest+ permissions:+ id-token: write+ contents: readsteps:- uses: actions/checkout@v4@@ -50,83 +53,100 @@ jobs:mkdir -p ~/.sshecho "$SSH_KEY" | base64 -d > ~/.ssh/deploy.pemchmod 600 ~/.ssh/deploy.pem- head -1 ~/.ssh/deploy.pem- wc -l < ~/.ssh/deploy.pem- ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy.pem -o BatchMode=yes ${{ env.SSH_USER }}@${{ secrets.CP2_IP }} "echo SSH_OK" || echo "SSH test failed"- ssh-keyscan -H ${{ secrets.CP1_IP }} >> ~/.ssh/known_hosts 2>/dev/null- ssh-keyscan -H ${{ secrets.CP2_IP }} >> ~/.ssh/known_hosts 2>/dev/nullecho -e "Host *\n StrictHostKeyChecking no\n UserKnownHostsFile /dev/null" >> ~/.ssh/configenv:SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY_B64 }}- - name: Deploy to CP2 (follower first)- run: |- echo "=== Deploying to CP2 (${{ secrets.CP2_IP }}) ==="- ssh -v -i ~/.ssh/deploy.pem -o StrictHostKeyChecking=no ${{ env.SSH_USER }}@${{ secrets.CP2_IP }} "echo SSH_OK" 2>&1 | grep -E "Offering|Authenticated|debug1.*identity|Permission|publickey" || true- scp -i ~/.ssh/deploy.pem -o StrictHostKeyChecking=no bin/opensandbox-server bin/web-dist.tar.gz \- ${{ env.SSH_USER }}@${{ secrets.CP2_IP }}:/tmp/-- ssh -i ~/.ssh/deploy.pem ${{ env.SSH_USER }}@${{ secrets.CP2_IP }} '- sudo systemctl stop opensandbox-server- sleep 1- sudo rm -f /usr/local/bin/opensandbox-server- sudo cp /tmp/opensandbox-server /usr/local/bin/opensandbox-server- sudo chmod +x /usr/local/bin/opensandbox-server- sudo mkdir -p /opt/opensandbox/web- sudo tar xzf /tmp/web-dist.tar.gz -C /opt/opensandbox/web- rm -f /tmp/opensandbox-server /tmp/web-dist.tar.gz- sudo systemctl start opensandbox-server- '-- - name: Wait for CP2 ready- run: |- for i in $(seq 1 15); do- STATUS=$(curl -sf --max-time 3 http://${{ secrets.CP2_IP }}:8080/readyz 2>/dev/null | jq -r .status 2>/dev/null)- if [ "$STATUS" = "ready" ]; then- echo "CP2 ready"- break- fi- echo "Waiting for CP2... ($i)"- sleep 2- done+ - name: Azure Login+ uses: azure/login@v2+ with:+ client-id: ${{ secrets.AZURE_CLIENT_ID }}+ tenant-id: ${{ secrets.AZURE_TENANT_ID }}+ subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}- - name: Deploy to CP1 (leader)+ - name: Discover control planesrun: |- echo "=== Deploying to CP1 (${{ secrets.CP1_IP }}) ==="- scp -i ~/.ssh/deploy.pem bin/opensandbox-server bin/web-dist.tar.gz \- ${{ env.SSH_USER }}@${{ secrets.CP1_IP }}:/tmp/-- ssh -i ~/.ssh/deploy.pem ${{ env.SSH_USER }}@${{ secrets.CP1_IP }} '- sudo systemctl stop opensandbox-server- sleep 1- sudo rm -f /usr/local/bin/opensandbox-server- sudo cp /tmp/opensandbox-server /usr/local/bin/opensandbox-server- sudo chmod +x /usr/local/bin/opensandbox-server- sudo mkdir -p /opt/opensandbox/web- sudo tar xzf /tmp/web-dist.tar.gz -C /opt/opensandbox/web- rm -f /tmp/opensandbox-server /tmp/web-dist.tar.gz- sudo systemctl start opensandbox-server- '-- - name: Wait for CP1 ready+ CPS=$(az vm list \+ --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \+ --show-details \+ --query "[?contains(name,'controlplane')].publicIps" \+ -o tsv 2>/dev/null | tr '\n' ',' | sed 's/,$//')+ echo "Discovered CPs: $CPS"+ echo "CP_IPS=$CPS" >> $GITHUB_ENV++ if [ -z "$CPS" ]; then+ echo "ERROR: No control plane VMs found"+ exit 1+ fi++ - name: Deploy to all control planesrun: |- for i in $(seq 1 15); do- STATUS=$(curl -sf --max-time 3 http://${{ secrets.CP1_IP }}:8080/readyz 2>/dev/null | jq -r .status 2>/dev/null)- if [ "$STATUS" = "ready" ]; then- echo "CP1 ready"- break- fi- echo "Waiting for CP1... ($i)"- sleep 2+ # CP_IPS discovered from Azure — comma-separated list+ IFS=',' read -ra CPS <<< "$CP_IPS"++ if [ ${#CPS[@]} -eq 0 ]; then+ echo "ERROR: No control planes found"+ exit 1+ fi++ deploy_one() {+ local IP=$1+ local LABEL=$2+ echo ""+ echo "=== Deploying to $LABEL ($IP) ==="++ scp -i ~/.ssh/deploy.pem bin/opensandbox-server bin/web-dist.tar.gz \+ ${{ env.SSH_USER }}@${IP}:/tmp/++ ssh -i ~/.ssh/deploy.pem ${{ env.SSH_USER }}@${IP} '+ sudo systemctl stop opensandbox-server+ sleep 1+ sudo rm -f /usr/local/bin/opensandbox-server+ sudo cp /tmp/opensandbox-server /usr/local/bin/opensandbox-server+ sudo chmod +x /usr/local/bin/opensandbox-server+ sudo mkdir -p /opt/opensandbox/web+ sudo tar xzf /tmp/web-dist.tar.gz -C /opt/opensandbox/web+ rm -f /tmp/opensandbox-server /tmp/web-dist.tar.gz+ sudo systemctl start opensandbox-server+ '++ echo "Waiting for $LABEL to be ready..."+ for i in $(seq 1 20); do+ STATUS=$(curl -sf --max-time 3 http://${IP}:8080/readyz 2>/dev/null | jq -r .status 2>/dev/null)+ if [ "$STATUS" = "ready" ]; then+ echo "$LABEL ready"+ return 0+ fi+ sleep 3+ done+ echo "WARNING: $LABEL not ready after 60s"+ return 1+ }++ # Deploy followers first (all except the first IP)+ for i in $(seq $((${#CPS[@]}-1)) -1 1); do+ deploy_one "${CPS[$i]}" "CP$((i+1))"done+ # Deploy leader last (first IP)+ deploy_one "${CPS[0]}" "CP1"+- name: Smoke testrun: |- # Create sandbox via CP1, exec via CP2, destroy+ IFS=',' read -ra CPS <<< "$CP_IPS"+ LEADER="${CPS[0]}"+ # Pick a follower for cross-CP test (or use leader if only 1 CP)+ if [ ${#CPS[@]} -gt 1 ]; then+ FOLLOWER="${CPS[1]}"+ else+ FOLLOWER="$LEADER"+ fi++ # Create sandbox via leaderSB=$(curl -sf --max-time 30 \-H "Content-Type: application/json" \-H "X-API-Key: ${{ secrets.API_KEY }}" \- -X POST "http://${{ secrets.CP1_IP }}:8080/api/sandboxes" \+ -X POST "http://${LEADER}:8080/api/sandboxes" \-d '{"timeout":60}' | jq -r .sandboxID)if [ -z "$SB" ] || [ "$SB" = "null" ]; then@@ -135,14 +155,14 @@ jobs:fiecho "Created sandbox: $SB"- # Wait for sandbox to be ready, then exec with retry+ # Exec via follower with retryRESULT=""for attempt in 1 2 3; dosleep 5RESULT=$(curl -sf --max-time 15 \-H "Content-Type: application/json" \-H "X-API-Key: ${{ secrets.API_KEY }}" \- -X POST "http://${{ secrets.CP2_IP }}:8080/api/sandboxes/$SB/exec/run" \+ -X POST "http://${FOLLOWER}:8080/api/sandboxes/$SB/exec/run" \-d '{"cmd":"echo","args":["deploy-ok"],"timeout":10}' | jq -r .stdout 2>/dev/null || echo "")echo "Attempt $attempt: '$RESULT'"echo "$RESULT" | grep -q "deploy-ok" && break@@ -150,10 +170,10 @@ jobs:curl -sf --max-time 10 \-H "X-API-Key: ${{ secrets.API_KEY }}" \- -X DELETE "http://${{ secrets.CP1_IP }}:8080/api/sandboxes/$SB" || true+ -X DELETE "http://${LEADER}:8080/api/sandboxes/$SB" || trueif echo "$RESULT" | grep -q "deploy-ok"; then- echo "Smoke test PASSED"+ echo "Smoke test PASSED (create on $LEADER, exec on $FOLLOWER)"elseecho "Smoke test FAILED: exec returned '$RESULT'"exit 1@@ -161,8 +181,10 @@ jobs:- name: Summaryrun: |+ IFS=',' read -ra CPS <<< "$CP_IPS"echo "## Control Plane Deploy Complete" >> $GITHUB_STEP_SUMMARYecho "- **Version:** $VERSION" >> $GITHUB_STEP_SUMMARY- echo "- **CP1:** ${{ secrets.CP1_IP }} ✅" >> $GITHUB_STEP_SUMMARY- echo "- **CP2:** ${{ secrets.CP2_IP }} ✅" >> $GITHUB_STEP_SUMMARY- echo "- **Smoke test:** Passed (create CP1 → exec CP2)" >> $GITHUB_STEP_SUMMARY+ for i in "${!CPS[@]}"; do+ echo "- **CP$((i+1)):** ${CPS[$i]} ✅" >> $GITHUB_STEP_SUMMARY+ done+ echo "- **Smoke test:** Passed" >> $GITHUB_STEP_SUMMARYdiff --git a/cmd/server/main.go b/cmd/server/main.goindex 2c42d4c3..76f18a35 100644--- a/cmd/server/main.go+++ b/cmd/server/main.go@@ -146,7 +146,6 @@ func main() {redisRegistry.Start()defer redisRegistry.Stop()opts.WorkerRegistry = redisRegistry- redisRegistry.SetIdleReserve(cfg.IdleReserveWorkers)opts.RedisClient = redisRegistry.RedisClient()log.Println("opensandbox: Redis worker registry started")diff --git a/cmd/worker/main.go b/cmd/worker/main.goindex 64c46fa1..953c4e44 100644--- a/cmd/worker/main.go+++ b/cmd/worker/main.go@@ -717,3 +717,4 @@ func recoverLocalQEMU(ctx context.Context, qmMgr *qm.Manager, store *db.Store, c}// build trigger 1775519665+// rolling replace test 1775598764diff --git a/internal/api/sandbox.go b/internal/api/sandbox.goindex 608af0dc..f29e3561 100644--- a/internal/api/sandbox.go+++ b/internal/api/sandbox.go@@ -57,11 +57,12 @@ func (s *Server) createSandbox(c echo.Context) error {"error": "upgrade to pro for larger instances",})}- // Force 4GB/1vCPU if not specified- if cfg.MemoryMB == 0 {- cfg.MemoryMB = 4096- cfg.CpuCount = 1- }+ }++ // Default to 4GB/1vCPU if not specified (all plans)+ if cfg.MemoryMB == 0 {+ cfg.MemoryMB = 4096+ cfg.CpuCount = 1}}}diff --git a/internal/controlplane/redis_registry.go b/internal/controlplane/redis_registry.goindex bb8179c1..bbee1a62 100644--- a/internal/controlplane/redis_registry.go+++ b/internal/controlplane/redis_registry.go@@ -40,20 +40,12 @@ type WorkerEntry struct {// backed by Redis pub/sub for real-time updates and periodic SCAN for reconciliation.// It also maintains a persistent gRPC connection pool to workers.type RedisWorkerRegistry struct {- rdb *redis.Client- mu sync.RWMutex- workers map[string]*WorkerEntry // in-memory hot cache- conns map[string]*grpc.ClientConn // persistent gRPC connections- clients map[string]pb.SandboxWorkerClient // cached gRPC clients- idleReserve int // target idle workers to protect from routing- stop chan struct{}-}--// SetIdleReserve configures how many idle workers to protect from normal routing.-func (r *RedisWorkerRegistry) SetIdleReserve(n int) {- r.mu.Lock()- defer r.mu.Unlock()- r.idleReserve = n+ rdb *redis.Client+ mu sync.RWMutex+ workers map[string]*WorkerEntry // in-memory hot cache+ conns map[string]*grpc.ClientConn // persistent gRPC connections+ clients map[string]pb.SandboxWorkerClient // cached gRPC clients+ stop chan struct{}}// RedisClient returns the underlying Redis client (for health checks, shared state, etc.).@@ -322,59 +314,47 @@ func (r *RedisWorkerRegistry) GetLeastLoadedWorker(region string) (*WorkerEntry,var best *WorkerEntrybestScore := -1.0- // Count idle workers to decide whether to protect reserves- idleCount := 0- for _, w := range r.workers {- if (region == "" || w.Region == region) && w.Current == 0 {- idleCount++- }- }- protectReserves := idleCount <= r.idleReserve-- // Bin-pack strategy: fill active workers to capacity, then overflow active- // workers (if reserves need protection), then use idle reserves, then- // over-provision across all workers.+ // Bin-pack strategy using committed memory:+ // 1. Active workers with memory headroom → fill the most-loaded first+ // 2. Idle workers → use for burst (scaler replaces idle reserves in background)+ // 3. Workers with no headroom data → fall back to sandbox count//- // Priority (when reserves are protected):- // 1. Active worker with capacity → score 100+- // 2. Over-capacity active worker → score 1-10- // 3. Idle reserve worker → score 0.1 (only when no active option)- //- // Priority (when surplus idle workers exist):- // 1. Active worker with capacity → score 100+- // 2. Idle worker (surplus, safe to use) → score 50- // 3. Over-capacity active worker → score 1-10+ // Idle reserves are NOT protected from routing — they exist for burst absorption.+ // The scaler will notice the idle count dropped and launch replacements.scoreWorker := func(w *WorkerEntry) float64 {if w.CPUPct > 90 || w.MemPct > 90 || w.DiskPct > 90 {- return -1 // skip+ return -1 // skip — under heavy pressure}- remaining := w.Capacity - w.Current- resourceScore := (100.0 - w.CPUPct) / 100.0 * (100.0 - w.MemPct) / 100.0 * (100.0 - w.DiskPct) / 100.0- if remaining <= 0 {- if w.Current == 0 {- return -1 // shouldn't happen but guard+ // Use committed memory if available (preferred — reflects real capacity)+ if w.TotalMemoryMB > 0 {+ reserveMB := w.TotalMemoryMB / 5 // 20% for OS+ usableMB := w.TotalMemoryMB - reserveMB+ committedPct := float64(w.CommittedMemoryMB) / float64(usableMB) // 0.0 to 1.0+++ if committedPct >= 1.0 {+ // No headroom — last resort, spread by how far over+ return 0.01 / (1.0 + committedPct)}- // Over capacity: spread evenly among overloaded workers- overBy := float64(w.Current - w.Capacity)- if protectReserves {- // Score 1-10: above idle reserves (0.1) so we overflow active- // workers before touching reserves- return 10.0 * resourceScore / (1.0 + overBy)+ if w.Current == 0 {+ // Idle worker — available for burst. Score below active workers+ // so we fill active ones first, but don't block routing here.+ return 10.0 * (1.0 - committedPct)}- return 0.01 * resourceScore / (1.0 + overBy)+ // Active with headroom: higher committed% = higher score (bin-pack).+ // This fills workers proportionally to their memory, not sandbox count.+ return 100.0 + committedPct*50.0+ }++ // Fallback: no committed memory data — use sandbox count heuristic+ remaining := w.Capacity - w.Current+ if remaining <= 0 {+ return 0.01 / float64(1+w.Current)}if w.Current == 0 {- if protectReserves {- // Reserves protected: score very low so active workers (including- // over-capacity) get used first. Only used as absolute last resort.- return 0.001 * resourceScore- }- // Surplus idle workers: safe to use, score below active but above over-capacity- return 50.0 * resourceScore+ return 10.0}- // Active with capacity: highest priority (bin-pack).- return 100.0 + float64(w.Current)*10.0 + float64(remaining)*resourceScore+ return 100.0 + float64(w.Current)*10.0}// First pass: try workers in the requested region