From 2a7e5b2d306396e95c56e121bc5f7a596124057a Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Thu, 15 Oct 2026 23:29:01 +0300 Subject: [PATCH] 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. --- packages/core/src/session/index.ts | 6 +++++- packages/core/src/session/session.test.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/src/session/index.ts b/packages/core/src/session/index.ts index 70157369..7b660544 100644 --- a/packages/core/src/session/index.ts +++ b/packages/core/src/session/index.ts @@ -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 = { requested: ['starting'], - starting: ['live', 'failed'], + starting: ['live', 'ended', 'failed'], live: ['ended', 'failed'], ended: [], failed: [] diff --git a/packages/core/src/session/session.test.ts b/packages/core/src/session/session.test.ts index 8b00caf7..42c6324e 100644 --- a/packages/core/src/session/session.test.ts +++ b/packages/core/src/session/session.test.ts @@ -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(); + }); });