fix os.Stat(pythonPath) error return #233

Closed
opened 2026-02-16 01:15:03 -05:00 by yindo · 1 comment
Owner

Originally created by @fatelei on GitHub (Jan 23, 2026).

Self Checks

To make sure we get to you in time, please check the following :)

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • "Please do not modify this template :) and fill in all the required fields."

Versions

  1. dify-plugin-daemon Version
  2. dify-api Version

Describe the bug

because

if _, err := os.Stat(pythonPath); err != nil {                                               
   return nil, fmt.Errorf("failed to find python: %s", err)                                   
}

return fmt.Errorf("failed to find python: %s", err)

venv, err := p.checkPythonVirtualEnvironment()
  switch err {
  case ErrVirtualEnvironmentInvalid:
      p.deleteVirtualEnvironment()
      venv, err = p.createVirtualEnvironment(uvPath)
  case ErrVirtualEnvironmentNotFound:
      venv, err = p.createVirtualEnvironment(uvPath)
  case nil:
      return nil
  default:
      return fmt.Errorf("failed to check virtual environment: %w", err)

can not self healing

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Originally created by @fatelei on GitHub (Jan 23, 2026). **Self Checks** To make sure we get to you in time, please check the following :) - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify-plugin-daemon/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] "Please do not modify this template :) and fill in all the required fields." **Versions** 1. dify-plugin-daemon Version 2. dify-api Version **Describe the bug** because ``` if _, err := os.Stat(pythonPath); err != nil { return nil, fmt.Errorf("failed to find python: %s", err) } ``` return fmt.Errorf("failed to find python: %s", err) ``` venv, err := p.checkPythonVirtualEnvironment() switch err { case ErrVirtualEnvironmentInvalid: p.deleteVirtualEnvironment() venv, err = p.createVirtualEnvironment(uvPath) case ErrVirtualEnvironmentNotFound: venv, err = p.createVirtualEnvironment(uvPath) case nil: return nil default: return fmt.Errorf("failed to check virtual environment: %w", err) ``` can not self healing **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. **Additional context** Add any other context about the problem here.
yindo added the bug label 2026-02-16 01:15:03 -05:00
yindo closed this issue 2026-02-16 01:15:03 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 23, 2026):

The current error handling for os.Stat(pythonPath) immediately returns an error if the Python interpreter is missing, which prevents any self-healing or automatic recovery of the environment. This check happens in the checkPythonVirtualEnvironment function, and if the interpreter is not found, the process stops with a fmt.Errorf("failed to find python: %s", err)—it does not attempt to recreate the virtual environment or repair the missing interpreter source.

Self-healing is only triggered when the entire virtual environment directory is missing (ErrVirtualEnvironmentNotFound) or flagged invalid (ErrVirtualEnvironmentInvalid). In those cases, the code deletes and recreates the environment. But if just the Python binary is missing, it does not treat this as a recoverable state source.

To enable self-healing for missing pythonPath, you could modify the error handling so that if os.Stat(pythonPath) fails, the code deletes the virtual environment and attempts to recreate it, similar to how it handles invalid environments. This would allow the daemon to recover from cases where the interpreter is missing or corrupted, rather than just reporting an error and stopping.

There are no existing mechanisms in the codebase that attempt this kind of recovery for missing Python binaries; the error is simply reported and the process stops source. Implementing this change would bring the missing interpreter case in line with the current self-healing logic for invalid or missing environments.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 23, 2026): <!-- Answer --> The current error handling for `os.Stat(pythonPath)` immediately returns an error if the Python interpreter is missing, which prevents any self-healing or automatic recovery of the environment. This check happens in the `checkPythonVirtualEnvironment` function, and if the interpreter is not found, the process stops with a `fmt.Errorf("failed to find python: %s", err)`—it does not attempt to recreate the virtual environment or repair the missing interpreter [source](https://github.com/langgenius/dify-plugin-daemon/blob/23a4662e65a2bdeb7e7731a9081e6ba545f9838a/internal/core/local_runtime/setup_python_environment.go#L254-L480). Self-healing is only triggered when the entire virtual environment directory is missing (`ErrVirtualEnvironmentNotFound`) or flagged invalid (`ErrVirtualEnvironmentInvalid`). In those cases, the code deletes and recreates the environment. But if just the Python binary is missing, it does not treat this as a recoverable state [source](https://github.com/langgenius/dify-plugin-daemon/blob/23a4662e65a2bdeb7e7731a9081e6ba545f9838a/internal/core/local_runtime/environment_python.go#L10-L92). To enable self-healing for missing `pythonPath`, you could modify the error handling so that if `os.Stat(pythonPath)` fails, the code deletes the virtual environment and attempts to recreate it, similar to how it handles invalid environments. This would allow the daemon to recover from cases where the interpreter is missing or corrupted, rather than just reporting an error and stopping. There are no existing mechanisms in the codebase that attempt this kind of recovery for missing Python binaries; the error is simply reported and the process stops [source](https://github.com/langgenius/dify-plugin-daemon/pull/79). Implementing this change would bring the missing interpreter case in line with the current self-healing logic for invalid or missing environments. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bf2ae0e6-fbd5-4211-810c-84f83347de2d?feedback_type=other)</sup> [![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20current%20error%20handling%20for%20%60os.Stat%28pythonPath%29%60%20immediately%20returns%20an%20error%20if%20the%20Python%20interpreter%20is%20missing%2C%20which%20prevents%20any%20self-healing%20or%20automatic%20recovery%20of%20the%20environment.%20This%20check%20happens%20in%20the%20%60checkPythonVirtualEnvironment%60%20function%2C%20and%20if%20the%20interpreter%20is%20not%20found%2C%20the%20process%20stops%20with%20a%20%60fmt.Errorf%28%22failed%20to%20find%20python%3A%20%25s%22%2C%20err%29%60%E2%80%94it%20does%20not%20attempt%20to%20recreate%20the%20virtual%20environment%20or%20repair%20the%20missing%20interpreter%20%5Bsource%5D%28https%3A//github.com/langgenius/dify-plugin-daemon/blob/23a4662e65a2bdeb7e7731a9081e6ba545f9838a/internal/core/local_runtime/setup_python_environment.go%23L254-L480%29.%0A%0ASelf-healing%20is%20only%20triggered%20when%20the%20entire%20virtual%20environment%20directory%20is%20missing%20%28%60ErrVirtualEnvironmentNotFound%60%29%20or%20flagged%20invalid%20%28%60ErrVirtualEnvironmentInvalid%60%29.%20In%20those%20cases%2C%20the%20code%20deletes%20and%20recreates%20the%20environment.%20But%20if%20just%20the%20Python%20binary%20is%20missing%2C%20it%20does%20not%20treat%20this%20as%20a%20recoverable%20state%20%5Bsource%5D%28https%3A//github.com/langgenius/dify-plugin-daemon/blob/23a4662e65a2bdeb7e7731a9081e6ba545f9838a/internal/core/local_runtime/environment_python.go%23L10-L92%29.%0A%0ATo%20enable%20self-healing%20for%20missing%20%60pythonPath%60%2C%20you%20could%20modify%20the%20error%20handling%20so%20that%20if%20%60os.Stat%28pythonPath%29%60%20fails%2C%20the%20code%20deletes%20the%20virtual%20environment%20and%20attempts%20to%20recreate%20it%2C%20similar%20to%20how%20it%20handles%20invalid%20environments.%20This%20would%20allow%20the%20daemon%20to%20recover%20from%20cases%20where%20the%20interpreter%20is%20missing%20or%20corrupted%2C%20rather%20than%20just%20reporting%20an%20error%20and%20stopping.%0A%0AThere%20are%20no%20existing%20mechanisms%20in%20the%20codebase%20that%20attempt%20this%20kind%20of%20recovery%20for%20missing%20Python%20binaries%3B%20the%20error%20is%20simply%20reported%20and%20the%20process%20stops%20%5Bsource%5D%28https%3A//github.com/langgenius/dify-plugin-daemon/pull/79%29.%20Implementing%20this%20change%20would%20bring%20the%20missing%20interpreter%20case%20in%20line%20with%20the%20current%20self-healing%20logic%20for%20invalid%20or%20missing%20environments.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-plugin-daemon/issues/578)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#233