Repository navigation
Fix camera/screen capture consent hang for unattended MCP callers - #1300
Conversation
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]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 4:10 PM ET / 20:10 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible 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 Review scores
Verification
How this fits togetherLocal 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
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…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]>
Summary
Fixes a current-
mainregression (introduced by 31a8c65 / 16cb689) wherescreen.snapshot,camera.snap, andlocation.getgate 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 brokeMcpHttpServerIntegrationTests.CameraSnap_ReturnsImageOrWellFormedErrorandScreenSnapshot_ReturnsImageOrWellFormedError(both only "recovered" when the test's own 30sHttpClient.Timeoutfired, 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→ShowCaptureConsentDialogAsynccreates the dialog and awaits itsTask<bool>, which only completes via the dialog'sClosedevent (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
SettingsData.CaptureConsentTimeoutMs(default120_000ms / 2 minutes), a real product-level configurable safety knob, mirrored inSettingsManager.ConsentPromptTimeoutGate.WithTimeout(promptTask, timeout, onTimedOut)— a small pure/testable helper that races the dialog task againstTask.Delay(timeout)and fail-closes tofalseon timeout, invokingonTimedOutto force-close the now-pointless dialog window exactly once.NodeService.EnsureCaptureConsentAsyncnow binds this timeout to the prompt itself (not to any single caller'sCancellationToken), 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.ShowCaptureConsentDialogAsyncgained acloseDialogcallback (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()setsCaptureConsentTimeoutMs = 3000(3s) so integration tests get fast, deterministic denials — this is a real settings knob, not a test/client timeout increase.ConsentPromptTimeoutGateTests.cscover: 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 scenarioNodeService's abandoned-prompt path relies on.ConsentAndSettingsSaveTests.csgained 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 realRecordingConsentDialogwindow directly — see Real behavior proof below.Not verified / blocked: no maintainer-scheduled pool run was requested/available in this session.Validation
Real behavior proof
Current-head, isolated tray data dir (
OPENCLAW_TRAY_DATA_DIRset 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:Same shape for
camera.snap("Snap failed",isError: true, bounded elapsed time).winnode --list-toolsconfirms bothcamera.snapandscreen.snapshotremain correctly advertised.Interactive UI consent preserved — computer-use proof: with
CaptureConsentTimeoutMs=25000, invokedcamera.snapviawinnodeand used computer-use automation to click Allow on the real, on-screenRecordingConsentDialogwindow ("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, andCameraRecordingConsentGivenflipped totrueand persisted tosettings.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:
ObserveAbandonedConsentPromptwas 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'sCancellationToken, 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 totrue/granted.Not merging this myself — flagging as ready for maintainer review/merge.