← Back to Pull requests

Fix `calculate_output_groups.py` failing or hanging on `build-request.json` #3389

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 10, 2026 19:27 UTC
Author

Summary

calculate_output_groups.py no longer fails when build-request.json is empty or half-written, and no longer depends on Xcode writing it at all in BwB mode. The script now uses the targets in the current build's manifest.json, which Xcode writes atomically before the build starts, and only reads build-request.json if the manifest is missing or has none of our targets. If neither is usable, it waits at most 30 seconds, then falls back to an earlier build description for the same scheme, or fails with an actionable error.

Why this change is needed

Two failures in the "Generate Bazel Dependencies" phase, both seen with Xcode 27.1 on a large BwB project:

1. Build fails with a parse error.

   error: Failed to parse '.../XCBuildData/<signature>.xcbuilddata/build-request.json':
   JSONDecodeError: Expecting value: line 1 column 1 (char 0).
   

Afterwards the same file was valid JSON (2,687 bytes), so the script read it while Xcode was still writing it.
2. Build hangs for 20+ minutes on newest 'buildRequest.json' file not updated yet, waiting.... The current build's .xcbuilddata folder had a complete manifest.json but never got a build-request.json. An earlier folder still had none 8 minutes after its build.

Both come from how Xcode's build system saves a build description (swift-build BuildDescriptionManager.swift):

  • It saves on a serial queue at background QoS, after the build has started, so the save can be delayed indefinitely on a busy machine.

  • build-request.json is written last, with a non-atomic write (create/truncate, then write), so it's briefly empty.

  • Write errors are silently ignored, so the file can be missing entirely.
  • manifest.json is different (swift-build BuildDescription.swift). It's the llbuild manifest, written atomically while the description is constructed, before the build starts, because llbuild loads the build from it.

    What changed

  • calculate_output_groups.py

  • - An empty, truncated, or deleted build-request.json is treated as "not ready yet" and polled again, for both the Xcode 14.3+ and older code paths.
    - BwB mode: the script reads the current build's manifest.json first and uses its targets right away, without waiting for build-request.json. It only reads build-request.json if there's no manifest.json (e.g. older Xcode versions) or the manifest has none of our targets. Configured targets appear there as target-<name>-<guid>-<parameters>. The script matches those against the PIF target GUIDs, which takes about 0.06 seconds for an 11 MB manifest. In BwB mode, every target in the build graph needs Bazel outputs, so this set is correct. BwX mode doesn't use the manifest, because it would make Bazel also build the libraries Xcode compiles.
    - The Xcode 14.3+ wait stops after 30 seconds (_BUILD_REQUEST_TIMEOUT_SECONDS). The script then uses, in order:
    1. the newest manifest.json that includes the scheme's target (BwB only);
    2. the newest build-request.json whose configuration, platform, and targets match.

    Either way it prints a warning naming the file. If neither matches, it fails with "Quit and reopen Xcode, then build again."
    - It now takes CONFIGURATION, PLATFORM_NAME, and RULES_XCODEPROJ_BUILD_MODE as arguments.

  • generate_bazel_dependencies.sh passes those three values.

  • CreateScheme.swift: the "Initialize Bazel Build Output Groups File" pre-action writes $BAZEL_LABEL (of the scheme's first build target) into the build marker file instead of just touching it. The post-timeout fallbacks only accept build descriptions that include that target, so they won't pick up another scheme's targets. An empty marker (a scheme generated before this change) disables them.
  • Known trade-off

    The post-timeout fallbacks can use an earlier build description for the same scheme. If the scheme's target list changed since then, the earlier list is used. The warning tells the user what to do in that case. The immediate manifest path doesn't have this problem, because it only reads the current build's folder.

    Testing

  • New //xcodeproj/internal/bazel_integration_files:calculate_output_groups_tests (35 tests): empty, truncated, and missing files; waiting then succeeding; timeouts; manifest GUID parsing, including GUIDs that contain - and :; preferring the manifest over build-request.json, and falling back to build-request.json when the manifest is missing or has no known targets; post-timeout fallback order and matching; warning and error output.

  • //tools/generators/xcschemes:xcschemes_tests passes with the updated pre-action script.

  • Ran _main end to end against a real Xcode 27.1 manifest.json, in a fake DerivedData folder whose current .xcbuilddata has no build-request.json. The script used the manifest immediately and printed the expected output groups.

  • On the affected BwB project, a diagnostic confirmed that the current build's manifest.json lists exactly the two targets that build needs.
  • Related

  • #2567: earlier report of the "still not updated after 10 seconds" hang.

  • #3295: fixed a related race when .xcbuilddata folders are deleted.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: aaronsky Review duration: 29221m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3389"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%