#13943

macOS: broken Swift toolchain and EMFILE during ownership preparation surface as `unreadable_output` / `ProviderAdapterError` instead of typed availability and capacity errors

Openzionccit-dotcomopened 3d ago

Two macOS-specific defects in the Darwin process-ownership preparation path. Both are reproducible on a stock macOS host with only Command Line Tools installed, and neither is covered by CI.

  • Defect A — a broken Swift/DEVELOPER_DIR toolchain makes provider discovery (binary_session) fail outright with unreadable_output, instead of reporting the affected provider as unavailable.
  • Defect B — open-file exhaustion (EMFILE) during Darwin ownership-helper preparation is reported as a non-retryable ProviderAdapterError that owns a retained cleanup root, instead of a retryable host-capacity constraint.

Both were found by running the full suite on macOS; the other 5 failing cases in that run are Linux-only dconf assertions and lldb tests needing a full Xcode install, and are not part of this issue.

Environment

OSmacOS 26.7.3 (Darwin), arm64
Nodev24.22.1
Python (test suite)3.15.2 (Homebrew, first on PATH)
REArea-agents@6.10.1, commit b38a49656
ToolchainCommand Line Tools only (xcode-select -p → /Library/Developer/CommandLineTools); no Xcode.app. Not required for either repro.
Descriptor limitulimit -n = 1048576 by default, so the repro lowers it explicitly

Full-suite result on this host:

 Test Files  5 failed | 3793 passed | 39 skipped (3837)
      Tests  7 failed | 53998 passed | 628 skipped (54633)
   Duration  3112.88s

Only the two cases below belong to this issue.


Defect A — unavailable compiler turns provider discovery into an unreadable result

Reproduction

cd rea
npx vitest run tests/acceptance/darwinAvailabilityMcp.test.ts
# → 1 failed, exit 1 (~1 s)

The test points DEVELOPER_DIR at a non-existent directory and calls the compiled scripts/rea.mjs mcp server over stdio, then calls binary_session.

Observed (tests/acceptance/darwinAvailabilityMcp.test.ts:45):

AssertionError: expected true not to be true
{
  "isError": true,
  "content": [{ "type": "text", "text": "{\"error\":{
    \"code\":\"unreadable_output\",
    \"category\":\"execution_failure\",
    \"message\":\"Analysis returned a result REA could not read. Review the reported details; repeating the unchanged request is not expected to succeed.\",
    \"retryable\":false,
    \"remediation\":{\"action\":\"Analysis returned a result REA could not read. Review the reported details; repeating the unchanged request is not expected to succeed.\"},
    \"details\":{
      \"diagnostics\":{\"selected_binary\":\"adb\",\"path_source\":\"path\"},
      \"captured_output\":{
        \"stdout\":\"\",
        \"stderr\":\"xcrun: error: missing DEVELOPER_DIR path: /private/var/folders/.../rea-darwin-unavailable-.../missing-developer\\n\",
        \"stdout_bytes\":0,\"stderr_bytes\":147,\"exit_code\":1,\"signal\":null,\"truncated\":false
      }
    }
  }}" }]
}

Expected

  1. binary_session succeeds and returns tool_availability; the apktool group reports available: false, reason: "provider_unavailable", and a remediation mentioning "Swift compiler configuration".
  2. A direct inspect_apktool_client then fails as an analysed execution failure, not an unreadable one:
    { "code": "execution_failure", "retryable": false,
      "details": { "provider_id": "apktool", "operation": "inspect_apktool_client",
        "diagnostics": { "stage": "ownership_preparation",
                         "compiler_outcome": { "outcome": "exited", "code": 1 } },
        "captured_output": { "exit_code": 1, "stderr": "<path>/missing-developer" } } }
  3. The MCP session stays healthy (client.ping() resolves).

Observed cause

The compiler failure is captured correctly — DarwinProcessRunTokenReader.compilerInspectionError builds macOS process ownership helper compilation failed via xcrun (compiler result: exit code 1): <stderr> (src/process/DarwinProcessRunTokenReader.ts:359-411) — but it is then projected as an AnalysisProtocolError (unreadable_output) somewhere above the provider boundary. Ownership preparation runs before the selected binary is launched, so the failure is attributed to the adb probe even though the compiler, not adb, failed. The availability helper that is supposed to turn this into unavailable only recognises the failure through darwinPrerequisiteRefusal (src/providers/ownedProcessAvailability.ts:36-77), which requires a ProviderAdapterError with diagnostics.stage === "ownership_preparation" and no cleanup owner; the observed probe error carries neither that stage nor a provider id, so it falls through to the generic AnalysisProtocolError fallback (src/adb/AdbConfiguration.ts:283-286, src/adb/AdbProcess.ts:260).

Effect on users: one missing/broken toolchain takes down the whole discovery surface and reports a non-actionable "could not read the result" message with retryable: false, hiding the real fix ("check the selected Xcode or Command Line Tools and Swift compiler configuration", DARWIN_PROCESS_OWNERSHIP_REMEDIATION, src/process/ProcessOwnershipObservation.ts:1930-1931).


Defect B — EMFILE during ownership-helper preparation loses its capacity classification

Reproduction

cd rea
npx vitest run tests/boundary/process/adbDescriptorPressure.test.ts
# → 1 failed, exit 1 (~0.4 s)

The test runs a script under ulimit -n 64, exhausts descriptors with /dev/null handles, then calls inspectAdbClient and runAdbCapture("adb devices", …) against a stub adb.

Observed (tests/boundary/process/adbDescriptorPressure.test.ts:103):

   "pressure": {
     "command": { "cleanupPending": true, "tag": "ProviderAdapterError" },
     "probe": {
-      "reportedLimits": {
-        "command": StringMatching /(?:^|\/)(?:adb|ps|xcrun)$/u,
-        "exhausted_resource": "file-descriptors",
-        "spawn_error": "EMFILE"
-      },
-      "resource": "capacity",
-      "retryable": true,
-      "tag": "AnalysisResourceConstraintError"
+      "cleanupPending": true,
+      "tag": "ProviderAdapterError"
     }
   }

Direct check with ulimit -n 64 and inspectAdbClient against a stub adb (no adb installed on the host):

{
  "tag": "ProviderAdapterError",
  "cleanupResources": 1,
  "causeName": "Error",
  "message": "Provider process-ownership adapter failed during prepare_owned_process"
}

Note retryable and resource are absent, and one cleanup resource is retained.

Expected

{ "tag": "AnalysisResourceConstraintError", "resource": "capacity", "retryable": true,
  "reportedLimits": { "spawn_error": "EMFILE", "exhausted_resource": "file-descriptors",
                      "command": "…/xcrun" } }

with stderr === "" (no unhandled child error event). For the follow-up device command on macOS the report may additionally carry cleanupPending: true, but the primary failure must still be the capacity constraint.

Observed cause

preparationHostCapacityFailure (src/process/OwnedCommand.ts:215-229) only maps EMFILE when it arrives as the cause of a DarwinProcessOwnershipInspectionError and launcherFailureOf(cause) classifies it as host-exhausted. Under descriptor pressure the failure also arises while allocating or removing the helper root — mkdtemp(join(tmpdir(), "rea-process-token-")) (src/process/DarwinProcessRunTokenReader.ts:623) and rm(target.path, { recursive: true, force: true }) in cleanupRoot (:537) — where the EMFILE is a plain Error (causeName: "Error"). cleanupRoot turns the removal failure into a ProviderCleanupError bound to an AnalysisCleanupRelease (src/process/DarwinProcessRunTokenReader.ts:543-556; same pattern in src/process/DarwinHelperCache.ts:451-465), and the resulting primary is a ProviderAdapterError (src/domain/providerAdapterError.ts:23) with a pending-cleanup dependency rather than a capacity error.

Effect on users: a transient, self-correcting host condition (EMFILE) is reported as a non-retryable adapter fault while REA still owns a temporary helper root. Callers that honour retryable will not retry, and the retained cleanup keeps the next call reporting pending cleanup — the opposite of the documented behaviour that host capacity ("EAGAIN, ENOMEM, EMFILE, ENFILE") is a resource constraint of the call (src/process/classifyProviderOutcome.ts, classifyLaunchFailure).


CI coverage: neither failure can be caught by the current lanes

$ grep -rn "darwinAvailabilityMcp\|adbDescriptorPressure\|lldbLauncherBoundary" .github/workflows/ .github/actions/
(no matches)
  • The full suite (test-shard, twelve shards) runs on ubuntu-latest (.github/workflows/ci.yml:336); test-source also runs on ubuntu-latest (:307).
  • The only macOS lane, apple-artifacts on macos-15 (.github/workflows/ci.yml:852-905), runs npm run test:focused -- over a curated file list (:886). That list includes tests/boundary/process/darwinProcessRunTokenReader.test.ts but not tests/acceptance/darwinAvailabilityMcp.test.ts or tests/boundary/process/adbDescriptorPressure.test.ts.
  • darwinAvailabilityMcp.test.ts is cliTest.skipIf(process.platform !== "darwin"), so it is skipped in every lane that would run it; adbDescriptorPressure.test.ts is not platform-gated, but this code path is only reached on Darwin; on the Linux shards the Darwin ownership branch is never taken.

Net: both regressions are only observable on a developer Mac running npm test. Adding the two files to the apple-artifacts focused list would give them coverage without a new runner.

Suggested fixes

  1. Availability: keep the Darwin preparation failure typed through the provider boundary so ownedProcessPrerequisiteAvailability reports runtime_unavailable with DARWIN_PROCESS_OWNERSHIP_REMEDIATION, and so a direct tool call keeps stage: "ownership_preparation" plus compiler_outcome/captured_output instead of collapsing to AnalysisProtocolError.
  2. Capacity: classify EMFILE/ENFILE raised during helper-root allocation and removal (not only during the compiler spawn) as AnalysisResourceConstraintError { resource: "capacity", retryable: true } with reportedLimits.spawn_error/exhausted_resource, while still surfacing any genuinely retained cleanup as a dependent cleanup rather than as the primary error.
  3. Coverage: add both test files to the apple-artifacts test:focused list (and the lldb ones if a full Xcode runner is available).

Activity

0

No activity yet.