Actions question / interaction

Update: problem identified.
The scrip runs OnResolve, so it first resolves, then links the tickets and as a result reopens.

Hi all
I have the following problem (in RTIR but I don’t think I use any RTIR specific functionality for the problem I have). I have two scrips to run OnResolve of the queue incidents.

The first scrip searches for all Incident Reports that have some similarities with the Incident that is getting resolved, and adds them as children. This works always as expected. Either it finds the tickets if they exist and links them, or not if they don’t exist.

The second scrip finds all the Incident Report children of the Incident that gets resolved, and takes some action on a third system.

The problem that I have is that the behavior of the second scrip is unpredictable.
If the first scrip generates newly linked incident reports, the “Quick resolve” action only resolves the pre-existing incident reports and nothing else (not the newly linked incident reports, nor the incident). No actions are taken on the incident reports.
If there are NO newly linked incident reports, then the expected actions are taken on the incident reports and everything gets resolved.

Both scrips are running as normal.
Any idea on what may be the problem?