Skip to content

fix(macos): stop cancelled share waits and cursor retries - #122

Merged
steipete merged 1 commit into
mainfrom
fix/macos-cancellation-reviewed
Aug 29, 2026
Merged

fix(macos): stop cancelled share waits and cursor retries#122
steipete merged 1 commit into
mainfrom
fix/macos-cancellation-reviewed

Conversation

@steipete

@steipete steipete commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where stopping or cancelling Share This Mac work could leave a video consumer waiting for its full frame timeout and treat a cancelled cursor configuration operation as a transient failure.

This supersedes #114 and preserves Sebastien Tardif's contribution with a co-author trailer and changelog credit. No linked bug issue exists in #114's closing references or the repository issue list, so this does not close an unrelated issue.

Why This Change Was Made

The mailbox now owns its timeout task alongside the waiter, cancels it on completion/replacement/finish, and rechecks cancellation after registration. That closes the race where the cancellation handler ran before a continuation existed. Cursor reconciliation stops on CancellationError and cancelled backoff; ordinary errors retain the existing exponential backoff. The retry loop remains owned by MacScreenCapture, with a small extraction for behavioral tests.

The integration starts from current main 830832deb6f31c43a2eeabb71cc051eb0d147fd3. It preserves the current release history and adds only an Unreleased entry. Listener admission, authentication, permission checks, and capture-configuration serialization are unchanged.

Provenance is clear: the mailbox path originated in ed2354d (#74), and cursor retry in 6471f31 (#90). The cursor problem is specifically an operation throwing CancellationError while the retry task remains active; cancelling the retry task itself already reached the loop's cancellation check on main.

User Impact

Cancelled video waits return promptly instead of consuming the remaining frame timeout. Timeout tasks are released when their wait ends, and cancelled cursor operations are not retried.

Evidence

Before any production edit, native Swift harnesses built from the unchanged owners on main reproduced both defects: an already-cancelled mailbox wait returned after 5.297 seconds, and the cursor loop made 2 attempts after the first operation threw CancellationError (expected 1). The larger package baseline build was interrupted during a filesystem stall and is not counted as a test result.

After integration, all 39 VideoPipelineTests passed, including seven new cancellation/retry cases. Coverage includes cancellation before registration, 100 cancellation/offer races, mailbox reuse, timeout release, cancellation errors, cancellation during backoff, and preserving transient retries.

Real macOS proof used macOS 26.6.2 (25G83), arm64, and Xcode 27 beta (27A5237l). A test-only executable linked against the unchanged compiled production capture/mailbox objects was signed with the OpenClaw Foundation Developer ID and run from the stable /Applications/Crabfleet.app path. It received an actual 2560×1440 ScreenCaptureKit frame, then returned nil from a cancelled five-second mailbox wait in 0.00021375 seconds. MacScreenCapture.stop() completed in 0.006607625 seconds, with zero consumers left. No pixels were saved or uploaded; no registry publication, audio, clipboard, remote input, or listener was enabled. The temporary installed probe was removed afterward.

A second paired live run used the preserved pre-edit main object files and then the integrated object files with the same signed probe and real captured frames: main took 5.006727 seconds to return nil from the cancelled wait (probe failed its 500ms bound), versus 0.000169542 seconds after the fix (probe passed). Both runs stopped capture cleanly and left zero consumers.

A full Share This Mac tailnet session was not exercised: the application's own signed Tailscale executable reported BackendState: Stopped. The host's network state and TCC permissions were not changed. The ScreenCaptureKit proof above is real capture/teardown evidence, not a claim of a connected remote viewer or a naturally occurring ScreenCaptureKit cancellation error.

Validation: pnpm format, pnpm check, pnpm test (1,003 passed), pnpm build, pnpm build:static, Worker package dry-run, go test ./..., go vet ./..., and git diff --check passed. The Go checks were rerun successfully with an isolated cache after the shared cache lost files during the first run. pnpm macos:test passed all tiers: 121 vendor, 301 application, and 7 serialized integration tests. The opt-in real-tailnet smoke returned early because it was not enabled; the other six serialized cases exercised real loopback/ARD/lifecycle behavior. The first full run hit a one-second completion deadline in the existing file-sharing fixture; it passed unchanged in isolation (0.296s), and the entire unchanged native gate then passed. No production or test deadlines were increased. The native script retains its normal tests and concurrency settings; a task-local launcher supplies only external scratch directories to avoid host filesystem stalls.

Codex autoreview completed with no accepted/actionable findings at the configured default P0 threshold. No merge is requested or performed.

Integrate the cancellation repair from #114 on current main. Own mailbox
expiry tasks with their continuations and close cancellation before waiter
registration. Stop cancelled cursor operations while preserving retries for
transient errors, with behavioral regressions at the capture owner.

Co-authored-by: Sebastien Tardif <sebtardif@ncf.ca>
@clawsweeper

clawsweeper Bot commented Aug 29, 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 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 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 9:05 AM ET / 13:05 UTC.

ClawSweeper review

What this changes

The PR makes Share This Mac cancellation release video-mailbox waits promptly and stop cursor reconciliation retries when cancellation is observed.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer landing review: the exact PR delta fixes two reproduced cancellation paths absent from its current-main base, with strong native before/after evidence and no actionable patch finding. The remaining Swift analysis check must complete and the repository’s exact-head gates must be confirmed before landing.

Priority: P2
Reviewed head: adf7f5ec2f3bc943ff4287c386c6fa955275d2b7

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused concurrency repair with strong paired native before/after evidence, targeted race coverage, and no identified correctness or security defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed production owners are the capture mailbox and cursor reconciliation loop; supplied signed macOS evidence exercised real ScreenCaptureKit capture and teardown, then showed the cancelled five-second mailbox wait improve from about five seconds on the preserved main objects to about 0.00017 seconds after this exact integration.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owners are the capture mailbox and cursor reconciliation loop; supplied signed macOS evidence exercised real ScreenCaptureKit capture and teardown, then showed the cancelled five-second mailbox wait improve from about five seconds on the preserved main objects to about 0.00017 seconds after this exact integration.
Evidence reviewed 7 items Mailbox cancellation implementation: The introduced mailbox associates a timeout task with its waiter, cancels it on completion and cancellation, and rechecks cancellation after waiter registration, preventing a cancelled consumer from waiting for the frame deadline.
Cursor cancellation implementation: The introduced retry helper returns for a CancellationError and for cancelled backoff sleep while retaining exponential retry for ordinary failures.
Regression coverage: Seven focused tests cover already-cancelled waits, cancellation/offer races, timeout-task release, cancellation errors, cancelled retry tasks, cancelled backoff, and ordinary retry preservation.
Findings None None.
Security None None.

How this fits together

Share This Mac captures macOS frames for connected viewers. Its capture owner uses a one-frame mailbox and cursor reconciliation task, so stopping a share must unblock both without leaving delayed background work.

flowchart LR
  A[Share stop or cancellation] --> B[Capture owner]
  B --> C[Video mailbox wait]
  B --> D[Cursor reconciliation]
  C --> E[Timeout task cleanup]
  D --> F[Retry decision]
  E --> G[Share teardown]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The required exact-head Swift analysis is still in progress; repository policy requires all listed check, test, and macOS test gates before landing.
  • Complete next step (P2) - Wait for the in-progress exact-head Swift analysis and complete normal maintainer landing review; no mechanical repair is identified.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus regression coverage production +73/-23, tests +96 The concurrency repair is accompanied by focused coverage for its cancellation and race boundaries.

Root-cause cluster

Relationship: canonical
Canonical: #122
Summary: This PR integrates the same mailbox and cursor-cancellation repair proposed by the older related PR on current main with broader cancellation coverage and native proof.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Preserve this bounded cancellation repair, confirm the exact-head gates, and land it so Share This Mac teardown does not retain frame waits or retry cancelled cursor configuration.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Preserve this bounded cancellation repair, confirm the exact-head gates, and land it so Share This Mac teardown does not retain frame waits or retry cancelled cursor configuration.

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

Yes. The supplied exact-head evidence includes a paired real ScreenCaptureKit baseline where an already-cancelled five-second mailbox wait took about five seconds before the change and returned in about 0.00017 seconds after it.

Is this the best way to solve the issue?

Yes. Owning each timeout alongside its waiter and treating cancellation separately from transient failure is the narrowest repair while preserving the existing bounded retry behavior for ordinary errors.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Cancelled Share This Mac teardown can delay active macOS sharing work, but the fix is bounded and no data, security, or crash emergency is established.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owners are the capture mailbox and cursor reconciliation loop; supplied signed macOS evidence exercised real ScreenCaptureKit capture and teardown, then showed the cancelled five-second mailbox wait improve from about five seconds on the preserved main objects to about 0.00017 seconds after this exact integration.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owners are the capture mailbox and cursor reconciliation loop; supplied signed macOS evidence exercised real ScreenCaptureKit capture and teardown, then showed the cancelled five-second mailbox wait improve from about five seconds on the preserved main objects to about 0.00017 seconds after this exact integration.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the merged Share This Mac video-pipeline and cursor-pipeline commits and the current focused repair. (role: feature owner and recent area contributor; confidence: high; commits: ed2354d85c14, 6471f31a7c98, adf7f5ec2f3b; files: macos/CrabfleetMac/Sources/CrabfleetMac/VideoMailbox.swift, macos/CrabfleetMac/Sources/CrabfleetMac/MacScreenCapture.swift)

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-08-29T13:00:28.313Z sha adf7f5e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 29, 2026
@steipete
steipete merged commit bdd5083 into main Aug 29, 2026
14 checks passed
@steipete
steipete deleted the fix/macos-cancellation-reviewed branch August 29, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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