Skip to content

Adopt structured process and signal lifecycles - #38

Open
lynnswap wants to merge 13 commits into
codex/phk-installer-releasefrom
codex/phk-runtime-lifecycle
Open

Adopt structured process and signal lifecycles#38
lynnswap wants to merge 13 commits into
codex/phk-installer-releasefrom
codex/phk-runtime-lifecycle

Conversation

@lynnswap

@lynnswap lynnswap commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Purpose

Give executable roots ownership of cancellation and signals while ensuring every subprocess group is fully torn down before an operation returns.

Changes

  • Replace the legacy process utilities with an async CommandRunning implementation based on swift-subprocess 1.0.
  • Add validated capture and streaming execution, process-group teardown, cancellation propagation, and explicit launch and termination errors.
  • Migrate generation and installation to structured async lifecycles and coordinate SIGINT and SIGTERM through swift-service-lifecycle.
  • Reuse one async process runner across shared-cache inventory, cohort validation, and raw-dump streaming.
  • Centralize executable resolution so PATH entry semantics and configured working-directory resolution have one tested owner.
  • Treat missing simctl as an unavailable optional simulator capability while propagating cancellation and real simulator-discovery failures.
  • Remove obsolete file-operation, signal-forwarding, and streaming-subprocess implementations.

Testing

  • Targeted Tooling process-lifecycle and CLI suites.
  • Final-stack swift test (310 tests in 32 suites).
  • iOS Simulator cross-builds for PrivateHeaderKitCore and PrivateHeaderKitCoreTests.
  • Branch-wide codex-review against the installer layer.

@lynnswap lynnswap changed the title codex/phk runtime lifecycle Adopt structured process and signal lifecycles Aug 9, 2026
@lynnswap
lynnswap marked this pull request as ready for review August 9, 2026 21:59
@lynnswap
lynnswap force-pushed the codex/phk-runtime-lifecycle branch from 667d685 to 6347b15 Compare August 10, 2026 06:25

@lynnswap lynnswap left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 6347b155ec

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lynnswap
lynnswap force-pushed the codex/phk-runtime-lifecycle branch from 6347b15 to b054a9b Compare August 10, 2026 23:10

@lynnswap lynnswap left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b054a9b644

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
// Subprocess completes capture and its group-leader lifecycle before returning.
// Preserve cancellation only after the catch path also proves group extinction.
try Task.checkCancellation()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Tear down descendants after a normal leader exit

When a launched command forks a background descendant that closes its inherited output descriptors and the group leader exits normally, this path returns the captured result after only checking cancellation. completeAbortedProcessGroupTeardown is invoked exclusively from catch paths, and the normal return in runStreaming has the same gap, so the descendant can outlive the CLI operation despite the newly owned process group. Verify the group is empty or tear down remaining members before returning a normal result.

Useful? React with 👍 / 👎.

}
)
let manifest = try makeReleaseManifest(
let manifest = try await makeReleaseManifest(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check cancellation before publishing the release manifest

If SIGINT or SIGTERM arrives after the final per-artifact cancellation check in makeReleaseManifest but before control reaches the synchronous filesystem operations below, the task is already canceled yet still creates the output directory and writes the manifest. The signal coordinator then exits with 130/143 even though the supposedly interrupted operation published its output; check cancellation again immediately before mutating the destination.

Useful? React with 👍 / 👎.

env: nil,
cwd: repoRoot
)
try Task.checkCancellation()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make untracked-source hashing cancellation-aware

When a source checkout contains many or very large untracked files, SIGINT or SIGTERM received after this check is not observed while untrackedPaths is sorted and every file is synchronously loaded and hashed. Because the new signal coordinator traps the signal and waits for the operation task, the installer can remain running and hold its install lock until the entire fingerprint completes instead of stopping promptly; check cancellation during traversal and use cancellation-aware chunked hashing for large files.

Useful? React with 👍 / 👎.

errorCode: errorCode
)
}
await Task.yield()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop waiting once a process group contains only zombies

When kill reports EPERM and processGroupHasLiveMember confirms that the group contains only zombies, this branch yields and retries forever rather than completing teardown. A zombie can persist indefinitely when its parent has moved to another process group and does not reap it, so cancellation never returns and callers such as the installer keep their lock held; treat a zombie-only group as fully terminated or impose a bounded wait.

Useful? React with 👍 / 👎.

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