Skip to content

fix(macos): stop cursor reconcile and mailbox waits on cancel - #114

Open
SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/macos-cancel-hangs
Open

fix(macos): stop cursor reconcile and mailbox waits on cancel#114
SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/macos-cancel-hangs

Conversation

@SebTardif

Copy link
Copy Markdown

What Problem This Solves

Fixes an issue where stopping Share This Mac (or cancelling a share task) could leave cursor-reconcile retries and mailbox timeout waits running. Cursor reconcile treated CancellationError as a normal failure and slept with try?, so cancel became another backoff retry. The video mailbox spawned an unstructured timeout task that used try? sleep and was never cancelled when a frame arrived or the waiter went away.

Why This Change Was Made

Honor cancellation in both loops: break when reconcile or its sleep is cancelled, and cancel the mailbox timeout task on offer, finish, replace, and expire. Task.sleep now uses try await so cancel stops the wait.

User Impact

Share teardown no longer waits out a 5s backoff or a leftover mailbox timeout after the user stops sharing.

Evidence

Terminal output from the patched tree. Before the patch, a cancelled mailbox waiter sat for the full 5s timeout:

$ swift test --package-path macos/CrabfleetMac --filter mailboxCancelledWaiter
Expectation failed: (ContinuousClock().now - startedAt -> 5.002 seconds) < 0.5 seconds
Test mailboxCancelledWaiterReturnsPromptlyWithoutResumingTwice() failed after 5.002 seconds

After the patch the same waiter returns immediately:

$ swift test --package-path macos/CrabfleetMac --filter mailboxCancelledWaiter
Test mailboxCancelledWaiterReturnsPromptlyWithoutResumingTwice() passed after 0.001 seconds.
Test run with 1 test in 1 suite passed after 0.001 seconds.

Real behavior proof

  • Behavior or issue addressed: Share cancel no longer retries cursor reconcile or leaves mailbox timeout tasks sleeping.

  • Real environment tested: macOS, Xcode at /Applications/Xcode.app, swift-testing on arm64, branch fix/macos-cancel-hangs at 0b6a6cc.

  • Exact steps or command run after this patch:

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
    swift test --package-path macos/CrabfleetMac --filter mailboxCancelledWaiter
  • Evidence after fix: terminal output from the patched tree:

    $ swift test --package-path macos/CrabfleetMac --filter mailboxCancelledWaiter
    Test mailboxCancelledWaiterReturnsPromptlyWithoutResumingTwice() passed after 0.001 seconds.
    Test run with 1 test in 1 suite passed after 0.001 seconds.
  • Observed result after fix: A cancelled mailbox next(timeout: 5s) returns in 0.001s instead of waiting the full 5s. Cursor reconcile treats CancellationError as non-retryable.

  • What was not tested: Live ScreenCaptureKit session with a real display share and TCC grants.

Related: introduced in #90 (cursor reconcile) and #74 (mailbox timeout Task).

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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

Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 9:16 AM ET / 13:16 UTC.

ClawSweeper review

What this changes

The PR makes Share This Mac stop cursor-reconciliation retries and video-mailbox timeout waits promptly when sharing is cancelled.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

Blocked until real behavior proof from a real setup is added - 3 items remain

Current main still has both cancellation gaps, so this PR remains necessary. The patch appears correct and focused, but its terminal transcript proves only a Swift test; a real signed Share This Mac stop trace is still needed before merge.

Priority: P2
Reviewed head: b3e2bd4f650a326f725435b4ad6d187886242249

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and source-supported, but real Share This Mac teardown proof is still missing.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body shows an after-fix Swift test transcript, but that is mock-only supplemental evidence and it explicitly omits the live ScreenCaptureKit share path; add redacted signed stable-path runtime proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body shows an after-fix Swift test transcript, but that is mock-only supplemental evidence and it explicitly omits the live ScreenCaptureKit share path; add redacted signed stable-path runtime proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current-main mailbox gap: Current main launches an unstructured timeout task with try? await Task.sleep and does not retain it for cancellation, leaving the wait alive after its caller stops.
Current-main cursor gap: Current main catches every reconcile error and suppresses cancellation from the retry sleep, so cancellation can be followed by another retry iteration.
Patch behavior: The branch retains each timeout task, id-fences it, and cancels it when a waiter is delivered, replaced, finished, or expired; it also exits retry backoff on cancellation.
Findings None None.
Security None None.

Live Verification

Command: DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test

Result: FAIL (failed) — step 1 run DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test: terminal command did not produce output within 20 seconds: "DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test"

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test
runner@runnervm76f27:/tmp/clawsweeper-live-proof-114-a9hrHB/target$ DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test

› crabfleet-ai@ macos:test /tmp/clawsweeper-live-proof-114-a9hrHB/target
› pnpm macos:test:vendor && sh macos/CrabfleetMac/scripts/run-tests.sh


› crabfleet-ai@ macos:test:vendor /tmp/clawsweeper-live-proof-114-a9hrHB/target
› swift test --package-path macos/CrabfleetMac/Vendor/RoyalVNCKit

DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer pnpm macos:test








































Assertions:

  • FAIL expect_output: Test run with

How this fits together

Share This Mac captures the macOS display and forwards video and cursor updates to connected viewers. Cancellation flows through capture reconciliation and mailbox waits, then determines whether share teardown can finish promptly.

flowchart LR
  A[User stops sharing] --> B[Capture task cancellation]
  B --> C[Cursor reconcile retry]
  B --> D[Video mailbox wait]
  C --> E[Stop backoff]
  D --> F[Cancel timeout]
  E --> G[Share teardown]
  F --> G
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body shows an after-fix Swift test transcript, but that is mock-only supplemental evidence and it explicitly omits the live ScreenCaptureKit share path; add redacted signed stable-path runtime proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Merging without a live signed-app stop trace leaves the ScreenCaptureKit teardown timing unproven; the current evidence is only a focused Swift test.
  • Complete next step (P2) - The sole remaining blocker is contributor-provided production-path proof, which an automated repair lane cannot supply.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +62/-15, tests +24 The production changes are limited to timeout ownership and retry cancellation, with focused regression coverage.

Merge-risk options

Maintainer options:

  1. Add a signed-app stop trace (recommended)
    Start a real Share This Mac session from the Developer-ID-signed app installed at its stable path, stop it while the affected work is pending, and attach redacted timing or runtime logs.

Technical review

Best possible solution:

Land this narrow cancellation repair after a redacted stable-path Share This Mac run demonstrates prompt teardown during the affected waits.

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

Yes, from source: current main retains neither the mailbox timeout task nor cancellation-aware retry backoff, and the branch adds a focused cancellation regression test; no live share reproduction is attached.

Is this the best way to solve the issue?

Yes: retaining and cancelling the timeout task plus exiting cancelled backoff is the narrowest repair for the observed ownership gaps, provided the live teardown path is demonstrated.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded teardown delay in the macOS sharing workflow.
  • merge-risk: 🚨 availability: Task-cancellation changes directly affect whether an active Share This Mac session terminates promptly.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body shows an after-fix Swift test transcript, but that is mock-only supplemental evidence and it explicitly omits the live ScreenCaptureKit share path; add redacted signed stable-path runtime proof before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: Git history shows Peter Steinberger authored the merged cursor pipeline and most changes across the two affected macOS files. (role: feature introducer and principal area contributor; confidence: high; commits: 6471f31a7c98, ed2354d85c14; files: macos/CrabfleetMac/Sources/CrabfleetMac/MacScreenCapture.swift, macos/CrabfleetMac/Sources/CrabfleetMac/VideoMailbox.swift)
  • Vincent Koc: History shows a recent merged change in the cursor-capture file, making this a relevant secondary routing contact. (role: recent adjacent contributor; confidence: medium; commits: 6bf5b198f261; files: macos/CrabfleetMac/Sources/CrabfleetMac/MacScreenCapture.swift)

Rank-up moves

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

  • Attach redacted runtime evidence from a Developer-ID-signed app at its stable path showing that stopping a live share cancels the affected wait promptly.

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 (21 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-23T18:06:21.352Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-23T22:08:58.562Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-24T03:14:17.250Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-24T14:12:01.814Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P1] Remove the release-owned changelog line
  • reviewed 2026-08-24T21:03:05.118Z sha 0b6a6cc :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-25T01:15:47.130Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P1] Remove the release-owned changelog line
  • reviewed 2026-08-25T07:16:31.353Z sha 0b6a6cc :: needs real behavior proof before merge. :: [P1] Remove the release-owned changelog entry
  • reviewed 2026-08-25T09:17:59.122Z sha b3e2bd4 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed 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. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 21, 2026
PLAN: cursor reconcile caught every error (including CancellationError)
then slept with try?, so cancel became another backoff retry. Mailbox
timeout Tasks used try? sleep and were not cancelled when a frame arrived.

DO: break on CancellationError, cancel the mailbox timeout Task, and
honor Task.sleep cancellation.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif
SebTardif force-pushed the fix/macos-cancel-hangs branch from 0b6a6cc to b3e2bd4 Compare August 25, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant