@@ -52,6 +52,17 @@ func main() {
5252 defer fcMgr .Close ()
5353 log .Println ("opensandbox-worker: Firecracker VM manager initialized" )
5454
55+ // Clean up orphaned Firecracker processes + TAP devices BEFORE starting golden snapshot.
56+ // Must run first to avoid killing the golden snapshot VM (race condition).
57+ fcMgr .CleanupOrphanedProcesses ()
58+
59+ // Prepare golden snapshot for fast default VM creation (~500ms vs ~2s cold boot)
60+ go func () {
61+ if err := fcMgr .PrepareGoldenSnapshot (); err != nil {
62+ log .Printf ("opensandbox-worker: golden snapshot preparation failed: %v (cold boot fallback active)" , err )
63+ }
64+ }()
65+
5566 // The Firecracker manager implements sandbox.Manager
5667 var mgr sandbox.Manager = fcMgr
5768
@@ -149,9 +160,6 @@ func main() {
149160 defer store .Close ()
150161 log .Println ("opensandbox-worker: PostgreSQL store connected (auto-wake enabled)" )
151162
152- // Kill orphaned Firecracker processes + TAP devices from previous run
153- fcMgr .CleanupOrphanedProcesses ()
154-
155163 // Local NVMe recovery: scan for sandbox data left from a previous run
156164 recoveries := fcMgr .RecoverLocalSandboxes ()
157165 if len (recoveries ) > 0 {
@@ -163,14 +171,14 @@ func main() {
163171 continue
164172 }
165173 if r .HasSnapshot {
166- // Full snapshot on NVMe — create checkpoint record so doWake finds local files
167- _ , _ = store .CreateCheckpoint (ctx , r .SandboxID , session .OrgID ,
174+ // Full snapshot on NVMe — create hibernation record so doWake finds local files
175+ _ , _ = store .CreateHibernation (ctx , r .SandboxID , session .OrgID ,
168176 "local://" + r .SandboxID , 0 , session .Region , session .Template , session .Config )
169177 _ = store .UpdateSandboxSessionStatus (ctx , r .SandboxID , "hibernated" , nil )
170178 snapshotCount ++
171179 } else {
172- // Workspace only — create local sentinel checkpoint for cold boot
173- _ , _ = store .CreateCheckpoint (ctx , r .SandboxID , session .OrgID ,
180+ // Workspace only — create local sentinel hibernation for cold boot
181+ _ , _ = store .CreateHibernation (ctx , r .SandboxID , session .OrgID ,
174182 "local://" + r .SandboxID , 0 , session .Region , session .Template , session .Config )
175183 _ = store .UpdateSandboxSessionStatus (ctx , r .SandboxID , "hibernated" , nil )
176184 workspaceCount ++
@@ -199,13 +207,13 @@ func main() {
199207 WorkerID : cfg .WorkerID ,
200208 OnHibernate : func (sandboxID string , result * sandbox.HibernateResult ) {
201209 log .Printf ("opensandbox-worker: sandbox %s auto-hibernated (key=%s, size=%d bytes)" ,
202- sandboxID , result .CheckpointKey , result .SizeBytes )
210+ sandboxID , result .HibernationKey , result .SizeBytes )
203211 if store != nil {
204- // Create checkpoint record so wake-on-request can find it
212+ // Create hibernation record so wake-on-request can find it
205213 session , err := store .GetSandboxSession (context .Background (), sandboxID )
206214 if err == nil {
207- _ , _ = store .CreateCheckpoint (context .Background (), sandboxID , session .OrgID ,
208- result .CheckpointKey , result .SizeBytes , session .Region , session .Template , session .Config )
215+ _ , _ = store .CreateHibernation (context .Background (), sandboxID , session .OrgID ,
216+ result .HibernationKey , result .SizeBytes , session .Region , session .Template , session .Config )
209217 }
210218 _ = store .UpdateSandboxSessionStatus (context .Background (), sandboxID , "hibernated" , nil )
211219 }
@@ -346,12 +354,12 @@ func main() {
346354 }
347355 continue
348356 }
349- log .Printf ("opensandbox-worker: hibernated %s (key=%s)" , r .SandboxID , r .CheckpointKey )
357+ log .Printf ("opensandbox-worker: hibernated %s (key=%s)" , r .SandboxID , r .HibernationKey )
350358 if store != nil {
351359 session , err := store .GetSandboxSession (context .Background (), r .SandboxID )
352360 if err == nil {
353- _ , _ = store .CreateCheckpoint (context .Background (), r .SandboxID , session .OrgID ,
354- r .CheckpointKey , 0 , session .Region , session .Template , session .Config )
361+ _ , _ = store .CreateHibernation (context .Background (), r .SandboxID , session .OrgID ,
362+ r .HibernationKey , 0 , session .Region , session .Template , session .Config )
355363 _ = store .UpdateSandboxSessionStatus (context .Background (), r .SandboxID , "hibernated" , nil )
356364 }
357365 }
0 commit comments