Skip to content

fix(process): report the Swift compiler outcome with bounded diagnostics - #1999

Merged
morluto merged 2 commits into
morluto:mainfrom
jimpablo:fix/darwin-compiler-diagnostics
Oct 12, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
jimpablo:fix/darwin-compiler-diagnostics

Conversation

@jimpablo

Copy link
Copy Markdown
Contributor

Summary

Fixes #1993. The Darwin process-ownership helper compilation surfaced only cause.code and cause.message from the rejected compile. At the 60 s deadline that produced compiler result: ETIMEDOUT): Command timed out after 60000 ms: /usr/bin/xcrun with the compiler's captured stderr discarded, so a broken Swift/SDK pairing was indistinguishable from a genuinely slow compile — the exact report in #1993.

Problem and expected behavior

  • Smallest trigger: a Command Line Tools pairing where xcrun swiftc prints SDK-mismatch diagnostics and stops responding; the helper failure reports only the generic timeout, with no exit code and no diagnostics.
  • Violated invariant: a failure must preserve its meaningful reason; the rejected execFileOutput error already carries stdout/stderr, and the reader dropped them.
  • New behavior: the failure message names the observed compiler outcome — exit code N, timed out after N ms, or stopped by signal S — followed by a bounded stderr excerpt (512 characters, truncation marked), or an explicit no compiler diagnostics were captured when nothing was captured. Toolchain breakage is now distinguishable from a slow compile in both shapes.

Change and scope

  • src/process/DarwinProcessRunTokenReader.ts: the compile catch now reads the failure through the existing execFileOutputFailure extractor. compilerOutcome names the outcome without implying an exit code a timeout lacks; compilerDiagnostics bounds the excerpt at 512 characters (following the stderr_excerpt precedent in AdbConfiguration/ApktoolConfiguration) and marks truncation, including the ERR_CHILD_PROCESS_STDIO_MAXBUFFER case. COMPILER_TIMEOUT_MS replaces the inline 60_000, and a compileTimeoutMs factory option lets verification exercise the deadline in milliseconds; the production default is unchanged.
  • ENOENT wording and the cancellation mapping are unchanged. NativeUiHelperRuntime compiles a sibling Swift helper with the same shape; it is left unchanged here and can follow separately with its own report.
  • Not attempted: root-causing why the reporter's mismatched-CLT invocation reached the deadline under REA's environment while a direct run failed in ~23 s. This change surfaces whatever the compiler printed in either shape.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the Darwin helper compilation failure mapping in src/process/DarwinProcessRunTokenReader.ts, before normalizeCaptureFailure wraps the message.
  • CLI and MCP/tool-catalog contract: none. Error message text only; no tool, schema, parameter, or error-code change.
  • Provider, bridge, target-format, or platform compatibility: macOS-only helper; no engine, bridge, or target-format change.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: none. Spawn, stop signal, grace kill, timeout semantics, and root cleanup are unchanged; the existing cancellation and cleanup tests in the same lane are unmodified and green.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated in tests/boundary/process/darwinProcessRunTokenReader.test.ts: the fast-failure case now asserts the exact message …(compiler result: exit code 1): module cache is not writable; a new deadline case runs a compiler that prints an SDK-style diagnostic and then stops responding, and asserts …(compiler result: timed out after 500 ms): <diagnostic>; a new bound case asserts a 600-character diagnostic is cut at 512 characters with an explicit truncation marker.

  • Base reproduction: with the source change stashed, the exact-message assertion fails on f28f33828 — the base message is Node's Command failed: … text and the captured stderr never reaches the message.

  • Real coverage: the whole lane ran on macOS 27 arm64, Node 24.18.0 — 21 passed, including the unmodified real-Darwin tests (parser probe, ownership keys, executable padding).

  • Remaining proof gaps: the reporter's mismatched-CLT hang itself was not reproduced (this host has a healthy toolchain); failure shapes are exercised with fake compilers, which is what the lane already uses for this boundary.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/process/darwinProcessRunTokenReader.test.ts — 21 passed
  • npm run check:fast — green (typecheck, lint)
  • npm run verify:test-discovery — 884 files discovered exactly once
  • npm run check — green (typecheck, lint, format, knip, metadata, architecture guards)
  • Base-failure check via git stash of the source change — new assertion fails on unmodified main

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Failure message text changes for the compile-failure path only.
  • Real Hopper/Ghidra, browser, or OS coverage: real macOS 27 arm64 host for the lane above; Hopper, Ghidra, browser, and Windows not applicable to this code path.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the excerpt is bounded at 512 characters; no new subprocess, capability, or write path. Request arguments and environment redaction are unchanged.

Review checklist

  • This PR addresses a concrete problem, not an unscoped refactor.
  • The PR has one focused outcome, and the title follows type(scope): outcome.
  • Related issue is linked.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed (none referenced this message).
  • User-visible CLI/MCP changes include representative output (shown in the tests above).
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T00:45:21.637190Z 1ccc26e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 85910838be

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

Comment on lines 228 to 230
failure?.code ??
(cause instanceof Error && "code" in cause
? String(cause.code)

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 Preserve null exit codes for signaled compilers

When swiftc terminates because of an unexpected signal (for example, SIGSEGV), Node's execFile error has code: null and a populated signal. This ?? treats that meaningful null as absent and falls through to String(cause.code), producing the string "null"; consequently the signal branch in compilerOutcome is never reached and users see compiler result: null instead of the actual signal. Preserve failure.code whenever a parsed failure exists so the new error retains the meaningful failure reason.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in 1ccc26e: the fallback now applies only when no parsed failure exists, so a signaled compiler's null exit code reaches compilerOutcome and reports stopped by signal SIGSEGV. Added a regression test that kills a fake compiler with SIGSEGV and asserts that exact message.

@morluto
morluto merged commit 091cb81 into morluto:main Oct 12, 2026
2 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto

morluto commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Thanks, @jimpablo, for making Swift helper failures report the actual compiler outcome and a bounded diagnostic excerpt. Covering exit, timeout, signal, and truncation cases should make these macOS setup failures much easier to diagnose without letting compiler output grow without bound. Welcome to REA!

@jimpablo

Copy link
Copy Markdown
Contributor Author

Thank you! The existing execFileOutputFailure extractor and the ADB/Apktool stderr_excerpt precedents made it straightforward to keep the diagnostics bounded and consistent. Happy to keep contributing — #2004 continues in the same spirit (load-selection rejections projected as caller input).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Darwin helper failure reported as timeout when the compiler actually errors

2 participants