@@ -84,8 +84,7 @@ def test_new_nexus_call_serializes_the_leased_service_operation() -> None:
8484def test_started_call_stays_pending_and_cold_replay_receives_terminal_result () -> None :
8585 started = _service_event ("ServiceCallStarted" , "started" )
8686 pending = replay (DurableNexusCaller , [started ], [], workflow_id = "caller" , run_id = "caller-run" )
87- assert len (pending .commands ) == 1
88- assert isinstance (pending .commands [0 ], NexusServiceCall )
87+ assert pending .commands == []
8988
9089 expected = {"greeting" : "hello world" }
9190 completed = _service_event ("ServiceCallCompleted" , "completed" , expected )
@@ -95,6 +94,26 @@ def test_started_call_stays_pending_and_cold_replay_receives_terminal_result() -
9594 assert resumed .commands [0 ].result == expected
9695
9796
97+ def test_cancellation_request_and_cold_replays_do_not_readmit_pending_call () -> None :
98+ started = _service_event ("ServiceCallStarted" , "started" )
99+ requested = {
100+ "event_type" : "CooperativeCancellationRequested" ,
101+ "recorded_at" : "2026-10-12T07:00:00Z" ,
102+ "payload" : {
103+ "workflow_command_id" : "original-cancellation" ,
104+ "workflow_run_id" : "caller-run" ,
105+ "cleanup_deadline_at" : "2026-10-12T07:00:30Z" ,
106+ },
107+ }
108+ for history in ([started ], [started , requested ]):
109+ for _ in range (3 ):
110+ # A fresh workflow instance represents both another task and a
111+ # replacement worker. Neither may allocate another admission.
112+ outcome = replay (DurableNexusCaller , history , [], workflow_id = "caller" , run_id = "caller-run" )
113+ assert outcome .commands == []
114+ assert outcome .cancellation_delivery is None
115+
116+
98117@workflow .defn (name = "tests.nexus.catch-failure" )
99118class CatchingNexusCaller :
100119 def run (self , ctx : WorkflowContext ): # type: ignore[no-untyped-def]
0 commit comments