Skip to content

feat: auto-detect pip mirror#750

Draft
BeautyyuYanli wants to merge 3 commits into
mainfrom
feat/auto-mirror
Draft

feat: auto-detect pip mirror#750
BeautyyuYanli wants to merge 3 commits into
mainfrom
feat/auto-mirror

Conversation

@BeautyyuYanli
Copy link
Copy Markdown
Contributor

@BeautyyuYanli BeautyyuYanli commented May 29, 2026

Description

This PR adds startup-time automatic PyPI mirror selection for plugin dependency installation.

Environment variables

  • PIP_MIRROR_AUTO_DETECT

    • Default: true
    • Controls whether the daemon should try to auto-select a suitable PyPI mirror during startup.
    • When enabled and no explicit mirror is configured, the daemon detects the public IP region and may assign a local mirror for regions with poor network connectivity.
  • PIP_MIRROR_URL

    • Default: empty
    • Manually specifies the PyPI mirror used for plugin dependency resolution.
    • When set, it takes precedence over auto detection and disables the auto-selected mirror.

Detection behavior

  • The daemon uses https://cloudflare.com/cdn-cgi/trace at startup to detect the public IP region.
  • If the detected region needs a local mirror, config.PipMirrorUrl is populated before plugin runtimes install Python dependencies.
  • Regions that do not need a mirror keep the default behavior.
  • Detection failures are non-fatal: the daemon logs a warning and continues startup without changing the mirror configuration.

Documentation and tests

  • Updates .env.example and README.md to describe the mirror-related configuration behavior.
  • Adds tests for config defaults, env overrides, trace parsing, mirror precedence, region-based application, and non-blocking failure handling.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

Local verification performed:

go build -o /tmp/opencode/dify-plugin-daemon-server cmd/server/main.go
go test ./cmd/server ./internal/types/app

This PR is drafted by gpt-5.4 and gpt-5.5. I'm responsible for all the changes. I have reviewed the code and varified the behavior, while breaks may still exist. Reach me to fix in this case.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code plugin-daemon labels May 29, 2026
gemini-code-assist[bot]

This comment was marked as low quality.

Comment thread cmd/server/main.go
)

const (
alibabaCloudPypiMirrorURL = "https://mirrors.aliyun.com/pypi/simple/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest moving mirror candidate to a environment variable instead of a const.

Having multiple default candidates may help improve the reliability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those who want to set ENV may set the mirror directly? This AUTO DETECT is meant to provide a default and out-of-box value.

Copy link
Copy Markdown
Contributor

@wylswz wylswz Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rethinking about the design. I'll try

  • Not to introduce another dependency on CF. Instead, rely on the connectivity to the configured mirror.
  • Make the connectivity issue visible to the user. If the mirrors are unavailable to the service (auto detected or explicitly configured, users should be able to see that installing plugins)

Approach 1

  1. Add a background checker, and expose the connectivity to healthiness probe of this service.
  2. Add on indicator to Dify console.

Approach 2

Do a connectivity check when starting up, fail fast with a clear log.

@wylswz wylswz marked this pull request as draft June 1, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code plugin-daemon size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants