Skip to content

fix(process): await Swift frontend lifetime pipe - #7948

Merged
morluto merged 1 commit into
mainfrom
codex/darwin-compiler-lifetime-5502
Oct 29, 2026
Merged

morluto merged 1 commit into
mainfrom
codex/darwin-compiler-lifetime-5502

Conversation

@morluto

@morluto morluto commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Related to #5502. Cancelling the Darwin ownership helper compile could remove its temporary root while a detached Swift frontend was still writing, leaving object files after normal server exit. The compiler command now retains and drains an extra inherited lifetime pipe before removing that root.

Problem and expected behavior

On current main, an isolated MCP cancellation sweep left two helper roots, each containing 256,904 bytes of Swift object files, after normal server exit and both 1 s and 2.5 s samples. A real compiler probe observed xcrun swiftc and stdout/stderr close around 45 ms while the descriptor retained by its frontend workers closed around 269 ms. Cleanup must wait for the writer, preserve cancellation and retain failed cleanup ownership.

Change and scope

execFileOutput optionally adds a drained inherited pipe for stoppable commands; only Darwin helper compilation opts in. Its closure makes settlement wait for copies inherited by the observed Swift frontend jobs. Cancellation, timeout and shared waiter policy remain unchanged. The fixture now models a detached writer whose standard streams close while it survives the interrupted driver, rather than killing the writer on SIGINT.

Contract and boundary impact

  • Semantic owner and earliest changed stage: compiler process output/lifetime supervision and Darwin helper-root cleanup.
  • Contribution scope fit and linked maintainer decision: existing local helper compilation; no new target authority.
  • CLI and MCP/tool-catalog contract: unchanged; cancelled requests remain cancelled.
  • Provider, bridge, target-format, or platform compatibility: tested on macOS arm64 with Apple Swift 6.3.2 and Node 24.22.1.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; cleanup failures retain the existing owner and diagnostics.
  • Target selection, authority, upstream behavior, and cleanup details: no PID/path-based signaling or unrelated process control.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Launch or attach to a process.
  • Change process memory, registers, files, or configuration.

Evidence and regression coverage

  • The deterministic detached-writer regression failed on baseline 21b1927 because the removed root was recreated and passed with the change. Existing tests cover shared callers, cancellation, cleanup failure/retry and successful compilation.
  • Three fresh-server MCP sweeps of 15 cancellations each (20–300 ms) left no roots at either post-exit sample; an uncancelled summary control succeeded and removed its helper root. Before the change one identical sweep retained two roots. Sample sizes do not establish a general failure rate.
  • lsof confirmed both actual Swift frontend workers inherited fd 3 on this host. In 24 xcrun and 18 direct swiftc short-cancellation trials, removal after descriptor closure did not lead to recreation during 350 ms. Eight link-stage interruption probes also saw sampled descendants absent at close and no recreation during 350 ms.
  • Limit: descriptor closure proves only that inherited copies closed. It does not prove every compiler descendant inherited the descriptor or that arbitrary Swift releases behave identically; some observed ld processes did not expose fd 3. The issue's original Apple Swift 6.4 / Node 26 combination, other compiler versions and later writes beyond these observations remain unverified. This PR does not claim that broader proof or close [Bug] Cancelled JavaScript analysis can still leave the macOS helper's temporary folder after #1194 #5502 automatically.

Validation performed

  • npm run test:focused -- tests/boundary/process/darwinProcessRunTokenReader.test.ts — 35 passed.
  • npm run test:local -- src/process/ExecFileOutput.test.ts — 44 passed.
  • npm run check:fast and git diff --check — passed.
  • Built source CLI/MCP runs and native compiler probes as above; independent review found no additional concrete defect in the final diff.

Compatibility, safety, and release

Cancellation may wait for Swift frontend-held descriptor closure before removing the owned root. No schema change. Cleanup completion for processes that do not inherit the descriptor remains unproven.

Author readiness

Human owner: @morluto

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge within its stated compiler-compatibility limits.

Summary

The PR makes Darwin helper compilation wait for an extra inherited pipe before removing its temporary root.

  • Darwin helper cleanup waits for inherited Swift writer pipes to close.

Diagram

sequenceDiagram
  participant Reader as Darwin helper owner
  participant Command as execFileOutput
  participant Driver as Compiler driver
  participant Writer as Detached frontend
  Reader->>Command: Compile with lifetimePipe
  Command->>Driver: Spawn with fd 3
  Driver->>Writer: Inherit fd 3
  Reader->>Command: Cancel
  Command->>Driver: SIGINT
  Driver-->>Command: Exit and close standard streams
  Writer->>Writer: Finish object writes
  Writer-->>Command: Close inherited fd 3
  Command-->>Reader: Settle command
  Reader->>Reader: Remove temporary root
Loading

Reviews (1) · Last reviewed commit: "fix(process): await Swift frontend lifet..." · Reviewed by Greptile

@morluto
morluto marked this pull request as ready for review October 28, 2026 22:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T22:59:06.499000Z dfd8f71 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto
morluto merged commit c92322b into main Oct 29, 2026
42 of 44 checks passed
@morluto
morluto deleted the codex/darwin-compiler-lifetime-5502 branch October 29, 2026 00:43
@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cancelled JavaScript analysis can still leave the macOS helper's temporary folder after #1194

1 participant