There is a way to directly create a field value using a QGIS expression in the field calculator to group together all those features that you want to join. Based on the value of this field, you than can use the function Aggregate
to join features with the same value (see second screenshot below). Bots steps should be easy to automate with a model.
Taking your data structure and field names, the expression looks like this (see below for explanation how the expression works):
array_last (
array_sort (
array_foreach (
array_remove_all (
array_agg (
if (
"trigger" = 1,
"fid" ,
0
)
) ,
0) ,
if (
if (
"trigger" = 1,
"fid" ,
0
) = @element,
@element,
if (
"fid" > @element ,
@element,0
)
)
)
)
)

Than you can use this field together with the function Menu Processing / Toolbox / Aggregate
to joint these features together.

To explain the idea behind the expression: for better understanding, let's call the "starting-segment" of the joined line you finally want to get the "head" - and the subsequent segments that are joined to it the "tails".
Get the fid-values of the heads, let's call it "group-ids". Final goal is to assign each tail-segment to a head (or: each tail should be assigned the group-id value of the next smaller head: 2 and 3 should be assigned to 1, 5 and 6 to 4 etc.)
a) If the trigger is 1 (head), get the value of the id: this is the group-id. Else (for tails) set a value of 0.
b) Aggregate these values creating an array.
c) Remove all 0 values from the array.
We thus get an array of group-ids (=fid of heads): [1,4,7,9,12]. We finally want to assign every feature to one of these values from the array.
Now iterate over all features of the layer with each of these group-ids from the array with the expression array_foreach
:
a) For the features with trigger = 1 (heads) we have no problem, these already have the right group-id (corresponding to their fid)
b) In the other cases (tails, trigger = 0), we must assign new values. We thus compare each input value from the array (list of all group-ids) with the fid and keep the group-id if it is smaller than the fid (as we want to assign to the next smaller value). Otherwise we set it to 0. So in no case there will result a value from the array that is bigger than the fid.
Sort the array to be sure we have the values in the right order (smallest to biggest) - to remove the final zeros from the last postition (see screenshot below). Without setting a sort order, we get the default value ascending=true
.
Get the last value from the sorted array, thus the last (biggest) group-id that is (remember step 2b) in no case bigger than the fid AND (in case trigger=1) is equal to the fid (step 2a) AND is always a number from the array we created in 1.
See a screenshot for the intermediate results of step 1 and 2:

Now it's easy to use the aggregate function with the field created as described above.
id=1
and the seconds three lines give themid=2
and so on, then run dissolve tool using this id field."fid"
) where"Trigger"
starts with1
and over all0
s until a new1
appears (this condition forms a group). So, the So, the real question is how to create a new grouping field rather than merging or dissolving which is easy.