docs(streaming): tighten the comments this branch grew

Several notes had run to four or more lines, a couple of them recounting
how the code was reordered rather than what it does now.
This commit is contained in:
Zach Clendenen
2026-09-17 16:59:38 -05:00
parent f425fb5553
commit 4f2d1198f2
4 changed files with 21 additions and 30 deletions

View File

@@ -350,10 +350,9 @@ async def _reserve_container(
platform: str,
) -> ResolvedContainer:
"""Walk the platform's containers and claim the first one available."""
# Status, heartbeat and release resolve by platform and answer with the
# first match, so a second game session on one platform is one nothing can
# reach. A session of theirs elsewhere (another platform, or a desktop) is
# not in the way; that container simply fails the reservation below.
# Status, heartbeat and release answer with the first match on a platform,
# so a second game session there is one nothing can reach. A session of
# theirs elsewhere is not in the way: that container fails the claim below.
held = await access.find_session_for_user(
candidates, request.user.id, platform=platform
)
@@ -434,11 +433,9 @@ async def _reserve_container(
if await try_claim(candidate):
return candidate
# A drain marker belongs to nobody: the previous session is over and its
# exit state is still coming out of the container, so it carries no
# rom_name and no claimed_at. One member draining is worth telling the
# player about, since that container is about to come free, but the holder
# has to come from a live session or the message names no one.
# A drain marker belongs to nobody, so it carries no rom_name and no
# claimed_at. Worth reporting, since that container is about to come free,
# but the holder 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)
holder = next(

View File

@@ -114,10 +114,10 @@ def _session_in_scope(
include_desktop: bool,
claimed_at: str | None = None,
) -> bool:
"""Whether a stored session is one the route asked about. A container serves
several platforms and holds one session, so the owner alone does not
identify it, a desktop only answers to the caller that named it, and a claim
is the holder plus the moment they took it."""
"""Whether a stored session is the one the route asked about: the owner alone
does not say, since a container holds one session across several platforms,
a desktop answers only to a caller that named it, and a claim is its holder
plus the moment they took it."""
if not include_desktop and session_is_desktop(session):
return False
if claimed_at is not None and session.get("claimed_at") != claimed_at:

View File

@@ -619,12 +619,9 @@ def container_for_session(
def configured_emulator(platform: str) -> str:
"""The emulator the container a claim wins serves this platform with.
Empty when no container can be claimed for it: slot ceilings are read off
this, so the answer has to come from the pool a claim walks rather than
from whichever record the file happens to list first.
"""
"""The emulator the container a claim wins serves this platform with, empty
when nothing can be claimed for it. Slot ceilings are read off this, so it
has to come from the pool a claim walks."""
pool = containers_for_platform(platform)
return pool[0].emulator if pool else ""

View File

@@ -146,9 +146,9 @@ async def collect_exit_saves(
desktop) has nowhere to file one, so neither schedules anything.
One home for the rule: every teardown path files a session's saves the same
way, and under the session's owner rather than whoever ended it. The pull is
marked pending here rather than inside the task, so a claim arriving on the
heels of the release waits for it whether the task has started or not.
way, and under the session's owner rather than whoever ended it. Marked
pending before the task starts, so a claim on the heels of the release waits
for it either way.
"""
rom_id = session.get("rom_id")
user_id = session.get("user_id")
@@ -351,10 +351,8 @@ async def teardown_released_session(
# Leave a note when this is a force-release rather than a player closing
# their own game. A different user is the obvious case; a reason covers
# the rest, since only the admin panel sends one and an admin can be
# logged in as the same account that is playing in another tab. It goes
# out before the drain: the session ended when the marker landed, and
# the quiesce below is seconds of broker round trips in which the
# displaced player's poll would otherwise find no reason at all.
# logged in as the same account that is playing in another tab. Before
# the drain, so a poll during the quiesce still finds a reason.
if session.get("user_id") != acting_user_id or reason is not None:
await record_termination(
session, session_key, ended_by=acting_username, reason=reason
@@ -431,10 +429,9 @@ async def _teardown_abandoned_session(
keepalive = asyncio.ensure_future(hold_drain_marker(session_key, token))
try:
# That tab may still be showing the stream, so leave the same note an
# admin force-release does rather than letting the picture simply stop,
# and leave it before the drain so a poll inside that window finds it.
# Not for the owner coming back: the note would reach the tab that just
# claimed this container and end the claim it is starting.
# admin force-release does rather than letting the picture simply stop.
# Not for the owner coming back: it would end the claim their new tab is
# starting.
if session.get("user_id") != claimed_by:
await record_termination(
session, session_key, ended_by=None, reason="abandoned"