diff --git a/python/cog/server/http.py b/python/cog/server/http.py index 478a5e3a72..7228f6ab3b 100644 --- a/python/cog/server/http.py +++ b/python/cog/server/http.py @@ -425,6 +425,16 @@ async def predict_idempotent( jsonable_encoder(task.result), status_code=202, ) + else: + # even if not busy (use concurrency and max > 1) , + # but someone put with the same prediction id repeatedly , + # return its current state. + task = runner.get_predict_task(request.id) + if task: + return JSONResponse( + jsonable_encoder(task.result), + status_code=202, + ) # TODO: spec-compliant parsing of Prefer header. respond_async = prefer == "respond-async"