orca icon indicating copy to clipboard operation
orca copied to clipboard

fix: pr-bug-scan validated finding from #6867

Open buf0-bot[bot] opened this issue 5 months ago • 1 comments

Automated fix-PR from pr-bug-scan for parent #6867.

Fixer status: FIXED_WITH_REPRO Summary: Added else-branch in resyncTerminalFocusForWindowFocus deferred reclaim: when a newer owner won focus, call syncFocused(false) to roll back the eager mirror=true set at line 114. Blocked proof link: src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.ts:124-132 — the deferred callback now issues syncFocused(false) when refocus is skipped, so the mirror set true at :114 no longer survives, breaking the createMainWindow.ts:611/901 'terminal' context mis-routing. Typecheck: pass

Proof (from validator)

  • C1 — proof_type: code_analysis
    • trigger: App window regains focus (window 'focus' event) after a blur in which a pane-owned xterm helper had owned focus (releasedHelperOnWindowBlur set); DOM focus has settled on document.body; then a newer focus owner (dialog autofocus / sidebar / rename input, reached programmatically or via keyboard, NOT an outside pointerdown) takes focus before the deferred reclaim rAF runs.
    • observable: The main-process terminalInputFocused mirror is left true while DOM focus is on a non-terminal element, so keyboard shortcuts resolve in 'terminal' context (createMainWindow.ts:901/1016) and a subset of app shortcuts are mis-routed/suppressed while the user is in the sidebar/dialog.
    • path:
      • src/renderer/src/components/terminal-pane/TerminalPane.tsx:1752 onWindowBlur -> releaseTerminalFocusForWindowBlur returns the owning helper, calls syncFocused(false) (mirror=false), stores releasedHelperOnWindowBlur=helper
      • src/renderer/src/components/terminal-pane/TerminalPane.tsx:1758-1770 onWindowFocus calls resyncTerminalFocusForWindowFocus({ releasedHelper: releasedHelperOnWindowBlur })
      • src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.ts:100-108 ownedActive is null and activeElement is body/null, so helper=releasedHelper and needsProgrammaticFocus=true
      • src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.ts:114 args.syncFocused(true) is called eagerly -> TerminalPane.tsx:1724-1725 sets attribute and window.api.ui.setTerminalInputFocused(true)
      • src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.ts:124-132 reclaim is deferred to scheduleNextFrame; at :128 the guard sees active === the newer owner (not reclaimedHelper, not body/null) so reclaimedHelper.focus() at :129 is skipped and no syncFocused(false) is issued
      • src/main/window/createMainWindow.ts:611 onTerminalInputFocused stores terminalInputFocused=true; :901 before-input-event sets context to 'terminal' whenever terminalInputFocused is true

Reproduction

pnpm exec vitest run --config config/vitest.config.ts -t 'rolls the focus mirror back to false' src/renderer/src/components/terminal-pane/regular-terminal-focus-ownership.test.ts

  • before fix: FAIL: syncFocused last called with [true] (mirror stuck true after newer owner grabs focus)
  • after fix: PASS: syncFocused last called with [false]; 17/17 tests pass

Generated by pr-bug-scan (proof-machine architecture). Human approval required before merge.


Open in Stage

buf0-bot[bot] avatar Jun 30 '26 19:06 buf0-bot[bot]

Ready to review this PR? Stage has broken it down into 2 individual chapters for you:

Title
1 Roll back terminal focus mirror on skipped reclaim
2 Verify focus mirror rollback in unit tests
Open in Stage

Chapters generated by Stage for commit 728ad67558ace43a22108b568247a6a85223223d on Jun 30, 2026 7:58pm UTC.

ghost avatar Jun 30 '26 19:06 ghost

Thanks for digging into the stale terminal-focus flag. Main now waits for the deferred reclaim to succeed before publishing terminal focus, and clears the flag when another input wins. It also preserves a newer terminal’s ownership. That covers the case here, so I’m closing this as already fixed: current reclaim handling. Appreciate the careful reproduction and test!

OrcaWin avatar Oct 27 '26 10:10 OrcaWin