Skip to content

Refresh the live runner O2R reader after re-registration - #96

Merged
j0sh merged 2 commits into
mainfrom
ja-codex/live-runner-o2r-restart
Dec 4, 2026
Merged

j0sh merged 2 commits into
mainfrom
ja-codex/live-runner-o2r-restart

Conversation

@j0sh

@j0sh j0sh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

When heartbeat authorization fails and a live runner registers again, read reservation events from the returned O2R channel. Reuse a healthy reader when the effective URL matches. A replacement can start while the previous reader finishes cleanup.

Alternative to #95.

Validation

  • 358 tests passed.
  • Ruff passed.
  • The changed-URL regression fails on main and passes with this patch.

@j0sh
j0sh marked this pull request as ready for review December 4, 2026 01:54
Copilot AI balanced review requested due to automatic review settings December 4, 2026 01:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Shutdown does not await retired readers, so it can return with cleanup tasks and HTTP sessions still alive.

1 open issue
What changed in this PR

Refreshes the live runner’s reservation-event reader after re-registration so it follows the returned O2R channel.

Changes:

  • Reuses healthy readers when normalized URLs match; otherwise starts a replacement.
  • Exposes subscriber state and tracks retired reader tasks.
  • Adds regression coverage for channel changes and reader health.
File Description
tests/​test_live_runner.py Tests reader reuse, replacement, and reservation delivery.
tests/​test_channel_reader.py Checks subscriber availability during callbacks.
src/​livepeer_gateway/​live_runner.py Implements reader refresh and retirement tracking.
src/​livepeer_gateway/​channel_reader.py Retains the active subscriber for health checks.

Review effort: Balanced

Comment on lines +580 to +581
self._retired_o2r_tasks.add(old_task)
old_task.add_done_callback(self._retired_o2r_tasks.discard)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced this window. Registration close() can return with a retired reader’s HTTP session still open. Cleanup completed while the event loop stayed up, and cancelling the retired task during teardown interrupted cleanup.

I also verified that a retired application callback can call registration.close() from its own task. Draining all retired tasks there would make that callback wait on itself. A safe drain needs explicit rules for reentrancy, caller cancellation, and how long shutdown should wait. For this PR, I’m keeping retirement asynchronous and the implementation at 14 added lines. A guaranteed drain is a separate shutdown change.

@j0sh
j0sh merged commit 2e45932 into main Dec 4, 2026
7 checks passed
@j0sh
j0sh deleted the ja-codex/live-runner-o2r-restart branch December 4, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants