@@ -294,6 +294,7 @@ async fn allocate_actor(
294294 . record ( dt, & [ KeyValue :: new ( "did_reserve" , res. is_ok ( ) . to_string ( ) ) ] ) ;
295295
296296 state. for_serverless = for_serverless;
297+ state. allocated_slot = true ;
297298
298299 match & res {
299300 Ok ( res) => {
@@ -339,8 +340,13 @@ pub struct DeallocateInput {
339340 pub actor_id : Id ,
340341}
341342
343+ #[ derive( Debug , Serialize , Deserialize ) ]
344+ pub struct DeallocateOutput {
345+ pub for_serverless : bool ,
346+ }
347+
342348#[ activity( Deallocate ) ]
343- pub async fn deallocate ( ctx : & ActivityCtx , input : & DeallocateInput ) -> Result < ( ) > {
349+ pub async fn deallocate ( ctx : & ActivityCtx , input : & DeallocateInput ) -> Result < DeallocateOutput > {
344350 let mut state = ctx. state :: < State > ( ) ?;
345351 let runner_name_selector = & state. runner_name_selector ;
346352 let namespace_id = state. namespace_id ;
@@ -353,8 +359,8 @@ pub async fn deallocate(ctx: &ActivityCtx, input: &DeallocateInput) -> Result<()
353359
354360 tx. delete ( & keys:: actor:: ConnectableKey :: new ( input. actor_id ) ) ;
355361
362+ // Only clear slot if we have a runner id
356363 if let Some ( runner_id) = runner_id {
357- // Only clear slot if we have a runner id
358364 destroy:: clear_slot (
359365 input. actor_id ,
360366 namespace_id,
@@ -374,8 +380,12 @@ pub async fn deallocate(ctx: &ActivityCtx, input: &DeallocateInput) -> Result<()
374380 state. connectable_ts = None ;
375381 state. runner_id = None ;
376382 state. runner_workflow_id = None ;
383+ // Slot was cleared by the above txn
384+ state. allocated_slot = false ;
377385
378- Ok ( ( ) )
386+ Ok ( DeallocateOutput {
387+ for_serverless : state. for_serverless ,
388+ } )
379389}
380390
381391/// Returns None if a destroy signal was received while pending for allocation.
@@ -393,6 +403,11 @@ pub async fn spawn_actor(
393403 } )
394404 . await ?;
395405
406+ // Always bump the autoscaler so it can scale up
407+ ctx. msg ( rivet_types:: msgs:: pegboard:: BumpServerlessAutoscaler { } )
408+ . send ( )
409+ . await ?;
410+
396411 let allocate_res = match allocate_res {
397412 Ok ( x) => x,
398413 Err ( pending_allocation_ts) => {
@@ -401,10 +416,6 @@ pub async fn spawn_actor(
401416 "failed to allocate (no availability), waiting for allocation" ,
402417 ) ;
403418
404- ctx. msg ( rivet_types:: msgs:: pegboard:: BumpServerlessAutoscaler { } )
405- . send ( )
406- . await ?;
407-
408419 // If allocation fails, the allocate txn already inserted this actor into the queue. Now we wait for
409420 // an `Allocate` signal
410421 match ctx. listen :: < PendingAllocation > ( ) . await ? {
0 commit comments