Skip to content

Fix camera/screen capture consent hang for unattended MCP callers - #1300

Merged
shanselman merged 1 commit into
mainfrom
shanselman-fix-capture-consent-mcp-hang
Sep 2, 2026
Merged

shanselman merged 1 commit into
mainfrom
shanselman-fix-capture-consent-mcp-hang

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

Summary

Fixes a current-main regression (introduced by 31a8c65 / 16cb689) where screen.snapshot, camera.snap, and location.get gate on an interactive consent dialog (RecordingConsentDialog, a real top-level WinUI window) with no timeout anywhere in the wait path. Any unattended caller — a local MCP HTTP client, an automated agent, a hosted CI test — hangs forever waiting for a human who will never click Allow/Deny. This broke McpHttpServerIntegrationTests.CameraSnap_ReturnsImageOrWellFormedError and ScreenSnapshot_ReturnsImageOrWellFormedError (both only "recovered" when the test's own 30s HttpClient.Timeout fired, since the MCP server's own request timeout is 6 minutes) and is currently blocking #1282, #1294, #1295, #1296.

Security invariant preserved: consent is never bypassed or auto-granted. A timeout always resolves to a fail-closed denial, never a grant. Interactive UI consent (Allow/Deny, persistence) is completely unchanged for a real user who responds in time.

Root cause

NodeService.EnsureCaptureConsentAsync → ShowCaptureConsentDialogAsync creates the dialog and awaits its Task<bool>, which only completes via the dialog's Closed event (i.e. a human click). There was no bound on that wait. Raising the MCP request timeout or the test/client timeout would not be a real fix (explicitly out of scope) — the dialog itself needed a bounded, fail-closed wait.

Fix

  • Added SettingsData.CaptureConsentTimeoutMs (default 120_000ms / 2 minutes), a real product-level configurable safety knob, mirrored in SettingsManager.
  • Added ConsentPromptTimeoutGate.WithTimeout(promptTask, timeout, onTimedOut) — a small pure/testable helper that races the dialog task against Task.Delay(timeout) and fail-closes to false on timeout, invoking onTimedOut to force-close the now-pointless dialog window exactly once.
  • NodeService.EnsureCaptureConsentAsync now binds this timeout to the prompt itself (not to any single caller's CancellationToken), then layers .WaitAsync(cancellationToken) on top so an owning caller can still stop waiting on its own cancellation without tearing down the shared timeout that other concurrent callers of the same consent type (_screen/_camera/_locationConsentInFlight) may still depend on for a bounded result.
  • ShowCaptureConsentDialogAsync gained a closeDialog callback (handles the race where the timeout fires before the dialog window even exists) and now rechecks whether a timeout already fired before persisting a "late" Allow click that raced the force-close, keeping settings state consistent with the outcome already returned to the timed-out caller.
  • TrayAppFixture.WriteSettings() sets CaptureConsentTimeoutMs = 3000 (3s) so integration tests get fast, deterministic denials — this is a real settings knob, not a test/client timeout increase.
  • New regression tests in ConsentPromptTimeoutGateTests.cs cover: fail-closed timeout + callback invocation, pass-through grant/deny when answered before timeout, and (added after rubber-duck review flagged a real bug) that the bounded task still fail-closes for other waiters even after the owning caller's own wait is cancelled — the exact shared in-flight-prompt scenario NodeService's abandoned-prompt path relies on.
  • ConsentAndSettingsSaveTests.cs gained a settings default/persistence test for the new field.

Required proof pools

  • windows-winui-interactive: the capture-consent approval dialog's timeout/close behavior changed. Not run as a scheduled pool (no scheduler invoked in this session); substituted with local computer-use proof against the isolated WinUI app driving the real RecordingConsentDialog window directly — see Real behavior proof below. Not verified / blocked: no maintainer-scheduled pool run was requested/available in this session.

Validation

.\build.ps1
  → Cli, SetupEngine, WinUI, Shared, WinNodeCli — all 5 projects succeeded.

dotnet test tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore
  → Passed: 3873, Failed: 0, Skipped: 32 (environmental Mxc integration tests
    requiring host MXC capability), Total: 3905.

dotnet test tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore
  → Passed: 2829, Failed: 0, Skipped: 0, Total: 2829
    (includes the 4 new ConsentPromptTimeoutGate tests + 1 new settings test).

OPENCLAW_RUN_INTEGRATION=1 dotnet test tests\OpenClaw.Tray.IntegrationTests\OpenClaw.Tray.IntegrationTests.csproj
  → Passed: 22, Failed: 0, Skipped: 0, Total: 22.
    CameraSnap_ReturnsImageOrWellFormedError: passed in ~3s (was: hung to the
    30s HttpClient.Timeout).
    ScreenSnapshot_ReturnsImageOrWellFormedError: passed in ~3s (was: hung to
    the 30s HttpClient.Timeout).

Real behavior proof

Current-head, isolated tray data dir (OPENCLAW_TRAY_DATA_DIR set to a temp dir, never touching %APPDATA%\OpenClawTray), local MCP server enabled.

Raw MCP JSON-RPC tools/call — unattended (nobody answers), fail-closed denial, not a hang:

// POST http://127.0.0.1:8765/  {"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"screen.snapshot","arguments":{}}}
// CaptureConsentTimeoutMs=5000 for this proof run; elapsed ~5.0s (was: unbounded hang)
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [ { "type": "text", "text": "Capture failed" } ],
    "isError": true
  }
}

Same shape for camera.snap ("Snap failed", isError: true, bounded elapsed time). winnode --list-tools confirms both camera.snap and screen.snapshot remain correctly advertised.

Interactive UI consent preserved — computer-use proof: with CaptureConsentTimeoutMs=25000, invoked camera.snap via winnode and used computer-use automation to click Allow on the real, on-screen RecordingConsentDialog window ("Allow camera capture?", Deny/Allow buttons) before the timeout elapsed. Confirmed via the accessibility tree that the dialog rendered with the expected copy, the click was processed, and CameraRecordingConsentGiven flipped to true and persisted to settings.json — proving the grant + persistence path is completely unchanged by this fix.

Rubber-duck review

Ran a rubber-duck review before this PR. It found one real, fixed-here bug: ObserveAbandonedConsentPrompt was awaiting the raw (unbounded) dialog task when the owning caller canceled, so a second concurrent caller sharing the same in-flight consent prompt could hang indefinitely even though the owning caller's own wait was correctly bounded. Fixed by decoupling the timeout (ConsentPromptTimeoutGate.WithTimeout) from any single caller's CancellationToken, and added a regression test for it. A secondary non-blocking finding (a late Allow click racing the force-close could persist a stale grant after a request was already denied) was also fixed by rechecking the timeout state before persisting settings. No path was found that lets a timeout resolve to true/granted.

Not merging this myself — flagging as ready for maintainer review/merge.

Root cause: after 31a8c65/16cb6897 gated screen.snapshot/camera.snap/
location.get behind interactive consent, NodeService.EnsureCaptureConsentAsync
awaited the RecordingConsentDialog's Task<bool> with no timeout anywhere. An
unattended caller (local MCP HTTP client, automated agent, hosted CI) hung
forever waiting for a human who would never appear, only "recovering" when
the caller's own HttpClient.Timeout (30s in the failing integration tests)
fired. This broke McpHttpServerIntegrationTests.CameraSnap_ReturnsImageOr-
WellFormedError and ScreenSnapshot_ReturnsImageOrWellFormedError, blocking
PRs #1282, #1294, #1295, #1296.

Fix: add a fail-closed, configurable consent-prompt timeout
(SettingsData.CaptureConsentTimeoutMs, default 120s) enforced by a new pure
ConsentPromptTimeoutGate helper. On timeout the prompt is denied (never
granted) and the dangling dialog window is force-closed. The bounded task is
independent of any single caller's CancellationToken so the shared in-flight
prompt (_screen/_camera/_locationConsentInFlight) still resolves for any
other concurrent waiter even if the owning caller cancels first. A late
Allow click that races the timeout no longer persists a stale grant after
the request has already been denied. Interactive UI consent (Allow/Deny,
persistence) is unchanged.

- Never bypasses or auto-grants consent: timeout always resolves to denied.
- TrayAppFixture sets CaptureConsentTimeoutMs=3000 for deterministic CI,
  not a test/client timeout change - this is a real product settings knob.
- New unit tests cover fail-closed timeout, pass-through grant/deny, and the
  shared-prompt-survives-caller-cancellation case a rubber-duck review found.

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

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 2, 2026
@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. 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 Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 4:10 PM ET / 20:10 UTC.

ClawSweeper review

What this changes

The PR adds a configurable, prompt-scoped timeout that closes unanswered screen, camera, or location consent dialogs and returns denial instead of leaving MCP capture calls indefinitely pending.

Regression provenance

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

Merge readiness

✅ Ready for maintainer review

Keep open. This focused fix bounds unattended capture-consent waits while retaining fail-closed denial and the interactive approval path; no introduced correctness or security defect was found.

Priority: P1
Reviewed head: cf1b651149fa36ed296f394e6a5f64f9cb847757

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused bug fix with direct current-head MCP and interactive-consent evidence plus targeted regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.
Evidence reviewed 5 items Introduced timeout behavior: The introduced NodeService change wraps the consent dialog task in a prompt-scoped timeout, returns false on expiry, and observes that bounded task after caller cancellation so concurrent waiters are not left on the original unbounded dialog task.
Fail-closed prompt helper: The new helper races only the shared prompt against its timeout, invokes the close callback on expiry, and returns false rather than granting consent.
Current-main regression context: The current-main security change introduced persisted consent for sensitive screen, camera, and location operations; the PR's bounded wait addresses the missing termination condition without removing that consent boundary.
Findings None None.
Security None None.

How this fits together

Local MCP capture commands enter the Windows tray node, which shares one consent prompt per capture type before invoking the device capture service. The result either authorizes the requested capture after a timely human decision or returns a tool error without performing capture.

flowchart LR
  A[Local MCP caller] --> B[Capture command]
  B --> C[Shared consent prompt]
  C --> D{Response before timeout?}
  D -->|Yes| E[Allow capture or deny]
  D -->|No| F[Close dialog and deny]
  E --> G[Capture result to caller]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +149, tests and fixture +138 The implementation is paired with focused helper, persistence, and isolated MCP integration coverage.

Technical review

Best possible solution:

Land the prompt-scoped fail-closed timeout with its shared-waiter behavior intact, preserving timely interactive approval and the existing MCP capture contract.

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

Yes, source-reproducible with high confidence: current main creates a shared consent task that completes only when the dialog closes, and the existing isolated MCP integration tests invoke the affected screen and camera commands. This review did not execute the Windows runtime.

Is this the best way to solve the issue?

Yes. Binding the deadline to the shared consent prompt, rather than extending a caller timeout, preserves denial-by-default and avoids cancellation of the shared result needed by concurrent callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 16cb6897941f.

Labels

Label changes:

  • add P1: The underlying regression leaves sensitive local MCP capture requests waiting until an unrelated client timeout instead of returning a bounded denial.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.

Label justifications:

  • P1: The underlying regression leaves sensitive local MCP capture requests waiting until an unrelated client timeout instead of returning a bounded denial.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the tray node's shared capture-consent path; the PR records current-head raw MCP invocation yielding a bounded fail-closed error and an isolated real WinUI approval that persists timely consent.

Evidence

What I checked:

  • Introduced timeout behavior: The introduced NodeService change wraps the consent dialog task in a prompt-scoped timeout, returns false on expiry, and observes that bounded task after caller cancellation so concurrent waiters are not left on the original unbounded dialog task. (src/OpenClaw.Tray.WinUI/Services/NodeService.cs:2317, cf1b651149fa)
  • Fail-closed prompt helper: The new helper races only the shared prompt against its timeout, invokes the close callback on expiry, and returns false rather than granting consent. (src/OpenClaw.Tray.WinUI/Services/ConsentPromptTimeoutGate.cs:27, cf1b651149fa)
  • Current-main regression context: The current-main security change introduced persisted consent for sensitive screen, camera, and location operations; the PR's bounded wait addresses the missing termination condition without removing that consent boundary. (src/OpenClaw.Tray.WinUI/Services/NodeService.cs:2276, 16cb6897941f)
  • Regression coverage and MCP integration fixture: The branch adds timeout, timely grant/denial, and abandoned-waiter tests, and configures the isolated tray integration fixture for a three-second denial so existing screen and camera MCP tests complete inside their client deadline. (tests/OpenClaw.Tray.Tests/Services/ConsentPromptTimeoutGateTests.cs:18, cf1b651149fa)
  • Current-head behavior proof: The complete PR body records a current-head raw MCP screen.snapshot call that returns a well-formed error after the configured five-second timeout, plus an interactive camera approval that persisted consent before timeout. (cf1b651149fa)

Likely related people:

  • Scott Hanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Cameron Beeley: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@shanselman
shanselman merged commit 297b6c8 into main Sep 2, 2026
30 of 33 checks passed
@shanselman
shanselman deleted the shanselman-fix-capture-consent-mcp-hang branch September 2, 2026 20:42
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 2, 2026
larroy pushed a commit to larroy/openclaw-windows-node that referenced this pull request Sep 3, 2026
…enclaw#1300)

Root cause: after 31a8c65/16cb6897 gated screen.snapshot/camera.snap/
location.get behind interactive consent, NodeService.EnsureCaptureConsentAsync
awaited the RecordingConsentDialog's Task<bool> with no timeout anywhere. An
unattended caller (local MCP HTTP client, automated agent, hosted CI) hung
forever waiting for a human who would never appear, only "recovering" when
the caller's own HttpClient.Timeout (30s in the failing integration tests)
fired. This broke McpHttpServerIntegrationTests.CameraSnap_ReturnsImageOr-
WellFormedError and ScreenSnapshot_ReturnsImageOrWellFormedError, blocking
PRs openclaw#1282, openclaw#1294, openclaw#1295, openclaw#1296.

Fix: add a fail-closed, configurable consent-prompt timeout
(SettingsData.CaptureConsentTimeoutMs, default 120s) enforced by a new pure
ConsentPromptTimeoutGate helper. On timeout the prompt is denied (never
granted) and the dangling dialog window is force-closed. The bounded task is
independent of any single caller's CancellationToken so the shared in-flight
prompt (_screen/_camera/_locationConsentInFlight) still resolves for any
other concurrent waiter even if the owning caller cancels first. A late
Allow click that races the timeout no longer persists a stale grant after
the request has already been denied. Interactive UI consent (Allow/Deny,
persistence) is unchanged.

- Never bypasses or auto-grants consent: timeout always resolves to denied.
- TrayAppFixture sets CaptureConsentTimeoutMs=3000 for deterministic CI,
  not a test/client timeout change - this is a real product settings knob.
- New unit tests cover fail-closed timeout, pass-through grant/deny, and the
  shared-prompt-survives-caller-cancellation case a rubber-duck review found.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Urgent regression or broken agent/channel workflow affecting real users now. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant