-
Notifications
You must be signed in to change notification settings - Fork 48
chore: monitoring for bg-process #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThis change introduces Sentry error reporting for background window lifecycle management in the main process. In Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/actions/setupIPCForwarding.js (1)
10-21: Stop forwarding when the background window is unavailable.You report the error but still register a reply listener and call
webContents.send, which will throw and leave a danglingipcMain.oncelistener. Return early (resolve/reject) before installing the listener and sending.🛠️ Proposed fix
- async (event, incomingData) => { - return new Promise((resolve) => { + async (event, incomingData) => { + return new Promise((resolve, reject) => { // Check if backgroundWindow is available and not destroyed (check on each IPC call) if (!backgroundWindow || backgroundWindow.isDestroyed()) { - const errorMessage = "Background process unavailable during IPC communication"; - console.error(errorMessage); - Sentry.captureException(new Error(errorMessage)); + const error = new Error( + "Background process unavailable during IPC communication" + ); + console.error(error.message); + Sentry.captureException(error); + return reject(error); }src/main/actions/startBackgroundProcess.js (1)
3-52: Use the Electron main-process Sentry SDK here.This runs in the main process;
@sentry/browseris for renderer processes only and will not initialize properly here. The codebase already establishes the correct pattern—src/main/actions/setupIPCForwarding.jsin the same directory uses@sentry/electron/main. Align with that pattern.🛠️ Proposed fix
-import { captureException } from "@sentry/browser"; +import { captureException } from "@sentry/electron/main";
🤖 Fix all issues with AI agents
In `@src/main/actions/startBackgroundProcess.js`:
- Around line 85-88: The on("closed") handler for backgroundWindow currently
logs and captures the error but doesn't reset state; update that handler
(backgroundWindow.on("closed", ...)) to: clear global.backgroundWindow (set to
null), set any active flag such as isBackgroundProcessActive to false,
remove/clean any IPC listeners or references tied to backgroundWindow, and
ensure any local backgroundWindow variable is nulled so future
startBackgroundProcess()/restart logic can create a new window; include a brief
log entry indicating state was cleared after close.
| backgroundWindow.on("closed", () => { | ||
| console.error("Background window closed unexpectedly"); | ||
| captureException(new Error("Background window closed unexpectedly")); | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear background window state on close to allow recovery.
The close handler reports the error but leaves global.backgroundWindow, state, and the active flag intact. That can block future restarts and keep IPC pointing at a destroyed window.
🛠️ Proposed fix
backgroundWindow.on("closed", () => {
console.error("Background window closed unexpectedly");
captureException(new Error("Background window closed unexpectedly"));
+ global.isBackgroundProcessActive = false;
+ global.backgroundWindow = null;
+ void setState(null, { stateName: "backgroundWindow", newValue: null });
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| backgroundWindow.on("closed", () => { | |
| console.error("Background window closed unexpectedly"); | |
| captureException(new Error("Background window closed unexpectedly")); | |
| }) | |
| backgroundWindow.on("closed", () => { | |
| console.error("Background window closed unexpectedly"); | |
| captureException(new Error("Background window closed unexpectedly")); | |
| global.isBackgroundProcessActive = false; | |
| global.backgroundWindow = null; | |
| void setState(null, { stateName: "backgroundWindow", newValue: null }); | |
| }) |
🤖 Prompt for AI Agents
In `@src/main/actions/startBackgroundProcess.js` around lines 85 - 88, The
on("closed") handler for backgroundWindow currently logs and captures the error
but doesn't reset state; update that handler (backgroundWindow.on("closed",
...)) to: clear global.backgroundWindow (set to null), set any active flag such
as isBackgroundProcessActive to false, remove/clean any IPC listeners or
references tied to backgroundWindow, and ensure any local backgroundWindow
variable is nulled so future startBackgroundProcess()/restart logic can create a
new window; include a brief log entry indicating state was cleared after close.
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.