fix(prediction): treat "aborted" as terminal state — prevents infinite polling#460
Open
devteamaegis wants to merge 3 commits into
Open
fix(prediction): treat "aborted" as terminal state — prevents infinite polling#460devteamaegis wants to merge 3 commits into
devteamaegis wants to merge 3 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When the Replicate API returns
"status": "aborted"for a prediction (server-side interruption), four polling loops don't recognize it as a terminal state and loop forever:This causes
replicate.run()/client.run()to hang indefinitely, matching the reports in #431.PR #449 correctly added
"aborted"to thePrediction.statusLiteraltype, but did not update the polling exit conditions, so the runtime behavior is unchanged.Root cause
Four places miss
"aborted":Prediction.wait()prediction.py:144run()hangs foreverPrediction.async_wait()prediction.py:153async_run()hangs foreverPrediction.output_iterator()prediction.py:254run()hangs foreverPrediction.async_output_iterator()prediction.py:276async_run()hangs foreverAdditionally, after
wait()returns,run()only checksprediction.status == "failed"— so an aborted prediction silently returnsNoneoutput instead of raising.Fix
"aborted"to all fourwhile … not in [...]terminal-state lists.output_iterator/async_output_iterator, extend the post-loop error check toif self.status in ("failed", "aborted").run()/async_run(), extend the error check toif prediction.status in ("failed", "aborted").No behaviour change for any currently-handled status (
succeeded,failed,canceled).Tests
Two new tests in
tests/test_run.py(both sync and async paths covered):test_run_raises_on_aborted_prediction[True/False]— a prediction that transitions to"aborted"causesrun()/async_run()to raiseModelErrorrather than hanging or returningNone.test_prediction_wait_terminates_on_aborted—wait()andasync_wait()exit immediately when status flips to"aborted".All 3 new test cases pass (
pytest tests/test_run.py -k "aborted").