Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread runs sometimes throws HttpException, Graph 'xxx' not found #3120

Open
4 tasks done
Jackoder opened this issue Jan 21, 2025 · 0 comments
Open
4 tasks done

Thread runs sometimes throws HttpException, Graph 'xxx' not found #3120

Jackoder opened this issue Jan 21, 2025 · 0 comments

Comments

@Jackoder
Copy link

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

import requests
import time
import logging

# Configure logging
logging.basicConfig(
    filename='thread_process.log',
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s'
)

console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)

def log_request_response(response):
    logging.info(f"Request URL: {response.request.url}")
    logging.info(f"Request Method: {response.request.method}")
    logging.info(f"Request Headers: {response.request.headers}")
    if response.request.body:
        logging.info(f"Request Body: {response.request.body}")
    logging.info(f"Response Status Code: {response.status_code}")
    logging.info(f"Response Headers: {response.headers}")
    logging.info(f"Response Body: {response.text}")

import uuid

def create_thread():
    # thread_id = str(uuid.uuid4())  # Generate a UUID for thread_id
    url = "http://127.0.0.1:8123/threads"
    payload = {
    }
    response = requests.post(url, json=payload)
    log_request_response(response)
    response.raise_for_status()
    thread_id = response.json()["thread_id"]
    logging.info(f"Thread created with ID: {thread_id}")
    return thread_id

def run_thread(thread_id):
    url = f"http://127.0.0.1:8123/threads/{thread_id}/runs/wait"
    payload = {
        "assistant_id": "0676914a-25a7-595a-a130-6f9e1ad87f7d",
        "input": {
            "knowledge": "Camera",
            "node": "Rule"
        },
        "after_seconds": 1
    }
    response = requests.post(url, json=payload)
    log_request_response(response)
    response.raise_for_status()
    run_id = response.json()["run_id"]
    logging.info(f"Thread run initiated with Run ID: {run_id}")
    return run_id

def get_thread_status(thread_id):
    url = f"http://127.0.0.1:8123/threads/{thread_id}/runs"
    response = requests.get(url)
    log_request_response(response)
    response.raise_for_status()
    status = response.json()[0]["status"]
    logging.info(f"Current status: {status}")
    return status

def get_thread_result(thread_id):
    url = f"http://127.0.0.1:8123/threads/{thread_id}"
    response = requests.get(url)
    log_request_response(response)
    response.raise_for_status()
    result = response.json()
    logging.info(f"Thread result: {result}")
    return result

def execute_test():
    try:
        thread_id = create_thread()
        retry_count = 0
        run_id = run_thread(thread_id)
        status = get_thread_status(thread_id)
        while status != "success":
            if status == "error":
                retry_count += 1
                if retry_count > 3:
                    logging.error("Thread run failed after 3 retries.")
                    return False
                logging.warning(f"Thread run encountered an error. Retrying {retry_count}/3...")
                run_id = run_thread(thread_id)  # Retry running the thread
            # time.sleep(2)
            status = get_thread_status(thread_id)
        result = get_thread_result(thread_id)
        return True
    except Exception as e:
        logging.error(f"Exception occurred: {e}")
        return False

def main():
    success_count = 0
    total_runs = 10
    for i in range(total_runs):
        logging.info(f"Starting test run {i+1}/{total_runs}")
        if execute_test():
            success_count += 1
        logging.info(f"Test run {i+1}/{total_runs} completed")

    success_rate = (success_count / total_runs) * 100
    logging.info(f"Success rate: {success_rate}%")

if __name__ == "__main__":
    main()

Error Message and Stack Trace (if applicable)

2025-01-21 12:33:33,813 - INFO - Request URL: http://127.0.0.1:8123/threads
2025-01-21 12:33:33,813 - INFO - Request Method: POST
2025-01-21 12:33:33,813 - INFO - Request Headers: {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '2', 'Content-Type': 'application/json'}
2025-01-21 12:33:33,813 - INFO - Request Body: b'{}'
2025-01-21 12:33:33,813 - INFO - Response Status Code: 200
2025-01-21 12:33:33,813 - INFO - Response Headers: {'date': 'Tue, 21 Jan 2025 04:33:33 GMT', 'server': 'uvicorn', 'content-length': '220', 'content-type': 'application/json'}
2025-01-21 12:33:33,813 - INFO - Response Body: {"thread_id":"2a6608cc-ec49-41f6-8926-a249dda7ff97","created_at":"2025-01-21T12:33:34.919186+08:00","updated_at":"2025-01-21T12:33:34.919186+08:00","metadata":{},"status":"idle","config":{},"values":null,"interrupts":{}}
2025-01-21 12:33:33,813 - INFO - Thread created with ID: 2a6608cc-ec49-41f6-8926-a249dda7ff97
2025-01-21 12:33:35,551 - INFO - Request URL: http://127.0.0.1:8123/threads/2a6608cc-ec49-41f6-8926-a249dda7ff97/runs/wait
2025-01-21 12:33:35,551 - INFO - Request Method: POST
2025-01-21 12:33:35,552 - INFO - Request Headers: {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Length': '126', 'Content-Type': 'application/json'}
2025-01-21 12:33:35,552 - INFO - Request Body: b'{"assistant_id": "0676914a-25a7-595a-a130-6f9e1ad87f7d", "input": {"knowledge": "Camera", "node": "Rule"}, "after_seconds": 1}'
2025-01-21 12:33:35,552 - INFO - Response Status Code: 200
2025-01-21 12:33:35,552 - INFO - Response Headers: {'date': 'Tue, 21 Jan 2025 04:33:33 GMT', 'server': 'uvicorn', 'location': '/threads/2a6608cc-ec49-41f6-8926-a249dda7ff97/runs/1efd7b0d-fa56-665c-a80c-a655ff544eea/join', 'content-type': 'application/json', 'transfer-encoding': 'chunked'}
2025-01-21 12:33:35,553 - INFO - Response Body: {"__error__":{"error":"HTTPException","message":"404: Graph 'rule' not found"}}
2025-01-21 12:33:35,553 - ERROR - Exception occurred: 'run_id'

Description

After I finished deploying using Docker, the Runs API sometimes throws a Graph 'rule' not found error, with an error rate of about 20%. Is there a problem somewhere, and how should it be resolved?

https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/#using-docker

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.11.11 (main, Dec 4 2024, 08:55:08) [GCC 9.4.0]

Package Information

langchain_core: 0.3.30
langchain: 0.3.12
langchain_community: 0.3.10
langsmith: 0.1.147
langchain_anthropic: 0.3.0
langchain_fireworks: 0.2.5
langchain_openai: 0.3.0
langchain_text_splitters: 0.3.3
langchainhub: 0.1.21
langgraph_api: 0.0.15
langgraph_cli: 0.1.65
langgraph_license: Installed. No version info available.
langgraph_sdk: 0.1.48
langgraph_storage: Installed. No version info available.
langserve: 0.3.0

Other Dependencies

aiohttp: 3.11.10
anthropic: 0.40.0
async-timeout: Installed. No version info available.
click: 8.1.7
cryptography: 43.0.3
dataclasses-json: 0.6.7
defusedxml: 0.7.1
fastapi: 0.115.6
fireworks-ai: 0.15.10
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch: 1.33
jsonschema-rs: 0.25.1
langgraph: 0.2.63
langgraph-checkpoint: 2.0.10
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
openai: 1.59.7
orjson: 3.10.12
packaging: 24.2
pydantic: 2.10.3
pydantic-settings: 2.6.1
pyjwt: 2.10.1
python-dotenv: 1.0.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
sse-starlette: 2.1.3
starlette: 0.41.3
structlog: 24.4.0
tenacity: 8.5.0
tiktoken: 0.8.0
types-requests: 2.32.0.20241016
typing-extensions: 4.12.2
uvicorn: 0.32.1
watchfiles: 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant