Skyvern-AI / skyvern

Automate browser-based workflows with LLMs and Computer Vision
https://www.skyvern.com
GNU Affero General Public License v3.0
10.78k stars 739 forks source link

Webhook failed issue #1130

Closed devinat1 closed 3 weeks ago

devinat1 commented 3 weeks ago
":50,"workflow_run_id":null} task_id=tsk_322439587611757096 webhook_callback_url=https://6642f909995b.ngrok.app/webhook
2024-11-04T21:59:32.018944Z [info     ] Webhook failed                 resp=<Response [400 Bad Request]> resp_code=400 resp_text=<!DOCTYPE html>
<html class="h-full" lang="en-US" dir="ltr">
  <head>
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Regular-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-RegularItalic-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Medium-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Semibold-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-MediumItalic-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-Text.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-TextItalic.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-SemiBold.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <meta charset="utf-8">
    <meta name="author" content="ngrok">
    <meta name="description" content="ngrok is the fastest way to put anything on the internet with a single command.">
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link id="style" rel="stylesheet" href="https://cdn.ngrok.com/static/css/error.css">
    <noscript>Traffic was successfully tunneled to the ngrok agent, but the agent failed to establish a connection to the upstream web service at localhost:5000. (ERR_NGROK_8012)</noscript>
    <script id="script" src="https://cdn.ngrok.com/static/js/error.js" type="text/javascript"></script>
  </head>
  <body class="h-full" id="ngrok">
    <div id="root" data-payload="eyJhZGRyIjoibG9jYWxob3N0OjUwMDAiLCJjZG5CYXNlIjoiaHR0cHM6Ly9jZG4ubmdyb2suY29tLyIsImNvZGUiOiI4MDEyIiwiZXJyb3JUZXh0IjoiZGlhbCB0Y3AgMTI3LjAuMC4xOjUwMDA6IGNvbm5lY3Q6IGNvbm5lY3Rpb24gcmVmdXNlZCIsIm1lc3NhZ2UiOiJUcmFmZmljIHdhcyBzdWNjZXNzZnVsbHkgdHVubmVsZWQgdG8gdGhlIG5ncm9rIGFnZW50LCBidXQgdGhlIGFnZW50IGZhaWxlZCB0byBlc3RhYmxpc2ggYSBjb25uZWN0aW9uIHRvIHRoZSB1cHN0cmVhbSB3ZWIgc2VydmljZSBhdCBsb2NhbGhvc3Q6NTAwMC4iLCJ0aXRsZSI6IkJhZCBSZXF1ZXN0In0="></div>
  </body>
</html>
 task_id=tsk_322439587611757096

This occurs with the following task payload:

 {
    "title": "null",
    "url": "https://airbnb.com",
    "webhook_callback_url": "https://6642f909995b.ngrok.app/webhook",
    "navigation_goal": "For airbnb.com, Navigate to the search page for short-term rentals, enter \"76002\" as the location, select the date range from \"August 27, 2024\" to \"September 7, 2024\", and apply the search. COMPLETE when the search results page displays listings for Arlington, Texas, within the given date range.",
    "data_extraction_goal": "Extract all available listings including details such as title, price per night, and host ratings for the specified location and date range.",
    "navigation_payload": {
        "location": "76002",
        "check_in": "2024-08-27",
        "check_out": "2024-09-07"
    },
    "error_code_mapping": {},
    "proxy_location": "NONE",
    "extracted_information_schema": "null"
}

My webhook is hosted via the ngrok http 5000 command. Here is the respective webhook flask code:

from flask import Flask, request, jsonify
import os
import redis
import json

app = Flask(__name__)

redis_host = os.getenv("REDIS_HOST", "localhost")
redis_port = int(os.getenv("REDIS_PORT", 6379))
redis_password = os.getenv("REDIS_PASSWORD", None)

r = redis.StrictRedis(
    host=redis_host, port=redis_port, password=redis_password, decode_responses=True
)

@app.route("/webhook", methods=["POST"])
def webhook():
    try:
        raw_data = request.data.decode(
            "utf-8", errors="replace"
        )  # Replace errors for debugging
        print("Raw request data:", raw_data)

        # Print headers and other request details
        print("Request headers:", request.headers)
        print("Content-Length header:", request.headers.get("Content-Length"))
        print("Length of raw data:", len(raw_data))

        if request.content_type != "application/json":
            print("Invalid content type:", request.content_type)
            return jsonify({"error": "Invalid content type"}), 400
        try:
            data = json.loads(raw_data)
            print("Webhook data:", data)
        except json.JSONDecodeError as e:
            print("JSON decode error:", str(e))
            r.incr("callback_count")  # Still incrementing to exit the skyvern script
            return jsonify({"status": "Bad Request", "error": str(e)}), 400

        r.incr("callback_count")
        return jsonify({"status": "success"}), 200

    except Exception as e:
        print("Exception occurred:", str(e))
        return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
devinat1 commented 3 weeks ago

Note that this happens only sometimes (sometimes the webhook succeeds). I cannot get to the root of the issue.

suchintan commented 3 weeks ago

@devinat1 This issue is definitely in your ngrok tunnel (not Skyvern)

    <noscript>Traffic was successfully tunneled to the ngrok agent, but the agent failed to establish a connection to the upstream web service at localhost:5000. (ERR_NGROK_8012)</noscript>