fix(macos): stop cursor reconcile and mailbox waits on cancel - #114
fix(macos): stop cursor reconcile and mailbox waits on cancel#114SebTardif wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 29, 2026, 5:09 AM ET / 09:09 UTC. ClawSweeper reviewWhat this changesUpdates Share This Mac’s cursor-retry loop and video mailbox so cancelling a share stops retry sleeps and pending timeout tasks promptly. Regression provenancePossible regression — probable (reviewed change; failure trace; known regression link). No predecessor PR is attributed. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 3 items remain Keep open: current main still has both cancellation races, and the patch is a focused repair with no discrete source-level correctness finding. The supplied evidence is only an isolated Swift test on an earlier revision and explicitly omits a real ScreenCaptureKit teardown, so real macOS behavior proof is still required before merge. Priority: P2 Review scores
Verification
How this fits togetherShare This Mac captures a Mac display and serves its frames to remote viewers. Capture configuration retries and the latest-wins video mailbox sit on the shutdown path, so their cancellation behavior affects how quickly a stopped share releases its work. flowchart LR
A[User stops Share This Mac] --> B[Capture shutdown]
B --> C[Cursor reconciliation task]
B --> D[Video mailbox wait]
C --> E[Cancellation decision]
D --> E
E --> F[Share teardown completes]
Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the narrow task-cancellation design and merge after a redacted real Share This Mac stop/cancel trace from the stable, Developer-ID-signed macOS app confirms prompt teardown. Do we have a high-confidence way to reproduce the issue? Yes—source inspection gives a high-confidence reproduction shape: cancel a task before Is this the best way to solve the issue? Yes—the mailbox-owned timeout and explicit cancellation exits are the narrowest maintainable repair for the two observed waits. A real signed Share This Mac teardown trace is still needed to validate the production boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 830832deb6f3. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (24 earlier review cycles; latest 8 shown)
|
0b6a6cc to
b3e2bd4
Compare
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>
b3e2bd4 to
366c643
Compare
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>
|
Superseded by #122 (merged) — a reviewed integration of this cancellation work rebased onto current main with your co-author credit preserved. Root causes fixed: cancellation arriving before mailbox waiter registration, unowned timeout tasks, and cursor reconciliation retrying CancellationError. Live signed macOS capture proof: cancellation went from 5.007s on main to 0.17ms, stopping cleanly with zero consumers. Thanks @SebTardif! |
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
CancellationErroras a normal failure and slept withtry?, so cancel became another backoff retry. The video mailbox spawned an unstructured timeout task that usedtry?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.sleepnow usestry awaitso 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:
After the patch the same waiter returns immediately:
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:
Evidence after fix: terminal output from the patched tree:
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).