Skip to content

[bug] Progress updates alone keep dead sessions alive forever — ghost sessions hold transcode slots for 15h with zero byte flow #666

Open

Description

@CoffeeKnyte

What happened

Sessions that stopped playing hours ago are still counted as "watching now", and the server keeps transcoding for them.

When someone stops watching, the server is supposed to notice and clean up — drop the
session from the active list and shut down the video conversion running for it. That
cleanup normally works. But there is a way for a session to slip past it and stay alive
forever.

The Android app sends the server a "here's where I am in the video" update roughly every
10 seconds. The server treats each of those updates as proof the person is still watching.
It never checks the thing that actually matters: is the app still downloading any video?

So if the app stops fetching video but keeps sending position updates, the server believes
the session is alive indefinitely. On our production server right now, two sessions have
been in this state for just under 15 hours. One of them downloaded a grand total of
one piece of video before it stopped, and has sent 5,324 position updates since.

The consequences, in order of how much they cost:

  • The server is transcoding video that nobody is receiving. One of these sessions still
    has a live video conversion running, 15 hours after the app last asked for any video. It
    has been converting a film into a stream that goes nowhere. This occupies one of the
    server's limited hardware video-conversion slots.
  • These ghost sessions count against the limit on simultaneous conversions. Real
    viewers can be refused a stream, or pushed onto a slower path, because slots are being
    held by sessions that stopped watching hours ago.
  • The admin "who is watching" view is wrong. It shows people as actively watching who
    closed the app hours ago. There is currently no way for an operator to tell the ghosts
    apart from the real viewers.
  • Leftover working files pile up on disk. 30 GB across 40 folders, against only 10
    conversions actually running.

None of this is visible as an error. Nothing crashes, nothing is logged as a failure, and
the sessions look completely normal in the admin view — they simply never end.

At the moment 4 of the 5 longest-running sessions on the server are ghosts. Only 1 is a
real viewer.

Where it shows up: Android app (all observed cases). Any client that reports position
independently of downloading video can trigger it.

What triggers it: every observed case began within ~25 seconds of a server restart. The
app reconnects, starts a session, fetches a little video, then stops fetching — but keeps
reporting position forever.

Steps to reproduce

Commands assume the repository root is the cwd.

  1. Start playback from a client that sends periodic progress updates.
  2. Let the session establish (one or two segment requests).
  3. Stop fetching media, but keep sending POST /api/v1/playback/{session_id}/progress
    more often than the 45-second active grace window.
  4. Wait. The session is never reaped: it stays in playback_sessions_sync, stays in the
    admin sessions view, keeps counting toward transcode limits, and its ffmpeg keeps
    running.

Reproduced deterministically against SessionManager — 14 simulated hours of 10-second
progress posts with zero byte flow, using the real 45-second active grace:

$ go test ./internal/playback/ -run TestReproPhantom -v
=== RUN   TestReproPhantomSessionSurvivesWithoutByteFlow
    zz_repro_phantom_test.go:35: session survived 14h and 5040 progress posts with ZERO byte flow (active grace 45s) — never reaped
--- FAIL: TestReproPhantomSessionSurvivesWithoutByteFlow (0.00s)
FAIL

5,040 simulated posts against ~5,300 observed in production on the real sessions.

Control — the identical session without progress posts is reaped immediately, confirming
the reaper itself works and that progress posts are what defeat it:

$ go test ./internal/playback/ -run TestReproControlNoProgress -v
=== RUN   TestReproControlNoProgressIsReaped
    zz_repro_phantom_test.go:49: control: reaped after 0s with no progress posts (grace 45s)
--- PASS: TestReproControlNoProgressIsReaped (0.00s)
ok  	github.com/Silo-Server/silo-server/internal/playback	0.040s

Expected behavior

Session liveness should require evidence that media is actually being delivered. A client
that reports position but has fetched no bytes for well beyond the grace window should be
reaped, its transcode stopped, its slot released, and its scratch directory cleaned up.

A progress update alone should not be sufficient to keep a transcoding session alive
indefinitely.

Silo version / commit

3ddc9d66 (deployed as silo:local). Not introduced by that commit — the liveness logic
described below is unchanged on origin/main.

Deployment

Docker.

Clients affected

  • Android (all observed occurrences, user_agent=ktor-client)
  • Not client-specific in principle — any client that reports progress independently of
    media fetching

Relevant logs

Raw copy-paste, with viewer IPs redacted to x.x.x.x; nothing else altered.

Current state of the two longest-lived sessions (observed over an 18-hour window):

$ docker logs silo 2>&1 | grep e27a4a62-51d2-4335-9892-174ca84ae48d | grep -c progress
5338
$ docker logs silo 2>&1 | grep e27a4a62-51d2-4335-9892-174ca84ae48d | grep -c 'segment/'
99
$ docker logs silo 2>&1 | grep e27a4a62-51d2-4335-9892-174ca84ae48d | grep 'segment/' | tail -1 | grep -oE '^time=[^ ]+'
time=2026-08-17T12:59:01.735Z

$ docker logs silo 2>&1 | grep bd37ef3c-563d-4991-8ef9-410699dc4a38 | grep -c progress
5324
$ docker logs silo 2>&1 | grep bd37ef3c-563d-4991-8ef9-410699dc4a38 | grep -c 'segment/'
1
$ docker logs silo 2>&1 | grep bd37ef3c-563d-4991-8ef9-410699dc4a38 | grep 'segment/' | tail -1 | grep -oE '^time=[^ ]+'
time=2026-08-17T12:58:34.113Z

A progress POST still arriving at 03:57, ~15 hours after that session's last byte:

time=2026-08-18T03:57:20.502Z level=INFO msg="api request" component=api component=api request_id=4580b34475a1/0JCmU13lz8-387609 method=POST path=/api/v1/playback/e27a4a62-51d2-4335-9892-174ca84ae48d/progress path_pattern=/api/v1/playback/{session_id}/progress status=204 duration_ms=22 client_ip=x.x.x.x user_agent=ktor-client node_id=4580b34475a1 user_id=747 session_id=45b732db-b7fc-4e3c-a78a-c84d6674f863 playback_session_id=e27a4a62-51d2-4335-9892-174ca84ae48d

The database rows — note is_paused = f, so the 45-second active grace applies, yet
last_sync_at is current and the rows are ~15 hours old:

$ psql -tAc "select session_id, is_paused, last_sync_at, started_at, now()-started_at as age from playback_sessions_sync where session_id in ('e27a4a62-...','bd37ef3c-...');"
bd37ef3c-563d-4991-8ef9-410699dc4a38|f|2026-08-18 03:57:40.515219+00|2026-08-17 12:58:32.714884+00|14:59:07.812459
e27a4a62-51d2-4335-9892-174ca84ae48d|f|2026-08-18 03:57:40.515219+00|2026-08-17 12:58:32.786686+00|14:59:07.740657

The orphaned ffmpeg still running for e27a4a62 — 14h59m elapsed, 21m28s of CPU:

$ ps -o pid=,etime=,time= -p 3155224
3155224    14:59:18 00:21:28

Sessions older than 2h, with segment fetches in the last 30 minutes. 4 of 5 are ghosts:

  bd37ef3c  transcode    age=14:59:18.647906  segments_last_30m=0
  e27a4a62  transcode    age=14:59:18.576104  segments_last_30m=0
  e6c83186  transcode    age=03:31:44.721189  segments_last_30m=0
  d3d21eee  transcode    age=03:10:57.546426  segments_last_30m=0
  6da19c9e  transcode    age=02:16:12.042946  segments_last_30m=901

Scratch directories vs live conversions:

$ docker exec silo sh -c 'du -sh /tmp/silo-transcode; ls /tmp/silo-transcode | wc -l'
30G	/tmp/silo-transcode
40

Technical detail

Root cause

Session liveness is keyed on LastActivityAt, and a progress POST refreshes it. Byte flow
is never consulted. The full chain:

  1. POST /api/v1/playback/{session_id}/progress → HandleUpdateProgress
    (internal/api/handlers/playback.go:1122) → sessionMgr.UpdateProgress
    (playback.go:1156).
  2. SessionManager.UpdateProgress (internal/playback/session.go:804) calls
    touchSessionLocked (session.go:816), which sets LastActivityAt = now
    (session.go:1439-1443).
  3. The in-memory reaper CleanInactive (session.go:1412) only expires sessions where
    sessionIsInactiveLocked is true — i.e. LastActivityAt older than the grace window.
    A 10-second post interval against DefaultActiveSessionGrace = 45 * time.Second
    (session.go:304) means that is never true.
  4. The reconciler upserts the row with last_sync_at = NOW()
    (internal/worker/reconciler.go:152-160) for as long as the session exists in memory.
  5. The DB reaper (internal/worker/cleanup.go:130-134) deletes
    playback_sessions_sync rows only WHERE is_paused = FALSE AND last_sync_at < NOW() - 45s. last_sync_at is always fresh, so the row is never deleted.
  6. The session therefore stays in activeSessionIDs, so
    CleanupOrphanedTranscodeDirs (internal/playback/transcode_cleanup.go:28) spares its
    directory, and the ffmpeg process is never stopped.

Nowhere in that chain is "has this client fetched a byte recently?" asked.

activeTransportCount / BeginTransport (session.go:1199) is the byte-path signal, but
it is only ever used to protect a session from reaping (session.go:1418, 1449) — it
can extend a session's life, never shorten it. There is no path by which absent byte flow
expires a session.

The assumption being violated

The design comment on remoteTransportGrace (session.go:1456-1466) states it plainly:

A proxy-served one has no such request here, so it is protected only by the client's
progress heartbeats … A client that has gone quiet for this long has genuinely stopped
watching.

That is the assumption: a client that stops watching goes quiet. These clients do not go
quiet — they stop fetching media while continuing to report position. The reasoning holds
for a client that disappears; it does not hold for one that half-disappears.

Transcode cap interaction

countsTowardLimitsLocked (session.go:1445-1453) returns
!sessionIsInactiveLocked(...), so these phantoms do count toward the configured
transcode cap for as long as they persist. This compounds the known cap-liveness defect
from the opposite direction: there the 45s grace is shorter than real client buffers, so
live sessions get dropped; here liveness is asserted with no byte flow at all, so dead
sessions are retained. Both stem from the same root — the cap's notion of "active" is not
grounded in bytes delivered.

How this was found

Surfaced by the stream-telemetry parity report during an 18-hour production soak. The
telemetry view is byte-path driven and correctly excluded these sessions; the legacy
playback_sessions_sync view included them. They appeared as legacy_only in 179 of
185
consecutive parity samples, which is what made them distinguishable from ordinary
timing skew between the two stores.

Suggested direction

Not proposing a specific patch — the right grace semantics are a judgement call — but the
shape of the fix is to make liveness require byte-path evidence rather than accept a
progress post as a proxy for it. For example: track a last-byte-delivered timestamp
alongside LastActivityAt, and let a session with an active transcode expire once byte
delivery has been silent well past the buffer horizon, regardless of progress posts.

The grace window must stay comfortably longer than a real client's buffer — web ~120s,
Media3 ~50s — so this cannot simply reuse the 45-second active window. Getting that wrong
in the other direction is the existing cap-liveness defect.

Worth deciding alongside: whether a reaped-for-no-bytes session should be revivable. The
comment at session.go:312-318 notes that reaping a paused session kills its transcode with
no revival path (referencing the now-closed #243), so any new expiry route needs the same
question answered.

Related

AI Disclosure

  • Tool(s): Claude Code
  • Model(s): claude-opus-5
  • Involvement: AI-generated, human verified the repro
  • Adversarial review: my first reading of this data was the opposite conclusion — that
    stream-telemetry was missing these sessions and had a coverage gap. Checking the
    request logs reversed it: the sessions have no byte flow, so telemetry is correct to
    exclude them and the legacy store is the one at fault. I then confirmed the sessions were
    genuinely live rather than stale rows (progress POSTs arriving within the last 30
    seconds), and confirmed is_paused = f in the DB so that the 45-second active window
    applies rather than the 30-minute paused one — without that check the behaviour could be
    mistaken for the paused grace working as intended. The control test was added because the
    failing repro alone does not prove progress posts are the cause rather than the reaper
    being broken outright.

Activity

  1. added
    bug
    go
    on Aug 18, 2026
  2. added
    triaged
    and removed
    triaged
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. removed
    bug
    on Sep 20, 2026
  5. CoffeeKnyte commented on Oct 28, 2026

    @CoffeeKnyte
    ContributorAuthor

    Still reproduces on main (564b906), and a fix now needs a protocol decision first.

    • updateProgress refreshes LastActivityAt on every report, paused or not (internal/playback/session.go:1003). The reaper and the cap count (sessionIsInactiveLocked, countsTowardLimitsLocked) read only that timestamp, so a session that posts progress every 10 seconds is never reaped and keeps its stream and transcode slots.
    • fix(playback): keep node-served sessions alive while media flows #2156 lets node delivery records keep a session alive. A lack of delivery never ends one.
    • docs(playback): document session liveness in the v3 protocol #2028 wrote the current behavior into the protocol: docs/architecture/playback-protocol-v3.md §2.5 calls the progress report "the heartbeat".
    • Remote transcode nodes kill ffmpeg after 10 minutes without a manifest or segment request (sessionIdleTTL, internal/transcodenode/server.go). That stops orphaned encodes and scratch files for node-served sessions only. The API session, the admin "watching now" entry, and the cap slot stay. Local transcodes have no equivalent.

    Narrowed scope: while a session is not paused, a progress report should not extend liveness past some bound, a multiple of the 45-second active grace, unless the server has seen media activity in that window (a local transport, a playlist or segment request, or a node delivery record). Paused sessions keep the 30-minute window. This means amending §2.5, so it needs a maintainer decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    go

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions