langflow-ai / langflow

Langflow is a low-code app builder for RAG and multi-agent AI applications. It’s Python-based and agnostic to any model, API, or database.
http://www.langflow.org
MIT License
27k stars 3.57k forks source link

Component has not been built yet #2656

Open zdql opened 1 month ago

zdql commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

We run langflow via a pip install in a docker file, passing in 4 celery workers like so:

FROM python:3.10-slim

COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

RUN pip install langflow==1.0.8 -U --user

COPY custom_components /app/custom_components

CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860", "--components-path", "/app/custom_components", "--workers", "4"]

Browser and Version

To Reproduce Host langflow with our docker file and attempt to run any flow. The error will happen sporadically when running flows

This is the stack trace we see:

Component Text Input has not been built yet

Traceback (most recent call last):
  File "/root/.local/lib/python3.10/site-packages/langflow/api/v1/chat.py", line 198, in build_vertex
    ) = await graph.build_vertex(
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 913, in build_vertex
    raise exc
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 893, in build_vertex
    await vertex.build(
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 721, in build
    await step(user_id=user_id, **kwargs)
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 421, in _build
    await self._build_each_vertex_in_params_dict(user_id)
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 484, in _build_each_vertex_in_params_dict
    await self._build_vertex_and_update_params(
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 560, in _build_vertex_and_update_params
    result = await vertex.get_result(self)
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 535, in get_result
    return await self._get_result(requester)
  File "/root/.local/lib/python3.10/site-packages/langflow/graph/vertex/types.py", line 84, in _get_result
    raise ValueError(f"Component {self.display_name} has not been built yet")
ValueError: Component Text Input has not been built yet

Additional context We've seen this occur on both our custom components and the langflow built in components. The error happens about 40% of the time when running a flow.

dosubot[bot] commented 1 month ago

To address the "Component has not been built yet" error in Langflow when running flows using your Docker setup, you can try the following steps:

  1. Verify Installation: Ensure that the Langflow package is installed correctly in your Dockerfile. You can add a verification step to check the installation.

  2. Concurrency Handling: Since you are using multiple workers, ensure that concurrency issues are handled properly. Langflow has known race conditions that might affect the build process.

  3. Improved Dockerfile: Update your Dockerfile to include verification steps and ensure all components are built correctly.

Here is an improved version of your Dockerfile:

FROM python:3.10-slim

COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

RUN pip install langflow==1.0.8 -U --user

COPY custom_components /app/custom_components

# Verify installation
RUN pip show langflow

CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860", "--components-path", "/app/custom_components", "--workers", "4"]
  1. Exception Handling and Logging: Enhance the exception handling and logging in your build_vertex function to better understand the root cause of the error. Here is an example:
@router.post("/build/{flow_id}/vertices/{vertex_id}")
async def build_vertex(
    flow_id: uuid.UUID,
    vertex_id: str,
    background_tasks: BackgroundTasks,
    inputs: Annotated[Optional[InputValueRequest], Body(embed=True)] = None,
    files: Optional[list[str]] = None,
    chat_service: "ChatService" = Depends(get_chat_service),
    current_user=Depends(get_current_active_user),
    telemetry_service: "TelemetryService" = Depends(get_telemetry_service),
):
    """Build a vertex instead of the entire graph."""
    flow_id_str = str(flow_id)

    next_runnable_vertices = []
    top_level_vertices = []
    start_time = time.perf_counter()
    try:
        cache = await chat_service.get_cache(flow_id_str)
        if not cache:
            logger.warning(f"No cache found for {flow_id_str}. Building graph starting at {vertex_id}")
            graph: "Graph" = await build_graph_from_db(
                flow_id=flow_id_str, session=next(get_session()), chat_service=chat_service
            )
        else:
            graph = cache.get("result")
            await graph.initialize_run()
        vertex = graph.get_vertex(vertex_id)
        # Additional logic to handle vertex building
        ...
    except Exception as exc:
        background_tasks.add_task(
            telemetry_service.log_package_component,
            ComponentPayload(
                name=vertex_id,
                seconds=int(time.perf_counter() - start_time),
                success=False,
                errorMessage=str(exc),
            ),
        )
        logger.error(f"Error building Component:\n\n{exc}")
        logger.exception(exc)
        message = parse_exception(exc)
        raise HTTPException(status_code=500, detail=message) from exc
  1. Concurrency Issues: Ensure that concurrency issues are managed properly. Langflow uses locks to handle concurrency, which might be necessary in your setup.
lock = chat_service._cache_locks[flow_id_str]
(
    result_dict,
    params,
    valid,
    artifacts,
    vertex,
) = await graph.build_vertex(
    chat_service=chat_service,
    vertex_id=vertex_id,
    user_id=current_user.id,
    inputs_dict=inputs.model_dump() if inputs else {},
    files=files,
)

By following these steps, you can improve the reliability of the component building process in Langflow and reduce the occurrence of the "Component has not been built yet" error [1][2].

To continue talking to Dosu, mention @dosu.