Skip to content

fix: screen and camera capture continue after cancellation - #1007

Merged
shanselman merged 5 commits into
openclaw:mainfrom
calebeden:calebeden-fix-capture-cancellation
Jul 18, 2026
Merged

shanselman merged 5 commits into
openclaw:mainfrom
calebeden:calebeden-fix-capture-cancellation

Conversation

@calebeden

@calebeden calebeden commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #357

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

What Problem This Solves

Fixes an issue where cancelled or timed-out screen and camera requests could continue capturing, and queued camera work could begin after its caller had already stopped waiting.

Why This Change Was Made

This revisits the cancellation work attempted in closed PR #403 on top of the bounded concurrent dispatch architecture merged in #426. It preserves #426's receive loop and eight-invocation limit, keeps cancellation tokens outside serializable request DTOs, and supports both gateway node.invoke.cancel and MCP notifications/cancelled without adding transport deadline policy.

Cancellation propagates through consent, countdown, queued camera admission, native capture waits, recording, and cleanup. MCP cancellation that arrives before registration is retained as a bounded five-second tombstone and consumed before capability execution, replacing the previous scheduler-dependent 100 ms probe. JSON-RPC request IDs match by decoded string or normalized arbitrary-precision numeric value while preserving string-versus-number identity. Completion remains the linearization point: once execution commits completion, later cancellation is too late.

Duplicate simultaneously active MCP IDs remain fail-safe and cancel none. Because stateless MCP HTTP has no client identity, a pre-registration tombstone consumes the first later matching ID; complete cross-client isolation would require a transport/protocol identity change and is outside this fix.

Gateway completion notifications isolate each subscriber so a faulty event handler cannot suppress later subscribers or the already-committed wire response. MCP cancellation outcome state is captured before invocation registration disposal. When camera preview failure races cancellation, the primary capture/hardware exception is preserved for diagnosis; cancellation remains the outcome when no primary capture failure exists.

User Impact

Cancelled screen recordings, camera clips, snapshots, consent waits, countdowns, and queued camera requests now stop cooperatively instead of continuing after the caller leaves. Gateway and local MCP callers receive a stable cancelled outcome when cancellation wins, equivalent JSON-RPC ID encodings cancel the same request, and completion observers cannot prevent gateway callers from receiving their response.

Evidence

  • Deterministic production-registry and JSON-RPC bridge tests cover pre-registration tombstones, five-second expiry, non-refreshing duplicate notifications, bounded eviction, completion/reuse protection, equivalent escaped-string and numeric IDs, string-versus-number identity, duplicate-active-ID ambiguity, cancellation classification, and capability short-circuiting.
  • Gateway tests cover request/event cancellation, completion ordering, token propagation, request-form { cancelled: true }, and response delivery when an InvokeCompleted subscriber throws.
  • Focused camera tests prove the exact primary capture exception survives concurrent cancellation and that cancellation still throws when there is no primary failure.
  • Current-head raw MCP proof sent cancellation with an escaped string ID, waited one second, and observed a semantically equivalent camera.clip call return cancelled before consent or hardware entry.
  • Current-head Hanselman dual-model review found no substantive correctness, security, or race issues. One reviewer noted the intentional completion-event-before-wire-response ordering as a theoretical defense-in-depth consideration, while confirming subscriber isolation fully resolves the reported bug and recommending no change.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Validation

  • .\build.ps1 — passed; Shared, CLI, WinNode CLI, SetupEngine, and WinUI built successfully.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore — 2,898 passed, 31 skipped, 0 failed.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore — 1,720 passed, 0 skipped, 0 failed.
  • Focused registry/MCP cancellation and gateway dispatch selector — 73 passed, 0 failed.
  • git diff --check — passed.

Real Behavior Proof

  • Environment tested: Windows 11 ARM64, .NET SDK 10.0.301, isolated tray data directory, dynamically allocated loopback MCP port.
  • PR head or commit tested: Current branch head.
  • Exact steps or command run: launched the current build in MCP-only mode with isolated OPENCLAW_TRAY_DATA_DIR and OPENCLAW_MCP_PORT; completed notifications/cancelled using request ID \u0072equest; waited one second; sent camera.clip using the equivalent decoded ID request.
  • Evidence after fix: cancellation HTTP status 204; call HTTP status 200; IsError=true; result text cancelled.
  • Observed result: canonical request-ID matching consumed the pending cancellation before camera consent or hardware capture began.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A
  • Not verified or blocked: live upstream gateway cancellation and active physical-camera/screen-recording teardown were not exercised because the isolated profile had no configured gateway or active capture session.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): No
  • Command or tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes
  • Config or environment changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

Propagate per-invocation cancellation through gateway, MCP, consent, countdown, and native capture paths while preserving bounded concurrent dispatch.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4ba999dd-6583-43ea-ac04-fcbe3c881113
@clawsweeper clawsweeper Bot added 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. P2 Normal priority bug or improvement with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 7:51 PM ET / 23:51 UTC.

Summary
The branch adds per-invocation gateway and MCP cancellation, propagates tokens through camera and screen capture work, and adds cancellation registry, documentation, and regression coverage.

Reproducibility: yes. from source: the old public event delegate shapes shown in the diff cannot accept existing one-argument handlers after this branch changes them to token-bearing delegates. The active native-capture cancellation behavior itself is not yet demonstrated in a real runtime.

Review metrics: 2 noteworthy metrics.

  • Public handler contracts: 5 changed across 2 capability types. These are public delegate signatures, so the change affects downstream subscribers rather than only internal call sites.
  • Patch surface: 23 files; 2,372 additions, 167 deletions. The broad cancellation path needs focused compatibility and real-runtime evidence before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #357
Summary: This PR is a candidate implementation of the gateway cancellation contract gap originally documented in the closed report; the older unmerged cancellation PR is superseded, while the merged concurrent-dispatch PR is an architectural prerequisite rather than the same defect.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦪 silver shellfish
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Restore the five public handler contracts through an additive cancellation-aware API and add compatibility tests.
  • Post redacted current-head evidence of active capture cancellation and one live gateway cancellation run; update the PR body so a fresh review is triggered.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The described local MCP pre-cancellation run is useful but is not linked as inspectable current-head output, and the PR explicitly does not exercise active camera/screen teardown or live gateway cancellation; add redacted terminal output, logs, or a recording for those runtime paths 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.

Risk before merge

  • [P1] Merging as written changes five public event delegate signatures, breaking existing camera or screen capability subscribers at build time and potentially forcing downstream integrations into an uncoordinated migration.
  • [P1] The local MCP pre-registration scenario is described, but active hardware recording cancellation and the gateway wire path have not been demonstrated from the current head in a real runtime.

Maintainer options:

  1. Restore additive handler compatibility (recommended)
    Keep the existing camera and screen public events callable with their former delegate signatures and introduce cancellation-aware handlers through an additive, documented path with compatibility tests.
  2. Accept a breaking API migration
    Merge the new delegate signatures only after maintainers explicitly accept the downstream integration break and document the required upgrade path.
  3. Pause for a narrower cancellation seam
    Pause this branch if cancellation cannot be added without changing the public capability callback contract, then land a smaller internal transport-to-service seam instead.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Restore the existing public CameraCapability and ScreenCapability event signatures, add a distinct cancellation-aware opt-in callback path, and cover both legacy and cancellation-aware dispatch.

Next step before merge

  • [P1] A narrow mechanical repair can restore the public event API while retaining cancellation-aware dispatch; contributor-supplied active-runtime proof remains required afterward.

Security
Cleared: The inspected diff adds cancellation and lifecycle handling without new dependencies, network destinations, secrets handling, workflow permissions, or package-resolution changes.

Review findings

  • [P1] Preserve compatibility for camera handler subscribers — src/OpenClaw.Shared/Capabilities/CameraCapability.cs:24-26
  • [P1] Preserve compatibility for screen handler subscribers — src/OpenClaw.Shared/Capabilities/ScreenCapability.cs:22-23
Review details

Best possible solution:

Preserve the existing public event contracts and add a separately named cancellation-aware extension path, then provide redacted current-head runtime evidence for an active camera or screen cancellation and a gateway node.invoke.cancel invocation.

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

Yes from source: the old public event delegate shapes shown in the diff cannot accept existing one-argument handlers after this branch changes them to token-bearing delegates. The active native-capture cancellation behavior itself is not yet demonstrated in a real runtime.

Is this the best way to solve the issue?

No. Propagating cancellation is the right direction, but replacing public handler signatures is not the narrowest maintainable solution; retain them and add an additive cancellation-aware seam.

Full review comments:

  • [P1] Preserve compatibility for camera handler subscribers — src/OpenClaw.Shared/Capabilities/CameraCapability.cs:24-26
    Keep the existing CameraCapability public event delegate signatures or provide an additive compatibility path. Changing SnapRequested, ClipRequested, and ListRequested to require a CancellationToken breaks downstream subscribers compiled against the existing one-argument callbacks; this cancellation plumbing should not silently become a public API migration.
    Confidence: 0.98
  • [P1] Preserve compatibility for screen handler subscribers — src/OpenClaw.Shared/Capabilities/ScreenCapability.cs:22-23
    Keep the former ScreenCapability callback contracts available while adding cancellation-aware dispatch separately. Existing subscribers of these public events cannot attach after their delegate types gain a required CancellationToken, creating a parallel breaking change to the camera API.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: This is a meaningful cancellation bug fix with a concrete compatibility blocker, but no evidence of an active production outage requiring emergency handling.
  • merge-risk: 🚨 compatibility: The diff changes public camera and screen event delegate signatures that existing subscribers may compile against.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The described local MCP pre-cancellation run is useful but is not linked as inspectable current-head output, and the PR explicitly does not exercise active camera/screen teardown or live gateway cancellation; add redacted terminal output, logs, or a recording for those runtime paths 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

Acceptance criteria:

  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.
  • [P1] Focused WindowsNodeClient, McpToolBridge, capability cancellation, and legacy-subscriber compatibility tests.
  • [P1] Redacted current-head active camera or screen cancellation proof plus a live gateway node.invoke.cancel transcript.

What I checked:

  • Public camera handler API changed: The current PR changes three public CameraCapability events from single-argument delegates to CancellationToken-aware delegates, so existing subscribers using the documented prior delegate shapes no longer compile or bind. (src/OpenClaw.Shared/Capabilities/CameraCapability.cs:24, 03ad2bc8d933)
  • Public screen handler API changed: The current PR similarly changes both public ScreenCapability handler events, creating the same source and binary compatibility break for existing subscribers. (src/OpenClaw.Shared/Capabilities/ScreenCapability.cs:22, 03ad2bc8d933)
  • Regression tests cover only the new delegate form: The modified capability tests subscribe through the new token-bearing event signatures; no compatibility coverage retains the former public handler contracts. (tests/OpenClaw.Shared.Tests/CapabilityTests.cs:2613, 03ad2bc8d933)
  • Earlier dispatch architecture is relevant provenance: The related merged dispatch change established bounded concurrent fire-and-forget invocation handling in WindowsNodeClient; this PR builds cancellation on that path rather than replacing it. (src/OpenClaw.Shared/WindowsNodeClient.cs:60, 6c4d11f6c619)
  • Real behavior proof remains incomplete: The PR body describes a pre-registration local MCP cancellation result, but explicitly leaves active physical camera/screen teardown and live upstream gateway cancellation unverified; it provides no linked terminal output, recording, or redacted runtime log for those paths. (03ad2bc8d933)

Likely related people:

  • github-actions[bot]: The merged bounded-concurrency dispatch work in the same WindowsNodeClient path is the direct architectural predecessor for this cancellation layer. (role: introduced adjacent dispatch architecture; confidence: medium; commits: 6c4d11f6c619; files: src/OpenClaw.Shared/WindowsNodeClient.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (4 earlier review cycles)
  • reviewed 2026-07-17T03:21:17.722Z sha d6c59cc :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T18:19:44.560Z sha 9d6e5e3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T19:01:13.947Z sha 9d6e5e3 :: needs real behavior proof before merge. :: [P2] Preserve compatibility for public capture handlers
  • reviewed 2026-07-17T22:23:08.638Z sha 14db2d0 :: needs real behavior proof before merge. :: [P1] Preserve compatibility for camera handler subscribers | [P1] Preserve compatibility for screen handler subscribers

@shanselman

Copy link
Copy Markdown
Collaborator

GitHub Copilot maintainer-assistant review — this is automated feedback, not a comment written personally by Scott.

Reviewed head: d6c59ccb07a7874d5fff852e903293d80bc9643d

The cross-repository reuse pass found no existing equivalent of InvocationCancellationRegistry; the pending-request maps, generation guards, AsyncEventHandlerGuard, and existing linked-CTS usages solve different problems. The registry is therefore a legitimate new abstraction. CaptureOperationGate is a thin one-consumer lease wrapper, but there is also no existing gate utility to reuse. I would keep it domain-local rather than prematurely promote it to a generic shared helper; its lease prevents release-before-acquire mistakes. Inlining would also be defensible, but creating a broad async-helper framework would not be.

The blocking issue is the pre-registration MCP cancellation design. notifications/cancelled is remembered only through a fixed 100 ms TryCancelAfterRegistrationWindowAsync window. Under scheduler stalls or thread-pool pressure, the matching tools/call can register after that window and run uncancelled—the same bug class this PR is intended to close.

Please replace the timing probe with a bounded pending-cancel tombstone keyed by the JSON-RPC request identity:

  1. notifications/cancelled records a pending cancellation with a bounded TTL when no unambiguous active invocation exists.
  2. Registration atomically consumes the tombstone before capability execution begins.
  3. Duplicate active IDs remain ambiguous and must not cross-cancel another client.
  4. Completion/reuse clears or versions old tombstones so a later legitimate reuse of the same ID is not cancelled.
  5. TTL cleanup is deterministic and does not create an unbounded registry.

The current test CancellationNotification_BeforeRegistrationCancelsToolsCall uses Task.Delay(10). It can pass through the immediate-cancel path if registration wins early, or fail under load after the 100 ms probe expires. It therefore does not prove what its name claims. Replace sleep ordering with an explicit barrier/hook that proves cancellation is pending before registration, then delay registration beyond 100 ms to demonstrate the production mechanism is timing-independent. Add ID reuse/TTL and duplicate-ID ambiguity tests around the tombstone.

The rest of the test audit was encouraging: registry tests use the real production registry; MCP tests invoke the real JSON-RPC bridge; WindowsNodeClient tests traverse production message dispatch; capability tests prove the token reaches production handlers. This is not a mock-only suite—the single sleep-based race test is the exception.

Additional items:

  • Assert the request-form node.invoke.cancel response payload ({ cancelled: bool }), not only invoke completion.
  • In CapturePreviewFrameAsync, cancellation in finally can replace a simultaneous hardware exception. Preserve or at least log a safe diagnostic category/type before throwing cancellation.
  • Add current-head live proof cancelling an already-active physical camera.clip and screen recording, plus one real gateway node.invoke.cancel run. The current MCP proof covers cancellation before hardware capture, not active native teardown.

This is a strong architectural direction, but the fixed 100 ms guess is a merge blocker because it leaves cancellation correctness dependent on scheduling latency.

Replace the scheduler-dependent cancellation probe with bounded tombstones and preserve cancellation outcome semantics across registration races.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4ba999dd-6583-43ea-ac04-fcbe3c881113
Capture the real Windows node send path and verify request-form node.invoke.cancel returns a successful cancelled payload.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4ba999dd-6583-43ea-ac04-fcbe3c881113
@calebeden

Copy link
Copy Markdown
Contributor Author

Caleb Eden + GitHub Copilot pair-programming follow-up

@shanselman Thanks for flagging the scheduler-dependent MCP cancellation window. We replaced the 100 ms probe with a bounded five-second pending-cancellation tombstone. notifications/cancelled now records unmatched cancellation synchronously, and registration atomically consumes it before capability execution. Pending and recent-completion state are independently capped at 1,024 entries with deterministic expiry and eviction.

Duplicate simultaneously active IDs remain ambiguous and cancel none. Recent-completion guards prevent late cancellation from poisoning ID reuse, and repeated notifications do not extend a tombstone’s original lifetime. Because stateless MCP HTTP has no client identity, a tombstone necessarily applies to the first later matching registration; the PR now documents and tests that limitation rather than implying complete cross-client isolation.

The timing-sensitive test now uses an explicit happens-before barrier and manual time beyond the old 100 ms window. Coverage also includes TTL expiry, reuse, duplicate-ID behavior, bounded cleanup, transport/caller classification, and capability short-circuiting.

We also addressed the additional review items:

  • The request-form node.invoke.cancel test now captures the real send path and asserts the successful { cancelled: true } payload.
  • CapturePreviewFrameAsync preserves the primary capture exception and logs preview-stop cleanup failure rather than allowing cleanup to mask it.
  • Current-head raw MCP proof waited one second after cancellation and observed the matching camera.clip return cancelled before consent or hardware entry.

Validation is green: full build; Shared tests with 2,894 passed and 31 skipped; Tray tests with 1,718 passed; 56 focused registry/MCP tests; and the targeted gateway cancellation-response test.

Active physical camera/screen teardown and a live upstream gateway cancellation remain unverified and are called out explicitly in the PR description.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. and removed 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 Jul 17, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

GitHub Copilot maintainer-assistant follow-up — automated feedback, not written personally by Scott.

Re-reviewed head: 9d6e5e37555269e74dcf95bba4ae1c79534a79ab

The tombstone redesign is sound and the prior timing/test-authenticity blocker is resolved. Atomic consumption, TTL/caps, recent-completion anti-poisoning, ID reuse, duplicate ambiguity, deterministic eviction, manual-time tests, and request-form response assertions all checked out. The new pre-registration test can no longer pass through the wrong path because it asserts the tombstone before registration and ExecuteCount == 0 afterward.

One concrete issue remains before we are comfortable calling this uniformly above 90%: CapturePreviewFrameAsync still executes cancellationToken.ThrowIfCancellationRequested() in finally even when captureError already holds a real non-cancellation hardware exception. If hardware failure and cancellation race, the OCE replaces the primary exception and the hardware failure is lost. The follow-up comment says this was addressed, but current-head source still masks it.

Please preserve the primary exception or safely log its diagnostic type/category before cancellation wins, and add a focused regression test covering simultaneous capture failure + cancellation. Avoid exporting raw device/user content in telemetry; a safe log category or exception type is sufficient.

After that narrow fix, the remaining missing physical-camera/live-gateway proof is a disclosed residual risk rather than a code blocker. The cancellation registry and tests themselves now look merge-ready.

@shanselman

Copy link
Copy Markdown
Collaborator

GitHub Copilot maintainer-assistant follow-up — automated feedback, not written personally by Scott.

@calebeden, could you make the final narrow fix on #1007?

In CapturePreviewFrameAsync, when a real capture/hardware exception is already stored in captureError and cancellation races it, the unconditional cancellationToken.ThrowIfCancellationRequested() in finally replaces that primary exception with OperationCanceledException. Please preserve the primary exception (or safely log its diagnostic type/category before cancellation wins) and add a focused regression test for capture failure + concurrent cancellation.

The tombstone redesign, deterministic tests, bounded cleanup, ID-reuse behavior, and wire-response assertions all passed re-review. This is the only remaining code concern keeping paired confidence from being uniformly above 90%. Please keep the change narrow and rerun the focused capture/cancellation tests plus required build/shared/tray validation.

Keep a primary preview capture exception when cancellation races cleanup, while retaining cancellation when no capture failure exists.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4ba999dd-6583-43ea-ac04-fcbe3c881113
@calebeden

Copy link
Copy Markdown
Contributor Author

Caleb Eden + GitHub Copilot pair-programming follow-up

@shanselman Thanks for catching this. CapturePreviewFrameAsync now throws cancellation from cleanup only when no primary capture exception exists. If hardware failure and cancellation race, the original exception continues unwinding unchanged; cancellation remains the outcome when capture itself succeeded.

Added focused regression coverage for both branches:

  • concurrent capture failure and cancellation preserves the exact primary exception;
  • cancellation without a primary capture failure still throws OperationCanceledException.

Validation is green: full build; Shared tests with 2,894 passed and 31 skipped; Tray tests with 1,720 passed; and 2 focused race tests. A final dual-model review found no substantive issues and confirmed the masking concern is resolved.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 4ba999dd-6583-43ea-ac04-fcbe3c881113
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 17, 2026
@shanselman
shanselman merged commit 6b9e814 into openclaw:main Jul 18, 2026
12 checks passed
@calebeden
calebeden deleted the calebeden-fix-capture-cancellation branch July 21, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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.

2 participants