Skip to content

fix(macos): back off approval socket retries - #116125

Merged
vincentkoc merged 1 commit into
mainfrom
perf-macos-runtime-profile-v6
Jul 29, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf-macos-runtime-profile-v6

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where users with overlapping native macOS app processes could see recurring CPU and filesystem spikes while both processes competed for the exec-approvals Unix socket.

A 15-second sample of the blocked process caught ExecApprovalsStore.resolve(agentId:) inside the prompt-server retry loop, while one-second process sampling observed bursts up to 9.4% CPU. The loop retried the SQLite credential read and socket bind every second indefinitely.

Why This Change Was Made

The prompt server now applies bounded exponential backoff after startup failures: 1, 2, 4, 8, 16, then 30 seconds. The first startup attempt remains immediate, and a listener that later stops unexpectedly starts a fresh immediate recovery cycle.

The retry policy is isolated and deterministic so its growth and cap can be tested without timing-sensitive assertions.

User Impact

Duplicate or briefly overlapping macOS app processes no longer keep reopening the approvals store and rebinding the same socket every second. Normal single-app startup and transient recovery behavior are unchanged.

Evidence

  • Profiler reproduction: competing app showed ExecApprovalsPromptServer.start() -> ExecApprovalsStore.resolve(agentId:) during recurring CPU bursts.
  • swift test --package-path apps/macos --build-path apps/macos/.build-local --filter ExecApprovalsPromptServerTests
    • 6 tests passed, including credential reload, cancellation, transient bind failure, unexpected listener recovery, and the new exponential-cap policy.
  • Full macOS Swift target compiled successfully as part of the focused test command.
  • swiftformat --lint ... --config config/swiftformat: clean.
  • swiftlint lint --strict --config config/swiftlint.yml ...: 0 violations.
  • git diff --check: clean.
  • Autoreview: clean, no accepted or actionable findings.

Maintainer Decision

  • Reviewed exact head 0b30b7b8fdfc4a7873d2dd84b633059c84614cf7.
  • Froze current main at cdab1764841a369951c6b525719ec6e11983956a; the clean three-way merge produced tree ab07bf9896f43be65e11d5a1d07397cd8a6d40c3.
  • No commit since this branch's base changed either touched file, so rebasing would only churn a reviewed exact head.
  • Confirmed the lifecycle invariant directly: stop() cancels and retires the current retry task, repeated start() calls cannot create a second task, and an unexpected active-listener stop calls start() with a fresh immediate attempt.
  • ClawSweeper's optional current-main and macOS lifecycle rank-up moves are therefore satisfied against the frozen merge result.

AI-assisted: yes. The implementation, tests, and profiler evidence were reviewed and verified by the maintainer.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: XS maintainer Maintainer-authored PR labels Jul 29, 2026
@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 29, 2026 23:35
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 7:48 PM ET / 23:48 UTC.

ClawSweeper review

What this changes

This PR changes the native macOS execution-approval prompt server from fixed one-second socket-start retries to capped exponential backoff and adds deterministic coverage for the retry schedule.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This remains a focused, apparently correct P2 macOS runtime fix: it replaces an unbounded one-second retry loop with a bounded retry policy while retaining immediate first attempts and immediate recovery after an active listener stops. The PR is authored by a repository member and carries the protected maintainer label, so it requires explicit maintainer handling rather than automated cleanup. Likely related people: vincentkoc is the clearest routing candidate from the focused macOS approval-server change, with medium confidence.

Priority: P2
Reviewed head: 0b30b7b8fdfc4a7873d2dd84b633059c84614cf7
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-scoped patch with deterministic coverage and maintainer-supplied lifecycle evidence; the remaining decision is the intentional maximum recovery delay.
Proof confidence 🌊 off-meta tidepool Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body nevertheless provides profiler observations and a focused macOS Swift validation report for the changed lifecycle.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body nevertheless provides profiler observations and a focused macOS Swift validation report for the changed lifecycle.
Evidence reviewed 4 items Changed retry lifecycle: The proposed macOS server adds a maximum retry delay, creates retry-backoff state for each startup generation, preserves the first attempt as immediate, and applies the delay only after failed starts.
Deterministic policy coverage: The added test verifies the retry sequence grows from 10ms to 20ms and caps at 40ms, which directly covers the new backoff helper without timing-sensitive sleeps.
Maintainer-reviewed merge context: The PR body records review of head 0b30b7b against a clean three-way merge, including the generation/task-cancellation and unexpected-listener-recovery invariants.
Findings None None.
Security None None.

How this fits together

The native macOS app starts a local Unix-socket server to receive execution-approval prompts. Startup resolves approval credentials and binds the socket; this change controls how the server retries after that startup path fails so overlapping app processes do not repeatedly reopen the approvals store and rebind the same path.

flowchart LR
  A[macOS app startup] --> B[Approval prompt server]
  B --> C[Resolve approval credentials]
  C --> D[Bind local approval socket]
  D -->|start succeeds| E[Receive approval prompts]
  D -->|start fails| F[Bounded retry backoff]
  F --> C
  E -->|listener stops unexpectedly| B
Loading

Decision needed

Question Recommendation
Is a maximum 30-second retry interval acceptable for persistent execution-approval socket startup failures in the native macOS app? Accept bounded recovery: Approve the capped exponential retry schedule because it prevents recurring contention work while preserving immediate initial and post-listener-stop attempts.

Why: The patch intentionally trades faster repeated recovery attempts for reduced CPU and filesystem pressure when overlapping processes contend for the same socket; the acceptable recovery latency is a product and platform-owner judgment.

Before merge

  • Resolve merge risk (P1) - After repeated socket-start failures, recovery attempts can be delayed by up to 30 seconds; that intentional availability tradeoff should be accepted by the macOS owner before merge.
  • Complete next step (P2) - Protected maintainer handling is required to accept the intentional availability tradeoff in the capped retry policy; no mechanical repair or automated close is appropriate.
Agent review details

Security

None.

PR surface

Other +37. Total +37 across 2 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 2 38 1 +37
Total 2 38 1 +37

Review metrics

Metric Value Why it matters
Retry schedule 1, 2, 4, 8, 16, then 30 seconds The cap defines the user-visible recovery-latency ceiling introduced to stop repeated socket and SQLite work under process contention.

Merge-risk options

Maintainer options:

  1. Confirm the recovery-latency tradeoff (recommended)
    Have the macOS owner accept the 30-second cap after confirming that persistent socket contention is preferable to one-second retry churn.
  2. Reduce the maximum delay
    Adjust the cap and retain the deterministic retry-policy test if the product requires more frequent recovery attempts after sustained startup failures.

Technical review

Best possible solution:

Land the bounded retry policy if the macOS owner accepts the 30-second cap for persistent bind failures, preserving the existing immediate initial attempt and immediate active-listener recovery behavior.

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

Yes, from source and the supplied profiler evidence: two overlapping native macOS processes contend for the execution-approval Unix socket, causing the existing fixed one-second retry path to repeat credential resolution and socket binding. The submitted focused Swift tests also cover the new retry-policy and lifecycle paths, although this review did not independently run a macOS process reproduction.

Is this the best way to solve the issue?

Yes. Keeping retry policy inside the existing prompt-server startup lifecycle is narrower and more maintainable than adding configuration or a separate contention mechanism; it preserves immediate first attempts and listener-stop recovery while bounding repeated failures.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 availability: The patch intentionally changes retry timing after approval-socket startup failures, potentially delaying eventual recovery by up to 30 seconds.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded native-app reliability and efficiency fix with limited blast radius rather than an emergency outage or security bypass.
  • merge-risk: 🚨 availability: The patch intentionally changes retry timing after approval-socket startup failures, potentially delaying eventual recovery by up to 30 seconds.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body nevertheless provides profiler observations and a focused macOS Swift validation report for the changed lifecycle.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Authored the focused macOS approval-socket retry implementation and supplied lifecycle, profiling, and focused Swift-test evidence for the exact head under review. (role: recent macOS approval-path contributor; confidence: medium; commits: 0b30b7b8fdfc; files: apps/macos/Sources/OpenClaw/ExecApprovalsSocket.swift, apps/macos/Tests/OpenClawIPCTests/ExecApprovalsPromptServerTests.swift)

Rank-up moves

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

  • Confirm that the 30-second recovery cap is acceptable for persistent approval-socket contention before merging.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-29T23:39:30.691Z sha 0b30b7b :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 29, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision for reviewed head 0b30b7b8fdfc4a7873d2dd84b633059c84614cf7:

  • Accept the 30-second maximum retry delay for persistent approval-socket contention. A process that cannot bind the single-owner socket cannot serve approvals, so continued one-second SQLite/socket churn has no availability benefit.
  • Preserve immediate recovery where it matters: the initial bind attempt remains immediate, and an established listener stopping unexpectedly starts a fresh immediate attempt.
  • The retry task remains generation-owned and cancelled by stop(), so overlapping starts cannot create parallel retry loops.
  • Current origin/main at b96ada06806f4346f0ecb2e64d7f9a10df39e21e was checked with a clean three-way merge (2aa1db81ac4e4292bd27ef11fdfb5b025fc406d7); no commit since the branch base touched either changed file.

This resolves the ClawSweeper availability tradeoff and maintainer-handling items.

@vincentkoc
vincentkoc merged commit 514ab48 into main Jul 29, 2026
114 of 122 checks passed
@vincentkoc
vincentkoc deleted the perf-macos-runtime-profile-v6 branch July 29, 2026 23:52
vincentkoc added a commit to licheer-zte/openclaw that referenced this pull request Jul 30, 2026
…id-retention

* origin/main: (83 commits)
  refactor(channels): own account config mutations (openclaw#115970)
  fix(discord): keep activity receipts in adopted threads (openclaw#116119)
  fix(feishu): preserve card actions through mention gating (openclaw#116105)
  perf(gateway): cache lazy server methods import (openclaw#116060)
  refactor: keep update timing constants private
  fix: reject stale update reconciliation
  refactor: keep update status response private
  fix: bound update status reconciliation
  fix: preserve uncertain update outcomes
  refactor: keep update reconciliation within size budgets
  fix: release update reconciliation on access loss
  docs: note control ui update reconciliation
  test: cover both managed update response orders
  fix: reconcile ambiguous gateway updates
  fix(codex): prevent approval promotion from blocking unattended runs (openclaw#116117)
  fix(daemon): require system-scope ownership before removing the user unit
  fix(daemon): only treat same-canonical-name user+system units as dueling
  fix(daemon): detect and resolve dueling user+system systemd gateway units
  fix(macos): back off approval socket retries (openclaw#116125)
  test: add stalled provider response body timeout coverage
  ...
vincentkoc added a commit to yetval/openclaw that referenced this pull request Jul 30, 2026
* origin/main: (23 commits)
  refactor(channels): own account config mutations (openclaw#115970)
  fix(discord): keep activity receipts in adopted threads (openclaw#116119)
  fix(feishu): preserve card actions through mention gating (openclaw#116105)
  perf(gateway): cache lazy server methods import (openclaw#116060)
  refactor: keep update timing constants private
  fix: reject stale update reconciliation
  refactor: keep update status response private
  fix: bound update status reconciliation
  fix: preserve uncertain update outcomes
  refactor: keep update reconciliation within size budgets
  fix: release update reconciliation on access loss
  docs: note control ui update reconciliation
  test: cover both managed update response orders
  fix: reconcile ambiguous gateway updates
  fix(codex): prevent approval promotion from blocking unattended runs (openclaw#116117)
  fix(daemon): require system-scope ownership before removing the user unit
  fix(daemon): only treat same-canonical-name user+system units as dueling
  fix(daemon): detect and resolve dueling user+system systemd gateway units
  fix(macos): back off approval socket retries (openclaw#116125)
  test: add stalled provider response body timeout coverage
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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