You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix live runner O2R recovery after orchestrator restart - #95
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.
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.
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.
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
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.