@@ -26,13 +26,13 @@ def call
2626 SolidObjects . instrument ( :"message.started" , **instrumentation_payload )
2727 result = invoke_actor ( message_context )
2828 observable_changes = changed_observables ( observables_before , actor . observable_values )
29- state_after = actor . state . to_h
30- ensure_query_did_not_mutate_state! ( state_before , state_after )
29+ state_after = actor . state . to_h_with_byte_size
30+ ensure_query_did_not_mutate_state! ( state_before , state_after . value )
3131 complete (
3232 result ,
3333 observable_changes ,
3434 state_after :,
35- state_changed : state_after != state_before
35+ state_changed : state_after . value != state_before
3636 )
3737 true
3838 rescue LostActivation
@@ -81,12 +81,9 @@ def changed_observables(before, after)
8181 end
8282 end
8383
84- # @rbs (untyped, Hash[String, untyped], state_after: Hash[String, untyped] , state_changed: bool) -> void
84+ # @rbs (untyped, Hash[String, untyped], state_after: Serialization::Dumped , state_changed: bool) -> void
8585 def complete ( result , observable_changes , state_after :, state_changed :)
86- dumped_state = Serialization . dump_with_byte_size (
87- state_after ,
88- max_bytes : SolidObjects . configuration . max_state_bytes
89- )
86+ ensure_state_fits! ( state_after . byte_size )
9087 serialized_result = Serialization . dump (
9188 ( message . delivery_mode == "sync" ) ? result : nil ,
9289 max_bytes : SolidObjects . configuration . max_result_bytes
@@ -108,7 +105,7 @@ def complete(result, observable_changes, state_after:, state_changed:)
108105 locked_message = Message . lock . find ( message . id )
109106 execute_commit_actions ( commit_action_intents )
110107 instance . update! (
111- state : dumped_state . value ,
108+ state : state_after . value ,
112109 state_version : actor . class . state_version ,
113110 state_revision : locked_message . sequence ,
114111 last_used_at : SolidObjects . database_adapter . database_now
@@ -154,11 +151,19 @@ def complete(result, observable_changes, state_after:, state_changed:)
154151 actor_id : message . actor_id
155152 )
156153 end
157- report_large_state ( dumped_state . byte_size )
154+ report_large_state ( state_after . byte_size )
158155 SolidObjects . instrument_after_commit ( :"message.completed" , **instrumentation_payload )
159156 SolidObjects . wake_up . signal
160157 end
161158
159+ # @rbs (Integer) -> void
160+ def ensure_state_fits! ( byte_size )
161+ max_bytes = SolidObjects . configuration . max_state_bytes
162+ return if byte_size <= max_bytes
163+
164+ raise PayloadTooLarge , "serialized value exceeds #{ max_bytes } bytes"
165+ end
166+
162167 # @rbs (Integer) -> void
163168 def report_large_state ( byte_count )
164169 threshold = SolidObjects . configuration . warn_state_bytes
0 commit comments