Skip to content

fix(macos): keep embedded CUA unavailable when PID tracking fails - #124572

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-plugin-short-write-v3
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-plugin-short-write-v3

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where macOS users enabling the embedded CUA computer provider could have it advertised as ready after a legal positive short write truncated its authoritative PID record. Later lifecycle cleanup could then be unable to attribute and reap the exact privileged daemon that OpenClaw spawned.

Why This Change Was Made

The PID publication owner now uses Foundation's throwing full-write operation on the existing securely opened, non-owning descriptor. Startup records the exact child before publication and, if publication fails, reuses the existing stop/kill, directory cleanup, and bounded restart lifecycle instead of advancing to readiness.

Successful launches keep the same path, ownership checks, file mode, readiness flow, and teardown behavior. This changes no config, protocol, persistence schema, public API, or permission policy.

User Impact

Embedded CUA will no longer become available with a truncated or missing authoritative PID record. On the rare publication failure path, OpenClaw leaves no endpoint, process, or owned socket directory behind and retries only through the existing bounded restart policy.

Evidence

  • A real local DYLD_INTERPOSE probe shortened the first write(2) targeting cua.pid; pre-fix code published only 424 instead of 424242.
  • Under the same injected positive short write, Foundation FileHandle.write(contentsOf:) persisted the complete 424242 payload. Public Swift Foundation source confirms its remaining-byte loop, EINTR retry, and zero/error failure behavior.
  • The owner-boundary regression proves failed PID publication leaves no ready endpoint, no live child, and no owned-directory residue.
  • Reviewed candidate 731bce49fe5a6ec1d29608b2f4f4e737527619d2: 17/17 focused Swift tests passed; six routed macOS Vitest shards passed 356 tests; native schema guard v8, strict Swift lint/format, TruffleHog, and exact-diff checks passed.
  • Fresh Codex autoreview reported no accepted/actionable findings, correctness 0.96.
  • After rebasing onto local origin/main at d437a4a, the stable patch ID and all three resulting source/test blobs remained byte-identical to the reviewed candidate, so the completed exact-candidate proof remains applicable.
  • Production LOC: +15/-7, net +8. The growth establishes the fail-closed readiness invariant and routes publication failure through existing lifecycle ownership; it adds no fallback or parallel cleanup path. Tests: +32/-0.
  • No changelog entry, release, or deployment is part of this PR.

AI-assisted maintainer repair; the implementation and proof were directly reviewed.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 16, 2026 12:38
@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: S maintainer Maintainer-authored PR labels Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 8:45 AM ET / 12:45 UTC.

ClawSweeper review

What this changes

The PR prevents embedded macOS CUA from becoming ready when its daemon PID record cannot be fully persisted, then stops and cleans up that daemon through the existing lifecycle.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: current main still ignores failed PID publication, while this focused owner-bound repair appears correct and has supplied native fault-injection evidence.

Priority: P2
Reviewed head: 12259f805a586cedcd51c6244ec856a9188bada4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported lifecycle repair with meaningful fault-path proof; exact-head native validation remains the material merge check.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.
Evidence reviewed 6 items Current-main defect: Current main ignores the Boolean result of PID publication and continues into readiness, so a failed or short PID write can still lead to an advertised endpoint.
Owner-bound repair: The PR records the spawned child before requiring successful PID publication; failure uses the existing stop, cleanup, and restart path before the readiness loop.
Regression coverage: The added test forces PID publication failure while readiness would otherwise succeed, then asserts no endpoint, no live child, and no owned-directory residue; it would fail before the caller began honoring the writer result.
Findings None None.
Security None None.

How this fits together

Embedded CUA starts a local macOS daemon, records its PID in an owned socket directory, and only then makes a worker endpoint available to node execution and the readiness UI. The PID file is the lifecycle record needed to stop the exact spawned daemon.

flowchart LR
  A[CUA enabled] --> B[Launch embedded daemon]
  B --> C[Record daemon PID]
  C --> D{PID publication succeeded?}
  D -->|Yes| E[Probe socket readiness]
  E --> F[Expose worker endpoint]
  D -->|No| G[Stop child and clean directory]
  G --> H[Bounded restart]
  F --> I[Node worker and readiness UI]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned macOS lifecycle repair proceed once the exact-head native macOS checks validate the Foundation full-write path? Wait for exact-head native validation: Merge after the native macOS checks confirm the supplied short-write behavior and lifecycle cleanup on this head.

Why: The patch changes privileged embedded-daemon startup behavior, and this review could not independently inspect the Foundation implementation that supplies its full-write guarantee.

Before merge

  • Resolve merge risk (P1) - The Foundation full-write contract could not be independently inspected in this environment; retain exact-head native macOS validation before merge.
  • Complete next step (P2) - This maintainer-labeled PR needs exact-head native macOS validation rather than an automated replacement or repair job.
Agent review details

Security

None.

PR surface

Other +40. Total +40 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 47 7 +40
Total 3 47 7 +40

Review metrics

Metric Value Why it matters
Production versus regression coverage production +8 net (+15/-7), tests +32 The production growth attaches PID-publication failure to the existing lifecycle owner; the added test covers the no-ready/no-orphan invariant.

Merge-risk options

Maintainer options:

  1. Confirm native lifecycle proof before merge (recommended)
    Wait for the exact-head macOS result that exercises short PID writes and verifies no endpoint, child, or socket directory survives failure.

Technical review

Best possible solution:

Land the fail-closed owner-bound lifecycle repair once exact-head macOS validation confirms complete PID persistence under the injected short-write path.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a partial PID write returns false on current main, yet startup ignores that result and can publish a ready endpoint when its readiness probe succeeds. The review did not execute the macOS fault injector locally.

Is this the best way to solve the issue?

Yes for the lifecycle boundary: PID publication must succeed before readiness, and failure belongs in the existing child-stop and restart owner rather than in downstream consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 751160109270.

Labels

Label changes:

  • add P2: This is a bounded macOS embedded-CUA reliability defect with a focused repair and limited blast radius.
  • add merge-risk: 🚨 availability: The PR changes startup cleanup and retry behavior for the embedded CUA daemon, so an error-path regression could make the provider unavailable.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.

Label justifications:

  • P2: This is a bounded macOS embedded-CUA reliability defect with a focused repair and limited blast radius.
  • merge-risk: 🚨 availability: The PR changes startup cleanup and retry behavior for the embedded CUA daemon, so an error-path regression could make the provider unavailable.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix DYLD_INTERPOSE positive-short-write probe and a patch-identical exact-head claim, supplemented by an owner-bound cleanup regression.

Evidence

What I checked:

Likely related people:

  • steipete: Local history, blame, and the PR head all connect this person to the embedded CUA PID lifecycle and its follow-up repair. (role: feature owner and recent area contributor; confidence: high; commits: 8cf85e3ceda4, 12259f805a58; files: apps/macos/Sources/OpenClaw/CuaDriverHostCoordinator.swift, apps/macos/Sources/OpenClaw/CuaDriverHostLifecycle.swift, apps/macos/Tests/OpenClawIPCTests/CuaDriverHostCoordinatorTests.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the queued exact-head macOS checks before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer landing verification for head 12259f805a586cedcd51c6244ec856a9188bada4:

  • Exact-head required CI is green: run 31947622334, including macos-node job 95166098642 and macos-swift job 95166098681.
  • ClawSweeper reviewed this exact head, found no actionable findings, marked proof sufficient, and named only the now-completed exact-head macOS validation as a rank-up move.
  • Direct dependency inspection: Swift Foundation commit 6f4ac1e9 routes write(contentsOf:) through _writeBytes, whose remaining-byte loop retries EINTR, advances after positive short writes, and throws on zero/error.
  • Focused candidate proof: swift test --package-path /tmp/openclaw-cua-shortwrite.Z7YF58/apps/macos --skip-build --filter CuaDriverHostCoordinatorTests passed 17/17; node scripts/check-changed.mjs -- <three changed files> passed native schema v8, strict Swift lint, and six routed macOS Vitest shards / 356 tests; swiftformat --lint, strict swiftlint, TruffleHog, and git diff --check passed.
  • Real syscall proof forced cua.pid from 424242 to truncated 424 pre-fix; the fixed Foundation path persisted all six bytes. The owner regression proves failure leaves no endpoint, process, or directory.
  • Rebase proof: stable patch ID and all three resulting blobs are identical to directly reviewed candidate 731bce49fe5a6ec1d29608b2f4f4e737527619d2; fresh candidate autoreview was clean at 0.96.
  • LOC: production +15/-7 (net +8), tests +32/-0. The +8 attaches publication failure to the existing lifecycle owner and adds no fallback or parallel cleanup path.

Known proof gap: CI does not rerun the local DYLD interposer, but the interposed candidate blobs are byte-identical to this head and exact-head native CI is green. No release or deployment is included.

@steipete
steipete merged commit 1787fd6 into main Aug 16, 2026
112 checks passed
@steipete
steipete deleted the fix/autoqa-plugin-short-write-v3 branch August 16, 2026 13:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

app: macos App: macos maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant