diff --git a/backend/endpoints/streaming.py b/backend/endpoints/streaming.py index 9ae343253..038715c79 100644 --- a/backend/endpoints/streaming.py +++ b/backend/endpoints/streaming.py @@ -358,7 +358,7 @@ async def _reserve_container( candidates, request.user.id, platform=platform ) if held is not None: - holder, _, mine = held + own_container, _, mine = held if not session_is_stale(mine): raise HTTPException( status_code=409, @@ -371,7 +371,7 @@ async def _reserve_container( ) # Their own session, abandoned. Take that container back rather than # rolling them onto a free one and stranding this one until its TTL. - candidates = [holder] + candidates = [own_container] async def try_claim(candidate: ResolvedContainer) -> bool: # SET NX is atomic: exactly one concurrent claim wins the key. The TTL @@ -441,7 +441,7 @@ async def _reserve_container( # has to come from a live session or the message names no one. snapshots = [await get_session(candidate.key) or {} for candidate in candidates] draining = any(snapshot.get("draining") for snapshot in snapshots) - existing = next( + holder = next( ( snapshot for snapshot in snapshots @@ -460,8 +460,8 @@ async def _reserve_container( detail={ "message": message, "draining": draining, - "rom_name": access.visible_rom_name(request, existing), - "claimed_at": existing.get("claimed_at"), + "rom_name": access.visible_rom_name(request, holder), + "claimed_at": holder.get("claimed_at"), }, ) diff --git a/backend/handler/streaming/access.py b/backend/handler/streaming/access.py index 82ea53042..6239be5cb 100644 --- a/backend/handler/streaming/access.py +++ b/backend/handler/streaming/access.py @@ -173,7 +173,7 @@ async def resolve_named_container( async def resolve_owned_session( - platform: str, request: Request, *, include_desktop: bool = False + platform: str, request: Request ) -> tuple[ResolvedContainer, str, dict[str, Any]]: """Find the caller's session for this platform in its first pool. @@ -194,7 +194,8 @@ async def resolve_owned_session( session = await get_live_session(session_key) if session is None: continue - if not _session_in_scope(session, platform, include_desktop): + # These routes act on a game; a desktop is reached by naming it. + if not _session_in_scope(session, platform, include_desktop=False): continue if session.get("user_id") == request.user.id: return candidate, session_key, session diff --git a/backend/handler/streaming/lifecycle.py b/backend/handler/streaming/lifecycle.py index cbb498e98..ad356f768 100644 --- a/backend/handler/streaming/lifecycle.py +++ b/backend/handler/streaming/lifecycle.py @@ -396,7 +396,7 @@ async def _teardown_abandoned_session( session_key: str, session: dict[str, Any], *, - claimed_by: int | None = None, + claimed_by: int, ) -> bool: """Free a container whose owner vanished without releasing (heartbeat went stale). Same order as an owner release: stop the emulator so the card is @@ -470,7 +470,7 @@ async def await_teardown_within_budget( session: dict[str, Any], budget: float, *, - claimed_by: int | None = None, + claimed_by: int, ) -> bool: """Tear down an abandoned session, but only wait `budget` seconds for it. diff --git a/backend/handler/streaming/session_store.py b/backend/handler/streaming/session_store.py index d3588c652..08e526ae2 100644 --- a/backend/handler/streaming/session_store.py +++ b/backend/handler/streaming/session_store.py @@ -426,7 +426,7 @@ async def hold_session_claim(session_key: str, claim: dict[str, Any]) -> None: async def stamp_launched( - session_key: str, claim: dict[str, Any], host: str | None = None + session_key: str, claim: dict[str, Any], host: str | None ) -> None: """Record that the activate returned, so the status poll stops asking the broker for an extraction phase.