Skip to content

Fix Windows focus stealing from agent foreground-process scan (hide conhost window) - #8053

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
Cainiaooo:fix/win-foreground-scan-windowshide
Jul 13, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
Cainiaooo:fix/win-foreground-scan-windowshide

Conversation

@Cainiaooo

@Cainiaooo Cainiaooo commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Windows, Orca steals keyboard focus from whatever window the user is typing in while an agent session is open — the caret silently drops out of the focused input (the mouse pointer does not move), so keystrokes are lost until the user clicks back in. It happens to any foreground app (editors, browsers, chat, other terminals) and even to Orca's own terminal panes.

Severity — high impact. In practice the focus is stolen roughly once every few tens of seconds for the whole time an agent is running (the underlying scan can fire more often under heavy agent output). Even at that rate it is a serious, recurring interruption: it repeatedly yanks you out of whatever you are typing, all day, for anyone who keeps Orca open while running agents. Multiple users are affected, and the disruption disappears the moment Orca is closed — so we'd really appreciate an expedited review/merge.

Root cause

Agent foreground-process inspection (windows-foreground-process-rows.ts) re-forks powershell.exe — or the wmic fallback — to detect which agent is running in each terminal. Both spawns omitted windowsHide. Electron's main process has no attached console, so Windows creates a fresh visible conhost window for each console child; it flashes for a few tens of milliseconds and vanishes, but that is long enough to grab the foreground and steal keyboard focus from the active window.

The scan runs on a per-pane poll cadence (750ms active / 2000ms), but is gated down by relaxed retry tiers (~5s after recent PTY output, ~15s when idle) and a 500ms shared-snapshot dedup, so a fresh fork/flash does not happen every second — in normal use it lands roughly once every few tens of seconds, matching the observed symptom, and more often only while an agent is streaming continuous output.

Every other Windows spawn in the codebase already sets windowsHide: true (git runner, rate-limit fetchers, account services, port scanner, …) — these two probes were the only ones missing it. Same class of bug reported against other agent tools: anthropics/claude-code#40334 and aaif-goose/goose#6701.

Note: a related Windows 11 24H2 (build 26100) TSF/MSCTFIME focus regression can cause similar symptoms independently of Orca, but the recurring theft during agent use is squarely this scan.

Fix

Add windowsHide: true to both the PowerShell and wmic process-table probes. Purely a window-visibility flag — args, stdout capture, and parsing are unchanged; it only suppresses the console window that should never have appeared.

Screenshots

No visual change (the fix removes an unwanted flashing console window; there is no in-app UI change to screenshot).

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

Added windows-foreground-process-rows.test.ts, which drives queryWindowsProcessDescendants under a mocked child_process and asserts both the PowerShell path and the wmic fallback pass windowsHide: true (guards against a future regression re-introducing the flash).

Note: the command checkboxes above are left unchecked because the contributor's local checkout did not have full dev dependencies installed, so lint/typecheck/test/build were not run locally — please rely on CI to validate them. Targeted run for reviewers:

pnpm test -- src/main/providers/windows-foreground-process-rows.test.ts \
             src/main/providers/windows-agent-foreground-process-scan-volume.test.ts

AI Review Report

Reviewed with an AI coding agent; passed with no changes required. Focus areas checked:

  • Correctness: windowsHide: true is a valid ExecFileOptions field; it changes only console-window visibility, not process args, stdout capture, or the JSON/value parsing that follows. Behavior of queryWindowsProcessesWithPowerShell -> queryWindowsProcessesWithWmic fallback is unchanged.
  • Cross-platform (macOS/Linux/Windows): the touched code path is entirely win32-gated (resolveAgentForegroundProcess routes non-Windows to the POSIX ps snapshot, which is unaffected). No shortcuts, labels, or path handling are involved. windowsHide is a no-op on non-Windows platforms. No Electron main-window/focus APIs are touched.
  • Convention alignment: matches the windowsHide: true pattern used by every other Windows spawn in the repo.
  • Test quality: the new test reuses the established vi.mock('child_process') pattern from windows-agent-foreground-process-scan-volume.test.ts and asserts the exact regression surface.

Security Audit

Low risk. No new input handling, no new command execution surface, no auth/secrets/IPC/dependency changes. The powershell.exe/wmic argument vectors are untouched (still fixed, non-interpolated argv). If anything this reduces a UI-integrity risk by eliminating an unexpected foreground window that hijacks user focus. No follow-up required.

Notes

Windows-only behavior change. No config or migration needed. Users on the shipped release will pick this up in the next build; meanwhile the only workaround is closing Orca or reducing agent activity.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: daa1dd69-c62c-4970-a517-ed0856ada220

📥 Commits

Reviewing files that changed from the base of the PR and between 4b7376d and f021829.

📒 Files selected for processing (1)
  • src/main/providers/windows-foreground-process-rows.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/providers/windows-foreground-process-rows.test.ts

📝 Walkthrough

Walkthrough

Windows foreground process enumeration now passes windowsHide: true to both PowerShell and WMIC subprocess probes. A Vitest regression suite mocks execFile, forces the Windows platform, verifies the PowerShell path and WMIC fallback options, and checks the discovered process PID.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the Windows-only focus-stealing fix and conhost window suppression.
Description check ✅ Passed The description includes all required sections and covers testing, cross-platform review, security, and notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Cainiaooo
Cainiaooo force-pushed the fix/win-foreground-scan-windowshide branch from 16ab295 to 87fbc0d Compare July 10, 2026 08:20
Agent foreground-process inspection re-forks powershell.exe (or the wmic fallback) to detect which agent runs in each terminal. Both spawns omitted windowsHide, so on Windows each fork popped a fresh conhost console window that flashed and stole keyboard focus from the foreground app — including Orca's own terminal — recurring roughly once every few tens of seconds while an agent session was open (and more often under continuous agent output).

Add windowsHide: true to both probes (matching the codebase-wide convention) plus a regression test asserting the spawn options.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Cainiaooo
Cainiaooo force-pushed the fix/win-foreground-scan-windowshide branch from 87fbc0d to 4b7376d Compare July 10, 2026 12:49
@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 10, 2026 16:47

@Jinwoo-H Jinwoo-H left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down. Reviewed and validated on Windows:

  • Both PowerShell and WMIC scans now suppress their console windows.
  • Updated the regression fixtures for compatibility with current main.
  • Typecheck, lint, and focused tests pass against current main.
  • Live Electron validation observed 9 real scans with no visible scan window or focus loss.

@Jinwoo-H
Jinwoo-H merged commit 91f56c7 into stablyai:main Jul 13, 2026
1 check passed
@Cainiaooo

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@Cainiaooo
Cainiaooo deleted the fix/win-foreground-scan-windowshide branch July 13, 2026 11:56
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…onhost window) (stablyai#8053)

* Hide console window for Windows agent foreground-process scan

Agent foreground-process inspection re-forks powershell.exe (or the wmic fallback) to detect which agent runs in each terminal. Both spawns omitted windowsHide, so on Windows each fork popped a fresh conhost console window that flashed and stole keyboard focus from the foreground app — including Orca's own terminal — recurring roughly once every few tens of seconds while an agent session was open (and more often under continuous agent output).

Add windowsHide: true to both probes (matching the codebase-wide convention) plus a regression test asserting the spawn options.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(windows): include scan root in foreground fixtures

---------

Co-authored-by: xucongwei <xucongwei@bytedance.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants