Skip to content

fix: close owned job event streams - #227

Open
allenflux wants to merge 1 commit into
Comfy-Org:mainfrom
allenflux:codex/fix-event-stream-ownership
Open

allenflux wants to merge 1 commit into
Comfy-Org:mainfrom
allenflux:codex/fix-event-stream-ownership

Conversation

@allenflux

@allenflux allenflux commented Oct 24, 2026 •

Copy link
Copy Markdown

Exhausting a job event iterator at a terminal frame, or explicitly closing it, does not currently close the low-level SSE generator it owns. That generator holds the HTTP response context across yields, so resource release can depend on generator finalization.

Close each owned stream with closing / aclosing inside the existing per-connection error handling. Preserve polling fallback and reconnection behavior, and accurately annotate the low-level generator return types. This covers terminal exhaustion and explicit iterator closure; it does not promise automatic cleanup for an arbitrary bare break while the caller retains the iterator.

Validation on Python 3.12.11 / macOS arm64:

  • Four resource regressions fail on unchanged main, while seven controls pass with identical final tests. All eleven pass with the fix.
  • Tests retain the real low-level generator and observe the real HTTP response context using the existing local API stub; no httpx mocks.
  • Full suite: 1270 passed, 9 environment-gated gateway tests skipped. Ruff, formatting and mypy src pass. The public-repo hygiene check passes with the new test tracked.
  • Independent automated verification reproduces the four failures, passes the fixed eleven cases and five additional read-idle/reconnect controls.

No live gateway or GPU was used. The cancellation case is a general control, not proof of cancellation during an active SSE read.

Summary by CodeRabbit

  • Bug Fixes
    • Event streams now close their underlying HTTP connections when iteration finishes, reaches a terminal status, or is closed early. This applies to both synchronous and asynchronous clients.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8185f0e and 2c75eca.

Files selected for processing: 4
  • CHANGELOG.md
  • src/comfy_low/transport.py
  • src/comfy_sdk/jobs.py
  • tests/test_event_stream_cleanup.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Synchronous and asynchronous job event iteration now closes the underlying HTTP stream when iteration completes or exits early. The changelog records this change, and tests cover terminal events, explicit closure, and asynchronous cancellation.

Changes: Job event stream cleanup

Layer / File(s) Summary
Close job event streams on exit
src/comfy_low/transport.py, src/comfy_sdk/jobs.py, tests/test_event_stream_cleanup.py, CHANGELOG.md
The low-level event methods declare generator return types. The synchronous and asynchronous Job.events methods close their iterators when iteration exits. Tests cover terminal completion, explicit closure, and asynchronous cancellation. The changelog records the cleanup behavior.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: wei-hai, mattmillerai

Merge Risk: Minimal · up to 2c75e

No actionable issue remains in the supplied evidence; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: closing owned job event streams.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@allenflux
allenflux marked this pull request as ready for review October 24, 2026 06:25
@allenflux
allenflux requested review from a team as code owners October 24, 2026 06:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant