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.
This commit is contained in:
Zach Clendenen
2026-09-18 13:21:12 -05:00
parent eaf1ee3c6f
commit 6ebc323ac2
4 changed files with 24 additions and 0 deletions

View File

@@ -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

View File

@@ -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(

View File

@@ -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
):

View File

@@ -16,6 +16,7 @@ export type SessionTerminationSchema = {
rom_id?: (number | null);
rom_name?: (string | null);
container?: (string | null);
claimed_at?: (string | null);
desktop?: boolean;
};