Skip to content

refactor(runtime)!: remove gevent runtime dependency in v0.12.0 #340

Open

Description

@WH-2099

Release target

Remove gevent and import-time monkey patching in SDK 0.12.0.
The release plan was updated on 2026-11-02: SDK 0.11.0 (#413) retains the existing runtime.
Coordinate this work with the native synchronous HTTPX2 migration in #414 / #415 for the same SDK 0.12.0 release.

Current state

  • SDK main declares gevent>=26.9.0 and applies monkey.patch_all(sys=True) through src/dify_plugin/_gevent.py at package import.
  • Stdio uses gevent.os.tp_read; TCP uses gevent socket/select/sleep; serverless includes a gevent WSGI path.
  • Model token estimation detects patched sockets and uses gevent.threadpool.ThreadPool.
  • IOServer dispatches synchronous plugin work through ThreadPoolExecutor(max_workers=MAX_WORKER), which is currently affected by global patching.
  • refactor(http)!: adopt native synchronous HTTPX2 for SDK 0.12 #415 moves SDK-owned HTTP calls to native synchronous HTTPX2 while retaining gevent in its current candidate.

Target for v0.12.0

  • Remove gevent and greenlet from SDK runtime dependencies and lock data.
  • Remove package import-time monkey patching entirely.
  • Keep synchronous plugin execution on native ThreadPoolExecutor and document its worker behavior.
  • Use the shared synchronous HTTPX2 transport from refactor(http)!: adopt native synchronous HTTPX2 in v0.12.0 #414 / refactor(http)!: adopt native synchronous HTTPX2 for SDK 0.12 #415 for SDK HTTP requests, streaming, uploads, downloads, and serverless callbacks.
  • Preserve local stdio, remote TCP, and serverless HTTP streaming behavior.
  • Keep runtime boundaries explicit so future concurrency work can be implemented without global monkey patching.

The earlier urllib.request helper proposal is superseded by the selected HTTPX2 migration.
tiktoken may retain Requests/urllib3 as transitive dependencies for its own resource downloads.

Implementation work

  • Delete the gevent import-side-effect module and its package-level import.
  • Rewrite stdio reading around standard library primitives.
  • Use native sockets and selectors or select for TCP, preserving timeout, reconnect, write serialization, and shutdown behavior.
  • Replace the serverless gevent WSGI branch with a supported server path using the native runtime.
  • Replace gevent token-estimation isolation with direct execution or the existing native thread pool as justified by blocking behavior.
  • Verify the HTTPX2 network backend, streaming ownership, timeouts, proxies, TLS, and cleanup with unpatched sockets.
  • Update worker configuration, runtime documentation, and affected examples.
  • Update the test entrypoint, coverage configuration, fixtures, and integration tests that currently assume gevent or patched threads.

Acceptance criteria

  • Runtime code and package metadata have no gevent/greenlet references, and the resolved dependencies no longer include them.
  • Package import leaves standard-library sockets, threads, and other modules unpatched.
  • SDK-owned HTTP calls use synchronous HTTPX2, with the proxy/TLS/streaming regressions from refactor(http)!: adopt native synchronous HTTPX2 for SDK 0.12 #415 passing under the native runtime.
  • Local stdio, remote TCP, and serverless smoke tests pass, including concurrent requests, reconnects, interruption, and shutdown.
  • just check, Python 3.12/3.13 tests and coverage gates, and just build pass for the combined SDK 0.12.0 candidate.
  • The SDK 0.12.0 release notes document the runtime and HTTP integration changes.

Activity

  1. added
    enhancement
    on May 20, 2026
  2. self-assigned this
    on May 20, 2026
  3. pinned this issue on May 20, 2026
  4. changed the title [-]refactor!: remove gevent runtime dependency in v0.10.0[/-] [+]refactor!: remove gevent runtime dependency in v0.11.0[/+] on Jul 14, 2026
  5. added this to the 0.12.0 milestone on Nov 2, 2026
  6. changed the title [-]refactor!: remove gevent runtime dependency in v0.11.0[/-] [+]refactor(runtime)!: remove gevent runtime dependency in v0.12.0[/+] on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions