Skip to content

Fix live runner O2R recovery after orchestrator restart - #95

Open
emranemran wants to merge 5 commits into
mainfrom
fix/live-runner-reregister-o2r-20261122
Open

emranemran wants to merge 5 commits into
mainfrom
fix/live-runner-reregister-o2r-20261122

Conversation

@emranemran

@emranemran emranemran commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

A live runner can keep reading its old reservation channel after an orchestrator restart. Heartbeat authentication recovers, but re-registration's new O2R URL was ignored while an old reader object still existed. This leaves the runner available without receiving new reservation events.

Replace and close the old reader when a heartbeat supplies a different channel. If the callback ends (including HTTP 404/EOF) or fails, use bootstrap registration on the next heartbeat. Serialize heartbeat/reader updates, preserve an active reader on the same URL, and retain cleanup ownership if replacement is cancelled. Shutdown cannot attach a new reader.

Validation: all 367 tests pass; Ruff passes; wheel and source distribution build without publishing. Thirteen added regression cases cover 401 → new channel → reservation delivery, EOF/error/cancellation recovery, overlapping heartbeat requests, shutdown during replacement, cancelled replacement, a real local HTTP 404, and repeated cancellation during subscriber cleanup with a real HTTP session. A retained shielded close task prevents a second cancellation from abandoning that session. Removing the heartbeat lock or cleanup shield makes the respective regression fail. Tests use local or fake transports and make no provider or payment calls.

The changelog describes recovery behavior. Natural EOF/error cleanup also survives reader shutdown. Subscriber close retains one cleanup task, defers caller cancellation for at most ten seconds, and lets later close calls await unfinished cleanup. Tests cover natural cleanup with a real HTTP session, bounded cancellation and callback-initiated close without self-await. Restoring the old subscriber implementation fails both natural-cleanup cases. Existing public CI and package publication are unchanged. Downstream consumers can update their immutable dependency after review; this PR does not deploy or publish a release.

@emranemran
emranemran requested a review from j0sh as a code owner November 22, 2026 06:38
Copilot AI balanced review requested due to automatic review settings November 22, 2026 06:38

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

Repeated cancellation during subscriber cleanup can leave the HTTP session open, and the concurrency regression runs sequentially without testing overlapping heartbeat requests.

2 open issues
What changed in this PR

This PR restores live-runner reservation-event delivery after an orchestrator restart by refreshing stale O2R readers during heartbeat recovery.

Changes:

  • Replace readers when channel URLs change and re-register when readers terminate.
  • Serialize heartbeat updates and guard reader attachment during shutdown.
  • Add eight lifecycle regression cases and document the recovery behavior.
File Description
tests/​test_live_runner_reconnect.py Adds recovery, concurrency, cancellation, and local HTTP 404 regression tests.
src/​livepeer_gateway/​live_runner.py Adds heartbeat locking, reader replacement, and ended-reader recovery.
CHANGELOG.md Documents reservation-event recovery after orchestrator restarts.

Review effort: Balanced

Comment thread src/livepeer_gateway/live_runner.py Resolved
Comment thread tests/test_live_runner_reconnect.py Resolved
Copilot AI balanced review requested due to automatic review settings November 22, 2026 06:49

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.

🔵 Needs a closer look

Cancellation during reader replacement can interrupt transport cleanup and leave the old HTTP session open, while retries and shutdown cannot recover the abandoned cleanup.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 22, 2026 06:56

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.

🔵 Needs a closer look

A replacement heartbeat can cancel the old callback’s in-progress cleanup and leave its HTTP session open because subscriber teardown is not independently cancellation-safe.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Replacement heartbeat can cancel in-progress subscriber cleanup

src/​livepeer_gateway/​live_runner.py:585

If a new-channel heartbeat arrives while the old callback is already cleaning up after EOF or an error, reader.close(wait_callback=False) cancels that cleanup and can leave its HTTP session open. The outer shield protects the close task, but not the subscriber cleanup running inside the callback. Make subscriber teardown independently cancellation-safe and await its completion before replacement; add a regression where natural cleanup starts before the replacement heartbeat.

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 22, 2026 07:08

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.

🔵 Needs a closer look

Human assessment is needed because callback cancellation can deadlock shutdown or replacement, while failed re-registration can leave the runner registered without a working reader or unregister credential.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 22, 2026 07:12

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.

🔵 Needs a closer look

Interactions between callback cancellation and teardown ownership risk incomplete cleanup or deadlock, requiring human assessment.

No open issues 🎉

Review effort: Balanced

@seanhanca
seanhanca self-requested a review November 23, 2026 14:43

This branch has not been deployed

No deployments
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.

3 participants