An open-source, faster Devin alternative
TypeScript
update the db on hibernate to not hit concurrent quota
Brian Reardonad21a966911a
diff --git a/cmd/server/main.go b/cmd/server/main.goindex 8000099e..69e33021 100644--- a/cmd/server/main.go+++ b/cmd/server/main.go@@ -148,11 +148,16 @@ func main() {OnHibernate: func(sandboxID string, result *sandbox.HibernateResult) {log.Printf("opensandbox: sandbox %s auto-hibernated (key=%s, size=%d bytes)",sandboxID, result.CheckpointKey, result.SizeBytes)- // Update PG session status if store is availableif opts.Store != nil {_ = opts.Store.UpdateSandboxSessionStatus(context.Background(), sandboxID, "hibernated", nil)}},+ OnKill: func(sandboxID string) {+ log.Printf("opensandbox: sandbox %s killed on timeout", sandboxID)+ if opts.Store != nil {+ _ = opts.Store.UpdateSandboxSessionStatus(context.Background(), sandboxID, "stopped", nil)+ }+ },})defer sbRouter.Close()opts.Router = sbRouterdiff --git a/cmd/worker/main.go b/cmd/worker/main.goindex 7d0ae615..c9dba021 100644--- a/cmd/worker/main.go+++ b/cmd/worker/main.go@@ -103,6 +103,15 @@ func main() {OnHibernate: func(sandboxID string, result *sandbox.HibernateResult) {log.Printf("opensandbox-worker: sandbox %s auto-hibernated (key=%s, size=%d bytes)",sandboxID, result.CheckpointKey, result.SizeBytes)+ if store != nil {+ _ = store.UpdateSandboxSessionStatus(context.Background(), sandboxID, "hibernated", nil)+ }+ },+ OnKill: func(sandboxID string) {+ log.Printf("opensandbox-worker: sandbox %s killed on timeout", sandboxID)+ if store != nil {+ _ = store.UpdateSandboxSessionStatus(context.Background(), sandboxID, "stopped", nil)+ }},})defer sbRouter.Close()diff --git a/internal/sandbox/router.go b/internal/sandbox/router.goindex a2942c0a..b4757718 100644--- a/internal/sandbox/router.go+++ b/internal/sandbox/router.go@@ -56,6 +56,7 @@ type RouterConfig struct {WorkerID stringDefaultTimeout time.DurationOnHibernate func(sandboxID string, result *HibernateResult)+ OnKill func(sandboxID string) // called when a sandbox is killed on timeout (hibernate failed or no checkpoint store)}// SandboxRouter routes sandbox interactions through a state machine,@@ -70,6 +71,7 @@ type SandboxRouter struct {workerID stringdefaultTimeout time.DurationonHibernate func(sandboxID string, result *HibernateResult)+ onKill func(sandboxID string)mu sync.RWMutexsandboxes map[string]*sandboxEntry@@ -90,6 +92,7 @@ func NewSandboxRouter(cfg RouterConfig) *SandboxRouter {workerID: cfg.WorkerID,defaultTimeout: dt,onHibernate: cfg.OnHibernate,+ onKill: cfg.OnKill,sandboxes: make(map[string]*sandboxEntry),}}@@ -464,6 +467,9 @@ func (r *SandboxRouter) onTimeout(sandboxID string) {log.Printf("router: hibernate failed for %s, killing: %v", sandboxID, err)_ = r.manager.podman.RemoveContainer(ctx, name, true)r.Unregister(sandboxID)+ if r.onKill != nil {+ r.onKill(sandboxID)+ }return}@@ -484,4 +490,7 @@ func (r *SandboxRouter) onTimeout(sandboxID string) {name := r.manager.ContainerName(sandboxID)_ = r.manager.podman.RemoveContainer(ctx, name, true)r.Unregister(sandboxID)+ if r.onKill != nil {+ r.onKill(sandboxID)+ }}