Skip to content

Guard system info requests during window teardown#702

Open
manux81 wants to merge 5 commits into
Autonomy-Logic:developmentfrom
manux81:fix/system-info-window-teardown
Open

Guard system info requests during window teardown#702
manux81 wants to merge 5 commits into
Autonomy-Logic:developmentfrom
manux81:fix/system-info-window-teardown

Conversation

@manux81
Copy link
Copy Markdown

@manux81 manux81 commented Mar 24, 2026

Pull request info

References

If applicable substitute the issue reference to the one that this PR refers

This PR resolve the N/A.

Link to Jira task

N/A

Description of the changes proposed

  • guard system:get-system-info in the main process when mainWindow is missing or already destroyed
  • prevent Object has been destroyed errors during BrowserWindow teardown
  • decouple app layout initialization reads so a failure in retrieveRecent() does not block system state setup
  • wrap startup bridge calls with independent error handling to avoid unhandled promise rejections during teardown races

DOD checklist

  • The code is complete and according to developers’ standards.
  • I have performed a self-review of my code.
  • Meet the acceptance criteria.
  • Unit tests are written and green.
  • Test coverage: N/A %.
  • Integration tests are written and green.
  • Changes were communicated and updated in the ticket description.
  • Reviewed and accepted by the Product Owner.
  • End-to-end test are successful.

Fix a race where the renderer could request system:get-system-info while the Electron BrowserWindow was already being destroyed.

The IPC handler previously called isMaximized() on a stale BrowserWindow reference, which raised "Object has been destroyed" and surfaced as an unhandled promise rejection in development logs.

This change guards the main-process handler with isDestroyed() before reading window state, and wraps the renderer initialization request in try/catch so startup or teardown races do not produce unhandled rejections.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

Walkthrough

The pull request adds defensive programming guards to prevent accessing destroyed mainWindow in the main process IPC handler, and wraps renderer-side bridge calls in try-catch error handling with corrected dependency array tracking for proper effect re-execution.

Changes

Cohort / File(s) Summary
Main Process IPC Handler
src/main/modules/ipc/main.ts
Modified handleGetSystemInfo to explicitly guard mainWindow access, returning false for isWindowMaximized when mainWindow is absent or destroyed, replacing optional chaining with explicit null checks.
Renderer Component Initialization
src/renderer/components/_templates/app-layout.tsx
Wrapped async initialization calls to window.bridge.getSystemInfo() and window.bridge.retrieveRecent() in try-catch blocks with error logging; updated useEffect dependency array to include setRecent alongside setSystemConfigs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 With guards so sturdy and catches so keen,
We shield from the crashes that never are seen,
The mainWindow is safe, the errors won't hide,
Dependencies true, dependencies wide,
A safer code burrow, our code's place to bide! 🛡️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Guard system info requests during window teardown' directly and clearly summarizes the main change: adding guards to prevent IPC calls from failing when the Electron window is being destroyed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description matches the required template structure with all sections completed, including References, Description of changes, and DOD checklist with appropriate selections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/components/_templates/app-layout.tsx (1)

31-47: Decouple init calls so one failure doesn’t block unrelated UI state setup.

Right now, if retrieveRecent() fails (Line 33), the already-fetched system info is discarded and setSystemConfigs / setIsLinux are skipped. Consider handling these calls independently.

♻️ Suggested refactor
   useEffect(() => {
     const getUserSystemProps = async () => {
-      try {
-        const { OS, architecture, prefersDarkMode, isWindowMaximized } = await window.bridge.getSystemInfo()
-        const recent = await window.bridge.retrieveRecent()
-
-        setRecent(recent)
-        setSystemConfigs({
-          OS,
-          arch: architecture,
-          shouldUseDarkMode: prefersDarkMode,
-          isWindowMaximized,
-        })
-        if (OS === 'darwin' || OS === 'win32') {
-          setIsLinux(false)
-        }
-      } catch (error) {
-        console.error('Failed to read system info during app layout initialization:', error)
-      }
+      const [systemInfoResult, recentResult] = await Promise.allSettled([
+        window.bridge.getSystemInfo(),
+        window.bridge.retrieveRecent(),
+      ])
+
+      if (systemInfoResult.status === 'fulfilled') {
+        const { OS, architecture, prefersDarkMode, isWindowMaximized } = systemInfoResult.value
+        setSystemConfigs({
+          OS,
+          arch: architecture,
+          shouldUseDarkMode: prefersDarkMode,
+          isWindowMaximized,
+        })
+        if (OS === 'darwin' || OS === 'win32') {
+          setIsLinux(false)
+        }
+      } else {
+        console.error('Failed to read system info during app layout initialization:', systemInfoResult.reason)
+      }
+
+      if (recentResult.status === 'fulfilled') {
+        setRecent(recentResult.value)
+      } else {
+        console.error('Failed to read recent projects during app layout initialization:', recentResult.reason)
+      }
     }
     void getUserSystemProps()
   }, [setRecent, setSystemConfigs])
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/components/_templates/app-layout.tsx` around lines 31 - 47, The
current combined try block around window.bridge.getSystemInfo() and
window.bridge.retrieveRecent() causes a failure in retrieveRecent() to prevent
setting system state; split these calls so each has its own error handling: call
await window.bridge.getSystemInfo() in its own try/catch and always call
setSystemConfigs(...) and setIsLinux(...) when getSystemInfo succeeds, then call
await window.bridge.retrieveRecent() in a separate try/catch and call
setRecent(...) only on success, logging each error independently; reference
functions: window.bridge.getSystemInfo, window.bridge.retrieveRecent,
setSystemConfigs, setRecent, setIsLinux.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/components/_templates/app-layout.tsx`:
- Around line 31-47: The current combined try block around
window.bridge.getSystemInfo() and window.bridge.retrieveRecent() causes a
failure in retrieveRecent() to prevent setting system state; split these calls
so each has its own error handling: call await window.bridge.getSystemInfo() in
its own try/catch and always call setSystemConfigs(...) and setIsLinux(...) when
getSystemInfo succeeds, then call await window.bridge.retrieveRecent() in a
separate try/catch and call setRecent(...) only on success, logging each error
independently; reference functions: window.bridge.getSystemInfo,
window.bridge.retrieveRecent, setSystemConfigs, setRecent, setIsLinux.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7d3a8c55-8b1d-4185-94ff-6bef2dddc0b9

📥 Commits

Reviewing files that changed from the base of the PR and between 195eacc and 94c4522.

📒 Files selected for processing (2)
  • src/main/modules/ipc/main.ts
  • src/renderer/components/_templates/app-layout.tsx

@manux81
Copy link
Copy Markdown
Author

manux81 commented Apr 16, 2026

I updated PR #702 by merging the latest development branch and resolving the merge conflict. The app layout initialization change is preserved in the new frontend path, with separate error handling for system info and recent projects. The PR is now mergeable again from a code/conflict standpoint.

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.

1 participant