replicate/replicate-javascript

Webhooks stopped working

Seanitzel opened this issue · 5 comments

For some reason, without any changes on my end, all webhooks stopped being called.

My code:

  const replicate = new Replicate({
    auth: REPLICATE_API_KEY.value(),
  });

  replicate.run(
    model,
    {
      input,
      webhook,
    }, // , (prediction) => {} optional callback with prediction
  );

I look at the UI for the prediction and the webhook appears to not exist

image

aron commented

Thanks for the bug report, I'll look into this. Does the prediction response have a webhook field containing the same URL you provided in the webhook input?

Yes, this is what one of the prediction progress callbacks looks like -

{
  "insertId": "671926060006977ecf210843",
  "jsonPayload": {
    "id": "25a4tvw8yxrgj0cjq8y9nb6j78",
    "model": "ryan5453/demucs",
    "output": null,
    "error": null,
    "input": {
      "overlap": 0.25,
      "stem": "vocals",
      "output_format": "mp3",
      "clip_mode": "rescale",
      "wav_format": "int24",
      "model": "htdemucs",
      "jobs": 0,
      "shifts": 1,
      "audio": "omitted",
      "split": true,
      "mp3_bitrate": 320,
      "mp3_preset": 2
    },
    "created_at": "2024-10-23T16:36:22.391Z",
    "urls": {
      "cancel": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78/cancel",
      "get": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78"
    },
    "status": "starting",
    "version": "7a9db77ed93f8f4f7e233a94d8519a867fbaa9c6d16ea5b53c1394f1557f9c61",
    "logs": "",
    "webhook": "my-webhook-which-i-omit-for-security-reasons",
    "data_removed": false
  },
  "resource": {
    "type": "cloud_run_revision",
    "labels": {
      "location": "us-central1",
      "revision_name": "separateaudio-00004-qop",
      "project_id": "lavocal-500b2",
      "configuration_name": "separateaudio",
      "service_name": "separateaudio"
    }
  },
  "timestamp": "2024-10-23T16:36:22.431998Z",
  "severity": "INFO",
  "labels": {
    "goog-managed-by": "cloudfunctions",
    "instanceId": "007989f2a14045525b564a8f5651c8a4c7ee5b28b983b982040803a55f687c728638079c84cd8ea556fa9b79edc34ee10e3241869defaee9b9fb38953e6a4b80a0b29e8e04cf5f",
    "execution_id": "m3jjh3lg2ml8"
  },
  "logName": "projects/lavocal-500b2/logs/run.googleapis.com%2Fstdout",
  "trace": "4d1a6fb52d7e162e9bfcdb38841ae401",
  "receiveTimestamp": "2024-10-23T16:36:22.633478430Z",
  "spanId": "6803285821735915836"
}

Also, the final prediction object looks like this in my logs:

{
  "insertId": "67192676000cef369534ec98",
  "jsonPayload": {
    "data_removed": false,
    "model": "ryan5453/demucs",
    "created_at": "2024-10-23T16:36:22.391Z",
    "status": "succeeded",
    "id": "25a4tvw8yxrgj0cjq8y9nb6j78",
    "error": null,
    "version": "7a9db77ed93f8f4f7e233a94d8519a867fbaa9c6d16ea5b53c1394f1557f9c61",
    "urls": {
      "get": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78",
      "cancel": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78/cancel"
    },
    "completed_at": "2024-10-23T16:38:13.864815738Z",
    "output": {
      "vocals": "https://storage.googleapis.com/replicate-files/OV61MRDVksbnPl5L483rmrWg9JfqDZspqlPc8VTKJyV6w20JA/file",
      "no_vocals": "https://storage.googleapis.com/replicate-files/BDz8xozFz0pdNNsR3hW6LQ6tDxfYCvV4347y4Kc2Aif1htpTA/file"
    },
    "webhook": "my-webhook-which-i-ommited",
    "started_at": "2024-10-23T16:38:08.769957957Z",
    "input": {
      "model": "htdemucs",
      "wav_format": "int24",
      "audio": "omitted",
      "clip_mode": "rescale",
      "stem": "vocals",
      "shifts": 1,
      "split": true,
      "mp3_preset": 2,
      "overlap": 0.25,
      "mp3_bitrate": 320,
      "jobs": 0,
      "output_format": "mp3"
    },
    "metrics": {
      "predict_time": 5.094857781
    },
    "logs": "  0%|                                                                     | 0.0/17.549999999999997 [00:00<?, ?seconds/s]\n 33%|████████████████████                                        | 5.85/17.549999999999997 [00:00<00:01, 10.52seconds/s]\n 67%|████████████████████████████████████████                    | 11.7/17.549999999999997 [00:00<00:00, 19.52seconds/s]\n100%|██████████████████████████████████████████████| 17.549999999999997/17.549999999999997 [00:00<00:00, 27.04seconds/s]\n100%|██████████████████████████████████████████████| 17.549999999999997/17.549999999999997 [00:00<00:00, 22.11seconds/s]\n"
  },
  "resource": {
    "type": "cloud_run_revision",
    "labels": {
      "configuration_name": "separateaudio",
      "service_name": "separateaudio",
      "revision_name": "separateaudio-00004-qop",
      "location": "us-central1",
      "project_id": "lavocal-500b2"
    }
  },
  "timestamp": "2024-10-23T16:38:14.847670Z",
  "severity": "INFO",
  "labels": {
    "execution_id": "m3jjh3lg2ml8",
    "goog-managed-by": "cloudfunctions",
    "instanceId": "007989f2a14045525b564a8f5651c8a4c7ee5b28b983b982040803a55f687c728638079c84cd8ea556fa9b79edc34ee10e3241869defaee9b9fb38953e6a4b80a0b29e8e04cf5f"
  },
  "logName": "projects/lavocal-500b2/logs/run.googleapis.com%2Fstdout",
  "trace": "4d1a6fb52d7e162e9bfcdb38841ae401",
  "receiveTimestamp": "2024-10-23T16:38:14.868455507Z",
  "spanId": "6803285821735915836"
}

And like this in replicate dashboard

{
  "completed_at": "2024-10-23T16:38:13.864815Z",
  "created_at": "2024-10-23T16:36:22.391000Z",
  "data_removed": false,
  "error": null,
  "id": "25a4tvw8yxrgj0cjq8y9nb6j78",
  "input": {
    "jobs": 0,
    "stem": "vocals",
    "audio": "omitted",
    "model": "htdemucs",
    "split": true,
    "shifts": 1,
    "overlap": 0.25,
    "clip_mode": "rescale",
    "mp3_preset": 2,
    "wav_format": "int24",
    "mp3_bitrate": 320,
    "output_format": "mp3"
  },
  "logs": "0%|                                                                     | 0.0/17.549999999999997 [00:00<?, ?seconds/s]\n 33%|████████████████████                                        | 5.85/17.549999999999997 [00:00<00:01, 10.52seconds/s]\n 67%|████████████████████████████████████████                    | 11.7/17.549999999999997 [00:00<00:00, 19.52seconds/s]\n100%|██████████████████████████████████████████████| 17.549999999999997/17.549999999999997 [00:00<00:00, 27.04seconds/s]\n100%|██████████████████████████████████████████████| 17.549999999999997/17.549999999999997 [00:00<00:00, 22.11seconds/s]",
  "metrics": {
    "predict_time": 5.094857781,
    "total_time": 111.473815
  },
  "output": {
    "vocals": "https://storage.googleapis.com/replicate-files/OV61MRDVksbnPl5L483rmrWg9JfqDZspqlPc8VTKJyV6w20JA/file",
    "no_vocals": "https://storage.googleapis.com/replicate-files/BDz8xozFz0pdNNsR3hW6LQ6tDxfYCvV4347y4Kc2Aif1htpTA/file"
  },
  "started_at": "2024-10-23T16:38:08.769957Z",
  "status": "succeeded",
  "urls": {
    "get": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78",
    "cancel": "https://api.replicate.com/v1/predictions/25a4tvw8yxrgj0cjq8y9nb6j78/cancel"
  },
  "version": "7a9db77ed93f8f4f7e233a94d8519a867fbaa9c6d16ea5b53c1394f1557f9c61"
}

(Without the webhook in the dashboard, for some reason...)

aron commented

Hmm, looking at the prediction metadata you're right. Though I notice your webhook URL has some JSON embedded in a query string parameter that doesn't look like it's correctly URL encoded. You could try running that through encodeURLComponent(json) and that should sort out the issue.

That actually seems to have fixed it.
Weird cause before it was definitely working like this...
Thanks for the help :)