From 65ea8da612d6e7bfc609e9defab6e01fa3e39f5f Mon Sep 17 00:00:00 2001 From: Zach Clendenen Date: Fri, 18 Sep 2026 12:58:08 -0500 Subject: [PATCH] fix(streaming): enter only the launch of the claim this tab holds A tab that missed its launch-failed keeps its container, so a second tab's re-claim of that container would otherwise hand it the other tab's room. --- frontend/src/services/api/streaming.ts | 3 +++ frontend/src/v2/views/Player/Stream.test.ts | 20 ++++++++++++++++++-- frontend/src/v2/views/Player/Stream.vue | 20 +++++++++++++------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/frontend/src/services/api/streaming.ts b/frontend/src/services/api/streaming.ts index c9415b30b..afda8886d 100644 --- a/frontend/src/services/api/streaming.ts +++ b/frontend/src/services/api/streaming.ts @@ -35,6 +35,7 @@ export type LaunchingSession = LaunchingSessionSchema; export interface LaunchReady { platform: string; container: string; + claimed_at: string; host: string; /** null when no resume was asked for; false means the state could not be * pushed and the session started fresh. */ @@ -45,6 +46,7 @@ export interface LaunchReady { export interface LaunchFailed { platform: string; container: string; + claimed_at: string; detail: string; } @@ -52,6 +54,7 @@ export interface LaunchFailed { export interface LaunchPhase { platform: string; container: string; + claimed_at: string; phase: string | null; } export type AdminStreamingSession = AdminSessionSchema; diff --git a/frontend/src/v2/views/Player/Stream.test.ts b/frontend/src/v2/views/Player/Stream.test.ts index 66bd42c76..20825db0a 100644 --- a/frontend/src/v2/views/Player/Stream.test.ts +++ b/frontend/src/v2/views/Player/Stream.test.ts @@ -397,14 +397,17 @@ function endSession(notice: Record): void { handler({ ended_by: "admin", reason: null, ...notice }); } -async function launchReady(): Promise { +async function launchReady( + payload: Record = {}, +): Promise { const handler = mocks.socketHandlers["streaming:launch-ready"]; expect(handler).toBeTypeOf("function"); await handler({ platform: "gba", - container: CLAIM.container, + ...CLAIM, host: "http://webstation-dev:8080", resume: null, + ...payload, }); } @@ -634,6 +637,19 @@ describe("Stream launch recovery", () => { wrapper.unmount(); }); + it("keeps waiting when the launch-ready is for a claim that replaced its own", async () => { + // Tab A missed its launch-failed, and tab B re-claimed the same container. + const wrapper = await launch({ picker: false }); + await vmOf(wrapper).onPlay(); + + await launchReady({ claimed_at: "2026-09-17T10:05:00" }); + await flushPromises(); + + expect(vmOf(wrapper).playerState).toBe("loading"); + expect(vmOf(wrapper).containerHost).toBe(""); + wrapper.unmount(); + }); + it("keeps waiting when the poll finds a game on another container", async () => { // The unnamed poll reports any session the player holds on the platform, // which can be another tab's. diff --git a/frontend/src/v2/views/Player/Stream.vue b/frontend/src/v2/views/Player/Stream.vue index dea7f886d..c915020f1 100644 --- a/frontend/src/v2/views/Player/Stream.vue +++ b/frontend/src/v2/views/Player/Stream.vue @@ -643,18 +643,24 @@ const stopSessionPoll = sessionPoll.pause; // and pushes what happened. A launch can take minutes on a title the broker // has to unpack, and these are the only progress the player sees. // -// The room is per-user, so a second tab streaming something else receives -// these too. The container is what identifies a launch: a pool can serve one -// platform from more than one, and the claim's 202 said which we got. +// The room is per-user, so a second tab receives these too. The container and +// the stamp the claim's 202 answered with identify a launch, since a re-claim +// of the same container shares its key. // Which container the claim won, so a launch push can be told from another // tab's. Null until the 202 lands, which is before any push can arrive. const claimedContainer = ref(null); -// The stamp the 202 answered with, which every release and heartbeat sends -// back so a claim that replaced this one is never the one they reach. +// The stamp the 202 answered with. Releases, heartbeats and launch pushes all +// carry it, so a claim that replaced this one is never taken for it. const claimedAt = ref(null); -function isOurLaunch(payload: { container?: string }): boolean { - return payload.container === claimedContainer.value; +function isOurLaunch(payload: { + container: string; + claimed_at: string; +}): boolean { + return ( + payload.container === claimedContainer.value && + payload.claimed_at === claimedAt.value + ); } useSocketEvent("streaming:launch-phase", (payload) => {