feat(session): a run stopped before it went live can end

A run stopped while its game is still downloading has failed at nothing,
and never reached live, where billing starts. Until now the only way out
of starting was failed, so a host that honoured the stop had to report a
stop the person asked for as a failure.
This commit is contained in:
Wanjohi
2026-10-15 23:29:01 +03:00
parent a90a4d8d06
commit 2a7e5b2d30
2 changed files with 18 additions and 1 deletions
+5 -1
View File
@@ -370,10 +370,14 @@ export namespace Session {
* the only mutual exclusion in this design. `ended` and `failed` are
* terminal, so their entries are empty rather than absent — a state with no
* exits is a fact worth writing down.
*
* `starting → ended` is a run stopped before it went live — the person
* stopping it while its game downloads, say. Nothing failed, so `failed`
* would be a lie, and it never reached `live`, so it was never billed.
*/
export const NEXT_STATES: Record<Info['state'], readonly Info['state'][]> = {
requested: ['starting'],
starting: ['live', 'failed'],
starting: ['live', 'ended', 'failed'],
live: ['ended', 'failed'],
ended: [],
failed: []
+13
View File
@@ -1200,4 +1200,17 @@ describe('Session end reasons', () => {
expect(ended.session?.endReason).toBe('idle');
expect((await Session.fromID(run.session.id))?.endReason).toBe('idle');
});
test('a run stopped before it went live ends, with its reason, and was never billed', async () => {
const run = await requestedRun('ses-stopped-starting', 5472);
await report(run, 'starting');
// Stopped while its game downloaded: nothing failed, and it never
// reached `live`, which is where billing starts.
const ended = await report(run, 'ended', 'user');
expect(ended.outcome).toBe('moved');
expect(ended.session?.state).toBe('ended');
expect(ended.session?.endReason).toBe('user');
expect(ended.session?.timeStarted).toBeNull();
});
});