Hi, your spec didn't seem quite consistent, but hopefully the code below will give you some ideas, particularly with the use of Accumulate and TakeWhile.
g[2] = {2, 4};
g[i_] := Nest[Join[#, g[i - 1]] &, g[i - 1], Prime[i] - 1]
hsum[i_] := Module[{g1, sum, p, g2, t},
g1 = g[i];
sum = g1[[i - 1]] + g1[[i]];
p = Prime[i];
If[Mod[sum, p] == 1,
g2 = ReplacePart[Delete[g1, i], (i - 1) -> sum];
t = TakeWhile[Drop[Accumulate[g1], 2], Mod[#, p] != 1 &];
Take[g2, Length[t] + 1]]]
hsum[3]