Skip to content

uv sync fails instantly with context canceled during plugin installation #653

@ebertti

Description

@ebertti

Bug Report: uv sync fails instantly with context canceled during plugin installation

Self Checks

  • I have searched for existing issues, including closed ones.
  • I confirm that I am using English to submit this report.

Versions

  1. dify-plugin-daemon Version: 0.5.4-local (langgenius/dify-plugin-daemon:0.5.4-local)
  2. dify-api Version: 1.13.2
  3. uv Version (inside container): 0.10.10
  4. Python Version (inside container): 3.12.3
  5. Deployment: Docker (via Coolify)

Describe the bug

When installing a plugin (e.g., langgenius/gemini:0.7.19) from the marketplace, the plugin daemon fails to initialize the Python environment. The uv sync command fails instantly (~0.4ms) with context canceled error, meaning the command never actually starts executing.

However, running uv sync manually inside the container in the same plugin directory succeeds without issues (completes in ~8 seconds, installs 70 packages).

Key observations

  1. The virtual environment is always marked as "invalid" and deleted before the install attempt.
  2. The !BADKEY in the log suggests a Go slog formatting bug in environment_python.go:27.
  3. The error occurs in 0.4ms — the Go context is already canceled before exec.Command starts.
  4. Network is fine: curl -s https://pypi.org/simple/dify-plugin/ works from inside the container.
  5. Disk space is fine: 337GB available on /app/storage.
  6. Memory is fine: container uses ~212MB of 31GB, no OOM kills in dmesg.
  7. Older plugin version works: langgenius/gemini:0.7.0 (which already had a valid .venv) loads correctly after restart.

To Reproduce

  1. Deploy Dify 1.13.2 with dify-plugin-daemon:0.5.4-local
  2. Try installing langgenius/gemini:0.7.19 from the marketplace
  3. Plugin fails with: failed to launch plugin: failed to install dependencies: failed to start command: context canceled

Relevant Logs

INFO  dify-plugin-daemon logger.go:15 local runtime starting plugin=langgenius/gemini:0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49
INFO  dify-plugin-daemon launcher_local.go:78 acquiring distributed init lock plugin=langgenius/gemini:0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49 expire=15m0s
WARN  dify-plugin-daemon environment_python.go:27 virtual environment for %s is invalid; deleting and recreating !BADKEY=langgenius/gemini:0.7.19
WARN  dify-plugin-daemon setup_python_environment.go:351 deleting existing Python virtual environment plugin=langgenius/gemini:0.7.19 path=/app/storage/cwd/langgenius/gemini-0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49/.venv
INFO  dify-plugin-daemon setup_python_environment.go:385 detected dependency file plugin=langgenius/gemini:0.7.19 file=pyproject.toml
INFO  dify-plugin-daemon setup_python_environment.go:157 installing plugin dependencies plugin=langgenius/gemini:0.7.19 method="uv sync" file=pyproject.toml
ERROR dify-plugin-daemon logger.go:24 local runtime start failed plugin=langgenius/gemini:0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49 error="failed to install dependencies: failed to start command: context canceled\nfailed to init environment"
INFO  dify-plugin-daemon launcher_local.go:93 released distributed init lock plugin=langgenius/gemini:0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49

Note: The time between "installing plugin dependencies" and "ERROR" is only 0.4ms (15:03:21.557979195Z15:03:21.5584203Z), confirming the command never actually starts.

Manual uv sync works

$ docker exec -w /app/storage/cwd/langgenius/gemini-0.7.19@8eada8d6c655509364283527db67e47a4603021cda289f571af10e217459cf49 \
    plugin_daemon-container uv sync 2>&1
Resolved 73 packages in 46ms
...
Installed 70 packages in 3.11s

Workaround

Running uv sync manually inside the container in the plugin directory, then restarting the plugin daemon, allows the plugin to load (since the .venv is already valid). However, the daemon still fails to install new plugins automatically.

Expected behavior

Plugin should be installed and initialized automatically without requiring manual intervention.

Possibly related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions