Repository navigation
feat(process): let callers own the macOS helper module cache - #2260
NIU-123370 wants to merge 1 commit into
Conversation
The ownership helper compiles with xcrun swiftc while REA deletes CLANG_MODULE_CACHE_PATH, so the module cache lands in Swift's shared default outside any caller-selected writable boundary and the compile fails with EPERM under a write restriction. Add an opt-in moduleCachePath on the reader, read through REA_SWIFTC_MODULE_CACHE_PATH when the system Darwin ownership host is built. The default command and environment stay unchanged; an opted-in directory is created, passed as -module-cache-path, exported as CLANG_MODULE_CACHE_PATH, and never removed by helper-root cleanup. Refs morluto#2218
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Thanks @NIU-123370. Your explicit cache flag, host selection, caller-owned cleanup and real-compiler coverage are folded into the earlier active PR #2252 with coauthor credit (head 35f0cdf). Kept the original public REA_DARWIN_MODULE_CACHE_PATH name, preserved authored whitespace, and completed the separate xcrun lookup-cache gap with explicit installed Swift compiler/SDK selection. All 29 ownership boundary tests, source/docs checks and the documented real restricted-write static CLI workflow pass. Closing this duplicate so #2218 review continues on the original contribution. |
* fix(process): add an opt-in Swift module cache Signed-off-by: Charan Rathore <[email protected]> * fix(process): preserve caller-owned Swift module caches Fold the complementary implementation from #2260 into the earlier #2252 proposal, retaining the original contribution history. Co-authored-by: NIU-123370 <[email protected]> * fix(process): bypass xcrun lookup for explicit Swift toolchains --------- Signed-off-by: Charan Rathore <[email protected]> Co-authored-by: morluto <[email protected]> Co-authored-by: NIU-123370 <[email protected]>
Summary
DarwinProcessRunTokenReadercompiles the Swift process-ownership helper withxcrun swiftc. The compiler's intermediate objects are already pinned inside the per-run temporary root that REA removes afterwards, but the module cache is deliberately left to Swift's shared default:src/process/DarwinProcessRunTokenReader.tsdeletesCLANG_MODULE_CACHE_PATHbefore invoking the compiler and passes no-module-cache-path.A caller whose writes are confined to one directory therefore sees the compile fail inside the module cache and has no supported way to move it. This adds one opt-in setting for that directory and leaves the default exactly as it is.
Fixes #2218.
Problem and expected behavior
From the report, observed under an enforced write boundary:
Expected: a documented setting selects the helper's module-cache directory inside the caller's boundary, the default reusable-cache behaviour stays unchanged, and REA never deletes what the caller owns.
Change and scope
createDarwinProcessRunTokenReaderacceptsmoduleCachePath. Unset or blank keeps today's argv and environment byte-for-byte. Set, REA creates the directory, inserts-module-cache-path <dir>directly afterswiftc— the same spellingsrc/native/NativeUiHelperRuntime.ts:43already uses — and exportsCLANG_MODULE_CACHE_PATH=<dir>so the Objective-C header modules the helper builds land there too.createSystemProcessOwnershipHostreadsREA_SWIFTC_MODULE_CACHE_PATHfrom the host environment it is given (or an explicitdarwinModuleCachePath) and passes it to the reader. Precedence is explicit option, then environment, then default.docs/process-capture.mddocuments the setting, that the directory outlives each run, and the cold-cache cost of pointing it somewhere new.Contract and boundary impact
src/process/DarwinProcessRunTokenReader.ts(runCompilation),src/process/ProcessOwnershipObservation.ts(createSystemProcessOwnershipHost).cleanup.unverified_processes, and the withheld-environment exemptions inProcessOwnership.tsare not touched.SIGINTinterruption ofswiftc, the cancellation retry path, and helper-temporary removal are unchanged.Evidence and regression coverage
tests/boundary/process/darwinProcessRunTokenReader.test.ts):swiftcthen the flag then the path), the childCLANG_MODULE_CACHE_PATH, the helper binary gone afterclose(), and the cache content still present.REA_SWIFTC_MODULE_CACHE_PATH" — the environment reaches the compiler through the system host.CLANG_MODULE_CACHE_PATHnull./usr/bin/xcrun, no fake; gatedit.skipIf(!onDarwin).not.toContain("-module-cache-path")and still passes, as do the two "ignores unusable inherited Swift module cache" arms that exercise the real compiler with an unusable inherited cache.Foundation-*.swiftmodule,Combine-*.swiftmodule,Darwin-*.swiftmodule… at the top level plus hash-named subdirectories holdingSwiftShims-*.pcm,xlocale-*.pcmetc. (29 entries). Cold compile into that private cache took 25.1 s inside the focused suite; the same suite's default-path test ran 0.6–1.0 s. That contrast is not a "default is 25x faster" claim — the shared cache on this host was already warm, so a first-ever default run would pay comparable cost.-module-cache-path-mutCLANG_MODULE_CACHE_PATHnot setclose()also removes the caller cachemkdirs a path nested under the helper root insteadclose()one above.xcrun's own lookup cache is not covered. I could not reproduce its write on this host: withTMPDIRredirected to an empty directory,xcrun --find swiftc,xcrun --find clang, andxcrun --sdk macosx --find clangproduced nothing there, andgetconf DARWIN_USER_CACHE_DIRstill held 404 entries before and after with noxcrun_db*file found. So the second half of [Feature] Support caller-controlled caches for macOS ownership-helper compilation #2218's request (containment forxcrun_dbwrites) stays open and needs reproduction conditions from the reporter.--flag. [Feature] Support caller-controlled caches for macOS ownership-helper compilation #2218 asked for "a supported CLI configuration".systemProcessOwnershipHostis constructed at module scope (src/process/ProcessOwnershipObservation.ts:432) during import, beforeparseConfigruns (src/main.ts:53), so a CLI-parsed value cannot reach it without restructuring that singleton. I took the smaller change and am flagging the gap rather than implying the CLI surface exists.fix(process): expose Darwin swiftc compile deadline via env): it edits the same options object atDarwinProcessRunTokenReader.ts:243andProcessOwnershipObservation.ts:222, so expect a textual conflict on those lines. Different knob; neither reverts the other, and fix(process): avoid cold ownership helper deadline exhaustion #1139's reusable-default is preserved here too.Validation performed
npm run check:fast(turbo typecheck + lint): 2/2 successful../node_modules/.bin/oxfmt --checkon the four changed files: all correct format. (Note:format:checkhere isoxfmt, not Prettier.)npx vitest run tests/boundary/process/darwinProcessRunTokenReader.test.ts: 26 passed (22 pre-existing + 4 new).npx vitest run src/process/ProcessOwnership.test.ts tests/boundary/process/ownedCommand.test.ts: 26 passed.Not run in this worktree:
npm run buildand the package/shard lanes. Typecheck and lint passed locally on Node 24.18.0; CI covers build, coverage shards, and the darwin package baselines.Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Compatibility, safety, and release
swiftccall, and never reads the directory back as trusted input. Pointing it at a shared location has the same concurrency exposure as Swift's own default cache, which is why the default stays untouched.Review checklist
type(scope): outcome.