A link's session is kept alive, and a channel rides out a session's end (#136) #166

Merged
cmoriarty merged 1 commit from claude/friendly-herschel-74e265 into main 2026-11-14 19:22:48 -05:00
Owner

Closes #136.

Why

A channel playing the embedsports player's stream stopped about ten minutes after its link was read, every time. On 2026-11-14 Penn vs. Harvard's channel failed 19 times and closed 11 times in under three hours, each time with "upstream error: 401".

  • The player's page is given a session of ten minutes by a key service (seckyes.cc), and the page renews it every five minutes.
  • The app closes a player page as soon as it has seen the stream, so nothing renewed the session. Eleven production sessions were each refused 596 to 601 s after their page was read.
  • Each end also took the game out of Ready, which handed its place among the background channels to the next-ranked game. North Florida vs. The Citadel's channel was opened and closed six times that way.

The measurements are in two comments on the ticket: the cause and the two-hour probe.

What changes

The session is kept alive

  • The reader keeps the page's session grant with the stream (backend/app/resolver/seckey.py).
  • The app sends the player's own renewal every five minutes for every link it keeps: the stream a channel plays or a Ready game would play, and its standbys (backend/app/keepalive.py).
  • Such a link's page is read again only when the key service says it must be: five minutes before the time it names, about two hours on.

When nothing keeps it alive

  • The link's end is read from the playlist's key line, and its page is read again with half its life left: first for the link a channel plays, with a round's spare read otherwise.
  • A link past its own end is dropped without a cooldown, a strike or a mark against its stream, and is never taken as a standby.

The channel

  • A channel whose link ends anyway waits for a renewal in flight, else plays a ready standby, else reads the same link again.
  • A background channel stays open through it, and its game keeps its place among the background channels.
  • A renewed link on another host of the player carries on by its segments' names: no splice, nothing played twice.

To watch it

  • /api/channels shows each link's ends_at, renew_at and session: its end, its next renewal, the renewals so far, and whether one was refused.
  • The log has one "kept alive" line per link, and one "keep-alive refused" line if a chain ends.

Specs: OpenSpec change sessions-kept-alive, with deltas for stream-supervision and stream-resolution.

Things to know

  • The app now sends the player's own keep-alive request to seckyes.cc, with the values the page was handed, every five minutes per kept link. LINK_KEEPALIVE_ENABLED=0 turns it off, and the app then reads the page again before each end instead. The owner has not ruled on this.
  • A background channel nobody watches now spends one page read at a session's end instead of closing. Any other failure there still closes the channel without a read. The owner has not ruled on this either.
  • Whether production's address is renewed is not known. Every live check ran from a second address, not through the VPN. In production the grant and the renewals both leave through the VPN, as both left from one address in the checks, so it should be. The first game on this player after a deploy will show it.
  • A session can be renewed for two hours at most. Measured once: 23 renewals accepted, a refusal at 120 minutes, and the stream played to 125. The app reads the page again at 110 minutes.
  • A merge deploys: the publish job restarts the app a few minutes later, whether or not a game is on.

Testing

Lanes run locally on the commit itself (9a8b5e1), since CI runs by hand only:

  • make test: 1367 passed, 1 skipped.
  • Frontend: 265 passed, build clean.
  • make e2e: passed.
  • openspec validate sessions-kept-alive --strict: valid.

Checked against live streams, from a second address:

  • The reader kept the grant on s2watch.cyou, suksukstreams.cfd and resports.cfd, and the session's end read from the key line equalled the grant's.
  • The app's keep-alive renewed a kept link eight times in a row over 45 minutes. Its playlist, polled every 2 s, answered every time.
  • A real channel, run in-process with the keep-alive loop beside it, played through its session's end and 198 s more with no failed reload, swap or filler.

Not yet run on the live app. The check after deploy is to open /api/channels while a game on this player is playing: link.session.renewals should grow every five minutes, and the channel should play past ten minutes.

🤖 Generated with Claude Code

Closes #136. ## Why A channel playing the embedsports player's stream stopped about ten minutes after its link was read, every time. On 2026-11-14 Penn vs. Harvard's channel failed 19 times and closed 11 times in under three hours, each time with "upstream error: 401". - The player's page is given a session of ten minutes by a key service (seckyes.cc), and the page renews it every five minutes. - The app closes a player page as soon as it has seen the stream, so nothing renewed the session. Eleven production sessions were each refused 596 to 601 s after their page was read. - Each end also took the game out of Ready, which handed its place among the background channels to the next-ranked game. North Florida vs. The Citadel's channel was opened and closed six times that way. The measurements are in two comments on the ticket: [the cause](https://forgejo.underthere.xyz/cmoriarty/sports-breaker/issues/136#issuecomment-9128) and [the two-hour probe](https://forgejo.underthere.xyz/cmoriarty/sports-breaker/issues/136#issuecomment-9135). ## What changes **The session is kept alive** - The reader keeps the page's session grant with the stream (`backend/app/resolver/seckey.py`). - The app sends the player's own renewal every five minutes for every link it keeps: the stream a channel plays or a Ready game would play, and its standbys (`backend/app/keepalive.py`). - Such a link's page is read again only when the key service says it must be: five minutes before the time it names, about two hours on. **When nothing keeps it alive** - The link's end is read from the playlist's key line, and its page is read again with half its life left: first for the link a channel plays, with a round's spare read otherwise. - A link past its own end is dropped without a cooldown, a strike or a mark against its stream, and is never taken as a standby. **The channel** - A channel whose link ends anyway waits for a renewal in flight, else plays a ready standby, else reads the same link again. - A background channel stays open through it, and its game keeps its place among the background channels. - A renewed link on another host of the player carries on by its segments' names: no splice, nothing played twice. **To watch it** - `/api/channels` shows each link's `ends_at`, `renew_at` and `session`: its end, its next renewal, the renewals so far, and whether one was refused. - The log has one "kept alive" line per link, and one "keep-alive refused" line if a chain ends. Specs: OpenSpec change `sessions-kept-alive`, with deltas for `stream-supervision` and `stream-resolution`. ## Things to know - **The app now sends the player's own keep-alive request to seckyes.cc**, with the values the page was handed, every five minutes per kept link. `LINK_KEEPALIVE_ENABLED=0` turns it off, and the app then reads the page again before each end instead. The owner has not ruled on this. - **A background channel nobody watches now spends one page read at a session's end** instead of closing. Any other failure there still closes the channel without a read. The owner has not ruled on this either. - **Whether production's address is renewed is not known.** Every live check ran from a second address, not through the VPN. In production the grant and the renewals both leave through the VPN, as both left from one address in the checks, so it should be. The first game on this player after a deploy will show it. - **A session can be renewed for two hours at most.** Measured once: 23 renewals accepted, a refusal at 120 minutes, and the stream played to 125. The app reads the page again at 110 minutes. - A merge deploys: the publish job restarts the app a few minutes later, whether or not a game is on. ## Testing Lanes run locally on the commit itself (9a8b5e1), since CI runs by hand only: - `make test`: 1367 passed, 1 skipped. - Frontend: 265 passed, build clean. - `make e2e`: passed. - `openspec validate sessions-kept-alive --strict`: valid. Checked against live streams, from a second address: - The reader kept the grant on s2watch.cyou, suksukstreams.cfd and resports.cfd, and the session's end read from the key line equalled the grant's. - The app's keep-alive renewed a kept link eight times in a row over 45 minutes. Its playlist, polled every 2 s, answered every time. - A real channel, run in-process with the keep-alive loop beside it, played through its session's end and 198 s more with no failed reload, swap or filler. Not yet run on the live app. The check after deploy is to open `/api/channels` while a game on this player is playing: `link.session.renewals` should grow every five minutes, and the channel should play past ten minutes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A channel playing the embedsports player's stream stopped about ten
minutes after its link was read, every time. Penn vs. Harvard on
2026-11-14: 19 failures and 11 closes in under three hours, each "the
playlist failed to load 2 times; last error: playlist: upstream error:
401".

The player's page is given a session of ten minutes by a key service
(seckyes.cc) and renews it every five minutes. The stream writes the
session's end on its playlist's key line, and at that second its hosts
answer 401 to the playlist, to segments already listed and to the
link's first address. The app closes a player page as soon as it has
seen the stream, so nothing renewed: eleven production sessions were
each refused 596 to 601 s after their page was read. Polling, idleness
and a second session make no difference.

The reader now keeps the page's session grant with the stream
(resolver/seckey.py), and the app sends the player's renewal itself for
every link it keeps: the stream a channel plays or a Ready game would
play, and its standbys (keepalive.py). Such a link's page is read again
only when the key service says it must be: five minutes before the time
it names, about two hours on. LINK_KEEPALIVE_ENABLED=0 turns the
renewals off.

Where nothing keeps a session alive, or a renewal is refused, the
link's end is read from the playlist's key line (verify.session_end)
and its page is read again with half its life left: first for the link
a channel plays, with a round's spare read otherwise. A link past its
own end is dropped without a cooldown, a strike or a mark against its
stream, and is never taken as a standby.

A channel whose link ends anyway waits for a renewal in flight, else
plays a ready standby, else reads the same link again. A background
channel stays open through it, and its game keeps its place among the
background channels. Each close used to hand that place to the
next-ranked game, which lost it minutes later: North Florida vs. The
Citadel's channel was opened and closed six times that afternoon. A
renewed link on another host of the player carries on by its segments'
names, with no splice and nothing played twice.

/api/channels shows each link's end, its next renewal and its session.

Checked against live streams from a second address: eight renewals
accepted in a row over 45 minutes with the playlist answering
throughout, and a channel run in-process played through its session's
end with no failed reload, swap or filler. One session renewed until it
was refused took 23 renewals, was refused at two hours, and its stream
played to 125 minutes.

Not yet run on the live app, so whether a renewal from production's
address is accepted is not known.

OpenSpec change: sessions-kept-alive.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cmoriarty/sports-breaker!166
No description provided.