Skip to content

Keep pyvoy ASGI completions valid and close disconnected idle streams #728

Closed

Description

@lumenpearson

Found while completing #724's real Windows host checks, before releasing the dependency cohort.

The six existing live-host RPC tests can pass while pyvoy reports asyncio.exceptions.InvalidStateError: invalid state after cancelling a receive or send consumer. Immediate orderly shutdown can also report idle WatchClass asynchronous generators still running. The receive defect reproduces with both pyvoy 1.4.0 / Envoy 1.40.2 / pyqwest 0.14.0 and the previous 1.3.0 / 1.39.3 / 0.11.0 baseline. Both winloop 0.8.3 and 0.7.2 reproduce it; one initially clean old-loop run was intermittent, not a version-specific fix.

Pyvoy's receive/send and dropped-completion callbacks complete Python Futures without checking consumer cancellation (upstream v1.4.0 source). Connect's disconnect monitor is cancelled at stream completion; for an idle disconnected stream it only sets a flag inspected when another message arrives. A plain receive shield removed InvalidStateError but still left a running generator at shutdown; that diagnostic is not clean proof.

The pyvoy-only ASGI entry now retains a pending receive across consumer cancellation/retry, serializes concurrent receive consumers so an event is delivered once, and protects send completion. After a cancelled send consumer, the completion is observed: a client-reset OSError is expected, while an unexpected failure still reaches the loop exception handler. Only a separate monitor's disconnect on POST WatchClass at the native or mounted RPC path cancels the request; normal REST/unary RPC retains its application disconnect handling. The generic host/Vercel/fallback entry and lifespan remain unchanged. There are no vendor-file patches or logger suppressions.

Existing-family regression evidence, each written and observed failing before its fix:

  • Receive completion/retry and idle-stream closure: 3 failed, 1 control passed; the initial focused host/lock/mirror selection then passed 40 cases.

  • Unary REST/RPC cancellation boundary: 2 failed with 2 WatchClass controls passing; the selection then passed 43.

  • Send completion after caller cancellation: 3 failed with the message/error-identity control passing; the selection passed 47. Delivered/reset/unexpected completions are observed and unexpected errors remain visible.

  • Concurrent receive consumers and immediate re-entry: 2 failed with a cancellation control passing; after the independent review's corrective pass, the full focused host/lock/mirror selection passed 50 cases.

On the corrected receive/send adapter, actual Windows pyvoy and Hypercorn each pass all six live RPC tests and orderly shutdown, release their ports, and log no ERROR/traceback/running-generator error. Ruff and mypy (242 modules) are clean. The actual dependency native gates (test, both assembles, detekt) passed, including an offline repeat; the corrected complete server run finished with 3860 passed, 17 skipped and 15 warnings in 2107.94s (3877 unique reported cases), on the same frozen source as the successful native gates (1823 logical Android cases). Final document/CI checks passed 201 cases.

All network runs use isolated SQLite databases, a disabled bot and fake local settings. Full onboarding, real provider/account flows and PostgreSQL coverage are not claimed. One fresh independent review and one corrective pass are complete; its Critical and six Important findings are addressed. Two minor observations remain deferred in full: terminal exceptional receive completion ownership, and broader OSError classification for abandoned sends. PR #729 passed exact-head CI and merged into dev as bf322643505eae613858ba8f23e065e819e92f63. Dev CI, promotion PR #730 CI and master CI all passed. Master 2487f38dddf1c7be6487f234eb3192540fb42b88 is in verified production: all four aliases point to it and return200/ok/API1/schema0019/v2true, with zero deployment-scoped error/fatal groups in the checked30-minute window. The source-pinned signed production APK code45 updated code44 in Studio API37 and passed Welcome/Home/launcher-reopen with the same PID and zero crashes; the Emulator stopped normally with data retained. Detailed run links, source identities and preservation readbacks are in #729/#730 and #724.

Refs #724.

Activity

  1. changed the title [-]Keep Windows host stream cancellation on the verified winloop version[/-] [+]Investigate Windows pyvoy stream cancellation diagnostics before dependency release[/+] on Nov 11, 2026
  2. changed the title [-]Investigate Windows pyvoy stream cancellation diagnostics before dependency release[/-] [+]Keep pyvoy receive completion valid and end idle streams on disconnect[/+] on Nov 11, 2026
  3. changed the title [-]Keep pyvoy receive completion valid and end idle streams on disconnect[/-] [+]Keep pyvoy ASGI completions valid and close disconnected idle streams[/+] on Nov 11, 2026
  4. moved this from Now to In progress in lessonson Nov 11, 2026
  5. added a commit that references this issue on Nov 11, 2026
    bf32264
  6. moved this from In progress to Done in lessonson Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions