fix(process_registry): finished processes no longer hold FDs for the TTL window (salvage #75162) - #98930
Merged
Conversation
Contributor
૮ >ﻌ< ა ci reviewran on 3080dad — test(process_registry): trim handle-release tests to invaria
|
Contributor
|
Heads-up: #68948 (open, CI green) also touches |
Finished sessions retained their subprocess.Popen pipe objects (and PTY masters) until the finished-process TTL (FINISHED_TTL_SECONDS, default 30 minutes) elapsed. Under heavy background churn — deployments, archivers, watchers — finished-but-unpruned sessions accumulated one open pipe FD each, exhausting the gateway process's file descriptor budget and surfacing as a 'file descriptor limit' error on new background spawns. The registry never rejects spawns (it prunes oldest-finished at MAX_PROCESSES), so the real defect was the retained-handle leak, not a registry-cap rejection. The fix closes each finished session's Popen stdout/stderr/stdin streams and PTY master in _move_to_finished(), right after the reader loop drains EOF. poll()/wait()/read_log() serve output from the buffered output_buffer — never from the pipe — so the release is lossless. Tests: 4 new cases in TestFinishedHandleRelease — Popen pipes closed, PTY closed, no-handle sessions safe, and poll() still serves buffered output after the release. All 4 fail on main (reproduction) and pass with the fix.
…llow-up) Widen #75162: _prune_if_needed() drops finished sessions (TTL expiry and oldest-finished eviction at MAX_PROCESSES) — release their Popen/PTY handles there too, covering sessions inserted into _finished without passing through _move_to_finished(). The release helper is idempotent, so double-close on the normal path is a no-op. Adds two tests: prune releases handles of dropped sessions, and a still-running session's pipe stays open.
…ath race _release_finished_handles read the dataclass fields through getattr fallbacks and swallowed every exception; use the real attributes, suppress only OSError/ValueError on the pipe close (an stdin flush can hit EPIPE), and rely on ptyprocess/pywinpty close() idempotence for the master fd. The call-site comment claimed the reader had always drained the pipe; on kill_process/_reconcile_local_exit the reader may still be reading, so state what actually happens (its next read raises, the loop exits).
…prune fixture Drop the no-op and still-running change-detectors (4 invariant tests remain: pipe closed on finish, PTY closed on finish, poll still serves buffered output, prune releases handles). The accretion-caps fake session now carries process/_pty like the real dataclass, since prune reads them.
teknium1
force-pushed
the
salvage/75162-process-registry-handle-release
branch
from
September 14, 2026 02:55
8b9c150 to
3080dad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Finished background processes now release their OS handles (Popen pipes + PTY masters) immediately instead of holding them for the 30-minute finished-TTL window — heavy background churn can no longer exhaust the gateway's file-descriptor budget.
Salvage of #75162 by @RGerrish (commit cherry-picked, authorship preserved) onto current main, plus a follow-up widening commit. Zed shipped the same fix class this week (zed-industries/zed#62978 — completed agent terminals retained live PTY resources), which is what surfaced this stalled PR in the weekly scout.
Changes
tools/process_registry.py: idempotent_release_finished_handles()called from_move_to_finished()(contributor commit) and from both_prune_if_needed()drop paths — TTL expiry + oldest-finished eviction — which the original PR missed (follow-up commit).tests/tools/test_process_registry.py: contributor'sTestFinishedHandleRelease+ 2 new tests (prune releases handles; still-running session's pipe stays open).Validation
tests/tools/test_process_registry.pyscripts/audit_pr_attribution.py --fix— all emails mappedLive repro: contributor's failing-first test red on main (
proc.stdout.closedstays False after finish); green on branch; live E2E above confirms on real processes.Safety notes: send-input paths already guard on
session.exited(gracefulalready_exited), reader threads drain before_move_to_finishedruns so handles never close under a live reader, checkpoint-recovered detached sessions carry no local handles.Infographic