From 6ebc323ac25ef088c80fea3e82cc211ccb42e82e Mon Sep 17 00:00:00 2001 From: Zach Clendenen Date: Fri, 18 Sep 2026 13:21:12 -0500 Subject: [PATCH] fix(streaming): name the ended claim's stamp in a termination notice A re-claim of the same container keeps its key, so the container alone cannot tell the tab that lost its claim from the tab holding the next one. --- backend/endpoints/responses/streaming.py | 1 + backend/handler/streaming/session_store.py | 2 ++ backend/tests/endpoints/test_streaming.py | 20 +++++++++++++++++++ .../models/SessionTerminationSchema.ts | 1 + 4 files changed, 24 insertions(+) diff --git a/backend/endpoints/responses/streaming.py b/backend/endpoints/responses/streaming.py index 72ae8f8f5..a08bd6995 100644 --- a/backend/endpoints/responses/streaming.py +++ b/backend/endpoints/responses/streaming.py @@ -54,6 +54,7 @@ class SessionTerminationSchema(BaseModel): rom_id: int | None = None rom_name: str | None = None container: str | None = None + claimed_at: str | None = None desktop: bool = False diff --git a/backend/handler/streaming/session_store.py b/backend/handler/streaming/session_store.py index 809bf0091..e55728439 100644 --- a/backend/handler/streaming/session_store.py +++ b/backend/handler/streaming/session_store.py @@ -593,6 +593,8 @@ async def record_termination( # Which claim ended: a user can hold one per container, plus a desktop, # and only the tab that holds this one should act on the notice. "container": session_key, + # A re-claim of the container keeps its key, so the stamp names the claim. + "claimed_at": session.get("claimed_at"), "desktop": session_is_desktop(session), } await async_cache.set( diff --git a/backend/tests/endpoints/test_streaming.py b/backend/tests/endpoints/test_streaming.py index ddd84e42d..35f76dc6c 100644 --- a/backend/tests/endpoints/test_streaming.py +++ b/backend/tests/endpoints/test_streaming.py @@ -3053,6 +3053,26 @@ def test_a_termination_notice_names_the_container_it_ended( assert notice["desktop"] is False +def test_a_termination_notice_names_the_claim_it_ended( + client, access_token, viewer_access_token, rom: Rom +): + """A re-claim of the same container keeps its key, so only the stamp tells + the tab that lost its claim from the one holding the next.""" + with _streaming(_container_for(rom)): + claimed_at = _claim_ok(client, viewer_access_token, rom.id).json()[ + "claimed_at" + ] + client.delete( + f"/api/streaming/sessions/{rom.platform_slug}", + headers=_auth(access_token), + ) + r = client.get( + f"/api/streaming/sessions/{rom.platform_slug}/status", + headers=_auth(viewer_access_token), + ) + assert r.json()["termination"]["claimed_at"] == claimed_at + + def test_a_termination_notice_lands_before_the_drain( client, access_token, viewer_access_token, rom: Rom ): diff --git a/frontend/src/__generated__/models/SessionTerminationSchema.ts b/frontend/src/__generated__/models/SessionTerminationSchema.ts index 19b77c5b0..8d592dc44 100644 --- a/frontend/src/__generated__/models/SessionTerminationSchema.ts +++ b/frontend/src/__generated__/models/SessionTerminationSchema.ts @@ -16,6 +16,7 @@ export type SessionTerminationSchema = { rom_id?: (number | null); rom_name?: (string | null); container?: (string | null); + claimed_at?: (string | null); desktop?: boolean; };