Repository navigation
mac: stop leaking flashtex-project-files helpers, one per test (#687) - #707
Merged
Merged
Conversation
What changed: - LineProcessClient (shared by the project-files, bridge, and edit-ledger helper clients) now terminates and reaps its child process in `deinit`, not only when a caller remembers to call `terminate()`. Root cause: no object in the DocumentFilesState -> ProjectFilesClient -> LineProcessClient chain ever tore down the spawned Process/pipes on its own, and most real-helper tests in DocumentFilesTests.swift never called detachHelper()/terminate() before returning, so each left its helper running (stdin pipe still open) as an orphan of the xctest process until the whole test binary exited. - PreviewControllerClient gets the same deinit safety net (same Process/Pipe launch pattern; flagged in #687 as worth auditing). - Added a regression test: dropping a ProjectFilesClient with no explicit terminate()/detachHelper() call must still kill and reap its helper. What was run (literal lines): - Before the fix, a temporary repro (spawn 15 real helpers, ping each, drop all references, no terminate()): REPRO_AT_SPAWN=15, REPRO_AFTER_DROP=15 -- confirms the leak. - After the fix, same repro: REPRO_AT_SPAWN=15, REPRO_AFTER_DROP=0. - `swift test --filter DocumentFilesTests` (14 tests incl. the new regression test): Executed 14 tests, with 0 failures. - `swift test --filter 'BridgeClientTests|BridgeRecoveryTests|RealEditLedgerTests|DirtySnapshotsTests'`: Executed 32 tests, with 3 tests skipped (missing optional real-binary env vars, pre-existing) and 0 failures. Next step: none; #687 is addressed. Not touched: flashtex-preview-controller's other call sites already call terminate() explicitly (DocumentKindsTests.swift, V2ConformanceTests.swift) -- the new deinit is a safety net, not a behavior change for them. Implementation-Agent: claude-sonnet-5 subagent of daniel-parent Commit-Executor: daniel-parent subagent Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
This was referenced Sep 16, 2026
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.
What
LineProcessClient(shared by theflashtex-project-files,flashtex-bridge,and
flashtex-edit-ledgerhelper clients) andPreviewControllerClientnowterminate and reap their child process in
deinit, not only when a callerremembers to call
terminate()/detachHelper()/detachController().Why
Root cause: no object in the
DocumentFilesState -> ProjectFilesClient -> LineProcessClientchain ever tore down the spawnedProcess/pipes on itsown. Most real-helper tests in
DocumentFilesTests.swiftnever calldetachHelper()/terminate()before returning, so each left its helperrunning (its stdin pipe still held open by the parent) as an orphan of the
xctestprocess until the whole test binary exited — exactly the "one pertest, reaped never [until run end]" behavior in #687.
Fix: tie the helper's lifetime to the Swift object's lifetime instead of to
every call site remembering cleanup.
PreviewControllerClientgets the sametreatment since #687 flagged it as the same launch pattern; its existing call
sites already call
terminate()explicitly, so this is a safety net, not abehavior change for them.
Overlap check
gh pr list --search "helper leak OR project-files OR 687"andpython3 scripts/coord.py claims: no open PR or claim on this issue.PreviewV2Tests.swiftdoes not compile on main) blockedswift testhere; fixed in the parallel, already-open PR mac: unbreak main — move PreviewV2 page-readout test into PreviewV2ShellTests (fixes #695) #698
(
agent/daniel-parent/fix-gh695-previewv2-test-class). I overlaid thatfile locally, off-branch, only to unblock building the test target for
verification, and reverted it before committing — this PR does not touch
PreviewV2Tests.swift.Test results
Before the fix, a temporary repro (spawn 15 real helpers,
ping()each toconfirm they are live, drop all references, no
terminate()call — the samething the real tests do):
15 helpers stayed alive after every Swift reference was dropped: the leak.
After the fix, identical repro:
All 15 are killed and reaped within the poll window, with no explicit
teardown call anywhere in the repro.
Regression suite runs on the fixed code:
(includes the new
testDroppedClientKillsAndReapsItsHelperWithoutExplicitTeardown)Not done
#695(PreviewV2Tests.swift); that's PR mac: unbreak main — move PreviewV2 page-readout test into PreviewV2ShellTests (fixes #695) #698, a parallellane's fix.
deinitanywhere beyondLineProcessClientandPreviewControllerClient— those two cover every helper Mac test harness leaks flashtex-project-files helpers — one per test, reaped only at run end #687 named(project-files, bridge, edit-ledger via
LineProcessClient; previewcontroller directly).
terminate()/detachHelper()/detachController()calls at other call sites; they're harmless (callingterminate()twice is idempotent) and keep helpers cleaned up immediatelyrather than at deinit time, so I left them as-is.
🤖 Generated with Claude Code
https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz