← Back to Pull requests

Contain xcodebuild's derived data in the test's temp dir #3050

Merged
erneestoc merged 1 files (10 lines) on Aug 21, 2026 05:46 UTC
View on GitHub
erneestoc erneestoc commented on Aug 21, 2026 00:34 UTC
Author

Every xcodebuild test-without-building invocation creates a ~/Library/Developer/Xcode/DerivedData/temporary-<hash>/ directory that nothing ever deletes. When the runner does not pass -resultBundlePath — i.e. any xcodebuild-path run without create_xcresult_bundle — that directory receives a full .xcresult of the run; and passing -resultBundlePath alone does not fix it, a bookkeeping directory still leaks per run.

One development machine had accumulated 267 of these directories totaling 26GB. Every CI agent running simulator tests through the xcodebuild path leaks one per test run, silently.

Fix: pass -derivedDataPath pointed into the runner's test_tmp_dir, which the existing EXIT trap already deletes. An explicit -resultBundlePath (from create_xcresult_bundle or xcodebuild_args) still wins for the result bundle itself.

Measurements

New DerivedData temporary-* directories created per invocation (Xcode 26.2, iOS 26.2 simulator, hosted unit test):

| xcodebuild flags | new dirs per run | contents |
|---|---|---|
| (none — today's runner without create_xcresult_bundle) | 1 | 152K, including a complete orphan .xcresult |
| -resultBundlePath only | 1 | 24K bookkeeping |
| -derivedDataPath (this PR) | 0 | — |
| both | 0 | — |

End-to-end through the runner after this change: default mode, dir count unchanged across runs (was +1 per run); with create_xcresult_bundle = True, the bundle still lands in TEST_UNDECLARED_OUTPUTS_DIR (verified present in outputs.zip) and DerivedData stays untouched.

Steps to reproduce the leak

ls -d ~/Library/Developer/Xcode/DerivedData/temporary-* | wc -l
# run any hosted test through ios_xctestrun_runner without create_xcresult_bundle,
# e.g. a unit test with a test_host (forces the xcodebuild path):
bazel test //your:HostedTest --runner=@rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner --nocache_test_results
ls -d ~/Library/Developer/Xcode/DerivedData/temporary-* | wc -l   # +1, forever

Test plan

  • Manual xcodebuild test-without-building flag matrix above (each variant run against the same xctestrun).

  • Runner end-to-end: default mode creates no DerivedData directories; CREATE_XCRESULT_BUNDLE=1 still produces tests.xcresult in undeclared outputs with DerivedData untouched.

  • Rendered template passes bash -n.
  • Diff: 10 lines (+10 / -0) across 1 files Reviewer: keith Review duration: 312m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.17) × (1 − Review Confidence (0.78)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.17 · 10 lines diff across 1 files
    0.17
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.73 · 1 substantive comment(s)
    0.73
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    78%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.143
    Real PR Conversation Timeline
    4 items
    keith keith approved these changes on Aug 21, 2026 00:36 UTC
    Approved Reviewer

    Approved these changes.

    erneestoc erneestoc commented on Aug 21, 2026 02:26 UTC
    Author

    The CI failures here are the pre-existing wedged-simulator flake, not this change:

  • The failing set (HelloWorldSwiftUITests, ButtonsUITests, ios_coverage_ui_test_coverage_new_runner) is the same session-sensitive group that has been failing on other PRs whose runner-test caches get invalidated (#3026 has the full diagnosis: a previously-terminated test leaves the reused, still-booted simulator with a dead device-side session, and every later xcodebuild test-without-building against it hangs or fails to initialize).

  • The attempt log shows the signature exactly: reused booted BAZEL_TEST_iPhone 16_26.0, a well-formed invocation with -derivedDataPath, then silence until the timeout SIGTERM.

  • 1163 tests passed on the same run — including the hosted unit tests, which exercise -derivedDataPath on every invocation.

  • All three failing targets pass locally on this branch (9.8s / 11.6s / 5.3s).
  • #3026 adds the recovery machinery for this (its own CI is now fully green, including the previously-failing 9.x job, because its first run self-heals a wedged agent). Suggest retrying this build after #3026 lands — no change needed here.

    adincebic adincebic approved these changes on Aug 21, 2026 05:18 UTC
    Approved Reviewer

    Good.

    Reviewers
    Assignees
    erneestoc erneestoc
    Labels
    risk: low confidence: 78.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 17.3% (LOW) · Higher = larger blast radius
    17.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 78.1% · Lower = rushed or shallow review
    78.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.8% · Safe to merge
    3.8%