replicate / replicate-swift

Swift client for Replicate
https://replicate.com
Apache License 2.0
157 stars 33 forks source link

Cancel function reports success but does not stop the ongoing process #79

Closed CanberkCig closed 1 month ago

CanberkCig commented 4 months ago

Environment:

Problem: I'm encountering an issue where the cancel() function in my PredictionManager class successfully changes the status to "canceled", yet the image generation process doesn't actually stop. Despite receiving a "canceled" status, the process continues and eventually returns an image.

Expected Behavior: When I invoke the cancel() function, the image generation process should immediately stop, and no image should be returned.

Steps to Reproduce:

  1. Start an image generation process using a prompt. (client.createPrediction)
  2. Before the process completes, call the cancel() function.
  3. Observe that the process status changes to "canceled", but the process still completes and returns an image.

Code Snippet:


class PredictionManager {
    var prediction: StableDiffusion.Prediction?

    func cancel() async throws {
        try await prediction?.cancel(with: client)
    }
}
mattt commented 4 months ago

Hi @CanberkCig. Thanks for reporting. Unfortunately, I'm unable to reproduce this issue based on the information provided. If the status is updated to cancelled in the client and you can verify this on your replicate.com dashboard, then it's very unlikely to produce output. In Replicate's API, once a prediction has reached a terminal state (either succeeded with output, failed with an error, or cancelled with neither), then it's guaranteed not to change.

What could be happening is that the request to cancel is happening after the prediction completes, which results in a successful prediction with output. Or else, maybe there's unintended behavior in your app code to start a new prediction and that's what you're seeing.

In either case, I'm unable to reproduce the reported behavior with the information provided.