I'm not 100% certain this is answers your question, but let me try my best, and please follow up if I misinterpreted. This is what I believe happens.
When running Ekos on the same machine as where image files are captured/stored, if you select the scheduler option called "Remember Job Progress" (in KStarsSettings->Ekos->Scheduler), then the scheduler and capture cooperate and does not repeat existing captures from previous Ekos session. So, if a scheduler job requires 8 red and 8 blue captures, and you had 7 reds and 3 blues on disk in the right directory, then the new job would just capture 1 red and 5 blues. If that job were "repeat until terminated", then, after those captures, it would restart all try to capture a new set of 8 reds and all 8 blues, and on and on.
Alternatively, if you were running Ekos on a remote machine, NOT the machine where images are captured, then it would act as if "Remember Job Progress" were unchecked, and each time the scheduler runs the job, it would attempt to capture the full 8 reds and 8 blues.
The key is that the scheduler directly checks the local filesystem when "Remember Job Progress" is checked, and if it doesn't see files on the local file system, it assumes they have not been captured. There is no communication with a remote indi server to see what files have been previously captured.
So, I guess you could say that for "remote captures" it counts remote captures for the current scheduler session, but it doesn't remember them across sessions.
In fact when the captures are NOT set to be on the box running EKOS, the scheduler doesn't remember anything. In my case, it simply repeats the current job forever as (as you say) it doesn't know how many images have been stored on the remote box.
Your last bit:
".... for remote captures" it counts remote captures for the current scheduler session, but it doesn't remember them across sessions"
Doesn't follow as in my case, the scheduler remembers neither the number of captures for current session nor across sessions.
I wonder that because of this there is a bug and indeed the scheduler should remember the captures for the current session; I do I have "Remember Job Progress" checked.
I copied the new code into scheduler.cpp and scheduler.h after a git pull and built.
I can confirm that it now works fine. The scheduler moves onto the next job after the correct number of captures or shuts down when the last job ends. The captures are stored correctly on the remote computer.
The Capture counter in the scheduler still remains at zero however: